Ejemplo n.º 1
0
    def test_recv_incorrect_state_request(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("request")

        raw_data = b""
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 2
0
    def test_recv_incorrect_state_request(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("request")

        raw_data = b""
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 3
0
    def test_recv_in_greeting_response_with_incorrect_auth_method(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        raw_data = struct.pack("!BB", 0x5, 0x2)
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 4
0
    def test_recv_in_greeting_response_with_valid_auth(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["USERNAME_PASSWD"]]

        raw_data = struct.pack("!BB", 0x5, 0x2)
        conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "auth_inprogress")
Ejemplo n.º 5
0
    def test_recv_in_greeting_response_with_unsupported_auth(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        raw_data = struct.pack("!BB", 0x5, 0xff)
        conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "end")
Ejemplo n.º 6
0
    def test_recv_in_greeting_response_socks4_incorrect_version(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        raw_data = struct.pack("!BB", 0x5, 0xff)
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 7
0
    def test_recv_in_greeting_response_socks4_incorrect_version(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        raw_data = struct.pack("!BB", 0x5, 0xff)
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 8
0
    def test_recv_in_greeting_response_with_unsupported_auth(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        raw_data = struct.pack("!BB", 0x5, 0xff)
        conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "end")
Ejemplo n.º 9
0
    def test_recv_in_greeting_response_with_valid_auth(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["USERNAME_PASSWD"]]

        raw_data = struct.pack("!BB", 0x5, 0x2)
        conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "auth_inprogress")
Ejemplo n.º 10
0
    def test_recv_in_greeting_response_with_incorrect_auth_method(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_SUPPORT_AUTH_METHOD"]]

        raw_data = struct.pack("!BB", 0x5, 0x2)
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 11
0
    def test_recv_in_response_with_incorrect_addr(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        raw_data = struct.pack("!BBxB4BH", 0x5, 0x0, 0x1, 127, 0, 0, 2, 8080)
        with self.assertRaises(ProtocolError):
            conn.recv(raw_data)
Ejemplo n.º 12
0
    def test_recv_need_more_data(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_request")

        raw_data = b"\x05"
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "greeting_request")
        self.assertEqual(event, "NeedMoreData")
Ejemplo n.º 13
0
    def test_recv_need_more_data(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_request")

        raw_data = b"\x05"
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "greeting_request")
        self.assertEqual(event, "NeedMoreData")
Ejemplo n.º 14
0
 def test_recv_in_greeting_request_socks4(self):
     conn = Connection(our_role="server")
     conn._conn.machine.set_state("greeting_request")
     raw_data = struct.pack("!BBH4B6sB", 0x4, 0x1, 5580, 127, 0, 0, 1, "Johnny".encode("ascii"), 0)
     event = conn.recv(raw_data)
     self.assertEqual(event, "Socks4Request")
     self.assertEqual(event.cmd, 1)
     self.assertEqual(event.port, 5580)
     self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
     self.assertEqual(event.name, "Johnny")
Ejemplo n.º 15
0
 def test_recv_in_greeting_request_socks4(self):
     conn = Connection(our_role="server")
     conn._conn.machine.set_state("greeting_request")
     raw_data = struct.pack("!BBH4B6sB", 0x4, 0x1, 5580, 127, 0, 0, 1,
                            "Johnny".encode("ascii"), 0)
     event = conn.recv(raw_data)
     self.assertEqual(event, "Socks4Request")
     self.assertEqual(event.cmd, 1)
     self.assertEqual(event.port, 5580)
     self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
     self.assertEqual(event.name, "Johnny")
Ejemplo n.º 16
0
    def test_recv_in_greeting_request(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_request")

        raw_data = struct.pack("!BB2B", 0x5, 0x2, 0x00, 0x01)
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "greeting_response")
        self.assertEqual(event, "GreetingRequest")
        self.assertEqual(event.nmethod, 2)
        self.assertIn(0, event.methods)
        self.assertIn(1, event.methods)
Ejemplo n.º 17
0
    def test_recv_in_greeting_request(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("greeting_request")

        raw_data = struct.pack("!BB2B", 0x5, 0x2, 0x00, 0x01)
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "greeting_response")
        self.assertEqual(event, "GreetingRequest")
        self.assertEqual(event.nmethod, 2)
        self.assertIn(0, event.methods)
        self.assertIn(1, event.methods)
Ejemplo n.º 18
0
    def test_recv_in_request(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("request")

        raw_data = struct.pack("!BBxB4BH", 0x5, 0x1, 0x1, 127, 0, 0, 1, 8080)
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "response")
        self.assertEqual(event, "Request")
        self.assertEqual(event.cmd, 1)
        self.assertEqual(event.atyp, 1)
        self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
        self.assertEqual(event.port, 8080)
Ejemplo n.º 19
0
    def test_recv_in_greeting_response_no_auth(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_AUTH"]]

        raw_data = struct.pack("!BB", 0x5, 0x0)
        event = conn.recv(raw_data)

        self.assertEqual(conn._conn.state, "request")
        self.assertEqual(event, "GreetingResponse")
        self.assertEqual(event.auth_type, 0)
Ejemplo n.º 20
0
    def test_recv_in_greeting_response_no_auth(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 5
        conn._conn._auth_methods = [AUTH_TYPE["NO_AUTH"]]

        raw_data = struct.pack("!BB", 0x5, 0x0)
        event = conn.recv(raw_data)

        self.assertEqual(conn._conn.state, "request")
        self.assertEqual(event, "GreetingResponse")
        self.assertEqual(event.auth_type, 0)
Ejemplo n.º 21
0
    def test_recv_in_request(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("request")

        raw_data = struct.pack("!BBxB4BH", 0x5, 0x1, 0x1, 127, 0, 0, 1, 8080)
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "response")
        self.assertEqual(event, "Request")
        self.assertEqual(event.cmd, 1)
        self.assertEqual(event.atyp, 1)
        self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
        self.assertEqual(event.port, 8080)
Ejemplo n.º 22
0
    def test_recv_in_greeting_response_socks4(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        raw_data = struct.pack("!BBH4B", 0, 0x5a, 5580, 127, 0, 0, 1)
        event = conn.recv(raw_data)

        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(event, "Socks4Response")
        self.assertEqual(event.status, 0x5a)
        self.assertEqual(event.port, 5580)
        self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
Ejemplo n.º 23
0
    def test_recv_in_greeting_response_socks4(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("greeting_response")
        conn._conn._version = 4
        conn._conn._port = 5580

        raw_data = struct.pack("!BBH4B", 0, 0x5a, 5580, 127, 0, 0, 1)
        event = conn.recv(raw_data)

        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(event, "Socks4Response")
        self.assertEqual(event.status, 0x5a)
        self.assertEqual(event.port, 5580)
        self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
Ejemplo n.º 24
0
    def test_recv_in_response(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        raw_data = struct.pack("!BBxB4BH", 0x5, 0x0, 0x1, 127, 0, 0, 1, 8080)
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(event, "Response")
        self.assertEqual(event.status, 0)
        self.assertEqual(event.atyp, 1)
        self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
        self.assertEqual(event.port, 8080)
Ejemplo n.º 25
0
    def test_recv_in_response(self):
        conn = Connection(our_role="client")
        conn._conn.machine.set_state("response")
        conn._conn._version = 5
        conn._conn._addr_type = ADDR_TYPE["IPV4"]
        conn._conn._addr = ipaddress.IPv4Address("127.0.0.1")
        conn._conn._port = 8080

        raw_data = struct.pack("!BBxB4BH", 0x5, 0x0, 0x1, 127, 0, 0, 1, 8080)
        event = conn.recv(raw_data)
        self.assertEqual(conn._conn.state, "end")
        self.assertEqual(event, "Response")
        self.assertEqual(event.status, 0)
        self.assertEqual(event.atyp, 1)
        self.assertEqual(event.addr, ipaddress.IPv4Address("127.0.0.1"))
        self.assertEqual(event.port, 8080)
Ejemplo n.º 26
0
    def test_recv_incorrect_state_response(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("response")

        with self.assertRaises(ProtocolError):
            conn.recv(b"")
Ejemplo n.º 27
0
    def test_recv_incorrect_state_response(self):
        conn = Connection(our_role="server")
        conn._conn.machine.set_state("response")

        with self.assertRaises(ProtocolError):
            conn.recv(b"")