tbotnz / cisshgo

simple concurrent ssh server posing as cisco ios
131 stars 26 forks source link

Add support for SSH exec #23

Open ddutt opened 3 years ago

ddutt commented 3 years ago

Hi, Thank you for providing this useful package. I can't seem to get any command to be returned if I use asyncssh. If I connect manually, it seems to work fine. I have asyncssh working without anything fancy across Cisco's NXOS, Arista, Juniper, Linux and so on. Would you be able to provide any hints as to why this might be happeniing or help me fix this?

The connection succeeds (as per asyncssh logs, and I see the same with cissshgo's output), but the command "show version" just hangs. I'm attaching the debug log from asyncssh if its of some value.

Thanks, Dinesh

2021-01-12 08:09:35,175 - asyncssh - INFO - Opening SSH connection to localhost, port 10000 2021-01-12 08:09:35,186 - asyncssh - INFO - [conn=0] Connection to localhost, port 10000 succeeded 2021-01-12 08:09:35,186 - asyncssh - INFO - [conn=0] Local address: 127.0.0.1, port 34924 2021-01-12 08:09:35,186 - asyncssh - DEBUG - [conn=0] Requesting key exchange 2021-01-12 08:09:35,187 - asyncssh - DEBUG - [conn=0] Received key exchange request 2021-01-12 08:09:35,192 - asyncssh - DEBUG - [conn=0] Beginning key exchange 2021-01-12 08:09:35,199 - asyncssh - DEBUG - [conn=0] Completed key exchange 2021-01-12 08:09:35,200 - asyncssh - INFO - [conn=0] Beginning auth for user admin 2021-01-12 08:09:35,202 - asyncssh - DEBUG - [conn=0] Trying password auth 2021-01-12 08:09:35,204 - asyncssh - INFO - [conn=0] Auth for user admin succeeded 2021-01-12 08:09:35,204 - suzieq.poller.nodes.node - INFO - Connected to localhost at 1610467775.2045498 2021-01-12 08:09:35,205 - asyncssh - DEBUG - [conn=0, chan=0] Set write buffer limits: low-water=16384, high-water=65536 2021-01-12 08:09:35,205 - asyncssh - INFO - [conn=0, chan=0] Requesting new SSH session 2021-01-12 08:09:35,207 - asyncssh - INFO - [conn=0, chan=0] Command: show version 2021-01-12 08:09:45,217 - suzieq.poller.nodes.node - ERROR - Unable to connect to localhost show version due to timeout

tbotnz commented 3 years ago

Cheers @ddutt, suspect its an issue detecting the carrige return used by asyncssh, will do some testing and update further in a few days

ddutt commented 3 years ago

Hi @tbotnz I wrote a program myself as I need it mostly for testing devops, not user interaction. I ran into the same problem with using asyncssh server as I did with your code. I finally got everything working when I started handling exec_requested instead of only shell_requested as my program was open an SSHSession to execute a single command, not a shell. Hope this helps. I can share my python code easily if that makes a difference.

Thanks for responding, Dinesh

tbotnz commented 3 years ago

Reproduced with asyncssh (python)

as below, not working

DEBUG:asyncio:Using selector: EpollSelector INFO:asyncssh:Opening SSH connection to 10.0.2.15, port 20049 INFO:asyncssh:[conn=0] Connection to 10.0.2.15, port 20049 succeeded INFO:asyncssh:[conn=0] Local address: 10.0.2.15, port 44968 DEBUG:asyncssh:[conn=0] Requesting key exchange DEBUG:asyncssh:[conn=0] Received key exchange request DEBUG:asyncssh:[conn=0] Beginning key exchange DEBUG:asyncssh:[conn=0] Completed key exchange INFO:asyncssh:[conn=0] Beginning auth for user admin DEBUG:asyncssh:[conn=0] Trying password auth INFO:asyncssh:[conn=0] Auth for user admin succeeded DEBUG:asyncssh:[conn=0, chan=0] Set write buffer limits: low-water=16384, high-water=65536 INFO:asyncssh:[conn=0, chan=0] Requesting new SSH session INFO:asyncssh:[conn=0, chan=0] Command: show version

working ( with async ssh in shell mode )

DEBUG:asyncio:Using selector: EpollSelector INFO:asyncssh:Opening SSH connection to 10.0.2.15, port 20049 INFO:asyncssh:[conn=0] Connection to 10.0.2.15, port 20049 succeeded INFO:asyncssh:[conn=0] Local address: 10.0.2.15, port 44958 DEBUG:asyncssh:[conn=0] Requesting key exchange DEBUG:asyncssh:[conn=0] Received key exchange request DEBUG:asyncssh:[conn=0] Beginning key exchange DEBUG:asyncssh:[conn=0] Completed key exchange INFO:asyncssh:[conn=0] Beginning auth for user admin DEBUG:asyncssh:[conn=0] Trying password auth INFO:asyncssh:[conn=0] Auth for user admin succeeded DEBUG:asyncssh:[conn=0, chan=0] Set write buffer limits: low-water=16384, high-water=65536 INFO:asyncssh:[conn=0, chan=0] Requesting new SSH session INFO:asyncssh:[conn=0, chan=0] Interactive shell requested INFO:asyncssh:[conn=0, chan=0] Received exit status 0 INFO:asyncssh:[conn=0, chan=0] Received channel close INFO:asyncssh:[conn=0, chan=0] Channel closed cisshgo1000v>show version Cisco IOS XE Software, Version 16.04.01 Cisco IOS Software [Everest], CSR1000V Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.4.1, RELEASE SOFTWARE (fc2) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2016 by Cisco Systems, Inc. Compiled Sun 27-Nov-16 13:02 by mcpre Cisco IOS-XE software, Copyright (c) 2005-2016 by cisco Systems, Inc. All rights reserved. Certain components of Cisco IOS-XE software are licensed under the GNU General Public License ("GPL") Version 2.0. The software code licensed under GPL Version 2.0 is free software that comes with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such GPL code under the terms of GPL Version 2.0. For more details, see the documentation or "License Notice" file accompanying the IOS-XE software, or the applicable URL provided on the flyer accompanying the IOS-XE software. ROM: IOS-XE ROMMON cisshgo1000v uptime is 4 hours, 55 minutes Uptime for this control processor is 4 hours, 56 minutes System returned to ROM by reload System image file is "bootflash:packages.conf" Last reload reason: reload This product contains cryptographic features and is subject to United States and local country laws governing import, export, transfer and use. Delivery of Cisco cryptographic products does not imply third-party authority to import, export, distribute or use encryption. Importers, exporters, distributors and users are responsible for compliance with U.S. and local country laws. By using this product you agree to comply with applicable laws and regulations. If you are unable to comply with U.S. and local laws, return this product immediately. A summary of U.S. laws governing Cisco cryptographic products may be found at: http://www.cisco.com/wwl/export/crypto/tool/stqrg.html If you require further assistance please contact us by sending email to export@cisco.com. License Level: ax License Type: Default. No valid license found. Next reload license Level: ax cisco CSR1000V (VXE) processor (revision VXE) with 2052375K/3075K bytes of memory. Processor board ID 9FKLJWM5EB0 10 Gigabit Ethernet interfaces 32768K bytes of non-volatile configuration memory. 3985132K bytes of physical memory. 7774207K bytes of virtual hard disk at bootflash:. 0K bytes of at webui:. Configuration register is 0x2102 cisshgo1000v>INFO:asyncssh:[conn=0] Closing connection INFO:asyncssh:[conn=0] Sending disconnect: Disconnected by application (11) INFO:asyncssh:[conn=0] Connection closed

This seems to confirm @ddutts theory about no support for exec mode,