Skip to content

Commit d90483e

Browse files
committed
Fixed paths issue
1 parent 35416b4 commit d90483e

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

optionsparser.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def parse_options(opts, version):
6464
opts.update(vars(params))
6565

6666
if params.list_plugins:
67-
with os.scandir(os.path.normpath(os.path.join(os.getcwd(), 'plugins/'))) as it:
68-
for entry in it:
69-
if entry.name.endswith(".py") and entry.is_file():
70-
print('[+] Plugin: {}'.format(entry.name))
67+
files = sorted([f for f in os.scandir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plugins/'))], key = lambda f: f.name)
68+
for _, entry in enumerate(files):
69+
if entry.name.endswith(".py") and entry.is_file() and entry.name.lower() not in ['iproxyplugin.py', '__init__.py']:
70+
print('[+] Plugin: {}'.format(entry.name))
7171

7272
sys.exit(0)
7373

@@ -76,7 +76,7 @@ def parse_options(opts, version):
7676
decomposed = PluginsLoader.decompose_path(opt)
7777
if not os.path.isfile(decomposed['path']):
7878
opt = opt.replace('.py', '')
79-
opt2 = os.path.normpath(os.path.join(os.getcwd(), 'plugins/{}.py'.format(opt)))
79+
opt2 = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plugins/{}.py'.format(opt)))
8080
if not os.path.isfile(opt2):
8181
raise Exception('Specified plugin: "%s" does not exist.' % decomposed['path'])
8282
else:
@@ -111,10 +111,10 @@ def parse_options(opts, version):
111111
def feed_with_plugin_options(opts, parser):
112112
logger = ProxyLogger()
113113
plugins = []
114-
with os.scandir(os.path.join(os.getcwd(), 'plugins/')) as it:
115-
for entry in it:
116-
if entry.name.endswith(".py") and entry.is_file():
117-
plugins.append(entry.path)
114+
files = sorted([f for f in os.scandir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plugins/'))], key = lambda f: f.name)
115+
for _, entry in enumerate(files):
116+
if entry.name.endswith(".py") and entry.is_file() and entry.name.lower() not in ['iproxyplugin.py', '__init__.py']:
117+
plugins.append(entry.path)
118118

119119
options = opts.copy()
120120
options['plugins'] = plugins

plugins/malleable_redirector.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ def help(parser):
279279
help='If someone who is not a beacon hits the proxy, where to redirect him (or where to proxy his request). Default: https://google.com',
280280
default = 'https://google.com'
281281
)
282+
parser.add_argument('--log-dropped',
283+
help='Logs full dropped requests bodies.',
284+
action = 'store_true'
285+
)
282286

283287
def request_handler(self, req, req_body):
284288
self.is_request = True
@@ -307,6 +311,17 @@ def response_handler(self, req, req_body, res, res_body):
307311
return res_body
308312

309313
def drop_action(self, req, req_body, res, res_body):
314+
if self.proxyOptions['log_dropped'] == True:
315+
if req_body == None: req_body = ''
316+
else: req_body = req_body.decode()
317+
318+
req_headers = ProxyRequestHandler.filter_headers(req.headers)
319+
request = '{} {} {}\r\n{}\r\n{}'.format(
320+
req.command, req.path, 'HTTP/1.1', req_headers, req_body
321+
)
322+
323+
self.logger.info('DROPPED REQUEST:\n\n{}'.format(request))
324+
310325
if self.proxyOptions['drop_action'] == 'reset':
311326
return DropConnectionException('Not a conformant beacon request.')
312327

proxy2.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454

5555
ssl._create_default_https_context = ssl._create_unverified_context
5656

57+
normpath = lambda p: os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), p))
58+
5759
# Global options dictonary, that will get modified after parsing
5860
# program arguments. Below state represents default values.
5961
options = {
@@ -66,10 +68,10 @@
6668
'proxy_self_url': 'http://proxy2.test/',
6769
'timeout': 5,
6870
'no_ssl': False,
69-
'cakey': os.path.normpath(os.path.join(os.getcwd(), 'ca-cert/ca.key')),
70-
'cacert': os.path.normpath(os.path.join(os.getcwd(), 'ca-cert/ca.crt')),
71-
'certkey': os.path.normpath(os.path.join(os.getcwd(), 'ca-cert/cert.key')),
72-
'certdir': os.path.normpath(os.path.join(os.getcwd(), 'certs/')),
71+
'cakey': normpath('ca-cert/ca.key'),
72+
'cacert': normpath('ca-cert/ca.crt'),
73+
'certkey': normpath('ca-cert/cert.key'),
74+
'certdir': normpath('certs/'),
7375
'cacn': 'proxy2 CA',
7476
'plugins': set(),
7577
'plugin_class_name': 'ProxyPlugin',
@@ -313,7 +315,7 @@ class Response(object):
313315
assert scheme in ('http', 'https')
314316
#if netloc:
315317
# req.headers['Host'] = netloc
316-
req_headers = self.filter_headers(req.headers)
318+
req_headers = ProxyRequestHandler.filter_headers(req.headers)
317319

318320
if not origin in self.tls.conns:
319321
logger.dbg('Connecting with {}'.format(outbound_origin))
@@ -359,7 +361,7 @@ class Response(object):
359361

360362
logger.info('[RESPONSE] HTTP {} {}, length: {}'.format(res.status, res.reason, len(res_body)), color=ProxyLogger.colors_map['yellow'])
361363

362-
res_headers = self.filter_headers(res.headers)
364+
res_headers = ProxyRequestHandler.filter_headers(res.headers)
363365
o = "%s %d %s\r\n" % (self.protocol_version, res.status, res.reason)
364366
self.wfile.write(o.encode())
365367
for k, v in res_headers.items():
@@ -385,7 +387,8 @@ class Response(object):
385387
do_TRACE = do_GET
386388
do_PATCH = do_GET
387389

388-
def filter_headers(self, headers):
390+
@staticmethod
391+
def filter_headers(headers):
389392
# http://tools.ietf.org/html/rfc2616#section-13.5.1
390393
hop_by_hop = ('connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'te', 'trailers', 'transfer-encoding', 'upgrade')
391394
for k in hop_by_hop:

0 commit comments

Comments
 (0)