1 # Python module to make it easy to manually encode SSH packets, by
2 # supporting the various uint32, string, mpint primitives.
4 # The idea of this is that you can use it to manually construct key
5 # exchange sequences of interesting kinds, for testing purposes.
10 return "\1" if b else "\0"
17 assert 0 <= u < 0x100000000
18 return struct.pack(">I", u)
21 assert 0 <= u < 0x10000000000000000
22 return struct.pack(">L", u)
25 return uint32(len(s)) + s
47 def ssh_rsa_key_blob(modulus, exponent):
48 return string(string("ssh-rsa") + mpint(modulus) + mpint(exponent))
50 def ssh_rsa_signature_blob(signature):
51 return string(string("ssh-rsa") + mpint(signature))
54 # Greeting at the start of an SSH connection.
55 return string + "\r\n"
58 SSH2_MSG_DISCONNECT = 1
60 SSH2_MSG_UNIMPLEMENTED = 3
62 SSH2_MSG_SERVICE_REQUEST = 5
63 SSH2_MSG_SERVICE_ACCEPT = 6
66 SSH2_MSG_KEXDH_INIT = 30
67 SSH2_MSG_KEXDH_REPLY = 31
68 SSH2_MSG_KEX_DH_GEX_REQUEST = 30
69 SSH2_MSG_KEX_DH_GEX_GROUP = 31
70 SSH2_MSG_KEX_DH_GEX_INIT = 32
71 SSH2_MSG_KEX_DH_GEX_REPLY = 33
72 SSH2_MSG_KEXRSA_PUBKEY = 30
73 SSH2_MSG_KEXRSA_SECRET = 31
74 SSH2_MSG_KEXRSA_DONE = 32
75 SSH2_MSG_USERAUTH_REQUEST = 50
76 SSH2_MSG_USERAUTH_FAILURE = 51
77 SSH2_MSG_USERAUTH_SUCCESS = 52
78 SSH2_MSG_USERAUTH_BANNER = 53
79 SSH2_MSG_USERAUTH_PK_OK = 60
80 SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ = 60
81 SSH2_MSG_USERAUTH_INFO_REQUEST = 60
82 SSH2_MSG_USERAUTH_INFO_RESPONSE = 61
83 SSH2_MSG_GLOBAL_REQUEST = 80
84 SSH2_MSG_REQUEST_SUCCESS = 81
85 SSH2_MSG_REQUEST_FAILURE = 82
86 SSH2_MSG_CHANNEL_OPEN = 90
87 SSH2_MSG_CHANNEL_OPEN_CONFIRMATION = 91
88 SSH2_MSG_CHANNEL_OPEN_FAILURE = 92
89 SSH2_MSG_CHANNEL_WINDOW_ADJUST = 93
90 SSH2_MSG_CHANNEL_DATA = 94
91 SSH2_MSG_CHANNEL_EXTENDED_DATA = 95
92 SSH2_MSG_CHANNEL_EOF = 96
93 SSH2_MSG_CHANNEL_CLOSE = 97
94 SSH2_MSG_CHANNEL_REQUEST = 98
95 SSH2_MSG_CHANNEL_SUCCESS = 99
96 SSH2_MSG_CHANNEL_FAILURE = 100
97 SSH2_MSG_USERAUTH_GSSAPI_RESPONSE = 60
98 SSH2_MSG_USERAUTH_GSSAPI_TOKEN = 61
99 SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE = 63
100 SSH2_MSG_USERAUTH_GSSAPI_ERROR = 64
101 SSH2_MSG_USERAUTH_GSSAPI_ERRTOK = 65
102 SSH2_MSG_USERAUTH_GSSAPI_MIC = 66
104 def clearpkt(msgtype, *stuff):
105 # SSH-2 binary packet, in the cleartext format used for initial
111 while padlen < 4 or len(s) % 8 != 3:
113 s += byte(random.randint(0,255))