Topic: Unable to connect wolfssh with Cisco IOS device

I'm trying to connect to a Cisco IOS device using SSH from Windows.

Following is the snippet

WOLFSSH_CTX* ctx = NULL;
    WOLFSSH* ssh = NULL;
    SOCKET_T sockFd = WOLFSSH_SOCKET_INVALID;
    SOCKADDR_IN_T clientAddr;
    socklen_t clientAddrSz = sizeof(clientAddr);
    char rxBuf[80];
    int ret;
    int ch;
    word16 port = 22;
    const char* host = "xx.xx.xx.xx";
    const char* username = "wwww";
    const char* password = "wwww";
    const char* cmd = "sh clock";

    wolfSSH_Debugging_ON();

    WSTARTTCP();
    wolfSSH_Init();

    ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_CLIENT, NULL);
    if (ctx == NULL)
        err_sys("Couldn't create wolfSSH client context.");

    wolfSSH_SetUserAuth(ctx, wsUserAuth);

    ssh = wolfSSH_new(ctx);
    if ( ssh == NULL ) {
        err_sys("Failed to create SSH");
    }

    wolfSSH_SetUserAuthCtx(ssh, (void*)password);

    ret = wolfSSH_SetUsername(ssh, username);
    if (ret != WS_SUCCESS)
        err_sys("Couldn't set the username.");

    build_addr(&clientAddr, (char *)host, port);
    tcp_socket(&sockFd);
    ret = connect(sockFd, (const struct sockaddr *)&clientAddr, clientAddrSz);
    if (ret != 0) {
        err_sys("Couldn't connect to server.");
    }
    else {
        cout << "Connected to "<<host<<endl;
    }

    ret = wolfSSH_set_fd(ssh, (int)sockFd);
    if (ret != WS_SUCCESS)
        err_sys("Couldn't set the session's socket.");



    ret = wolfSSH_SetChannelType(ssh, WOLFSSH_SESSION_EXEC,
        NULL, 0);

Seeing the following error log

2020-05-13 07:01:55 [DEBUG] Entering wolfSSH_Init()
2020-05-13 07:01:55 [DEBUG] Leaving wolfSSH_Init(), returning 0
2020-05-13 07:01:55 [DEBUG] Entering wolfSSH_CTX_new()
2020-05-13 07:01:55 [DEBUG] Entering CtxInit()
2020-05-13 07:01:55 [DEBUG] Leaving wolfSSH_CTX_new(), ctx = 00000072FB1E7D80
2020-05-13 07:01:55 [DEBUG] Entering wolfSSH_new()
2020-05-13 07:01:55 [DEBUG] Entering SshInit()
2020-05-13 07:01:55 [DEBUG] Entering HandshakeInfoNew()
2020-05-13 07:01:55 [DEBUG] Leaving wolfSSH_new(), ssh = 00000072FB1E93E0
Connected to xx.xx.xx.xx
2020-05-13 07:01:55 [DEBUG] Entering wolfSSH_set_fd()
2020-05-13 07:01:55 [DEBUG] No subsystem name or name was too large
2020-05-13 07:02:04 [DEBUG] Entering wolfSSH_connect()
2020-05-13 07:02:30 [DEBUG] SSH-2.0-wolfSSHv1.4.3

2020-05-13 07:02:30 [DEBUG] Entering wolfSSH_SendPacket()
2020-05-13 07:02:30 [DEBUG] Embed Send trying to send 23
2020-05-13 07:02:30 [DEBUG] Embed Send sent 23
2020-05-13 07:02:30 [DEBUG] SB: Shrinking output buffer
2020-05-13 07:02:30 [DEBUG] Entering ShrinkBuffer()
2020-05-13 07:02:30 [DEBUG] SB: usedSz = 0, forcedFree = 0
2020-05-13 07:02:30 [DEBUG] SB: releasing dynamic buffer
2020-05-13 07:02:30 [DEBUG] Leaving ShrinkBuffer()
2020-05-13 07:02:34 [DEBUG] connect state: CLIENT_VERSION_SENT
2020-05-13 07:02:41 [DEBUG] Receive: recvd = 255
2020-05-13 07:03:30 [DEBUG] get input text failed
2020-05-13 07:03:35 [DEBUG] connect error: CLIENT_VERSION_SENT, -1013

Any idea about what went wrong?

Share

Re: Unable to connect wolfssh with Cisco IOS device

Hi jijo7thomas,

As the error indicates it would seem the wrong version or a non-supported version was used. Do you know which SSH version was sent?

Warm Regards,

K