Skip to content

Commit

Permalink
[REF] main: refactor the entry function to make it more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
s0md3v authored Nov 3, 2024
2 parents 53afa55 + c1fcde3 commit 93c6c96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 43 deletions.
46 changes: 15 additions & 31 deletions arjun/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,51 +182,35 @@ def initialize(request, wordlist, single_url=False):


def main():
request = prepare_requests(args)
requests = prepare_requests(args)

final_result = {}
is_single = False if args.import_file else True

try:
if type(request) == dict:
# in case of a single target
mem.var['kill'] = False
mem.var['kill'] = False
count = 0
for request in requests:
url = request['url']
these_params = initialize(request, wordlist, single_url=True)
these_params = initialize(request, wordlist, single_url=is_single)
count += 1
mem.var['kill'] = False
mem.var['bad_req_count'] = 0
print('%s Scanning %d/%d: %s' % (run, count, len(requests), url))
if these_params == 'skipped':
print('%s Skipped %s due to errors' % (bad, url))
elif these_params:
final_result[url] = {}
final_result[url]['params'] = these_params
final_result[url]['method'] = request['method']
final_result[url]['headers'] = request['headers']
print('%s Parameters found: %s' % (good, ', '.join(final_result[url]['params'])))
exporter(final_result)
print('%s Parameters found: %s\n' % (good, ', '.join(final_result[url]['params'])))
if not mem.var['json_file']:
final_result = {}
continue
else:
print('%s No parameters were discovered.' % info)
elif type(request) == list:
# in case of multiple targets
count = 0
for each in request:
count += 1
url = each['url']
mem.var['kill'] = False
mem.var['bad_req_count'] = 0
print('%s Scanning %d/%d: %s' % (run, count, len(request), url))
these_params = initialize(each, list(wordlist))
if these_params == 'skipped':
print('%s Skipped %s due to errors' % (bad, url))
elif these_params:
final_result[url] = {}
final_result[url]['params'] = these_params
final_result[url]['method'] = each['method']
final_result[url]['headers'] = each['headers']
exporter(final_result)
print('%s Parameters found: %s\n' % (good, ', '.join(final_result[url]['params'])))
if not mem.var['json_file']:
final_result = {}
continue
else:
print('%s No parameters were discovered.\n' % info)
print('%s No parameters were discovered.\n' % info)
except KeyboardInterrupt:
exit()

Expand Down
8 changes: 5 additions & 3 deletions arjun/core/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ def urls_import(path, method, headers, include):
def request_import(path):
"""
imports request from a raw request file
returns dict
returns list
"""
return parse_request(reader(path))
result = []
result.append(parse_request(reader(path)))
return result


def importer(path, method, headers, include):
Expand All @@ -112,4 +114,4 @@ def importer(path, method, headers, include):
return urls_import(path, method, headers, include)
elif line.startswith(('GET', 'POST')):
return request_import(path)
return 'unknown'
return []
21 changes: 12 additions & 9 deletions arjun/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def fetch_params(host):
def prepare_requests(args):
"""
creates a list of request objects used by Arjun from targets given by user
returns list (of targs)
returns list (of targets)
"""
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0',
Expand All @@ -258,6 +258,7 @@ def prepare_requests(args):
'Connection': 'close',
'Upgrade-Insecure-Requests': '1'
}
result = []
if type(args.headers) == str:
headers = extract_headers(args.headers)
elif args.headers:
Expand All @@ -266,15 +267,17 @@ def prepare_requests(args):
headers['Content-type'] = 'application/json'
if args.url:
params = get_params(args.include)
return {
'url': args.url,
'method': mem.var['method'],
'headers': headers,
'include': params
}
result.append(
{
'url': args.url,
'method': mem.var['method'],
'headers': headers,
'include': params
}
)
elif args.import_file:
return importer(args.import_file, mem.var['method'], headers, args.include)
return []
result = importer(args.import_file, mem.var['method'], headers, args.include)
return result


def nullify(*args, **kwargs):
Expand Down

0 comments on commit 93c6c96

Please sign in to comment.