Пример #1
0
    def test_6_gex_server_with_old_client(self):
        transport = FakeTransport()
        transport.server_mode = True
        kex = KexGex(transport)
        kex.start_kex()
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_REQUEST, ssh.kex_gex._MSG_KEXDH_GEX_REQUEST_OLD), transport._expect)

        msg = Message()
        msg.add_int(2048)
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_REQUEST_OLD, msg)
        x = b'1F0000008100FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF0000000102'
        self.assertEquals(x, hexlify(bytes(transport._message)).upper())
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_INIT,), transport._expect)

        msg = Message()
        msg.add_mpint(12345)
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_INIT, msg)
        K = 67592995013596137876033460028393339951879041140378510871612128162185209509220726296697886624612526735888348020498716482757677848959420073720160491114319163078862905400020959196386947926388406687288901564192071077389283980347784184487280885335302632305026248574716290537036069329724382811853044654824945750581
        H = b'75A12FD284C6536BA768307579DBE6F9B5087BC6'
        x = b'210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
        self.assertEquals(K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals(x, hexlify(bytes(transport._message)).upper())
        self.assert_(transport._activated)
Пример #2
0
    def test_2_group1_server(self):
        transport = FakeTransport()
        transport.server_mode = True
        kex = KexGroup1(transport)
        kex.start_kex()
        self.assertEquals((ssh.kex_group1._MSG_KEXDH_INIT,), transport._expect)

        msg = Message()
        msg.add_mpint(69)
        msg.rewind()
        kex.parse_next(ssh.kex_group1._MSG_KEXDH_INIT, msg)
        H = b'D38CD8117B01531F518D7AE79BB9B0B6FA79B593'
        x = b'1F0000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
        self.assertEquals(self.K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals(x, hexlify(bytes(transport._message)).upper())
        self.assert_(transport._activated)
Пример #3
0
    def test_1_group1_client(self):
        transport = FakeTransport()
        transport.server_mode = False
        kex = KexGroup1(transport)
        kex.start_kex()
        x = '1E000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4'
        self.assertEquals(x, hexlify(str(transport._message)).upper())
        self.assertEquals((ssh.kex_group1._MSG_KEXDH_REPLY, ),
                          transport._expect)

        # fake "reply"
        msg = Message()
        msg.add_string('fake-host-key')
        msg.add_mpint(69)
        msg.add_string('fake-sig')
        msg.rewind()
        kex.parse_next(ssh.kex_group1._MSG_KEXDH_REPLY, msg)
        H = '00EA521556297D544B4D98745424593B1E6D59E1'
        self.assertEquals(self.K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals(('fake-host-key', 'fake-sig'), transport._verify)
        self.assert_(transport._activated)
Пример #4
0
    def test_1_write (self):
        rsock = LoopSocket()
        wsock = LoopSocket()
        rsock.link(wsock)
        p = Packetizer(wsock)
        p.set_log(util.get_logger('ssh.transport'))
        p.set_hexdump(True)
        cipher = AES.new('\x00' * 16, AES.MODE_CBC, '\x55' * 16)
        p.set_outbound_cipher(cipher, 16, SHA, 12, '\x1f' * 20)

        # message has to be at least 16 bytes long, so we'll have at least one
        # block of data encrypted that contains zero random padding bytes
        m = Message()
        m.add_byte(chr(100))
        m.add_int(100)
        m.add_int(1)
        m.add_int(900)
        p.send_message(m)
        data = rsock.recv(100)
        # 32 + 12 bytes of MAC = 44
        self.assertEquals(44, len(data))
        self.assertEquals('\x43\x91\x97\xbd\x5b\x50\xac\x25\x87\xc2\xc4\x6b\xc7\xe9\x38\xc0', data[:16])
Пример #5
0
    def test_1_group1_client(self):
        transport = FakeTransport()
        transport.server_mode = False
        kex = KexGroup1(transport)
        kex.start_kex()
        x = b'1E000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4'
        self.assertEquals(x, hexlify(bytes(transport._message)).upper())
        self.assertEquals((ssh.kex_group1._MSG_KEXDH_REPLY,), transport._expect)

        # fake "reply"
        msg = Message()
        msg.add_string(b'fake-host-key')
        msg.add_mpint(69)
        msg.add_string(b'fake-sig')
        msg.rewind()
        kex.parse_next(ssh.kex_group1._MSG_KEXDH_REPLY, msg)
        H = b'00EA521556297D544B4D98745424593B1E6D59E1'
        self.assertEquals(self.K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals((b'fake-host-key', b'fake-sig'), transport._verify)
        self.assert_(transport._activated)
Пример #6
0
    def test_1_write (self):
        rsock = LoopSocket()
        wsock = LoopSocket()
        rsock.link(wsock)
        p = Packetizer(wsock)
        p.set_log(util.get_logger('ssh.transport'))
        p.set_hexdump(True)
        cipher = AES.new('\x00' * 16, AES.MODE_CBC, '\x55' * 16)
        p.set_outbound_cipher(cipher, 16, SHA, 12, '\x1f' * 20)

        # message has to be at least 16 bytes long, so we'll have at least one
        # block of data encrypted that contains zero random padding bytes
        m = Message()
        m.add_byte(chr(100))
        m.add_int(100)
        m.add_int(1)
        m.add_int(900)
        p.send_message(m)
        data = rsock.recv(100)
        # 32 + 12 bytes of MAC = 44
        self.assertEquals(44, len(data))
        self.assertEquals('\x43\x91\x97\xbd\x5b\x50\xac\x25\x87\xc2\xc4\x6b\xc7\xe9\x38\xc0', data[:16])
Пример #7
0
    def test_2_group1_server(self):
        transport = FakeTransport()
        transport.server_mode = True
        kex = KexGroup1(transport)
        kex.start_kex()
        self.assertEquals((ssh.kex_group1._MSG_KEXDH_INIT, ),
                          transport._expect)

        msg = Message()
        msg.add_mpint(69)
        msg.rewind()
        kex.parse_next(ssh.kex_group1._MSG_KEXDH_INIT, msg)
        H = 'D38CD8117B01531F518D7AE79BB9B0B6FA79B593'
        x = '1F0000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
        self.assertEquals(self.K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals(x, hexlify(str(transport._message)).upper())
        self.assert_(transport._activated)
Пример #8
0
    def test_6_gex_server_with_old_client(self):
        transport = FakeTransport()
        transport.server_mode = True
        kex = KexGex(transport)
        kex.start_kex()
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_REQUEST,
                           ssh.kex_gex._MSG_KEXDH_GEX_REQUEST_OLD),
                          transport._expect)

        msg = Message()
        msg.add_int(2048)
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_REQUEST_OLD, msg)
        x = '1F0000008100FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF0000000102'
        self.assertEquals(x, hexlify(str(transport._message)).upper())
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_INIT, ),
                          transport._expect)

        msg = Message()
        msg.add_mpint(12345)
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_INIT, msg)
        K = 67592995013596137876033460028393339951879041140378510871612128162185209509220726296697886624612526735888348020498716482757677848959420073720160491114319163078862905400020959196386947926388406687288901564192071077389283980347784184487280885335302632305026248574716290537036069329724382811853044654824945750581L
        H = '75A12FD284C6536BA768307579DBE6F9B5087BC6'
        x = '210000000866616B652D6B6579000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D40000000866616B652D736967'
        self.assertEquals(K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals(x, hexlify(str(transport._message)).upper())
        self.assert_(transport._activated)
Пример #9
0
    def test_4_gex_old_client(self):
        transport = FakeTransport()
        transport.server_mode = False
        kex = KexGex(transport)
        kex.start_kex(_test_old_style=True)
        x = '1E00000800'
        self.assertEquals(x, hexlify(str(transport._message)).upper())
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_GROUP, ),
                          transport._expect)

        msg = Message()
        msg.add_mpint(FakeModulusPack.P)
        msg.add_mpint(FakeModulusPack.G)
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_GROUP, msg)
        x = '20000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4'
        self.assertEquals(x, hexlify(str(transport._message)).upper())
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_REPLY, ),
                          transport._expect)

        msg = Message()
        msg.add_string('fake-host-key')
        msg.add_mpint(69)
        msg.add_string('fake-sig')
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_REPLY, msg)
        H = 'F1234C57E0946943B3757806BCEB8DC0C95B8D4B'
        self.assertEquals(self.K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals(('fake-host-key', 'fake-sig'), transport._verify)
        self.assert_(transport._activated)
Пример #10
0
    def test_4_gex_old_client(self):
        transport = FakeTransport()
        transport.server_mode = False
        kex = KexGex(transport)
        kex.start_kex(_test_old_style=True)
        x = b'1E00000800'
        self.assertEquals(x, hexlify(bytes(transport._message)).upper())
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_GROUP,), transport._expect)

        msg = Message()
        msg.add_mpint(FakeModulusPack.P)
        msg.add_mpint(FakeModulusPack.G)
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_GROUP, msg)
        x = b'20000000807E2DDB1743F3487D6545F04F1C8476092FB912B013626AB5BCEB764257D88BBA64243B9F348DF7B41B8C814A995E00299913503456983FFB9178D3CD79EB6D55522418A8ABF65375872E55938AB99A84A0B5FC8A1ECC66A7C3766E7E0F80B7CE2C9225FC2DD683F4764244B72963BBB383F529DCF0C5D17740B8A2ADBE9208D4'
        self.assertEquals(x, hexlify(bytes(transport._message)).upper())
        self.assertEquals((ssh.kex_gex._MSG_KEXDH_GEX_REPLY,), transport._expect)

        msg = Message()
        msg.add_string(b'fake-host-key')
        msg.add_mpint(69)
        msg.add_string(b'fake-sig')
        msg.rewind()
        kex.parse_next(ssh.kex_gex._MSG_KEXDH_GEX_REPLY, msg)
        H = b'F1234C57E0946943B3757806BCEB8DC0C95B8D4B'
        self.assertEquals(self.K, transport._K)
        self.assertEquals(H, hexlify(transport._H).upper())
        self.assertEquals((b'fake-host-key', b'fake-sig'), transport._verify)
        self.assert_(transport._activated)