[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking for examples on using libssh as a server


Yeah, unfortunately you're right about the docs - but if I can figure out how it was meant to work, I'd kinda like to contribute on that front. If nothing else they could replace "to be done" with "for an example of a server see [link to my GitHub]" lol... I've done some socket programming (using Linux/POSIX functions like accept() and listen() - which is how I managed to get as far as I did - but it would sure be great if I could figure out what comes next (or at least how to debug since that last_error function isn't helping).

Anyway, I'll check out that link after work. idk what a "honeypot" is, tho it's a term I've heard movie-hackers use (did not realize they were actually a thing - gonna have to Duck that later lol). Regardless, your example includes a server component so I am definitely gonna have to check it out! Thank you. :)

It's interesting to see too how our ideas were similar. Yes mine was a game and yours was a (paid?) service - but like you I couldn't help but consider the more practical uses of a system you designed running over SSH (instead of a full-on remote shell with all the security holes of letting someone else into your server :D ). I've been thinking games cuz if it gets hacked, who cares, delete the cheapo Linode it runs on and problem solved. But man, you took it a step further and created an "as-a-service" thing - that's awesome! But my point is, I'm surprised there isn't something like that already out there. You'd think remote systems over an encrypted connection would be more of a thing. But then again, if you're into snazzy bloated spyware-infected GUIs that's basically the web. :D

Okay, in all seriousness, I appreciate the quick reply on this. I don't ever expect to do something as amazing as what you did here - but a few more SSH games would be nice (and if I build enough of them, and they don't get hacked to smithereens, maybe then I'll move on to something else, lol). Anywayz, I'm off to work. Have a great day! :)

------- Original Message -------
On Wednesday, May 17th, 2023 at 2:57 AM, Skalák, Zdeněk <zskalak@xxxxxxxxxxxx> wrote:

> Hello,
>
> once upon a time, I tried to implement HaaS (Honeypot as a Service) project from CZ.NIC written in Python to something 'smaller' to be able to put it on my OpenWrt .....
>
> The result is here: https://github.com/OgarSkali/HaaS-libssh
>
> Basically it waits for SSH connection, captures username+password and the makes another SSH connection to the haas.nic.cz 'real' honeypot.
> It then creates the channel and forwards all the communication between these two channels. It kind of supports port forwarding too :-)
>
> Hope this helps and inspires you.
>
> The overall problem with libssh is that the 'server side' part is not documented at all - the only documentation is the source code of the libssh itself and their examples :-)
>
> Regards
>
> Zdenek OGAR Skalak
> On Wed, May 17, 2023 at 5:04 AM The Geek on Skates <geekonskates@xxxxxxxxxxxxxx> wrote:
>
>>> Good evening(or afternoon, or morning), :)
>>>
>>> I've been on something of a quest, a project that (at the moment) is just for fun, but maybe not exclusively a game thing. I would like to create something like [SSH Tron](http://sshtron.zachlatta.com/); the workflow is simple:
>>>
>>> - ssh sshtron.zachlatta.com
>>> - You play the game
>>> - You get disconnected
>>>
>>> No room for shenanigans. No passing commands, no CTRL-C or CTRL-Z to kill the program (you do that, you get disconnected). Even so, I'm shocked it hasn't been hacked into oblivion. 😄
>>>
>>> But unfortunately, it's written in Go (a language I don't know and don't care to learn) and some library that's just for Go. Now I'm an experienced C/C++ programmer - I'm all too familiar with things like buffer overflows, double-frees, dereferencing NULL pointers etc. but all I really know about SSH is basic stuff like how to configure sshd, how to generate keys and stuff like that. I also know a bunch of other languages, but since C is my goto (see what I did there? 😄) I started playing with libssh. I'm trying to see if I can figure out how to set up a program to receive incoming connections, send data to the client (the default ssh "command"), receive data from the client and disconnect. I think I've got it connecting (on localhost) but I'm a bit stuck on the reading/writing. ssh_channel_new is failing, ssh_last_error or whatever it is isn't giving me anything... and there are no tutorials.
>>>
>>> So what I'm asking for - if this is okay - is a high-level walkthrough of the process. I'm not asking you to write my program for me (people who do that drive me nuts too 😄) but I'd like to get some idea of the workflow. Like right now what I have is:
>>>
>>> - Some forum posts say you need to call ssh_init(), so I started there.
>>>
>>> - Then I created a "bind" structure using ssh_bind_new()
>>> - Then I used ssh_bind_options_set to set the host name, port, and private key path
>>> - I also used ssh_set_blocking (with 0) because a game like Tron shouldn't wait for the user to press Enter (like getchar())
>>> - Then I used ssh_new() to create a new session structure
>>> - Then ssh_bind_listen. At this point, my program waits for a new connection. Then I do ssh me@localhost -p 12345 or whatever. This seems to work.
>>> - Then ssh_bind_accept. It seems to accept my connection and then immediately disconnect. So that's progress.
>>> - With NULL-checks and error-checks and all that every step of the way, cuz this is C and that's how we roll. 😄
>>>
>>> And here's where I am stuck. Forum posts suggest I need to create a "channel" with ssh_channel_new; from there, theoretically, the ssh_channel_write and ssh_channel_read do the reading/writing. Then of course are all the close and free functions to clean up at the end. And of course to support multiple users it would probably have to call fork() and all that... but I'm nowhere near that point. ssh_channel_new fails. I tried using session->channel, but apparently that is a pointer to an "incomplete" type (an error I've never seen before and will be researching this evening after work 😄)... so... stalemate.
>>> Any ideas? What am I missing here? At this point, my best guess is that there another step required to "complete" the session's channel pointer, some secondary initialization involved that isn't clear from a long list of function names. 😄 Any ideas would be greatly appreciated. Thanks and have a great day!
>
> --
>
> Ing. Zdeněk OGAR Skalák
> Monet+ a.s. <http://www.monetplus.cz>
> Za Dvorem 505, 763 14 Zlín - Štípa, CZ
> Tel: +420 / 577 110 411, Fax: +420 / 577 914 557

References:
Looking for examples on using libssh as a serverThe Geek on Skates <geekonskates@xxxxxxxxxxxxxx>
Re: Looking for examples on using libssh as a serverSkalák, Zdeněk <zskalak@xxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org