三重Des SSH2通过phpseclib

时间:2014-04-05 08:57:23

标签: ssh phpseclib 3des tripledes

我的目的是使用phpseclib创建一个连接到启用ssh2的开关的脚本。

我发现这个开关只允许3DES加密,我不知道如何将Crypt_TripleDES()类与NET_SSH2一起使用。

我无法在互联网上找到答案,我会帮助你。

谢谢!

这是我没有3Des的代码,下面你可以看到日志。

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

include('./ssl/Crypt/TripleDES.php');
include('./ssl/Net/SSH2.php');

define('NET_SSH2_LOGGING', 3);

//$des = new Crypt_TripleDES();
//$des->setKey('');
//$des->encrypt('');

$ssh = new Net_SSH2('172.16.1.1');
if (!$ssh->login('admin','admin')) {
print_r($ssh->getLog());

    exit('Login Failed');
}

以下是日志:

->
00000000  53:53:48:2d:32:2e:30:2d:70:68:70:73:65:63:6c:69  SSH-2.0-phpsecli
00000010  62:5f:30:2e:33:20:28:6d:63:72:79:70:74:2c:20:62  b_0.3 (mcrypt, b
00000020  63:6d:61:74:68:29:0d:0a                          cmath)..

<- NET_SSH2_MSG_KEXINIT (since last: 0.0687, network: 0.0124s)
00000000  ea:54:14:67:67:97:ab:2d:34:85:07:67:76:57:51:c1  .T.gg..-4..gvWQ.
00000010  00:00:00:1a:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ....diffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:00:00  an-group1-sha1..
00000030  00:07:73:73:68:2d:72:73:61:00:00:00:08:33:64:65  ..ssh-rsa....3de
00000040  73:2d:63:62:63:00:00:00:08:33:64:65:73:2d:63:62  s-cbc....3des-cb
00000050  63:00:00:00:09:68:6d:61:63:2d:73:68:61:31:00:00  c....hmac-sha1..
00000060  00:09:68:6d:61:63:2d:73:68:61:31:00:00:00:04:6e  ..hmac-sha1....n
00000070  6f:6e:65:00:00:00:04:6e:6f:6e:65:00:00:00:00:00  one....none.....
00000080  00:00:00:00:00:00:00:00                          ........

