-
Notifications
You must be signed in to change notification settings - Fork 16
/
censys_ip.py
55 lines (48 loc) · 1.65 KB
/
censys_ip.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
import itertools
from recon.core.module import BaseModule
from censys.search import CensysHosts
from censys.common.exceptions import CensysException
def grouper(n, iterable):
# via https://stackoverflow.com/a/8991553
it = iter(iterable)
while True:
chunk = tuple(itertools.islice(it, n))
if not chunk:
return
yield chunk
class Module(BaseModule):
meta = {
"name": "Censys - Ports by IP",
"author": "Censys, Inc. <support@censys.io>",
"version": 2.1,
"description": (
"Retrieves the open ports for each IP address. "
"Updates the 'ports' table with the results."
),
"query": (
"SELECT DISTINCT ip_address FROM hosts WHERE ip_address IS NOT"
" NULL"
),
"required_keys": ["censysio_id", "censysio_secret"],
"dependencies": ["censys>=2.1.2"],
}
def module_run(self, hosts):
api_id = self.get_key("censysio_id")
api_secret = self.get_key("censysio_secret")
c = CensysHosts(api_id, api_secret)
for ip in hosts:
ip = ip.strip('"')
self.heading(ip, level=0)
try:
host = c.view(ip)
except CensysException:
self.print_exception()
continue
for service in host.get("services", []):
self.insert_ports(
ip_address=ip,
port=service["port"],
protocol=service["transport_protocol"],
banner=service.get("banner"),
notes=service["service_name"],
)