Skip to content

Commit 48d4b8f

Browse files
committed
Adds to documentation, fixes a bug in importer
1 parent ea4f6af commit 48d4b8f

File tree

9 files changed

+141
-27
lines changed

9 files changed

+141
-27
lines changed

README.md

+50-16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ deltascan --help
5757
sudo -E env PATH=${PATH} deltascan <command & arguments>
5858
```
5959

60+
<b>NOTE</b>: `data_for_html.json` is the schema of the Python dict exposed to use inside your custom html template (see core/templates)
61+
62+
6063
### Tests
6164
Run tests
6265
```bash
@@ -67,45 +70,76 @@ pipenv run pytest
6770

6871
Scan:
6972
```bash
70-
sudo -E env PATH=${PATH} pipenv run deltascan -a scan -c config.yaml -p MY_PROFILE -t 192.168.0.100
71-
sudo -E env PATH=${PATH} pipenv run deltascan -a scan -c config.yaml -p MY_PROFILE -t 192.168.0.100/24
72-
sudo -E env PATH=${PATH} pipenv run deltascan -a scan -c config.yaml -p MY_PROFILE -t 192.168.0.100 -o export.<csv|pdf|html>
73+
sudo -E env PATH=${PATH} pipenv run deltascan scan -c config.yaml -p MY_PROFILE -t 192.168.0.100
74+
sudo -E env PATH=${PATH} pipenv run deltascan scan -c config.yaml -p MY_PROFILE -t 192.168.0.100/24
75+
sudo -E env PATH=${PATH} pipenv run deltascan scan -c config.yaml -p MY_PROFILE -t 192.168.0.100 -o export.<csv|pdf|html>
7376

7477
# The -s bool flag exports each scan in a separate file
75-
sudo -E env PATH=${PATH} pipenv run deltascan -a scan -c config.yaml -p MY_PROFILE -t 192.168.0.100 -s
78+
sudo -E env PATH=${PATH} pipenv run deltascan scan -c config.yaml -p MY_PROFILE -t 192.168.0.100 -s
7679

7780
# The below command uses a custom template file (it has to be an .html file)
78-
sudo -E env PATH=${PATH} pipenv run deltascan -a scan -c config.yaml -p MY_PROFILE -t 192.168.0.100 --template your_template.html
81+
sudo -E env PATH=${PATH} pipenv run deltascan scan -c config.yaml -p MY_PROFILE -t 192.168.0.100 --template your_template.html
7982
```
8083

8184
Compare:
8285
```bash
83-
pipenv run deltascan -a compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100
84-
pipenv run deltascan -a compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24
85-
pipenv run deltascan -a compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24 -o export.<csv|pdf|html>
86+
pipenv run deltascan compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100
87+
pipenv run deltascan compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24
88+
pipenv run deltascan compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24 -o export.<csv|pdf|html>
8689

8790
# The "--n-scans 20 --n-diffs -2" means "from below command mean from the last 20 scans show the latest differences"
88-
pipenv run deltascan -a compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" --n-scans 20 --n-diffs -2 -t 192.168.0.100
91+
pipenv run deltascan compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" --n-scans 20 --n-diffs -2 -t 192.168.0.100
8992

9093
# The below command uses a custom template file (it has to be an .html file)
91-
pipenv run deltascan -a compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" --n-scans 20 --n-diffs -2 -t 192.168.0.100 --template your_template.html
94+
pipenv run deltascan compare -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" --n-scans 20 --n-diffs -2 -t 192.168.0.100 --template your_template.html
9295
```
9396

9497
View:
9598
```bash
96-
pipenv run deltascan -a view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100
97-
pipenv run deltascan -a view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24
98-
pipenv run deltascan -a view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24 -o export.<csv|pdf|html>
99+
pipenv run deltascan view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100
100+
pipenv run deltascan view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24
101+
pipenv run deltascan view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" -t 192.168.0.100/24 -o export.<csv|pdf|html>
99102

100103
# The below command brings only the open ports from the defined scans
101-
pipenv run deltascan -a view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" --port-type open -t 192.168.0.100
104+
pipenv run deltascan view -c config.yaml -p MY_PROFILE --from-date "2024-01-01 10:00:00" --to-date "2024-01-02 10:00:00" --port-type open -t 192.168.0.100
102105

103106
```
104107