-> NET_SSH2_MSG_KEXINIT (since last: 0.0021, network: 0.0001s)
00000000  de:fa:51:fc:c3:63:3f:2e:3c:44:1a:03:7d:07:cb:b3  ..Q..c?..D..}...
00000010  00:00:00:36:64:69:66:66:69:65:2d:68:65:6c:6c:6d  ...6diffie-hellm
00000020  61:6e:2d:67:72:6f:75:70:31:2d:73:68:61:31:2c:64  an-group1-sha1,d
00000030  69:66:66:69:65:2d:68:65:6c:6c:6d:61:6e:2d:67:72  iffie-hellman-gr
00000040  6f:75:70:31:34:2d:73:68:61:31:00:00:00:0f:73:73  oup14-sha1....ss
00000050  68:2d:72:73:61:2c:73:73:68:2d:64:73:73:00:00:00  h-rsa,ssh-dss...
00000060  dc:61:72:63:66:6f:75:72:32:35:36:2c:61:72:63:66  .arcfour256,arcf
00000070  6f:75:72:31:32:38:2c:61:72:63:66:6f:75:72:2c:61  our128,arcfour,a
00000080  65:73:31:32:38:2d:63:74:72:2c:61:65:73:31:39:32  es128-ctr,aes192
00000090  2d:63:74:72:2c:61:65:73:32:35:36:2d:63:74:72:2c  -ctr,aes256-ctr,
000000a0  74:77:6f:66:69:73:68:31:32:38:2d:63:74:72:2c:74  twofish128-ctr,t
000000b0  77:6f:66:69:73:68:31:39:32:2d:63:74:72:2c:74:77  wofish192-ctr,tw
000000c0  6f:66:69:73:68:32:35:36:2d:63:74:72:2c:61:65:73  ofish256-ctr,aes
000000d0  31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d:63  128-cbc,aes192-c
000000e0  62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:74:77  bc,aes256-cbc,tw
000000f0  6f:66:69:73:68:31:32:38:2d:63:62:63:2c:74:77:6f  ofish128-cbc,two
00000100  66:69:73:68:31:39:32:2d:63:62:63:2c:74:77:6f:66  fish192-cbc,twof
00000110  69:73:68:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  ish256-cbc,twofi
00000120  73:68:2d:63:62:63:2c:33:64:65:73:2d:63:74:72:2c  sh-cbc,3des-ctr,
00000130  33:64:65:73:2d:63:62:63:2c:6e:6f:6e:65:00:00:00  3des-cbc,none...
00000140  dc:61:72:63:66:6f:75:72:32:35:36:2c:61:72:63:66  .arcfour256,arcf
00000150  6f:75:72:31:32:38:2c:61:72:63:66:6f:75:72:2c:61  our128,arcfour,a
00000160  65:73:31:32:38:2d:63:74:72:2c:61:65:73:31:39:32  es128-ctr,aes192
00000170  2d:63:74:72:2c:61:65:73:32:35:36:2d:63:74:72:2c  -ctr,aes256-ctr,
00000180  74:77:6f:66:69:73:68:31:32:38:2d:63:74:72:2c:74  twofish128-ctr,t
00000190  77:6f:66:69:73:68:31:39:32:2d:63:74:72:2c:74:77  wofish192-ctr,tw
000001a0  6f:66:69:73:68:32:35:36:2d:63:74:72:2c:61:65:73  ofish256-ctr,aes
000001b0  31:32:38:2d:63:62:63:2c:61:65:73:31:39:32:2d:63  128-cbc,aes192-c
000001c0  62:63:2c:61:65:73:32:35:36:2d:63:62:63:2c:74:77  bc,aes256-cbc,tw
000001d0  6f:66:69:73:68:31:32:38:2d:63:62:63:2c:74:77:6f  ofish128-cbc,two
000001e0  66:69:73:68:31:39:32:2d:63:62:63:2c:74:77:6f:66  fish192-cbc,twof
000001f0  69:73:68:32:35:36:2d:63:62:63:2c:74:77:6f:66:69  ish256-cbc,twofi
00000200  73:68:2d:63:62:63:2c:33:64:65:73:2d:63:74:72:2c  sh-cbc,3des-ctr,
00000210  33:64:65:73:2d:63:62:63:2c:6e:6f:6e:65:00:00:00  3des-cbc,none...
00000220  30:68:6d:61:63:2d:73:68:61:31:2d:39:36:2c:68:6d  0hmac-sha1-96,hm
00000230  61:63:2d:73:68:61:31:2c:68:6d:61:63:2d:6d:64:35  ac-sha1,hmac-md5
00000240  2d:39:36:2c:68:6d:61:63:2d:6d:64:35:2c:6e:6f:6e  -96,hmac-md5,non
00000250  65:00:00:00:30:68:6d:61:63:2d:73:68:61:31:2d:39  e...0hmac-sha1-9
00000260  36:2c:68:6d:61:63:2d:73:68:61:31:2c:68:6d:61:63  6,hmac-sha1,hmac
00000270  2d:6d:64:35:2d:39:36:2c:68:6d:61:63:2d:6d:64:35  -md5-96,hmac-md5
00000280  2c:6e:6f:6e:65:00:00:00:04:6e:6f:6e:65:00:00:00  ,none....none...
00000290  04:6e:6f:6e:65:00:00:00:00:00:00:00:00:00:00:00  .none...........
000002a0  00:00                                            ..

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.0225, network: 0s)
00000000  00:00:00:81:00:b4:0c:f4:1e:a8:31:3c:35:2a:c0:c1  ..........1.5*..
00000010  ca:51:51:9a:6c:9a:b4:b2:f0:63:80:ee:0f:6a:f8:3b  .QQ.l....c...j.;
00000020  b0:9d:ce:b7:35:50:1c:09:11:88:c7:fc:96:47:1f:21  ....5P.......G.!
00000030  e5:36:da:7d:b7:be:06:11:c6:ac:ee:b1:2e:64:50:d2  .6.}.........dP.
00000040  65:b6:78:64:84:2d:b8:7f:62:87:29:eb:75:ab:ee:71  e.xd.-..b.).u..q
00000050  d5:db:53:31:0c:27:e2:51:b9:e0:55:98:22:1c:c3:38  ..S1.'.Q..U."..8
00000060  46:36:5d:d1:e9:b6:5d:f6:a3:ce:95:2a:fe:30:27:5a  F6]...]....*.0'Z
00000070  95:9b:e7:f2:34:ce:04:1b:4a:ce:37:5a:80:f8:ac:b3  ....4...J.7Z....
00000080  18:c1:7f:0f:c0                                   .....

