forked from UbuntuEvangelist/KatanaFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.py
executable file
·413 lines (356 loc) · 16.1 KB
/
Function.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/usr/bin/env python2
#HEAD#########################################################
#
# Katana Framework | API functions
# Last Modified: 23/12/2016
#
#########################################################HEAD#
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
from Design import *
from Config import *
from Default import *
from lib.adb.adb import adb_commands
import xml.etree.ElementTree as ET
from sys import stdout
import fcntl ,struct ,readline,rlcompleter,subprocess
import threading ,StringIO ,httplib ,commands ,random ,re , json
import logging ,urllib ,socket ,time ,sys
from Internal import (
Maquetar,
saveRegister,
MakeTable,
G_KTFVAR
)
AGENT_ARRAY=[]
File_Agent_Open=False
NUMBER_AGENTS=0
ap_list = []
prks = printk()
class NET:
def CheckConnectionHost(self, defaulthost, defaultport, timeout):
try :
redTEST=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
redTEST.settimeout(timeout)
redTEST.connect((defaulthost, int(defaultport)))
redTEST.close()
return True
except: return False
return False
def StartMonitorMode(self,interface):
state=commands.getoutput("airmon-ng start "+interface)
if state.find("monitor mode enabled"):return True
return False
def InterfaceSupportAPMode(self):
output = commands.getoutput('iw list | grep "* AP"')
if len(output) > 0 : return True
prk.err("You device not support AP mode.")
return False
def GetLocalIp(self):
SocCKet = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
SocCKet.connect(("google.com",80))
if True:
IP_Address=SocCKet.getsockname()[0]
SocCKet.close()
return IP_Address
except:
SocCKet.close()
return "NULL"
def GetPublicIp(self):
try:
site = urllib.urlopen("http://checkip.dyndns.org/").read()
grab = re.findall('([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)', site)
address = grab[0]
return address
except:
return "NULL"
def GetInterfacesOnSystem(self):
Interfaces=commands.getoutput("netstat -i | awk '{print $1}'")
Interfaces=Interfaces.replace("\n",",")
Interfaces=Interfaces.replace("Kernel,Iface,","")
Interfaces=Interfaces.split(",")
if len(Interfaces) >= 0:
return Interfaces
return "NULL"
def CheckIfExistInterface(self,device):
devices=commands.getoutput("netstat -i | awk '{print $1}'")
devices=devices.split("\n")
for interface in devices:
if device == interface : return True
NoDeviceFound(device)
return False
def GetMonitorInterfaces(self):
Monitor=commands.getoutput("airmon-ng | grep 'mon' | awk '{print $2}'")
Monitor=Monitor.split("\n")
if len(Monitor) >= 0:
return Monitor
return "NULL"
def GetLanIps(self,output):
test=isConect()
count=0
if test!=False:
array_ip=[]
commands.getoutput('nmap -sn '+test+'/24 -oX tmp/ips.xml > null')
xmldoc = minidom.parse('tmp/ips.xml')
itemlist = xmldoc.getElementsByTagName('address')
for s in itemlist:
ip=s.attributes['addr'].value
if ip!=test:
array_ip.append(ip)
if output==1 and test!=False:
for ip in array_ip:
if ip.find(":") <= 0 :
mac=ip
if get_gateway(2)==mac:
mac+="]["+colors.B+"GATEWAY"+colors.W
else:
count=count+1
print " [ "+str(count),"] Host's up : ["+mac+"]["+ip+"]"
commands.getoutput('rm tmp/ips.xml > null')
else:
return False
def GetGateway(self):
ip_r_l=subprocess.Popen("ip r l",shell=True,stdout=subprocess.PIPE).communicate()[0]
s = StringIO.StringIO(ip_r_l)
for line in s:
if "default" in line:
gateway = re.search(r'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b',line).group(0)
return gateway
return "NULL"
def AmIConectedToANetwork(self):
ip_r_l=subprocess.Popen("ip r l",shell=True,stdout=subprocess.PIPE).communicate()[0]
s = StringIO.StringIO(ip_r_l)
for line in s:
if "default" in line:
return True
prk.err("you not is connected to a network.\n")
return False
def GetMacAddress(self):
if self.AmIConectedToANetwork()!=False:
my_macs = [get_if_hwaddr(i) for i in get_if_list()]
for maca in my_macs:
if(maca != "00:00:00:00:00:00"):
return maca
return "NULL"
def CheckWebStatus(self,host, port, filerequest):
connection = httplib.HTTPConnection(host,port)
connection.request("GET", "/"+filerequest)
response = connection.getresponse()
code = response.status
description = ["unknowk","unknowk"]
if code == 200 : description = [ "OK" , "Suf" ]
if code == 201 : description = [ "Created" , "Suf" ]
if code == 202 : description = [ "Accepted" , "Suf" ]
if code == 203 : description = [ "Non/Authoritative Information (HTTP/1.1)" , "Suf" ]
if code == 204 : description = [ "No Content" , "Suf" ]
if code == 205 : description = [ "Reset Content" , "Suf" ]
if code == 206 : description = [ "Partial Content" , "Suf" ]
if code == 207 : description = [ "Multi/Status (Multi/Status, WebDAV)" , "Suf" ]
if code == 208 : description = [ "Already Reported (WebDAV)" , "Suf" ]
if code == 300 : description = [ "Multiple Choices" , "Inf:Redirection" ]
if code == 301 : description = [ "Moved Permanently" , "Inf:Redirection" ]
if code == 302 : description = [ "Found" , "Inf:Redirection" ]
if code == 303 : description = [ "See Other (from HTTP/1.1)" , "Inf:Redirection" ]
if code == 304 : description = [ "Not Modified" , "Inf:Redirection" ]
if code == 305 : description = [ "Use Proxy (desde HTTP/1.1)" , "Inf:Redirection" ]
if code == 306 : description = [ "Switch Proxy" , "Inf:Redirection" ]
if code == 307 : description = [ "Temporary Redirect (desde HTTP/1.1)" , "Inf:Redirection" ]
if code == 308 : description = [ "Permanent Redirect" , "Inf:Redirection" ]
if code == 400 : description = [ "Bad Request" , "Inf:Redirection" ]
if code == 401 : description = [ "Unauthorized" , "Err:Client" ]
if code == 402 : description = [ "Payment Required" , "Err:Client" ]
if code == 403 : description = [ "Forbidden" , "Err:Client" ]
if code == 404 : description = [ "Not Found" , "Err:Client" ]
if code == 405 : description = [ "Method Not Allowed" , "Err:Client" ]
if code == 406 : description = [ "Not Acceptable" , "Err:Client" ]
if code == 407 : description = [ "Proxy Authentication Required" , "Err:Client" ]
if code == 408 : description = [ "Request Timeout" , "Err:Client" ]
if code == 409 : description = [ "Conflict" , "Err:Client" ]
if code == 410 : description = [ "Gone" , "Err:Client" ]
if code == 411 : description = [ "Length Required" , "Err:Client" ]
if code == 412 : description = [ "Precondition Failed" , "Err:Client" ]
if code == 413 : description = [ "Request Entity Too Large" , "Err:Client" ]
if code == 414 : description = [ "Request/URI Too Long" , "Err:Client" ]
if code == 415 : description = [ "Unsupported Media Type" , "Err:Client" ]
if code == 416 : description = [ "Requested Range Not Satisfiable" , "Err:Client" ]
if code == 417 : description = [ "Expectation Failed" , "Err:Client" ]
if code == 418 : description = [ "I'm a teapot" , "Err:Client" ]
if code == 422 : description = [ "Unprocessable Entity (WebDAV / RFC 4918)" , "Err:Client" ]
if code == 423 : description = [ "Locked (WebDAV / RFC 4918)" , "Err:Client" ]
if code == 424 : description = [ "Failed Dependency (WebDAV) (RFC 4918)" , "Err:Client" ]
if code == 425 : description = [ "Unassigned" , "Err:Client" ]
if code == 426 : description = [ "Upgrade Required (RFC 7231)" , "Err:Client" ]
if code == 428 : description = [ "Precondition Required" , "Err:Client" ]
if code == 429 : description = [ "Too Many Requests" , "Err:Client" ]
if code == 431 : description = [ "Request Header Fileds Too Large)" , "Err:Client" ]
if code == 451 : description = [ "Unavailable for Legal Reasons" , "Err:Client" ]
if code == 500 : description = [ "Internal Server Error" , "Err:Server" ]
if code == 501 : description = [ "Not Implemented" , "Err:Server" ]
if code == 502 : description = [ "Bad Gateway" , "Err:Server" ]
if code == 503 : description = [ "Service Unavailable" , "Err:Server" ]
if code == 504 : description = [ "Gateway Timeout" , "Err:Server" ]
if code == 505 : description = [ "HTTP Version Not Supported" , "Err:Server" ]
if code == 506 : description = [ "Variant Also Negotiates (RFC 2295)" , "Err:Server" ]
if code == 507 : description = [ "Insufficient Storage (WebDAV / RFC 4918)" , "Err:Server" ]
if code == 508 : description = [ "Loop Detected (WebDAV)" , "Err:Server" ]
if code == 510 : description = [ "Not Extended (RFC 2774)" , "Err:Server" ]
if code == 511 : description = [ "Network Authentication Required" , "Err:Server" ]
if (description[1]=="Err:Server"):
prk.err("Connection : "+description[0])
return False
if (description[1]=="Err:Client"):
prk.war("Connection : "+description[0])
return False
if (description[1]=="Suf") :
prk.suff("Connection : "+description[0])
return True
class UTIL:
def sRegister(self,init,goal):
saveRegister(init,goal)
def CheckProjectInstalled(self,project):
status=subprocess.call("if ! hash "+project+" 2>/dev/null; then echp 3 >/dev/null 2>&1 ; fi", shell=True)
if status==0:
return True
else:
return False
def CheckIfIsMacAddress(self,mac):
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower()): return True
return False
class GRAPHICAL:
def CreateTable(self,table):
MakeTable(table)
class COM:
def ListDevicesConnectADB(self):
try:
NumberDevice=0
LIST = ""
for d in adb_commands.AdbCommands.Devices():
NumberDevice+=1
LIST += (' %s) %s\t device\t%s' % (NumberDevice, d.serial_number, ','.join(str(p) for p in d.port_path)))
return LIST
except:N=2
class WIFI:
def get_aps(mon,timeout):
commands.getoutput('rm '+FOLDER_KATANA+'tmp/*.netxml')
prk.inf("Scanning Access Points in Interface '"+mon+"', Please wait "+str(timeout)+"seg")
Subprocess("airodump-ng "+mon+" -w '"+FOLDER_KATANA+"tmp/ktf.wifi' --wps --output-format netxml --write-interval "+str(timeout))
time.sleep(timeout+1)
APCOUNTER = 0
CLCOUNTER = 0
ESSIDs = []
BSSIDs = []
MANUs = []
CHANNELs = []
ENCRYPTAIONs = []
PWRs = []
CLIENTMACs = []
CLIENTMANs = []
CLIENTESSs = []
tree = ET.parse(FOLDER_KATANA+'tmp/ktf.wifi-01.kismet.netxml')
root = tree.getroot()
try:
Space()
b = [["#","MAC","CH","PWR","ENCRYPTION","VENDOR","ESSID"]]
for network in root.findall('wireless-network'):
if network.get('type')=="infrastructure":
for essid in network.findall('SSID'):
APCOUNTER += 1
if essid.find('essid') is not None:
ESSIDs.append(essid.find('essid').text)
else:
ESSIDs.append("NULL")
if essid.find('encryption') is not None:
ENCRYPTAIONs.append(essid.find('encryption').text)
else:
ENCRYPTAIONs.append("NULL")
for network in root.findall('wireless-network'):
if network.get('type')=="infrastructure":
BSSIDs.append(network.find('BSSID').text)
MANUs.append(network.find('manuf').text)
CHANNELs.append(network.find('channel').text)
for network in root.findall('wireless-network'):
if network.get('type')=="infrastructure":
for essid in network.findall('snr-info'):
PWRs.append(essid.find('last_signal_rssi').text)
for network in root.findall('wireless-network'):
if network.get('type')=="probe":
for probe in network.findall('wireless-client'):
CLCOUNTER+=1
CLIENTMACs.append(probe.find('client-mac').text)
CLIENTMANs.append(probe.find('client-manuf').text)
for essid in probe.findall('SSID'):
if essid.find('ssid') is not None:
CLIENTESSs.append(essid.find('ssid').text)
else:
CLIENTESSs.append("NULL")
LIST=0
while LIST < APCOUNTER:
b += [[str(LIST),str(BSSIDs[LIST]),str(CHANNELs[LIST]),str(PWRs[LIST]),str(ENCRYPTAIONs[LIST]),str(MANUs[LIST]),str(ESSIDs[LIST])]]
LIST+=1
b += [["","","","","","",""]]
b += [["#","MAC","","","","VENDOR","PROBE"]]
b += [["","","","","","",""]]
LIST=0
while LIST < CLCOUNTER:
b += [[str(LIST),str(CLIENTMACs[LIST]),"","","",str(CLIENTMANs[LIST]),str(CLIENTESSs[LIST])]]
LIST+=1
Maquetar(b)
commands.getoutput('killall airodump-ng')
except:FAIL=1292
class SYSTEM:
def Command_exe(self,msg,cmd,std):
i = "\033[1mSTATUS"+colors[0]+":[Processing]"
stdout.write(" " + information + " " + msg + " %s" % i)
stdout.flush()
if std:status_1=subprocess.call(cmd, shell=True)
else :status_1=subprocess.call(cmd+' >/dev/null 2>&1', shell=True)
if status_1==0:
i = "[\033[1m"+colors[2]+"OK"+colors[0]+"]"+colors[0]
else:
i = "["+colors[1]+"\033[1mERROR"+colors[0]+"]"+colors[0]+"["+colors[3]+"\033[1mWARNING"+colors[0]+"]"
stdout.write("\r" + " " + information + " " + msg +" STATUS:%s \r" % i)
stdout.write(" |\n")
def Rtask(self,process):
xtem=""
if XTERM_OPTION:xtem="xterm -e "
commands.getoutput(xtem+process)
def Subprocess(self,process):
Hire=threading.Thread(target=self.Rtask, args=(process,))
Hire.start()
def KillProcess(self,process):
commands.getoutput("killall "+process)
class WEB:
def RamdonAgent(self):
global NUMBER_AGENTS,File_Agent_Open
NUMBER_AGENTS=0
if File_Agent_Open==False:
with open(AGENTS_BROWSER,'r') as AGENT_LIST:
for AGENT in AGENT_LIST:
NUMBER_AGENTS=1+NUMBER_AGENTS
AGENT_ARRAY.append(AGENT.replace("\n",""))
File_Agent_Open=True
Generate = 0
Generate = random.randint(0, NUMBER_AGENTS)
return AGENT_ARRAY[Generate]
### API EXECUTE FUNCTION ####################################################################################################
def Executefunction(query):
NET_API = NET()
WIFE_API= WIFI()
try:
if query[len("f::"):len("get_aps")+len("f::")] == "get_aps":
query = query[len("f::")+len("get_aps"):].replace("(","").replace(")","").split(",")
WIFE_API.get_aps(str(query[0]),int(query[1]))
elif query[len("f::"):len("start_monitor")+len("f::")] == "start_monitor":
query = query[len("f::")+len("start_monitor"):].replace("(","").replace(")","").split(",")
if NET_API.StartMonitorMode(query[0]):prks.suff(str(query[0])+" now is in monitor mode.")
else:NoDeviceFound(query[0])
elif query[len("f::"):len("get_interfaces")+len("f::")] == "get_interfaces": print " ",NET_API.GetInterfacesOnSystem()
elif query[len("f::"):len("get_monitors_mode")+len("f::")] == "get_monitors_mode": print " ",NET_API.GetMonitorInterfaces()
elif query[len("f::"):len("get_local_ip")+len("f::")] == "get_local_ip": print " ",NET_API.GetLocalIp()
elif query[len("f::"):len("get_external_ip")+len("f::")] == "get_external_ip": print " ",NET_API.GetPublicIp()
elif query[len("f::"):len("get_gateway")+len("f::")] == "get_gateway": print " ",NET_API.GetGateway()
else:functionNotFound()
except Exception:print " "+warning+" Check Again your Functions command."
##############################################################################################################################