105108
Import:
106109
```bash
107-
pipenv run deltascan -a import -i previous_exports.csv
108-
pipenv run deltascan -a import -i raw_nmap_results.xml
110+
pipenv run deltascan import -i previous_exports.csv
111+
pipenv run deltascan import -i raw_nmap_results.xml
112+
```
113+
Interactive shell options:
114+
115+
```bash
116+
deltascan>: ? # Display help
117+
Documented commands (type help <topic>):
118+
========================================
119+
clear diff exit imp q report view
120+
conf diff_files help profiles quit scan
121+
Interactive shell:
122+
deltascan>: conf # Display current configuration
123+
output_file: out_file.html
124+
template_file: None
125+
import_file: None
126+
diff_files: None
127+
n_scans: 1
128+
n_diffs: 1
129+
From date [fdate]: None
130+
To date [tdate]: None
131+
suppress: False
132+
host: 0.0.0.0
133+
profile: None
134+
deltascan>: conf suppress=true # Modify configuration value
135+
deltascan>: view # View result based on current configuration parameters
136+
# ... Results ...
137+
deltascan>: diff 1,2 # Difference between previous view results (always user suppress=True to find diff indexes)
138+
deltascan>: imp nmap_dump_file.0.0.0.0.xml # Import nmap dump file
139+
deltascan>: report # Report last results
140+
deltascan>: diff_files d1.xml,d2.xml # Differences between two nmap dump files
141+
deltascan>: profiles # List profiles in database
142+
deltascan>: scan 0.0.0.0 PROFILE # Scan with IP and profile
109143
```
110144

111145
### Documentation

data_for_html.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"field_names": [
3+
"Port",
4+
"State",
5+
"Service",
6+
"Service FP",
7+
"Service Product"
8+
],
9+
"scans": [
10+
{
11+
"uuid": "61cd5fb4-sddf-49cf-bda8-740b50d355f4",
12+
"results": {
13+
"hops": {
14+
"1": "10.0.0.0",
15+
"2": "17.0.0.0",
16+
"3": "17.0.0.1",
17+
"4": "17.0.0.2",
18+
"5": "18.0.0.3"
19+
},
20+
"status": "up",
21+
"last_boot": "none",
22+
"host": "0.0.0.1",
23+
"osfingerprint": "TEST_FINGERPRINT",
24+
"os": {
25+
"1": "OS2",
26+
"2": "OS2",
27+
"3": "OS3"
28+
},
29+
"ports": [
30+
{
31+
"servicefp": "none",
32+
"service": "service_name",
33+
"service_product": "Apache",
34+
"portid": "12",
35+
"proto": "tcp",
36+
"state": {
37+
"state": "open",
38+
"reason": "syn-ack",
39+
"reason_ttl": "43"
40+
}
41+
},
42+
{
43+
"servicefp": "none",
44+
"service": "service_name",
45+
"service_product": "Nginx",
46+
"portid": "13",
47+
"proto": "tcp",
48+
"state": {
49+
"state": "open",
50+
"reason": "syn-ack",
51+
"reason_ttl": "32"
52+
}
53+
}
54+
]
55+
},
56+
"arguments": "-sS -vv -n -A --osscan-guess --version-all -Pn -T4 -p12,13",
57+
"result_hash": "11f16af5472e3d1d1396234242a0jd3usio9d17de28ee4e1020c6a32359fd10f",
58+
"host": "0.0.0.1",
59+
"host_subnet": "0.0.0.0",
60+
"created_at": "2023-05-24 10:00:00",
61+
"profile_name": "IMPORTED_1711267305"
62+
}
63+
],
64+
"section_title": "Report for company",
65+
"section_info": "Information"
66+
}