<- NET_SSH2_MSG_KEXDH_REPLY (since last: 3.6055, network: 3.6038s)
00000000  00:00:00:55:00:00:00:07:73:73:68:2d:72:73:61:00  ...U....ssh-rsa.
00000010  00:00:01:23:00:00:00:41:00:e5:01:cd:e0:ac:c9:17  ...#...A........
00000020  a8:ed:8b:c8:a8:3c:1c:0b:ae:b5:a2:f4:35:60:51:fe  ............5`Q.
00000030  46:01:1c:45:65:77:7a:df:86:58:a7:60:2b:6f:53:de  F..Eewz..X.`+oS.
00000040  e6:02:1a:06:91:1a:08:50:52:df:ed:b3:42:de:5d:1d  .......PR...B.].
00000050  84:44:cf:95:d5:ac:ea:35:e7:00:00:00:81:00:a2:30  .D.....5.......0
00000060  11:61:c6:c6:c5:ac:77:18:d6:bc:57:30:da:91:df:e1  .a....w...W0....
00000070  14:19:d8:07:1b:6a:ac:dd:b3:23:eb:0a:17:44:b8:43  .....j...#...D.C
00000080  65:b5:cc:8b:24:dd:be:07:c5:48:15:f6:3d:7f:7d:c3  e...$....H..=.}.
00000090  7e:b1:6a:e3:ee:1b:b3:23:f6:b2:64:21:b6:c6:f2:e3  ~.j....#..d!....
000000a0  ce:a6:79:b4:a7:ce:50:6e:a4:a3:2d:15:69:9e:e3:69  ..y...Pn..-.i..i
000000b0  68:45:43:7f:e0:c5:21:e8:b2:cb:83:c0:1e:64:16:58  hEC...!......d.X
000000c0  d9:06:fa:01:64:e3:28:c4:2d:84:86:34:94:25:df:68  ....d.(.-..4.%.h
000000d0  1a:fa:53:7a:31:5c:e4:bd:23:30:45:2b:fb:2c:00:00  ..Sz1\..#0E+.,..
000000e0  00:4f:00:00:00:07:73:73:68:2d:72:73:61:00:00:00  .O....ssh-rsa...
000000f0  40:6a:36:35:0a:1d:a7:30:48:1d:56:ce:4d:1c:af:40  @j65...0H.V.M..@
00000100  96:24:44:f7:83:bd:96:7f:bd:99:3b:a1:df:0c:43:42  .$D.......;...CB
00000110  4b:cc:a9:3a:70:c2:cc:19:e8:7b:0e:fe:b9:f6:55:1d  K..:p....{....U.
00000120  af:df:fc:c4:b4:9b:6e:cd:8f:8c:7f:ac:5e:d8:b6:5d  ......n.....^..]
00000130  65                                               e

-> NET_SSH2_MSG_NEWKEYS (since last: 0.0217, network: 0.0001s)


<- NET_SSH2_MSG_NEWKEYS (since last: 0.0131, network: 0.0125s)


-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.0018, network: 0.0001s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

<- NET_SSH2_MSG_SERVICE_ACCEPT (since last: 0.0109, network: 0.0104s)
00000000  00:00:00:0c:73:73:68:2d:75:73:65:72:61:75:74:68  ....ssh-userauth

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0012, network: 0.0001s)
00000000  00:00:00:08:75:73:65:72:6e:61:6d:65:00:00:00:0e  ....username....
00000010  73:73:68:2d:63:6f:6e:6e:65:63:74:69:6f:6e:00:00  ssh-connection..
00000020  00:08:70:61:73:73:77:6f:72:64:00:00:00:00:08:70  ..password.....p
00000030  61:73:73:77:6f:72:64                             assword

<- NET_SSH2_MSG_USERAUTH_FAILURE (since last: 0.0164, network: 0.0155s)
00000000  00:00:00:12:70:61:73:73:77:6f:72:64:2c:70:75:62  ....password,pub
00000010  6c:69:63:6b:65:79:00                             lickey.

Login Failed<pre>-> NET_SSH2_MSG_DISCONNECT (since last: 0.0012, network: 0.0001s)
00000000  00:00:00:0b:00:00:00:00:00:00:00:00              ............

1 个答案:

答案 0 :(得分:0)

3des-cbc已被使用。入站&lt; - NET_SSH2_MSG_KEXINIT数据包是phpseclib知道必须使用3des-cbc的方式,你知道它正在使用它,因为入站&lt; - NET_SSH2_MSG_NEWKEYS都被接收并成功解密。

你的代码的问题不在于没有使用3des-cbc - 密码是坏的,按照这个:

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0012, network: 0.0001s)
00000000  00:00:00:08:75:73:65:72:6e:61:6d:65:00:00:00:0e  ....username....
00000010  73:73:68:2d:63:6f:6e:6e:65:63:74:69:6f:6e:00:00  ssh-connection..
00000020  00:08:70:61:73:73:77:6f:72:64:00:00:00:00:08:70  ..password.....p
00000030  61:73:73:77:6f:72:64                             assword

<- NET_SSH2_MSG_USERAUTH_FAILURE (since last: 0.0164, network: 0.0155s)
00000000  00:00:00:12:70:61:73:73:77:6f:72:64:2c:70:75:62  ....password,pub
00000010  6c:69:63:6b:65:79:00                             lickey.