Fixing eviltwin. Lots of changes.

This commit is contained in:
derv82
2018-05-13 12:39:28 -04:00
parent 94dd02b3ab
commit 1dcb23659b
11 changed files with 424 additions and 131 deletions

View File

@@ -2,42 +2,71 @@
# -*- coding: utf-8 -*-
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from threading import Thread
class EviltwinServer(HTTPServer):
class EviltwinServer(HTTPServer, object):
def __init__(self, success_callback, port=80):
super(EviltwinServer, self).__init__('', port, EviltwinRequestHandler)
def __init__(self, success_callback, error_callback, port=80):
self.thread = None
# Store state in server
self.success_callback = success_callback
self.error_callback = error_callback
self.request_count = 0
self.router_pages_served = 0
# Initialize with our request handler
super(EviltwinServer, self).__init__(('', port), EviltwinRequestHandler)
def start(self):
self.thread = Thread(target=self.serve_forever)
self.thread.start()
def serve_forever(self):
super(EviltwinServer, self).serve_forever()
def stop(self):
# From https://stackoverflow.com/a/268686
self.shutdown()
self.socket.close()
if self.thread:
self.thread.join()
def request_count(self):
return self.request_count
def router_pages_served(self):
return self.router_pages_served
class EviltwinRequestHandler(BaseHTTPRequestHandler):
def __init__(self, success_callback):
self.success_callback = success_callback
def do_GET(self):
self.server.request_count += 1
request_path = self.path
# TODO: URL mappings to load specific pages.
# TODO: URL mappings to load specific pages. E.g. Apple/Android "pings"
print("\n----- Request Start ----->\n")
print('\n----- Request Start ----->\n')
print(request_path)
print(self.headers)
print("<----- Request End -----\n")
print('<----- Request End -----\n')
self.send_response(200)
self.send_header("Set-Cookie", "foo=bar")
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write('<html><head><title>Title goes here.</title></head>')
self.wfile.write('<body><p>This is a test.</p>')
# If someone went to 'http://something.somewhere.net/foo/bar/',
# then s.path equals '/foo/bar/'.
self.wfile.write('<p>You accessed path: %s</p>' % self.path)
self.wfile.write('</body></html>')
def do_POST(self):
self.server.request_count += 1
request_path = self.path
# TODO: If path includes router password, call self.success_callback
# TODO: If path includes router password, call self.server.success_callback
# TODO: Verify router passwords via separate interface?
print("\n----- Request Start ----->\n")
print('\n----- Request Start ----->\n')
print(request_path)
request_headers = self.headers
@@ -46,19 +75,10 @@ class EviltwinRequestHandler(BaseHTTPRequestHandler):
print(request_headers)
print(self.rfile.read(length))
print("<----- Request End -----\n")
print('<----- Request End -----\n')
self.send_response(200)
do_PUT = do_POST
do_DELETE = do_GET
if __name__ == "__main__":
parser = OptionParser()
parser.usage = ("Creates an http-server that will echo out any GET or POST parameters\n"
"Run:\n\n"
" reflect")
(options, args) = parser.parse_args()
main()