Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何编写一个简单的SSH客户端?_C++_C_Ssh - Fatal编程技术网

C++ 如何编写一个简单的SSH客户端?

C++ 如何编写一个简单的SSH客户端?,c++,c,ssh,C++,C,Ssh,我计划用C/C++为我的intro networking类中的一个项目编写一个简单的SSH客户端。然而,我很难找到关于如何做到这一点的好文档。我不想要广泛的协议规范,只是一个简单的指南。有什么建议吗?步骤: 获取现有服务器端实例的凭据 安装开源客户端 在命令行上执行连接 包括CLI上的详细日志开关 使用日志推断在双方同意的密码实现上获取经过身份验证的会话所涉及的来回(C/S协议)消息 标准: $ ssh -vvv myhost.com OpenSSH_5.9p1, OpenSSL 0.9.8t

我计划用C/C++为我的intro networking类中的一个项目编写一个简单的SSH客户端。然而,我很难找到关于如何做到这一点的好文档。我不想要广泛的协议规范,只是一个简单的指南。有什么建议吗?

步骤:

  • 获取现有服务器端实例的凭据
  • 安装开源客户端
  • 在命令行上执行连接
  • 包括CLI上的详细日志开关
  • 使用日志推断在双方同意的密码实现上获取经过身份验证的会话所涉及的来回(C/S协议)消息 标准:

    $ ssh -vvv myhost.com
    OpenSSH_5.9p1, OpenSSL 0.9.8t 18 Jan 2012
    debug1: Reading configuration data /home/myself/.ssh/config
    debug2: ssh_connect: needpriv 0
    debug1: Connecting to myhost.com [74.99.99.99] port 22.
    debug1: Connection established.
    debug3: Incorrect RSA1 identifier
    debug3: Could not load "/home/myself/.ssh/id_rsa" as a RSA1 public key
    debug1: identity file /home/myself/.ssh/id_rsa type 1
    debug1: identity file /home/myself/.ssh/id_rsa-cert type -1
    debug3: Incorrect RSA1 identifier
    debug3: Could not load "/home/myself/.ssh/id_dsa" as a RSA1 public key
    debug1: identity file /home/myself/.ssh/id_dsa type 2
    debug1: identity file /home/myself/.ssh/id_dsa-cert type -1
    debug1: identity file /home/myself/.ssh/id_ecdsa type -1
    debug1: identity file /home/myself/.ssh/id_ecdsa-cert type -1
    debug1: Remote protocol version 2.0, remote software version OpenSSH_3.5p1
    debug1: match: OpenSSH_3.5p1 pat OpenSSH_3.*
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_5.9
    debug2: fd 3 setting O_NONBLOCK
    debug3: load_hostkeys: loading entries for host "myhost.com" from file "/home/myself/.ssh/known_hosts"
    debug3: load_hostkeys: found key type RSA in file /home/myself/.ssh/known_hosts:12
    debug3: load_hostkeys: loaded 1 keys
    debug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diff
    ie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v
    01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-
    sha2-nistp521,ssh-dss
    debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij
    ndael-cbc@lysator.liu.se
    debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij
    ndael-cbc@lysator.liu.se
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@op
    enssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@op
    enssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
    debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit: first_kex_follows 0
    debug2: kex_parse_kexinit: reserved 0
    debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
    debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: none,zlib
    debug2: kex_parse_kexinit: none,zlib
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit: first_kex_follows 0
    debug2: kex_parse_kexinit: reserved 0
    debug2: mac_setup: found hmac-md5
    debug1: kex: server->client aes128-cbc hmac-md5 none
    debug2: mac_setup: found hmac-md5
    debug1: kex: client->server aes128-cbc hmac-md5 none
    debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
    debug2: dh_gen_key: priv key bits set: 124/256
    debug2: bits set: 510/1024
    debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
    debug1: Server host key: RSA ac:24:92:03:fd:24:f8:01:a6:86:2a:bf:37:e9:a8:fe
    debug3: load_hostkeys: loading entries for host "myhost.com" from file "/home/myself/.ssh/known_hosts"
    debug3: load_hostkeys: found key type RSA in file /home/myself/.ssh/known_hosts:12
    debug3: load_hostkeys: loaded 1 keys
    debug3: load_hostkeys: loading entries for host "74.99.99.99" from file "/home/myself/.ssh/known_hosts"
    debug3: load_hostkeys: found key type RSA in file /home/myself/.ssh/known_hosts:25
    debug3: load_hostkeys: loaded 1 keys
    debug1: Host 'myhost.com' is known and matches the RSA host key.
    debug1: Found key in /home/myself/.ssh/known_hosts:12
    debug2: bits set: 532/1024
    debug1: ssh_rsa_verify: signature correct
    debug2: kex_derive_keys
    debug2: set_newkeys: mode 1
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug2: set_newkeys: mode 0
    debug1: SSH2_MSG_NEWKEYS received
    debug1: Roaming not allowed by server
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug2: service_accept: ssh-userauth
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug2: key: /home/myself/.ssh/id_rsa (0x800471d8)
    debug2: key: /home/myself/.ssh/id_dsa (0x80048380)
    debug2: key: /home/myself/.ssh/id_ecdsa (0x0)
    debug3: input_userauth_banner
    
    debug1: Authentications that can continue: publickey,password
    debug3: start over, passed a different list publickey,password
    debug3: preferred publickey,keyboard-interactive,password
    debug3: authmethod_lookup publickey
    debug3: remaining preferred: keyboard-interactive,password
    debug3: authmethod_is_enabled publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /home/myself/.ssh/id_rsa
    debug3: send_pubkey_test
    debug2: we sent a publickey packet, wait for reply
    debug1: Authentications that can continue: publickey,password
    debug1: Offering DSA public key: /home/myself/.ssh/id_dsa
    debug3: send_pubkey_test
    debug2: we sent a publickey packet, wait for reply
    debug1: Server accepts key: pkalg ssh-dss blen 433
    debug2: input_userauth_pk_ok: fp 15:6c:78:1e:76:02:03:26:2e:53:1a:44:8e:59:97:b1
    debug3: sign_and_send_pubkey: DSA 15:6c:78:1e:76:02:03:26:2e:53:1a:44:8e:59:97:b1
    debug1: read PEM private key done: type DSA
    debug1: Authentication succeeded (publickey).
    Authenticated to myhost.com ([74.99.99.99]:22).
    debug1: channel 0: new [client-session]
    debug3: ssh_session2_open: channel_new: 0
    debug2: channel 0: send open
    debug1: Entering interactive session.
    debug2: callback start
    debug2: client_session2_setup: id 0
    debug2: fd 3 setting TCP_NODELAY
    debug2: channel 0: request pty-req confirm 1
    debug2: channel 0: request shell confirm 1
    debug2: callback done
    debug2: channel 0: open confirm rwindow 0 rmax 32768
    debug2: channel_input_status_confirm: type 99 id 0
    debug2: PTY allocation request accepted on channel 0
    debug2: channel 0: rcvd adjust 131072
    debug2: channel_input_status_confirm: type 99 id 0
    debug2: shell request accepted on channel 0
    
    $ssh-vvv myhost.com
    OpenSSH_5.9p1,OpenSSL 0.9.8t 2012年1月18日
    debug1:读取配置数据/home/imf/.ssh/config
    debug2:ssh\u connect:needpriv 0
    debug1:连接到myhost.com[74.99.99.99]端口22。
    debug1:已建立连接。
    debug3:错误的RSA1标识符
    debug3:无法将“/home/imf/.ssh/id_rsa”作为RSA1公钥加载
    debug1:identity file/home/imf/.ssh/id\u rsa类型1
    debug1:identity file/home/imf/.ssh/id\u rsa-cert类型-1
    debug3:错误的RSA1标识符
    debug3:无法将“/home/imf/.ssh/id_dsa”作为RSA1公钥加载
    debug1:identity file/home/imf/.ssh/id_dsa类型2
    debug1:identity file/home/imf/.ssh/id_dsa-cert type-1
    debug1:identity file/home/imf/.ssh/id_ecdsa type-1
    debug1:identity file/home/imf/.ssh/id_ecdsa-cert type-1
    debug1:远程协议版本2.0,远程软件版本OpenSSH_3.5p1
    debug1:match:OpenSSH_3.5p1 pat OpenSSH_3*
    debug1:启用协议2.0的兼容模式
    debug1:本地版本字符串SSH-2.0-OpenSSH_5.9
    调试2:fd 3设置O_非块
    debug3:load_hostkeys:从文件“/home/imf/.ssh/known_hosts”加载主机“myhost.com”的条目
    debug3:load_hostkeys:在文件/home/imf/.ssh/known_hosts:12中找到密钥类型RSA
    debug3:加载主机密钥:加载1个密钥
    debug3:order\u hostkeyalgs:preference hostkeyalgs:ssh rsa证书-v01@openssh.com,ssh rsa证书-v00@openssh.com,ssh-rsa
    debug1:SSH2\u MSG\u KEXINIT已发送
    debug1:SSH2\u MSG\u KEXINIT已收到
    debug2:kex_parse_kexinit:ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diff
    ie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2:kex_parse_kexinit:ssh rsa证书-v01@openssh.com,ssh rsa证书-v00@openssh.com,ssh rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v
    01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-dss证书-v01@openssh.com,ssh-dss证书-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-
    sha2-nistp521,ssh dss
    debug2:kex_parse_kexinit:aes128 ctr、aes192 ctr、aes256 ctr、arcfour256、arcfour128、aes128 cbc、3des cbc、河豚cbc、cast128 cbc、aes192 cbc、aes256 cbc、arcfour、rij
    恩代尔-cbc@lysator.liu.se
    debug2:kex_parse_kexinit:aes128 ctr、aes192 ctr、aes256 ctr、arcfour256、arcfour128、aes128 cbc、3des cbc、河豚cbc、cast128 cbc、aes192 cbc、aes256 cbc、arcfour、rij
    恩代尔-cbc@lysator.liu.se
    debug2:kex_parse_kexinit:hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@op
    enssh.com,hmac-sha1-96,hmac-md5-96
    debug2:kex_parse_kexinit:hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-ripemd160@op
    enssh.com,hmac-sha1-96,hmac-md5-96
    debug2:kex_parse_kexinit:none,zlib@openssh.com,zlib
    debug2:kex_parse_kexinit:none,zlib@openssh.com,zlib
    debug2:kex_parse_kexinit:
    debug2:kex_parse_kexinit:
    debug2:kex_parse_kexinit:first_kex_跟随0
    debug2:kex_parse_kexinit:保留0
    debug2:kex_parse_kexinit:diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
    debug2:kex_parse_kexinit:ssh rsa,ssh dss
    debug2:kex_parse_kexinit:aes128 cbc、3des cbc、河豚cbc、cast128 cbc、arcfour、aes192 cbc、aes256 cbc、rijndael-cbc@lysator.liu.se
    debug2:kex_parse_kexinit:aes128 cbc、3des cbc、河豚cbc、cast128 cbc、arcfour、aes192 cbc、aes256 cbc、rijndael-cbc@lysator.liu.se
    debug2:kex_parse_kexinit:hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2:kex_parse_kexinit:hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
    debug2:kex_parse_kexinit:none,zlib
    debug2:kex_parse_kexinit:none,zlib
    debug2:kex_parse_kexinit:
    debug2:kex_parse_kexinit:
    debug2:kex_parse_kexinit:first_kex_跟随0
    debug2:kex_parse_kexinit:保留0
    debug2:mac_安装程序:找到hmac-md5
    debug1:kex:server->client aes128 cbc hmac-md5无
    debug2:mac_安装程序:找到hmac-md5
    debug1:kex:client->server aes128 cbc hmac-md5无
    
    debug1:SSH2_MSG_KEX_DH_GEX_请求(1024我将查看
    libssl
    libcrypto
    库,它们是基于debian的系统的一部分。在基于debian的系统上,您可以使用以下方法获得开发库:

    sudo apt-get install libssl-dev
    

    我想看看
    /usr/share/doc/libssl dev/demos


    编辑:此外,您可以或在安装后运行
    man ssl

    ,因为这是一个家庭作业项目,您可以告诉我们更多关于您的限制吗?例如,您可以使用现有的网络库,还是必须直接调用套接字相关调用?您可以使用库吗?我可以这样做,但我是第一个首选是直接调用与套接字相关的调用。但是,如果这需要我做更多的工作,我愿意使用库。这是否类似于绘制owl()?如果您想从头开始实现它,SSH是非常复杂的协议系列(从加密算法和所有jazz开始)。您最好的选择是获取OpenSSH源代码并进行研究。