-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (63 loc) · 2.47 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import asyncio
from sys import stdout
from common.messaging.vumos.vumos import VumosServiceStatus
import shlex
import json
from common.messaging.vumos import ScheduledVumosService
loop = asyncio.get_event_loop()
async def task(service: ScheduledVumosService, _: None = None):
print("Performing scan...")
# Get domains
domains: str = service.get_config("domains")
domains = domains.split(',')
domains = list(map(lambda d: d.strip(), domains))
for domain in domains:
# Set status
print(f"Scanning domain {domain}")
service.set_status(VumosServiceStatus(
"running", f"scanning domain {domain}"))
# Perform scan, sending json output to stdout
amass = await asyncio.subprocess.create_subprocess_shell(f"amass enum -nolocaldb -noalts -d {shlex.quote(domain)} -json /dev/stdout",
stdout=asyncio.subprocess.PIPE)
# Parse stdout while subprocess is running
while True:
data = await amass.stdout.readline()
if len(data) == 0:
break
line = data.decode('utf-8').rstrip()
# If it is a json parseable line
try:
data = json.loads(line)
for address in data["addresses"]:
ip = address["ip"]
# Ignore anything other than ipv4 addresses
if len(ip.split(".")) != 4:
continue
await service.send_target_data(ip, [data["name"]], {
data["name"]: {
"amass-tag": data["tag"],
"amass-sources": data["sources"]
}
})
except:
pass
await amass.wait()
print("Finished scan")
# Initialize Vumos service
service = ScheduledVumosService(
"Periodic Amass Scanner",
"A amass scanners that performs extensive DNS enumerations on a list of domains periodically",
conditions=lambda s: True, task=task, parameters=[
{
"name": "Domains",
"description": "List of domains to perform enumerations on",
"key": "domains",
"value": {
"type": "string",
"default": "default.local"
}
}],
pool_interval=60 * 60 * 24 # Runs task every day
)
loop.run_until_complete(service.connect(loop))
service.loop(loop)