[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Key exchange fail
[Thread Prev] | [Thread Next]
[Date Prev] | [Date Next]
- Subject: Re: Key exchange fail
- From: Jakub Jelen <jjelen@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 31 Mar 2025 14:06:46 +0200
- To: libssh@xxxxxxxxxx
Can you install debug symbols for libssh to see where exactly it crashes? This sounds like some variable is not initialized. My guess would be the size field of your callbacks structure, which needs to be initialized with `ssh_callbacks_init()`. Jakub On Fri, Mar 28, 2025 at 5:00 PM Yusuf Saka <yusufsaka5481@xxxxxxxxx> wrote: > > Also here is what valgrind says > > > ==52658== Conditional jump or move depends on uninitialised value(s) > ==52658== at 0x48A8B7C: ssh_execute_server_request (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48A8F17: ssh_execute_server_callbacks (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48A9057: ssh_message_queue (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48A99DC: ssh_packet_service_request (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48B5EA8: ssh_packet_process (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48B5825: ssh_packet_socket_callback (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48C5C07: ssh_socket_pollcallback (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48C0598: ssh_poll_ctx_dopoll (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x48C0A57: ssh_event_dopoll (in /usr/lib/x86_64-linux-gnu/libssh.so.4.10.1) > ==52658== by 0x10BB63: SSHServer::handle_session(ssh_event_struct*, ssh_session_struct*) (ssh_server.cpp:220) > ==52658== by 0x10B571: SSHServer::start() (ssh_server.cpp:110) > ==52658== by 0x10A7A4: main (main.cpp:21) > ==52658== Uninitialised value was created by a stack allocation > ==52658== at 0x10B7C5: SSHServer::handle_session(ssh_event_struct*, ssh_session_struct*) (ssh_server.cpp:147) > > > > On Fri, Mar 28, 2025 at 10:02 AM Yusuf Saka <yusufsaka5481@xxxxxxxxx> wrote: >> >> Hey, >> Thank you for replying back so soon >> I believe key exchange fail is somehow related to race conditions in my class which which can be solved but I am unable to figure out the other problem and why it persists >> >> I get the following output after key exchange which indicates that client requested authentication. I already set the appropriate callback functions to handle these requests. I also checked in my debugger that session is indeed connected, session is not NULL event is not NULL and ssh_event_add_session is also succesful. >> >> [2025/03/28 09:50:02.784775, 4] ssh_socket_pollcallback: Poll callback on socket 4 (POLLIN POLLOUT ), out buffer 0 >> [2025/03/28 09:50:02.784863, 4] ssh_socket_unbuffered_read: read 44 >> [2025/03/28 09:50:02.784899, 3] ssh_packet_socket_callback: packet: read type 5 [len=24,padding=6,comp=17,payload=17] >> [2025/03/28 09:50:02.784905, 3] ssh_packet_process: Dispatching handler for packet type 5 >> [2025/03/28 09:50:02.784911, 3] ssh_packet_service_request: Received a SERVICE_REQUEST for service ssh-userauth >> >> But ssh_event_dopoll causes segmentation fault. What would be the following debugging processes >> >> ``` >> // Authenticate and open a channel >> while (sdata.authenticated == 0 || sdata.channel == NULL) { >> /* To Do! Simulate a successful brute force attempt at random X attempts to make the attacker get inside*/ >> if (sdata.auth_attempts >= 3) { >> std::cout << YELLOW << "[SSHServer::handle_session]: Auth attempts exceeded" << RESET << std::endl; >> goto cleanup; >> } >> if (ssh_event_dopoll(event, 100) == SSH_ERROR) { >> std::cerr << RED << "[SSHServer::handle_session]: " << ssh_get_error(session) << RESET << std::endl; >> goto cleanup; >> } >> } >> std::cout << GREEN << "[SSHServer::handle_session]: Authenticated user" << RESET << std::endl; >> >> >> >> >> On Fri, Mar 28, 2025 at 7:54 AM Jakub Jelen <jjelen@xxxxxxxxxx> wrote: >>> >>> Hi, >>> do you have some error? >>> >>> Please, try to set the libssh log level to SSH_LOG_TRACE. It will then >>> print more information about what is going on under the hood and might >>> show up some path to the failure. >>> >>> Jakub >>> >>> On Fri, Mar 28, 2025 at 12:20 PM Yusuf Saka <yusufsaka5481@xxxxxxxxx> wrote: >>> > >>> > Hey there, >>> > >>> > I recently read your docs on implementing a ssh connection and read one of your example codes called ssh_server.c which works quite fine in my own device. I've been trying to implement the C++ version of this code with classes in play for days but the code just won't work. I am trying to create a ssh server with threads (pthread) mainly and it fails in >>> > ssh_server.cpp >>> > in handle_session function at line 187. >>> > KEY_FILE macro is defined in my cmake file. I've been able to get connection but key exchange fails somehow. >>> > I've been trying to solve the problem for few days now and being a beginner in programming it is starting to get quite frustrating so I've decided to reach out for help. >>> > >>> > Best regards >>> > >>> > >>> >>>
Key exchange fail | Yusuf Saka <yusufsaka5481@xxxxxxxxx> |
Re: Key exchange fail | Jakub Jelen <jjelen@xxxxxxxxxx> |
Re: Key exchange fail | Yusuf Saka <yusufsaka5481@xxxxxxxxx> |
Re: Key exchange fail | Yusuf Saka <yusufsaka5481@xxxxxxxxx> |