Skip to content

Commit 6274cfe

Browse files
committed
Fix mistake with rescann and remove not used import
1 parent d363e86 commit 6274cfe

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Nmap_Vuln_Scanner_ServiceNow.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
2. Rescanning when there are probability of missing packets
1010
3. Checking if device is vulnerable using nmap scripts in provided file
1111
4. Gathering more information about device using nmap script port is opened and device is vulnerable.
12-
5. Script is checking site name from /root/script/site_lists base on discovered ip
13-
7. After detection of vulnerable device script will check if there is ticket in SeviceNow , if not it will create new one or if ticket has been resolved it will reopen it .
14-
8. Results are recorded in csv
12+
5. After detection of vulnerable device script will check if there is ticket in SeviceNow , if not it will create new one or if ticket has been resolved it will reopen it .
13+
6. Results are recorded in csv
1514
1615
1716
Usage:
@@ -48,7 +47,6 @@
4847
import sys
4948
import re
5049
import csv
51-
import ipaddress
5250
import logging
5351
import time
5452
import configparser
@@ -97,7 +95,7 @@
9795
SN_PASSWORD = CONFIG['DEFAULT']['SNpass']
9896
SN_INSTANCES = CONFIG['DEFAULT']['SNinstance']
9997

100-
def servicenow(computer_hostname, computer_ip, site_location, computer_domain, computer_workgroup, computer_os):
98+
def servicenow(computer_hostname, computer_ip, computer_domain, computer_workgroup, computer_os):
10199
'''
102100
Function is checking if there is already ticket for device if now create new one. If ticket is resolve it will reopen it if device is still vulnerable
103101
'''
@@ -106,7 +104,7 @@ def servicenow(computer_hostname, computer_ip, site_location, computer_domain, c
106104
incident = pysnow_c.resource(api_path='/table/incident')
107105
query_pysnow = 'problem_id='+CONFIG['nmap']['problem_id']+'^short_descriptionLIKE '+computer_hostname+' ^ORdescriptionLIKE '+computer_hostname+' '
108106
response = incident.get(query=query_pysnow)
109-
short_describtion = "Vulnerability for WannaCry for IP: "+computer_ip+" , Site: "+site_location+" , Computer Name: "+computer_hostname +" , Domain or workgoup: "+computer_domain+computer_workgroup+" , OS :"+computer_os
107+
short_describtion = "Vulnerability for WannaCry for IP: "+computer_ip+" , Computer Name: "+computer_hostname +" , Domain or workgoup: "+computer_domain+computer_workgroup+" , OS :"+computer_os
110108
describtion = "Computer is vulnerable. "
111109
new_record = {
112110
'short_description': short_describtion,
@@ -329,7 +327,7 @@ def nmap_sync_scan(local_line, local_row):
329327
if port_state == "filtered":
330328
port_filtered = str(port_nr)
331329
# when scanning large complex subnets, some ack can miss and it is marking open ports us filtered, need to scan againg it per ip is working fine. In normal enviroment it can be removed
332-
if host_status == "up" and port_filtered != "" and port_str == "":
330+
if host_status == "up" and port_filtered != "" and port_str == "":
333331
for port_nr in host_tcp:
334332
port_nr_str = str(port_nr)
335333
port_state = local_nm._scan_result['scan'][host]['tcp'][port_nr]['state']
@@ -342,13 +340,14 @@ def nmap_sync_scan(local_line, local_row):
342340
logging.info(host+",Scan_error,"+port_nr_str)
343341
else:
344342
r4_rescan = local_nm3._scan_result['scan'][host]['tcp']
345-
for port_nr_rescan in r4_rescan:
346-
port_state = local_nm3._scan_result['scan'][host]['tcp'][port_nr_rescan]['state']
343+
344+
if port_nr_str in str(r4_rescan):
345+
port_state = local_nm3._scan_result['scan'][host]['tcp'][port_nr]['state']
347346
if port_state == "open":
348-
port_str = str(port_nr_rescan)
347+
port_str = str(port_nr)
349348
print("rescanned "+str(host) +" "+port_str)
350-
GLOBAL_COUNTER_RESCAN = GLOBAL_COUNTER_RESCAN+1
351-
#if ports are open start smb discovery scripit
349+
GLOBAL_COUNTER_RESCAN = GLOBAL_COUNTER_RESCAN+1
350+
#if ports are open start smb discovery scripit
352351
print(host+","+host_status+","+port_state+",")
353352
if host_status == "up" and port_state == "open":
354353
local_nm2.scan(host, port_str, "--script "+local_row[1])

0 commit comments

Comments
 (0)