-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrappy.py
148 lines (115 loc) · 4.9 KB
/
scrappy.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
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
import argparse
import textwrap
import sys
import json
from scapy.layers.l2 import Ether, ARP, srp
from scapy.layers.inet import IP, sr1, UDP, ICMP, TCP
from scapy.sendrecv import sniff
from scapy.layers.http import HTTPRequest
class Scrappy:
def __init__(self, args):
self.args = args
def run(self):
target = self.args.target
if not target:
sys.exit("no target specified")
if self.args.discoverhost:
self.discoverHost(target)
elif self.args.service:
self.discoverService(target)
elif self.args.os:
self.discoverOS(target)
elif self.args.pcap:
self.pcap(target)
def discoverHost(self, range):
answer, unanswer= srp( Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=range), timeout=10)
f = open(self.args.file, "a")
f.write("#### All hosts in your network ####\n" )
for sent, received in answer:
tempjson = {'IP': received.psrc, 'MAC': received.hwsrc}
f.write(json.dumps(tempjson)+"\n")
f.write("########################################################################\n")
f.close()
def discoverService(self, ip):
f = open(self.args.file, "a")
f.write(f"#### All open ports for host:{ip} ####\n")
for x in range(1,1025):
res = sr1( IP(dst=ip) / UDP(sport=x, dport=x), timeout=2 )
if res == None:
f.write(f"Port: {x} open / filtered\n")
else:
if res.haslayer(ICMP):
next()
elif res.haslayer(UDP):
f.write(f"Port: {x} open / filtered\n")
else:
f.write(f"Port: {x} status unknown\n")
f.write("########################################################################\n\n")
f.close()
def discoverOS(self, ip):
res = sr1( IP(dst=ip) / ICMP(id=100), timeout=10)
os = ""
if res :
if IP in res:
ttl = res.getlayer(IP).ttl
if ttl <= 64:
os = "Linux"
elif ttl > 64:
os = "Windows"
else:
os = None
if os is None or os =="":
sys.exit("no OS found")
f = open(self.args.file, "a")
f.write("#### OS detection ####\n")
f.write(f"host: {ip} has os: {os}\n")
f.write("########################################################################\n\n")
f.close()
def pcap(self, ip):
f= open(self.args.file, "a")
f.write("#### Sniff network for http traffic ####\n")
sniff(prn=self.process_packet, timeout=20)
def process_packet(self, packet):
f = open(self.args.file, "a")
if packet.haslayer(HTTPRequest):
ipS = packet[IP].src
ipD = packet[IP].dst
ttl = packet[IP].ttl
portS = packet[TCP].sport
portD = packet[TCP].dport
f.write(f"source: {ipS}:{portS}\tdestination: {ipD}:{portD}\t\ttime to life:{ttl}\n")
f.write("########################################################################\n\n")
f.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description= "A tool based on scapy",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog= textwrap.dedent('''
.'\ /`.
.'.-.`-'.-.`.
..._: .-. .-. :_...
.' '-.(o ) (o ).-' `. -- let's get scrappy
: _ _ _`~(_)~`_ _ _ :
: /: ' .-=_ _=-. ` ;\ :
: :|-.._ ' ` _..-|: :
: `:| |`:-:-.-:-:'| |:' :
`. `.| | | | | | |.' .'
`. `-:_| | |_:-' .'
`-._ ```` _.-'
``-------''
examples:
"python scrappy.py -t 0.0.0.0/24 -p" # Analyse the traffic on your network
"python scrappy.py -t 0.0.0.0 -o" # Discover what OS a host is using
"python scrappy.py -t 0.0.0.0 -s" # Perform a portscan on a specific host
"python scrappy.py -t 0.0.0.0/24 -d" # Discover all hosts in your network range
!if no file is given to write to(-f), default txt "scrrappy" will be used
'''))
parser.add_argument("-d", "--discoverhost", action= "store_true", help="search network for alive hosts")
parser.add_argument("-s", "--service", action= "store_true", help="port scan of a perticular host")
parser.add_argument("-o", "--os", action= "store_true", help="detect the operating system a host is using")
parser.add_argument("-p", "--pcap", action= "store_true", help="analysing of the present traffic")
parser.add_argument("-t", "--target", help="specify target to scan")
parser.add_argument("-f", "--file", default="Scrrappy.txt", help="specify which name to write findings to")
args = parser.parse_args()
scrappy = Scrappy(args)
scrappy.run()