Created
February 5, 2013 02:35
-
-
Save ssimpson89/4711666 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server.py | |
------------- | |
import SocketServer | |
import json | |
import os | |
import subprocess | |
import commands | |
class MyTCPServer(SocketServer.ThreadingTCPServer): | |
allow_reuse_address = True | |
class MyTCPServerHandler(SocketServer.BaseRequestHandler): | |
os.chdir("/root/test") | |
def handle(self): | |
try: | |
data = json.loads(self.request.recv(1024).strip()) | |
if "ls" in data["command"]: | |
print data | |
command = commands.getoutput(data["command"]) | |
tuple(command) | |
self.request.sendall(json.dumps({'return':command})) | |
print command | |
elif "cat" in data["command"]: | |
print data | |
command = commands.getoutput(data["command"]) | |
self.request.sendall(json.dumps({'return':command})) | |
else: | |
self.request.sendall(json.dumps({'return':'Command not found'})) | |
except Exception, e: | |
print "Exception wile receiving message: ", e | |
server = MyTCPServer(('127.0.0.1', 13373), MyTCPServerHandler) | |
server.serve_forever() | |
client.py | |
------------- | |
import socket | |
import json | |
data = {'command':"cat /etc/shadow| grep root"} | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('hydra.techss.net', 13373)) | |
s.send(json.dumps(data)) | |
result = json.loads(s.recv(1024)) | |
print result['return'] | |
s.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment