diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-29 13:37:46 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-29 13:37:46 +0200 |
commit | 37104032902281caefa144ed039b88c4f3b6e81e (patch) | |
tree | 560e1ab570dde87edebbbb6c8e28fba30f80e738 /sockettest.py | |
parent | added download plugin for fileuploadx.de, fixed some bugs (diff) | |
download | pyload-37104032902281caefa144ed039b88c4f3b6e81e.tar.xz |
socket encryption
Diffstat (limited to 'sockettest.py')
-rw-r--r-- | sockettest.py | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/sockettest.py b/sockettest.py index afac02bb9..30a4deb81 100644 --- a/sockettest.py +++ b/sockettest.py @@ -1,14 +1,57 @@ #!/usr/bin/env python # -'- coding: utf-8 -*. """ -authored by: Captain Blackbeard +authored by: RaNaN script only for socket testing """ +import base64 +import cPickle +import random +import string +from Crypto.Cipher import AES +from Crypto.Hash import SHA + +class handler: + def __init__(self): + key = SHA.new("pwhere") + self.aes = AES.new(key.hexdigest()[:32], AES.MODE_ECB) + + def proceed(self, data): + return self.decrypt(self.encrypt(str(("lol","mehrlol","pff")))) + + def decrypt(self, dec_str): + try: + dec_str = base64.standard_b64decode(dec_str) + dec_str = self.aes.decrypt(dec_str) + + dec_str = dec_str[:-(int(dec_str[-1],16)+1)] + obj = cPickle.loads(dec_str) + except: + obj = None + return obj + + def encrypt(self, obj): + enc_str = cPickle.dumps(obj, 1) + padding = len(enc_str) % 16 + padding = 16 - padding + + p_str = "" + for i in range(padding - 1): + p_str += random.choice(string.letters+string.digits) + p_str += hex(len(p_str)).replace("0x","") + enc_str += p_str + + enc_str = self.aes.encrypt(enc_str) + enc_str = base64.standard_b64encode(enc_str) + return enc_str + + import socket +handler = handler() sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('localhost', 7272)) print "Connected to server" @@ -20,5 +63,5 @@ for line in data.splitlines(): response = sock.recv(8192) -print "Received:", response +print "Received:", handler.decrypt(response) sock.close() |