summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Core.py6
-rw-r--r--config4
-rw-r--r--module/remote/RequestHandler.py38
-rw-r--r--module/remote/SocketServer.py6
-rw-r--r--sockettest.py47
5 files changed, 84 insertions, 17 deletions
diff --git a/Core.py b/Core.py
index 336995846..2969e1c90 100644
--- a/Core.py
+++ b/Core.py
@@ -74,6 +74,7 @@ class Core(object):
for section in config.sections():
for option in config.options(section):
self.config[option] = config.get(section, option)
+ self.config[option] = False if self.config[option].lower == 'False' else self.config[option]
self.config['download_folder'] = config.get('general', 'downloadFolder')
self.config['link_file'] = config.get('general', 'linkFile')
@@ -229,7 +230,8 @@ class Core(object):
if __name__ == "__main__":
testLoader = Core()
- #server = ServerThread(testLoader)
- #server.start()
+ if testLoader.config['remoteactivated']:
+ server = ServerThread(testLoader)
+ server.start()
testLoader.start()
diff --git a/config b/config
index 7aeccfdff..5be068413 100644
--- a/config
+++ b/config
@@ -12,6 +12,6 @@ fullLog = True
start = 0:00
end = 6:00
[remote]
-activated = True
+remoteActivated = True
port = 7272
-passwort = pwhere
+remotePassword = pwhere
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):
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()