-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullscan.py
65 lines (52 loc) · 2.14 KB
/
fullscan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import datetime
from modules.vulns import nuclei_active
from subs import db_get_modified, nuclei_notify
import logging
import compare
import random
import math
import os
def alert(nuclei_hits, chunk_index, chunks_len):
nuclei_notify(
nuclei_hits,
lambda x: f'{x["scope"]}: {x["matched-at"]} [{x["info"]["severity"]}] {x["template-id"]} {x.get("matcher-name","")} {x.get("extracted-results","")}',
f"FullScan chunk {chunk_index}/{chunks_len}\n"
)
def fullscan(hosts):
nuclei_hits = list(nuclei_active(config['fullscan']['nuclei_cmd'], hosts))
#new nuclei hits
up_fields = ["template-id","info","type","matcher-name","host","matched-at","meta","extracted-results","interaction","scope","curl-command"]
index_fields = ["template-id","matcher-name","matched-at"]
nuclei_hits_new = db_get_modified(nuclei_hits, db['nuclei_hits'], index_fields, up_fields, compare.nuclei_hit)
return nuclei_hits
if __name__ == "__main__":
from config import config, scopes, db, glob, alerter
os.makedirs(glob.tmp_dir, exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt='%Y-%m-%d %H:%M',
handlers=[
logging.StreamHandler(),
logging.FileHandler(glob.tmp_dir + '/fullscan.log', 'w')
]
)
ndaysago = datetime.datetime.now() - datetime.timedelta(days=config['fullscan']['host_alive_in_days'])
q = {"last_alive": {"$gte": ndaysago}}
db_res = db['http_probes'].find(q)
http_probes = list(db_res)
random.shuffle(http_probes)
allc = len(http_probes)
# medium chunk size
chunks_num = math.ceil(allc / config['fullscan']['chunk_max'])
chunk_size = math.ceil(allc / chunks_num)
logging.info(f"Fullscan of {len(http_probes)} with chunk medium size {chunk_size}")
chi = 1
for i in range(0, allc, chunk_size):
logging.info(f"start chunk {chi}/{chunks_num}")
x = i
chunk = http_probes[x:x+chunk_size]
nuclei_hits = fullscan(chunk)
if len(nuclei_hits) > 0:
alert(nuclei_hits, chi, chunks_num)
chi += 1