deltascan/cli/cmd.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
TextColumn)
1515
from rich.text import Text
1616
from rich.columns import Columns
17+
import pkg_resources
1718
import threading
1819
import signal
1920
import select
@@ -288,8 +289,7 @@ def run():
288289
parser = argparse.ArgumentParser(
289290
prog='deltascan', description='A package for scanning deltas')
290291
parser.add_argument(
291-
"-a", "--action", help='the command to run',
292-
required=False, choices=['scan', 'diff', 'view', 'import'])
292+
"action", help='the command to run', choices=['scan', 'diff', 'view', 'import', 'version'])
293293
parser.add_argument("-o", "--output", help='output file', required=False)
294294
parser.add_argument("-d", "--diff-files",
295295
help='comma separated files to find their differences (xml)',
@@ -408,8 +408,13 @@ def run():
408408
_dscan = DeltaScan(config, ui_context, result)
409409

410410
try:
411+
_version = pkg_resources.require("deltascan")[0].version
412+
if clargs.action == "version":
413+
print(_version)
414+
os._exit(0)
415+
411416
print(BANNER.format(
412-
"version",
417+
_version,
413418
_dscan.stored_scans_count(),
414419
_dscan.stored_profiles_count(),
415420
clargs.profile,

deltascan/core/deltascan.py

+2
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ def view(self):
680680
to_date=self._config.tdate,
681681
from_date=self._config.fdate,
682682
pstate=self._config.port_type)
683+
if self._config.output_file is not None:
684+
self._report_scans(scans, output_file=f"scans_{self._config.output_file}")
683685

684686
return scans
685687
except DScanRDBMSEntryNotFound as e:

deltascan/core/importer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, filename, logger=None):
3232

3333
self.logger = logger if logger is not None else logging.basicConfig(**LOG_CONF)
3434
self._filename = filename
35-
self.store = store.Store()
35+
self.store = store.Store(self.logger)
3636
if filename.split(".")[-1] in [CSV, XML]:
3737
self._file_extension = filename.split(".")[-1]
3838
self._filename = filename[:-1*len(self._file_extension)-1]

deltascan/core/parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def extract_port_scan_dict_results(cls, results):
115115
scan["os"][str(_idx+1)] = _match["osmatch"]["name"]
116116
except (KeyError, IndexError):
117117
if len(scan["os"]) == 0:
118-
scan["os"] = ["none"]
118+
scan["os"] = {"1": "unknown"}
119119
else:
120120
pass
121121

@@ -125,7 +125,7 @@ def extract_port_scan_dict_results(cls, results):
125125
scan["hops"][str(_idx+1)] = _hop["ipaddr"]
126126
except (KeyError, IndexError):
127127
if len(scan["hops"]) == 0:
128-
scan["hops"] = ["none"]
128+
scan["hops"] = {"1": "unknown"}
129129
else:
130130
pass
131131

deltascan/core/store.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ def save_scans(self, profile_name, host_with_subnet, scan_data, created_at=None)
4949
try:
5050
_uuid = uuid.uuid4()
5151
json_scan_data = json.dumps(single_host_scan)
52-
single_host_scan["os"] = ["none"] if len(single_host_scan.get("os", [])) == 0 else single_host_scan.get("os", [])
52+
single_host_scan["os"] = {"1": "unknown"} if len(
53+
single_host_scan.get("os", {"1": "unknown"})) == 0 else single_host_scan.get("os", {"1": "unknown"})
5354
_n = self.store.create_port_scan(
5455
_uuid,
55-
single_host_scan.get("host", "none"),
56+
single_host_scan.get("host", "unknown"),
5657
host_with_subnet,
57-
single_host_scan.get("os", [])[0],
58+
single_host_scan.get("os", {})["1"],
5859
profile_name,
5960
json_scan_data,
6061
hash_string(json_scan_data),

deltascan/core/templates/scans_report.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ <h4>Scan report for {{ scan.host }}</h2>
6464
<p>Nmap arguments: {{ scan.arguments }}</p>
6565
<p>Profile: {{ scan.profile_name }}</p>
6666
<p>Date: {{ scan.created_at }}</p>
67-
67+
<p>Last boot: {{ scan.results.last_boot }}</p>
68+
<h4>Hops</h4>
69+
{% for khop, vhop in scan.results.hops.items() %}
70+
<p>{{ khop }}: {{ vhop }}</p>
71+
{% endfor %}
6872
<table>
6973
<thead>
7074
<tr>
@@ -83,6 +87,7 @@ <h4>Scan report for {{ scan.host }}</h2>
8387
<td>{{ row.service_product }}</td>
8488
</tr>
8589
{% endfor %}
90+
8691
</tbody>
8792
</table>
8893
</section>

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from setuptools import setup, find_packages
22

3+
34
setup(
45
name='deltascan',
5-
version='0.0.1',
6+
version='1.0.0-alpha',
67
description='A package for scanning deltas',
78
author='logisek',
89
url='https://github.com/Logisek/DeltaScan',

0 commit comments

Comments
 (0)