Skip to content

Commit d9f0cbc

Browse files
author
derpadoo
committed
Added masscan GUI support, added missing static files, updated .gitignore
1 parent dfad1a4 commit d9f0cbc

File tree

17 files changed

+1209
-18
lines changed

17 files changed

+1209
-18
lines changed

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ __pycache__/
1919
.Python
2020
build/
2121
develop-eggs/
22-
dist/
2322
downloads/
2423
eggs/
2524
.eggs/
26-
lib/
2725
lib64/
2826
parts/
2927
sdist/
@@ -110,4 +108,4 @@ venv.bak/
110108
/site
111109

112110
# mypy
113-
.mypy_cache/
111+
.mypy_cache/

agent/modules/nmap_scanner.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ def scan_site(scan_job_dict):
119119
process.wait()
120120

121121
# nmap process completed successfully.
122+
# Move files from "pending" directory to "complete" directory.
122123
if process.returncode == 0:
123-
# Move files from "pending" directory to "complete" directory.
124-
shutil.move(nmap_file, os.path.join(complete_files_dir, os.path.basename(nmap_file)))
125-
shutil.move(gnmap_file, os.path.join(complete_files_dir, os.path.basename(gnmap_file)))
126-
shutil.move(xml_file, os.path.join(complete_files_dir, os.path.basename(xml_file)))
124+
125+
if scan_binary == "masscan":
126+
shutil.move(json_file, os.path.join(complete_files_dir, os.path.basename(json_file)))
127+
128+
elif scan_binary == "nmap":
129+
shutil.move(nmap_file, os.path.join(complete_files_dir, os.path.basename(nmap_file)))
130+
shutil.move(gnmap_file, os.path.join(complete_files_dir, os.path.basename(gnmap_file)))
131+
shutil.move(xml_file, os.path.join(complete_files_dir, os.path.basename(xml_file)))
127132

128133
# Update completed_time, scan_status, and result_file_base_name.
129134
now_datetime = utils.get_current_time()
@@ -136,6 +141,6 @@ def scan_site(scan_job_dict):
136141
api.update_scan_information(config_data, scan_job, update_info)
137142

138143
except Exception as e:
139-
logger.ROOT_LOGGER.error("Error with scan ID {}. Exception: {}".format(scan_job["id"], e))
144+
logger.ROOT_LOGGER.exception("Error with scan ID {}. Exception: {}".format(scan_job["id"], e))
140145
update_info = {"scan_status": "error"}
141146
api.update_scan_information(config_data, scan_job, update_info)

ansible-playbooks/roles/agent/tasks/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
repo: "https://github.com/robertdavidgraham/masscan.git"
2020
dest: "{{ agent_dir }}/masscan"
2121
version: master
22+
ignore_errors: true # For re-runs only.
2223

2324
- name: Run make for masscan.
2425
command: make -j

master/django_scantron/results/views.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@
44
from django_scantron.models import ScheduledScan
55

66

7-
@login_required(login_url='login')
7+
@login_required(login_url="login")
88
def retrieve_scan_file(request, id):
99
# Lookup result_file_base_name based of scan ID.
10-
result_file_base_name = ScheduledScan.objects.get(id=id).result_file_base_name
11-
file_extension = 'nmap'
12-
scan_file = '{}.{}'.format(result_file_base_name, file_extension)
10+
requested_scan = ScheduledScan.objects.get(id=id)
11+
12+
result_file_base_name = requested_scan.result_file_base_name
13+
scan_binary = requested_scan.scan_binary
14+
15+
file_extension = ""
16+
17+
if scan_binary == "nmap":
18+
file_extension = "nmap"
19+
20+
elif scan_binary == "masscan":
21+
file_extension = "json"
22+
23+
scan_file = "{}.{}".format(result_file_base_name, file_extension)
1324

1425
# Serve file using nginx X-Accel-Redirect.
1526
# https://wellfire.co/learn/nginx-django-x-accel-redirects/
1627
response = HttpResponse()
17-
response['Content-Type'] = 'text/plain'
18-
response['Content-Disposition'] = 'inline; filename={}'.format(scan_file)
19-
response['X-Accel-Redirect'] = '/protected/complete/{}'.format(scan_file)
28+
response["Content-Type"] = "text/plain"
29+
response["Content-Disposition"] = "inline; filename={}".format(scan_file)
30+
response["X-Accel-Redirect"] = "/protected/complete/{}".format(scan_file)
2031
return response

master/django_scantron/templates/django_scantron/scheduled_scan_list.html

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ <h3>
2222
<th>Site Name</th>
2323
<th>Scan Agent</th>
2424
<th>Scheduled Start Time</th>
25-
<th>nmap Command</th>
25+
<th>Scan Binary</th>
26+
<th>Scan Command</th>
2627
<th>Scan Status</th>
2728
<th>Completion Time</th>
2829
<th>Results File</th>
@@ -36,10 +37,17 @@ <h3>
3637
<td>{{ scan.site_name }}</td>
3738
<td>{{ scan.scan_agent }}</td>
3839
<td>{{ scan.start_time|date:"Y-m-j H:i:s" }}</td>
39-
<td>{{ scan.nmap_command }}</td>
40+
<td>{{ scan.scan_binary }}</td>
41+
<td>{{ scan.scan_binary }} {{ scan.nmap_command }}</td>
4042
<td>{{ scan.scan_status }}</td>
4143
<td>{{ scan.completed_time|date:"Y-m-j H:i:s" }}</td>
42-
<td><a href={% url "retrieve_scan_file" scan.id %}>{{ scan.result_file_base_name }}.nmap</a></td>
44+
{% if scan.scan_binary == "nmap" %}
45+
<td><a href={% url "retrieve_scan_file" scan.id %}>{{ scan.result_file_base_name }}.nmap</a></td>
46+
{% elif scan.scan_binary == "masscan" %}
47+
<td><a href={% url "retrieve_scan_file" scan.id %}>{{ scan.result_file_base_name }}.json</a></td>
48+
{% else %}
49+
<td>Unknown scan_binary</td>
50+
{% endif %}
4351
</tr>
4452
{% endfor %}
4553
</tbody>

master/static/bower_components/bootstrap/dist/css/bootstrap.min.css

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)