summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-29 13:37:46 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-05-29 13:37:46 +0200
commit37104032902281caefa144ed039b88c4f3b6e81e (patch)
tree560e1ab570dde87edebbbb6c8e28fba30f80e738 /module
parentadded download plugin for fileuploadx.de, fixed some bugs (diff)
downloadpyload-37104032902281caefa144ed039b88c4f3b6e81e.tar.xz
socket encryption
Diffstat (limited to 'module')
-rw-r--r--module/remote/RequestHandler.py38
-rw-r--r--module/remote/SocketServer.py6
2 files changed, 33 insertions, 11 deletions
diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py
index 9964c90c0..c72f6eaaa 100644
--- a/module/remote/RequestHandler.py
+++ b/module/remote/RequestHandler.py
@@ -8,22 +8,44 @@ this module handels the incoming requests
"""
import base64
-from cPickle import Pickler
-from cStringIO import StringIO
+import cPickle
+import random
+import string
from Crypto.Cipher import AES
+from Crypto.Hash import SHA
class RequestHandler():
def __init__(self, core):
self.core = core
- self.p = Pickler(string)
- self.obj = AES.new('pw', AES.MODE_ECB)
+ key = SHA.new(core.config['remotepassword'])
+ self.aes = AES.new(key.hexdigest()[:32], AES.MODE_ECB)
def proceed(self, data):
- return "the answer."
+ return self.encrypt({'befehl' : None , 'args':[1,2,3], 'test': 'lol'})
+
+ def decrypt(self, dec_str):
+ 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)
+ 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
- def decrypt(self, string):
- string = string
- buf = StringIO(string)
diff --git a/module/remote/SocketServer.py b/module/remote/SocketServer.py
index 3635e16d8..1252547ad 100644
--- a/module/remote/SocketServer.py
+++ b/module/remote/SocketServer.py
@@ -17,7 +17,7 @@ class ServerThread(threading.Thread):
def __init__(self, pycore):
threading.Thread.__init__(self)
self.setDaemon(True)
- self.server = MainServerSocket(7272, pycore)
+ self.server = MainServerSocket(int(pycore.config['port']), pycore)
def run(self):
asyncore.loop()
@@ -52,8 +52,8 @@ class SecondaryServerSocket(asynchat.async_chat):
def collect_incoming_data(self, data):
self.data.append(data)
def found_terminator(self):
- self.handler.proceed(self.data)
- self.push(str(self.pycore.plugins_avaible))
+ rep = self.handler.proceed(self.data)
+ self.push(rep)
self.data = []
#having fun with the data
def handle_close(self):