-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscanning.py
More file actions
executable file
·208 lines (167 loc) · 5.68 KB
/
scanning.py
File metadata and controls
executable file
·208 lines (167 loc) · 5.68 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python3
# nmap Scanning Module
# %%%%%%%%%%% Libraries %%%%%%%%%%%#
import re
import nmap
import urllib3
import logging
import globals
import requests
from colorama import Fore
from colorama import Style
from globals import http
from globals import https
from globals import SEPARATOR
from globals import HTTPS_TCP_PORT
from globals import SPLUNK_TCP_PORT
from globals import GRAYLOG_TCP_PORT
from globals import ELASTIC_TCP_PORT
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# %%%%%%%%%%% Functions %%%%%%%%%%%#
def input_ip():
siemip = input(
Fore.CYAN + Style.NORMAL + "[!] Enter IP address of the SIEM: ")
if re.search(globals.ip_val, siemip):
return siemip
else:
return ''
def input_port():
siemport = input(
Fore.CYAN + Style.NORMAL +
"[!] Enter Port use of the SIEM: {Enter for default}")
if siemport == '':
siemport = 0
return siemport
elif 0 <= int(siemport) <= 65535:
return siemport
else:
return ''
def input_net():
siemnet = input(
Fore.CYAN + Style.NORMAL +
"[!] Enter network to scan for SIEMs in CIDR notation, "
"for example: 192.168.1.0/24: ")
return siemnet
def scan_host(ip, port):
siemdetected = "None"
siemip = ip
siemport = port
try:
argument = \
'-sT -T4 -Pn -p ' + str(HTTPS_TCP_PORT) + ',' + \
str(GRAYLOG_TCP_PORT) + ',' + str(SPLUNK_TCP_PORT) + ',' + \
str(ELASTIC_TCP_PORT) + ',' + str(siemport)
nm = nmap.PortScanner()
nm.scan(hosts=siemip, arguments=argument)
if nm[
siemip]['tcp'][SPLUNK_TCP_PORT]['state'] == 'open' or nm[
siemip]['tcp'][HTTPS_TCP_PORT]['state'] == 'open' or nm[
siemip]['tcp'][GRAYLOG_TCP_PORT]['state'] == 'open' or nm[
siemip]['tcp'][ELASTIC_TCP_PORT]['state'] == 'open' or nm[
siemip]['tcp'][int(siemport)]['state'] == 'open':
print('[!] IP Address: %s' % ip)
print('[!] Hostname: %s' % nm[siemip].hostname())
print('[!] State: %s' % nm[siemip].state())
print(SEPARATOR)
if nm[siemip]['tcp'][SPLUNK_TCP_PORT]['state'] == 'open':
siemdetected = splunk_detect(siemip, str(SPLUNK_TCP_PORT))
elif nm[siemip]['tcp'][GRAYLOG_TCP_PORT]['state'] == 'open':
siemdetected = graylog_detect(siemip, str(GRAYLOG_TCP_PORT))
elif nm[siemip]['tcp'][ELASTIC_TCP_PORT]['state'] == 'open':
siemdetected = elasticsiem_detect(siemip, str(ELASTIC_TCP_PORT))
elif nm[siemip]['tcp'][HTTPS_TCP_PORT]['state'] == 'open':
siemdetected = ossim_detect(siemip, str(HTTPS_TCP_PORT))
siemdetected = qradar_detect(siemip, str(HTTPS_TCP_PORT))
siemdetected = mcafee_detect(siemip, str(HTTPS_TCP_PORT))
siemdetected = smonster_detect(siemip, str(HTTPS_TCP_PORT))
elif nm[
siemip]['tcp'][int(siemport)]['state'] == 'open' and siemport == str(port):
siemdetected = splunk_detect(siemip, port)
siemdetected = graylog_detect(siemip, port)
siemdetected = ossim_detect(siemip, port)
siemdetected = qradar_detect(siemip, port)
siemdetected = mcafee_detect(siemip, port)
siemdetected = smonster_detect(siemip, port)
siemdetected = elasticsiem_detect(siemip, port)
except Exception as e:
logging.error(e, exc_info=True)
return siemdetected
def splunk_detect(siemip, siemport):
url = https + siemip + ":" + siemport
try:
response = requests.get(url, verify=False)
if "splunkd" in response.text:
siemdetected = "Splunk"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def graylog_detect(siemip, siemport):
url = http + siemip + ":" + siemport
try:
response = requests.get(url)
if "Graylog Web Interface" in response.text:
siemdetected = "Graylog"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def elasticsiem_detect(siemip, siemport):
url = http + siemip + ":" + siemport + '/app/siem'
try:
response = requests.get(url)
if "Elastic" in response.text and "elasticsiem" in response.headers[
'kbn-name']:
siemdetected = "ElasticSIEM"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def ossim_detect(siemip, siemport):
url = https + siemip + ":" + siemport + "/ossim/session/login.php"
try:
response = requests.get(url, verify=False)
if "AlienVault OSSIM" in response.text:
siemdetected = "OSSIM"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def qradar_detect(siemip, siemport):
url = https + siemip + ":" + siemport + "/console/"
try:
response = requests.get(url, verify=False)
if "QRadar" in response.headers['Server']:
siemdetected = "QRadar"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def mcafee_detect(siemip, siemport):
url = https + siemip + ":" + siemport
try:
response = requests.get(url, verify=False)
if 'McAfee' in response.text and 'SIEM' in response.text:
siemdetected = "McAfee"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def smonster_detect(siemip, siemport):
url = https + siemip + ":" + siemport
try:
response = requests.get(url, verify=False)
if 'title>SIEMonster ' in response.text:
siemdetected = "SIEMonster"
globals.messages(5, [siemdetected, siemport])
return siemdetected
except Exception as e:
logging.error(e, exc_info=True)
def scan_network(siemnet):
try:
nm = nmap.PortScanner()
nm.scan(hosts=siemnet, arguments='-PS -Pn -p 8089,443,9000')
return nm.all_hosts()
except Exception as e:
logging.error(e, exc_info=True)
# %%%%%%%%%% The End %%%%%%%%%%#