[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Looking for examples on using libssh as a server
[Thread Prev] | [Thread Next]
- Subject: Re: Looking for examples on using libssh as a server
- From: Skalák, Zdeněk <zskalak@xxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 17 May 2023 08:57:39 +0200
- To: libssh@xxxxxxxxxx
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: > > 1. ssh sshtron.zachlatta.com > 2. You play the game > 3. 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
Re: Looking for examples on using libssh as a server | The Geek on Skates <geekonskates@xxxxxxxxxxxxxx> |
Looking for examples on using libssh as a server | The Geek on Skates <geekonskates@xxxxxxxxxxxxxx> |