diff --git a/README.md b/README.md index 52af4b9..a0fd768 100644 --- a/README.md +++ b/README.md @@ -3,25 +3,20 @@ The Socks Proxy Plugin runs a Socks Proxy Server for [Invoke-SocksProxy](https:/ that supports Socks 4 and 5 protocols. This plugin is entirely contained in [Empire](https://github.com/BC-SECURITY/Empire/) and runs in the background. -`socksproxyserver [handler port] [proxy port] [certificate] [private key]` - -![image](https://user-images.githubusercontent.com/20302208/95637897-d8221480-0a47-11eb-8a69-3f132fe5d079.png) - ## Getting Started * To run the plugin, you can download it fom the releases [Releases](https://github.com/BC-SECURITY/Invoke-SocksProxy/releases) page. ## Install Prerequisites: -- Empire 3.5.0+ +- Empire >= 4.0.0 1. Add SocksServer.py to the plugins folder of Empire. -![image](https://user-images.githubusercontent.com/20302208/95636534-49f85f00-0a44-11eb-87c1-754a2368febb.png) - - -2. Plugins are automatically loaded into Empire as of 3.4.0, otherwise run ```plugin SocksServer``` +![image](https://user-images.githubusercontent.com/20302208/120246969-b4098280-c226-11eb-9345-4ff994ee5312.png) -![image](https://user-images.githubusercontent.com/20302208/95636737-b5dac780-0a44-11eb-9f82-34dcb66c24fe.png) +## Usage +### Client +![image](https://user-images.githubusercontent.com/20302208/120247213-8ffa7100-c227-11eb-8a7a-5f0de195f2e9.gif) ## Future Features - Add multiple socks server support (similar to agents and listeners) diff --git a/plugins/socksproxyserver.py b/socksproxyserver.py similarity index 77% rename from plugins/socksproxyserver.py rename to socksproxyserver.py index 7b27925..2fb3242 100644 --- a/plugins/socksproxyserver.py +++ b/socksproxyserver.py @@ -1,7 +1,7 @@ from __future__ import print_function -from lib.common.plugins import Plugin -import lib.common.helpers as helpers +from empire.server.common.plugins import Plugin +import empire.server.common.helpers as helpers import socket import _thread @@ -14,8 +14,8 @@ class Plugin(Plugin): description = "Launches a Socks Proxy Server to run in the background of Empire" def onLoad(self): - """ any custom loading behavior - called by init, so any - behavior you'd normally put in __init__ goes here """ + print(helpers.color("[*] Loading Empire Socks Proxy Server plugin")) + self.main_menu = None self.info = { 'Name': 'socksproxyserver', @@ -32,9 +32,11 @@ def onLoad(self): self.options = { 'status': { - 'Description': 'Start/stop the Chisel server. Specify a port or default to 8080.', + 'Description': 'Start/stop the Socks Proxy server.', 'Required': True, - 'Value': 'start' + 'Value': 'start', + 'SuggestedValues': ['start', 'stop'], + 'Strict': True }, 'handlerport': { 'Description': 'Port number.', @@ -47,7 +49,7 @@ def onLoad(self): 'Value': '1080' }, 'certificate': { - 'Description': 'Certifcate directory [Default: Empire self-signed cert].', + 'Description': 'Certificate directory [Default: Empire self-signed cert].', 'Required': False, 'Value': '' }, @@ -58,9 +60,8 @@ def onLoad(self): }, } - # load default empire certs - self.cert_path = os.path.abspath("./data/") + self.cert_path = os.path.abspath("./empire/server/data/") self.certificate = "%s/empire-chain.pem" % self.cert_path self.private_key = "%s/empire-priv.key" % self.cert_path @@ -83,14 +84,18 @@ def execute(self, command): def get_commands(self): return self.commands - def register(self, main_menu): - """ any modifications to the mainMenu go here - e.g. - registering functions to be run by user commands """ - main_menu.__class__.do_socksproxyserver = self.do_socksproxyserver + def register(self, mainMenu): + """ + any modifications to the main_menu go here - e.g. + registering functions to be run by user commands + """ + mainMenu.__class__.do_socksproxyserver = self.do_socksproxyserver + self.main_menu = mainMenu def do_socksproxyserver(self, args): - "Launches a SocksProxy Server to run in the background of Empire" - + """ + Launches a SocksProxy Server to run in the background of Empire + """ if not args: # Load defaults for server self.status = self.options['status']['Value'] @@ -99,16 +104,10 @@ def do_socksproxyserver(self, args): if not self.options['certificate']['Value'] or self.options['privatekey']['Value']: # load default empire certs - self.cert_path = os.path.abspath("./data/") + self.cert_path = os.path.abspath("./empire/server/data/") self.certificate = "%s/empire-chain.pem" % self.cert_path self.private_key = "%s/empire-priv.key" % self.cert_path - print(helpers.color( - "[!] Usage: socksserver [handler port] [proxy port] [certificate] [private key]")) - print(helpers.color( - "[+] Defaults: socksserver " + self.status + " " + self.handler_port + " " + self.proxy_port + " " + - self.certificate + " " + self.private_key)) - else: args = args.split(" ") @@ -131,7 +130,7 @@ def do_socksproxyserver(self, args): self.private_key = args[4] else: # load default empire certs - self.cert_path = os.path.abspath("./data/") + self.cert_path = os.path.abspath("./empire/server/data/") self.certificate = "%s/empire-chain.pem" % self.cert_path self.private_key = "%s/empire-priv.key" % self.cert_path @@ -141,8 +140,7 @@ def do_socksproxyserver(self, args): elif self.status == "stop": self.shutdown() else: - print(helpers.color("[!] Usage: socksserver [handler port] [proxy port] [certificate] [" - "private key]")) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Usage: ") def start_socks_server(self): if not self.running: @@ -150,17 +148,20 @@ def start_socks_server(self): _thread.start_new_thread(self.server, (self.handler_port, self.proxy_port, self.certificate, self.private_key)) else: - print(helpers.color("[!] Socks Proxy Server Already Running!")) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Socks Proxy Server Already Running!") def shutdown(self): - """if the plugin spawns a process provide a shutdown method for when Empire exits else leave it as pass""" + """ + if the plugin spawns a process provide a shutdown method for when Empire exits else leave it as pass + """ if self.running: self.running = False - print(helpers.color("[*] Stopping socks proxy server...")) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[*] Stopping socks proxy server...") socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("127.0.0.1", int(self.handler_port))) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("127.0.0.1", int(self.proxy_port))) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Socks proxy server stopped") else: - print(helpers.color("[!] Server is not running!")) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Server is not running!") def handler_server(self, q, handler_port, certificate, private_key): context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) @@ -170,10 +171,8 @@ def handler_server(self, q, handler_port, certificate, private_key): dock_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) dock_socket.bind(('', int(handler_port))) dock_socket.listen(5) - print(helpers.color("[*] Handler listening on: " + handler_port)) - print(helpers.color("[*] Using certificate: " + certificate)) - print(helpers.color("[*] Using private key: " + private_key)) - print(helpers.color("[+] Socks proxy server started")) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[+] Socks proxy server started") + while self.running: try: clear_socket, address = dock_socket.accept() @@ -192,7 +191,7 @@ def handler_server(self, q, handler_port, certificate, private_key): except Exception as e: pass except Exception as e: - pass + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] " + e.strerror) finally: dock_socket.close() @@ -215,7 +214,8 @@ def server(self, handler_port, proxy_port, certificate, private_key): dock_socket2.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) dock_socket2.bind(('127.0.0.1', int(proxy_port))) dock_socket2.listen(5) - print(helpers.color("\n[*] Socks server listening on: " + proxy_port)) + self.mainMenu.plugin_socketio_message(self.info[0]["Name"], "[*] Socks server listening on: " + proxy_port) + while self.running: try: client_socket2, address = dock_socket2.accept() @@ -225,12 +225,12 @@ def server(self, handler_port, proxy_port, certificate, private_key): _thread.start_new_thread(self.forward, (client_socket, client_socket2)) _thread.start_new_thread(self.forward, (client_socket2, client_socket)) except Exception as e: - print(helpers.color("[!] Exception: %s" % e)) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Exception: %s" % e) except Exception as e: - print(helpers.color("[!] Exception: %s" % e)) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Exception: %s" % e) finally: dock_socket2.close() - print(helpers.color("\n[+] Socks proxy server stopped")) + self.main_menu.plugin_socketio_message(self.info[0]["Name"], "[!] Socks proxy server stopped") def forward(self, source, destination): try: