Skip to content

Commit

Permalink
Fix API port
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpt-erikgeiser committed Nov 9, 2023
1 parent 8ccb103 commit b183343
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
22 changes: 8 additions & 14 deletions examples/ntlmrelayx.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
RELAY_SERVERS = []

class MiniShell(cmd.Cmd):
def __init__(self, relayConfig, threads):
def __init__(self, relayConfig, threads, api_address):
cmd.Cmd.__init__(self)

self.prompt = 'ntlmrelayx> '
self.api_address = api_address
self.tid = None
self.relayConfig = relayConfig
self.intro = 'Type help for list of commands'
Expand Down Expand Up @@ -108,7 +109,7 @@ def do_socks(self, line):
'''

headers = ["Protocol", "Target", "Username", "AdminStatus", "Port"]
url = "http://localhost:9090/ntlmrelayx/api/v1.0/relays"
url = "http://{}/ntlmrelayx/api/v1.0/relays".format(self.api_address)
try:
proxy_handler = ProxyHandler({})
opener = build_opener(proxy_handler)
Expand Down Expand Up @@ -305,7 +306,9 @@ def stop_servers(threads):
'SMB Server (16 hex bytes long. eg: 1122334455667788)')
parser.add_argument('-socks', action='store_true', default=False,
help='Launch a SOCKS proxy for the connection relayed')
parser.add_argument('-socks-address', default='127.0.0.1:1080', help='SOCKS5 server address, port or address:port, the address is also used for the HTTP API')
parser.add_argument('-socks-address', default='127.0.0.1', help='SOCKS5 server address (also used for HTTP API)')
parser.add_argument('-socks-port', default=1080, type=int, help='SOCKS5 server port')
parser.add_argument('-http-api-port', default=9090, type=int, help='SOCKS5 HTTP API port')
parser.add_argument('-wh','--wpad-host', action='store',help='Enable serving a WPAD file for Proxy Authentication attack, '
'setting the proxy host to the one supplied.')
parser.add_argument('-wa','--wpad-auth-num', action='store', type=int, default=1, help='Prompt for authentication N times for clients without MS16-077 installed '
Expand Down Expand Up @@ -472,18 +475,9 @@ def stop_servers(threads):
threads = set()
socksServer = None
if options.socks is True:
socks_address_parts = options.socks_address.split(":")
if len(socks_address_parts) == 1 and socks_address_parts[0].isdigit():
socks_address = ("127.0.0.1", int(socks_address_parts[0]))
elif len(socks_address_parts) == 1 and not socks_address_parts[0].isdigit():
socks_address = (socks_address_parts[0], 1080)
elif len(socks_address_parts) == 2 and socks_address_parts[1].isdigit():
socks_address = (socks_address_parts[0], int(socks_address_parts[1]))
else:
raise ValueError(f"malformed SOCKS5 server address: {options.socks_address}")

# Start a SOCKS proxy in the background
socksServer = SOCKS(server_address=socks_address)
socksServer = SOCKS(server_address=(options.socks_address, options.socks_port), api_port=options.http_api_port)
socksServer.daemon_threads = True
socks_thread = Thread(target=socksServer.serve_forever)
socks_thread.daemon = True
Expand All @@ -496,7 +490,7 @@ def stop_servers(threads):
logging.info("Servers started, waiting for connections")
try:
if options.socks:
shell = MiniShell(c, threads)
shell = MiniShell(c, threads, api_address='{}:{}'.format(options.socks_address, options.http_api_port))
shell.cmdloop()
else:
sys.stdin.read()
Expand Down
8 changes: 4 additions & 4 deletions impacket/examples/ntlmrelayx/servers/socksserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def activeConnectionsWatcher(server):
client.killConnection()


def webService(addr):
def webService(addr, port):
def _webService(server):
from flask import Flask, jsonify

Expand Down Expand Up @@ -274,7 +274,7 @@ def get_relays():
def get_info(relay):
pass

app.run(host=addr, port=9090)
app.run(host=addr, port=port)

return _webService

Expand Down Expand Up @@ -457,7 +457,7 @@ def handle(self):


class SOCKS(socketserver.ThreadingMixIn, socketserver.TCPServer):
def __init__(self, server_address=('127.0.0.1', 1080), handler_class=SocksRequestHandler):
def __init__(self, server_address=('127.0.0.1', 1080), handler_class=SocksRequestHandler, api_port=9090):
LOG.info('SOCKS proxy started. Listening on %s:%d', server_address[0], server_address[1])

self.activeRelays = {}
Expand All @@ -480,7 +480,7 @@ def __init__(self, server_address=('127.0.0.1', 1080), handler_class=SocksReques
self.__timer = RepeatedTimer(KEEP_ALIVE_TIMER, keepAliveTimer, self)

# Let's start our RESTful API
self.restAPI = Thread(target=webService(server_address[0]), args=(self, ))
self.restAPI = Thread(target=webService(server_address[0], api_port), args=(self, ))
self.restAPI.daemon = True
self.restAPI.start()

Expand Down

0 comments on commit b183343

Please sign in to comment.