Example #1
0
def main():
    options = parse_options()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    print "[*] Setting a proxy between %s:%d and remote SAP Router %s:%d" % (options.local_host,
                                                                             options.local_port,
                                                                             options.remote_host,
                                                                             options.remote_port)
    proxy = SAPNIProxy(options.local_host, options.local_port,
                       options.remote_host, options.remote_port,
                       SAPRouterNativeRouter, keep_alive=False,
                       options=options)

    try:
        while (True):
            try:
                proxy.handle_connection()
            except SocketError as e:
                print "[*] Socket Error %s" % e

    except KeyboardInterrupt:
        print "[*] Cancelled by the user !"
    except RouteException, e:
        print "[*] Closing routing do to error %s" % e
Example #2
0
 def start_sapniproxy(self, handler_cls):
     self.proxy = SAPNIProxy(self.test_address,
                             self.test_proxyport,
                             self.test_address,
                             self.test_serverport,
                             handler=handler_cls)
     self.proxy_thread = Thread(target=self.handle_sapniproxy)
     self.proxy_thread.start()
Example #3
0
def main():
    options = parse_options()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    print "[*] Establishing a Diag proxy between %s:%d and remote %s:%d" % (options.local_host, options.local_port, options.remote_host, options.remote_port)
    proxy = SAPNIProxy(options.local_host, options.local_port,
                     options.remote_host, options.remote_port,
                     SAPDiagProxyHandler)
    while(True):
        proxy.handle_connection()
Example #4
0
def main():
    options = parse_options()

    if options.verbose:
        logging.basicConfig(level=logging.DEBUG)

    print("[*] Establishing a Diag proxy between %s:%d and remote %s:%d" %
          (options.local_host, options.local_port, options.remote_host,
           options.remote_port))
    proxy = SAPNIProxy(options.local_host, options.local_port,
                       options.remote_host, options.remote_port,
                       SAPDiagProxyHandler)
    while (True):
        proxy.handle_connection()
Example #5
0
class PySAPNIProxyTest(PySAPBaseServerTest):

    test_proxyport = 8005
    test_serverport = 8006
    test_address = "127.0.0.1"
    test_string = "TEST" * 10
    proxyhandler_cls = SAPNIProxyHandler
    serverhandler_cls = SAPNIServerTestHandler

    def start_sapniproxy(self, handler_cls):
        self.proxy = SAPNIProxy(self.test_address,
                                self.test_proxyport,
                                self.test_address,
                                self.test_serverport,
                                handler=handler_cls)
        self.proxy_thread = Thread(target=self.handle_sapniproxy)
        self.proxy_thread.daemon = True
        self.proxy_thread.start()

    def handle_sapniproxy(self):
        self.proxy.handle_connection()

    def stop_sapniproxy(self):
        self.proxy.stop()

    def test_sapniproxy(self):
        self.start_server(self.test_address, self.test_serverport,
                          self.serverhandler_cls, SAPNIServerThreaded)
        self.start_sapniproxy(self.proxyhandler_cls)

        sock = socket.socket()
        sock.connect((self.test_address, self.test_proxyport))
        sock.sendall(pack("!I", len(self.test_string)) + self.test_string)

        response = sock.recv(4)
        self.assertEqual(len(response), 4)
        ni_length, = unpack("!I", response)
        self.assertEqual(ni_length, len(self.test_string) + 4)

        response = sock.recv(ni_length)
        self.assertEqual(unpack("!I", response[:4]), (len(self.test_string), ))
        self.assertEqual(response[4:], self.test_string)

        sock.close()
        self.stop_sapniproxy()
        self.stop_server()

    def test_sapniproxy_process(self):
        self.start_server(self.test_address, self.test_serverport,
                          self.serverhandler_cls, SAPNIServerThreaded)

        class SAPNIProxyHandlerTest(SAPNIProxyHandler):
            def process_client(self, packet):
                return packet / Raw("Client")

            def process_server(self, packet):
                return packet / Raw("Server")

        self.start_sapniproxy(SAPNIProxyHandlerTest)

        sock = socket.socket()
        sock.connect((self.test_address, self.test_proxyport))
        sock.sendall(pack("!I", len(self.test_string)) + self.test_string)

        expected_reponse = self.test_string + "Client" + "Server"

        response = sock.recv(4)
        self.assertEqual(len(response), 4)
        ni_length, = unpack("!I", response)
        self.assertEqual(ni_length, len(expected_reponse) + 4)

        response = sock.recv(ni_length)
        self.assertEqual(unpack("!I", response[:4]),
                         (len(self.test_string) + 6, ))
        self.assertEqual(response[4:], expected_reponse)

        sock.close()
        self.stop_sapniproxy()
        self.stop_server()
Example #6
0
 def start_sapniproxy(self, handler_cls):
     self.proxy = SAPNIProxy(self.test_address, self.test_proxyport,
                             self.test_address, self.test_serverport,
                             handler=handler_cls)
     self.proxy_thread = Thread(target=self.handle_sapniproxy)
     self.proxy_thread.start()
Example #7
0
class PySAPNIProxyTest(unittest.TestCase):

    test_proxyport = 8005
    test_serverport = 8006
    test_address = "127.0.0.1"
    test_string = "TEST" * 10
    proxyhandler_cls = SAPNIProxyHandler
    serverhandler_cls = SAPNIServerTestHandler

    def setUp(self):
        self.server = SAPNIServerThreaded((self.test_address, self.test_serverport),
                                          self.serverhandler_cls,
                                          bind_and_activate=False)
        self.server.allow_reuse_address = True
        self.server.server_bind()
        self.server.server_activate()
        self.server_thread = Thread(target=self.server.serve_forever)
        self.server_thread.start()

    def tearDown(self):
        self.server.shutdown()
        self.server.server_close()

    def start_sapniproxy(self, handler_cls):
        self.proxy = SAPNIProxy(self.test_address, self.test_proxyport,
                                self.test_address, self.test_serverport,
                                handler=handler_cls)
        self.proxy_thread = Thread(target=self.handle_sapniproxy)
        self.proxy_thread.start()

    def handle_sapniproxy(self):
        self.proxy.handle_connection()

    def stop_sapniproxy(self):
        self.proxy.stop()

    def test_sapniproxy(self):
        self.start_sapniproxy(self.proxyhandler_cls)

        sock = socket.socket()
        sock.connect((self.test_address, self.test_proxyport))
        sock.sendall(pack("!I", len(self.test_string)) + self.test_string)

        response = sock.recv(1024)

        self.assertEqual(len(response), len(self.test_string) + 8)
        self.assertEqual(unpack("!I", response[:4]), (len(self.test_string) + 4, ))
        self.assertEqual(unpack("!I", response[4:8]), (len(self.test_string), ))
        self.assertEqual(response[8:], self.test_string)

        sock.close()
        self.stop_sapniproxy()

    def test_sapniproxy_process(self):

        class SAPNIProxyHandlerTest(SAPNIProxyHandler):

            def process_client(self, packet):
                return packet / Raw("Client")

            def process_server(self, packet):
                return packet / Raw("Server")

        self.start_sapniproxy(SAPNIProxyHandlerTest)

        sock = socket.socket()
        sock.connect((self.test_address, self.test_proxyport))
        sock.sendall(pack("!I", len(self.test_string)) + self.test_string)

        response = sock.recv(1024)

        expected_reponse = self.test_string + "Client" + "Server"
        self.assertEqual(len(response), len(expected_reponse) + 8)
        self.assertEqual(unpack("!I", response[:4]), (len(expected_reponse) + 4, ))
        self.assertEqual(unpack("!I", response[4:8]), (len(self.test_string) + 6, ))
        self.assertEqual(response[8:], expected_reponse)

        sock.close()
        self.stop_sapniproxy()
Example #8
0
class PySAPNIProxyTest(unittest.TestCase):

    test_proxyport = 8005
    test_serverport = 8006
    test_address = "127.0.0.1"
    test_string = "TEST" * 10
    proxyhandler_cls = SAPNIProxyHandler
    serverhandler_cls = SAPNIServerTestHandler

    def setUp(self):
        self.server = SAPNIServerThreaded(
            (self.test_address, self.test_serverport),
            self.serverhandler_cls,
            bind_and_activate=False)
        self.server.allow_reuse_address = True
        self.server.server_bind()
        self.server.server_activate()
        self.server_thread = Thread(target=self.server.serve_forever)
        self.server_thread.start()

    def tearDown(self):
        self.server.shutdown()
        self.server.server_close()

    def start_sapniproxy(self, handler_cls):
        self.proxy = SAPNIProxy(self.test_address,
                                self.test_proxyport,
                                self.test_address,
                                self.test_serverport,
                                handler=handler_cls)
        self.proxy_thread = Thread(target=self.handle_sapniproxy)
        self.proxy_thread.start()

    def handle_sapniproxy(self):
        self.proxy.handle_connection()

    def stop_sapniproxy(self):
        self.proxy.stop()

    def test_sapniproxy(self):
        self.start_sapniproxy(self.proxyhandler_cls)

        sock = socket.socket()
        sock.connect((self.test_address, self.test_proxyport))
        sock.sendall(pack("!I", len(self.test_string)) + self.test_string)

        response = sock.recv(1024)

        self.assertEqual(len(response), len(self.test_string) + 8)
        self.assertEqual(unpack("!I", response[:4]),
                         (len(self.test_string) + 4, ))
        self.assertEqual(unpack("!I", response[4:8]),
                         (len(self.test_string), ))
        self.assertEqual(response[8:], self.test_string)

        sock.close()
        self.stop_sapniproxy()

    def test_sapniproxy_process(self):
        class SAPNIProxyHandlerTest(SAPNIProxyHandler):
            def process_client(self, packet):
                return packet / Raw("Client")

            def process_server(self, packet):
                return packet / Raw("Server")

        self.start_sapniproxy(SAPNIProxyHandlerTest)

        sock = socket.socket()
        sock.connect((self.test_address, self.test_proxyport))
        sock.sendall(pack("!I", len(self.test_string)) + self.test_string)

        response = sock.recv(1024)

        expected_reponse = self.test_string + "Client" + "Server"
        self.assertEqual(len(response), len(expected_reponse) + 8)
        self.assertEqual(unpack("!I", response[:4]),
                         (len(expected_reponse) + 4, ))
        self.assertEqual(unpack("!I", response[4:8]),
                         (len(self.test_string) + 6, ))
        self.assertEqual(response[8:], expected_reponse)

        sock.close()
        self.stop_sapniproxy()