├── AdvancedPortScanner.py ├── BannerGrabber.py ├── PortScanner.py ├── PortScanner1000Ports.py ├── PortScannerInput.py └── README.md /AdvancedPortScanner.py: -------------------------------------------------------------------------------- 1 | #Advanced Port Scanner Optimized For Faster Scans 2 | #Script Usage: python AdvancedPortScanner.py -H 192.168.1.1 -P 22 3 | 4 | 5 | #!/usr/bin/env python 6 | 7 | from socket import * 8 | import optparse 9 | from threading import * 10 | 11 | 12 | def connScan(tgtHost,tgtPort): 13 | try: 14 | sock = socket(AF_INET, SOCK_STREAM) 15 | sock.connect((tgtHost, tgtPort)) 16 | print '[=>]%d/tcp open' % tgtPort 17 | except: 18 | print '[=>]%d/tcp closed' % tgtPort 19 | finally: 20 | sock.close() 21 | 22 | def portScan(tgtHost, tgtPorts): 23 | try: 24 | tgtIP = gethostbyname(tgtHost) 25 | 26 | except: 27 | print 'Cannot resolve the target %s' %tgtHost 28 | 29 | try: 30 | tgtName = gethostbyaddr(tgtIP) 31 | print '[=>] Scan results for : ' + tgtName[0] 32 | 33 | except: 34 | print '[=>] Scan results for: ' + tgtIP 35 | 36 | setdefaulttimeout(5) 37 | for tgtPort in tgtPorts: 38 | t = Thread(target=connScan, args=(tgtHost, int(tgtPort))) 39 | t.start() 40 | 41 | 42 | 43 | def main(): 44 | parser = optparse.OptionParser('Script usage: ' + ' -H -P ') 45 | parser.add_option('-H', dest='tgtHost', type='string', help='please sopecify the target IP') 46 | parser.add_option('-P', dest='tgtPort', type='string', help='please specify the target port') 47 | (options, args) = parser.parse_args() 48 | tgtHost = options.tgtHost 49 | tgtPort = str(options.tgtPort).split('.') 50 | 51 | if (tgtHost == None) | (tgtPort[0] == None): 52 | print parser.usage 53 | exit(0) 54 | portScan(tgtHost, tgtPort) 55 | 56 | if __name__ == '__main__': 57 | main() 58 | 59 | -------------------------------------------------------------------------------- /BannerGrabber.py: -------------------------------------------------------------------------------- 1 | #Simple Banner Grabber 2 | 3 | #!/usr/bin/python 4 | 5 | import socket 6 | 7 | def bannerGrab(ip, port): 8 | try: 9 | socket.setdefaulttimeout(5) 10 | s = socket.socket() 11 | s.connect((ip, port)) 12 | banner = s.recv(1024) 13 | return banner 14 | except: 15 | return 16 | 17 | def main(): 18 | ip = raw_input("[=>] Enter IP: ") 19 | port = str(raw_input("[=>] Enter Port: ")) 20 | for port in range (20, 100): 21 | banner = bannerGrab(ip, port) 22 | if banner: 23 | print "[=>] " + ip + "/" + str(port) + ": " + banner.strip('/n') 24 | exit() 25 | 26 | main() -------------------------------------------------------------------------------- /PortScanner.py: -------------------------------------------------------------------------------- 1 | #Basic Port Scanner 2 | 3 | #!/usr/bin/python 4 | 5 | import socket 6 | 7 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 8 | 9 | host = "192.168.1.1" 10 | port = 80 11 | 12 | def portScanner(port): 13 | if sock.connect_ex((host, port)): 14 | print "Port %d is closed" % (port) 15 | else: 16 | print "Port %d is open" % (port) 17 | 18 | portScanner(port) 19 | 20 | -------------------------------------------------------------------------------- /PortScanner1000Ports.py: -------------------------------------------------------------------------------- 1 | #Port Scanner That Scans The First 1000 Ports 2 | 3 | #!/usr/bin/python 4 | 5 | import socket 6 | 7 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 8 | socket.setdefaulttimeout(10) #Timeout is set to 10 seconds by default 9 | 10 | 11 | host = raw_input("[=>] Enter the IP address you want to scan: ") 12 | 13 | def portScanner(port): 14 | if sock.connect_ex((host, port)): 15 | print "Port %d is closed" % (port) 16 | else: 17 | print "Port %d is open" % (port) 18 | 19 | #Port range can be changed here 20 | for port in range(20, 1000): 21 | portScanner(port) 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /PortScannerInput.py: -------------------------------------------------------------------------------- 1 | #Basic Port Scanner With User Input Functionality 2 | 3 | #!/usr/bin/python 4 | 5 | import socket 6 | 7 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 8 | socket.setdefaulttimeout(10) #Timeout is set to 10 seconds by default 9 | 10 | 11 | host = raw_input("[=>] Enter the IP address you want to scan: ") 12 | port = int(raw_input("[=>] Enter the port you want to scan: ")) 13 | 14 | def portScanner(port): 15 | if sock.connect_ex((host, port)): 16 | print "Port %d is closed" % (port) 17 | else: 18 | print "Port %d is open" % (port) 19 | 20 | portScanner(port) 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PythonPentestingTools 2 | A collection of penetration testing tools written in Python 2. These are Python 2 scripts that are used in the Python For Penetration Testing Python Course on HackerSploit Academy. 3 | --------------------------------------------------------------------------------