-
Notifications
You must be signed in to change notification settings - Fork 0
/
stealth_scan.py
29 lines (26 loc) · 1001 Bytes
/
stealth_scan.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
#! /bin/python
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
if len(sys.argv) != 3:
print("python stealth_scan.py <ip> <ports>")
exit()
src_port = RandShort()
dst_ip = sys.argv[1]
ports = sys.argv[2]
ports.replace(" ", "")
scanPorts = ports.strip().split(':')
for port in scanPorts:
response = sr1(IP(dst=dst_ip)/TCP(sport=src_port,dport=int(port),flags="S"))
if(str(type(response))=="<type 'NoneType'>"):
print(port+" Port Filtered")
elif(response.haslayer(TCP)):
if(response.getlayer(TCP).flags == 0x12):
send_rst=sr1(IP(fst=dst_ip)/TCP(sport=src_port,dport=int(port),flags="R"))
print(port+" Port Open")
elif(response.getlayer(TCP).flags == 0x14):
print(port+" Port Closed")
elif(response.haslayer(ICMP)):
if(int(response.getLayer(ICMP).type)==3 and
int(response.getLayer(ICMP).code) in [1, 2, 3, 9, 10, 13]):
print (port+": Filtered")