├── Basic_python_tips └── readme.md ├── Encryption └── XOR_encryption.py ├── Meet_Scapy ├── first_face.py ├── readme.md ├── s_and_r.py └── s_and_r1.py ├── TCP Port Connect ├── TCP_Port_Scan_using_nmap.py └── TCP_Port_Scanner.py ├── UNIX_Password_Cracker └── UNIX_Password_Cracker.py ├── Zip_Password_Cracker └── Zip_Password_Cracker.py └── readme.md /Basic_python_tips/readme.md: -------------------------------------------------------------------------------- 1 | #Python tips 2 | 3 | - In python latest result can be called back again with _ (underscore) 4 | -------------------------------------------------------------------------------- /Encryption/XOR_encryption.py: -------------------------------------------------------------------------------- 1 | from itertools import izip, cycle 2 | 3 | def xor(data, key): 4 | return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key))) 5 | def xor3(s,t): 6 | """xor two strings together""" 7 | return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t)) 8 | 9 | def xor2(s, key): 10 | output = "" 11 | length = len(key) 12 | j=0 13 | for i in range(0, len(s)): 14 | if j -p ' ) 11 | parser.add_option( '-H', dest = 'tgtHost', type = "string", help = 'Specify target host' ) 12 | parser.add_option( '-p', dest = 'tgtPort', type = "string", help = 'Specify target port seperated by comma, e.g. 21,22,23' ) 13 | ( options, args ) = parser.parse_args() 14 | tgtHost = options.tgtHost 15 | tgtPorts = str(options.tgtPort).split(',') 16 | if( tgtHost == None ) | ( tgtPorts[0] == None ): 17 | print parser.usage 18 | exit(0) 19 | for tgtPort in tgtPorts: 20 | nmapScan( tgtHost, tgtPort ) 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /TCP Port Connect/TCP_Port_Scanner.py: -------------------------------------------------------------------------------- 1 | import optparse 2 | from socket import * 3 | from threading import * 4 | 5 | screenLock = Semaphore( value = 1 ) 6 | 7 | def connScan( tgtHost, tgtPort ): 8 | try: 9 | connSkt = socket( AF_INET, SOCK_STREAM) 10 | connSkt.connect( ( tgtHost, tgtPort ) ) 11 | connSkt.send( 'ViolentPython\r\n' ) 12 | results = connSkt.recv( 100 ) 13 | screenLock.acquire() 14 | print '[+]%d/tcp open'% tgtPort 15 | print '[+] ' + str(results) 16 | except: 17 | screenLock.acquire() 18 | print '[-]%d/tcp closed'%tgtPort 19 | finally: 20 | screenLock.release() 21 | connSkt.close() 22 | 23 | def portScan( tgtHost, tgtPorts ): 24 | try: 25 | tgtIP = gethostbyname( tgtHost ) 26 | except: 27 | "[-] Cannot resolve '%s': Unknown Host"% tgtHost 28 | return 29 | try: 30 | tgtName = gethostbyaddr( tgtIP ) 31 | print '\n[+] Scan Results for:' + tgtName[0] 32 | except: 33 | print '\n[+] Scan Results for:' + tgtIP 34 | setdefaulttimeout(1) 35 | for tgtPort in tgtPorts: 36 | t = Thread( target = connScan, args = ( tgtHost, int( tgtPort ) ) ) 37 | print 'Scanning Port ' + tgtPort 38 | t.start() 39 | 40 | def main(): 41 | parser = optparse.OptionParser( "usage%prog"+ "-H -p ") 42 | parser.add_option('-H',dest='tgtHost',type="string", help="Specify a target host") 43 | parser.add_option('-p',dest='tgtPort',type="string", help="Specify target ports seperated by commas E.g. 21,22,23") 44 | (options, args) = parser.parse_args() 45 | tgtHost = options.tgtHost 46 | tgtPorts = str( options.tgtPort ).split(',') 47 | if( tgtHost == None ) | (tgtPorts[0] == None): 48 | print '[-] You must specify a target host and target port(s)' 49 | exit(0) 50 | portScan( tgtHost, tgtPorts ) 51 | 52 | if __name__ == '__main__' : 53 | main() 54 | -------------------------------------------------------------------------------- /UNIX_Password_Cracker/UNIX_Password_Cracker.py: -------------------------------------------------------------------------------- 1 | import crypt 2 | def testPass(cryptPass): 3 | salt = cryptPass[0:2] 4 | dictfile = open('dictionary.txt','r') 5 | 6 | for word in dictfile.readlines(): 7 | word = word.strip('\n') 8 | cryptWord = crypt.crypt(word,salt) 9 | if( cryptWord == cryptPass): 10 | print "[+] Found Password: "+word+"\n" 11 | return 12 | print "[-]Password not found. \n" 13 | return 14 | def main(): 15 | passFile = open("password.txt") 16 | for line in passFile.readline(): 17 | if ":" in line: 18 | user = line.split(':')[0] 19 | cryptPass = line:split(':')[1].strip(' ') 20 | print "[*] Cracking password for "+user 21 | testPass(cryptPass) 22 | 23 | if __name__ == "__main__": 24 | main() -------------------------------------------------------------------------------- /Zip_Password_Cracker/Zip_Password_Cracker.py: -------------------------------------------------------------------------------- 1 | #Without using optparse 2 | # import zipfile 3 | # from threading import Thread 4 | # def extractFile( zFile, Password ): 5 | # try: 6 | # zFIle.extractAll(pwd= Password) 7 | # print '[+] Found password'+password+'\n' 8 | # except: 9 | # pass 10 | # def main(): 11 | # zFile = zipFile.ZipFile('evil.zip') 12 | # passFile = open( 'dictionary.txt' ) 13 | # for lines in passFile.readlines(): 14 | # password = line.strip('\n') 15 | # t= Thread( target = extractFile, args=(zFile, password)) 16 | # t.start() 17 | # if __name__ == __main__: 18 | # main() 19 | 20 | 21 | #####End 22 | 23 | #Using optparse 24 | import zipfile 25 | import optparse 26 | from threading import Thread 27 | def extractFile( zFile, Password ): 28 | try: 29 | zFile.extractall(pwd= Password) 30 | print '[+] Found password'+password+'\n' 31 | except: 32 | pass 33 | def main(): 34 | parser = optParse.OptionParser( "usage%prog"+ "-f -d ") 35 | parser.add_option('-f',dest='zname',type="string", help="Specify a zip file") 36 | parser.add_option('-d',dest='dname',type="string", help="Specify a dict file") 37 | (options, args) = parser.parse_args() 38 | if( options.zname == None) | (option.dname == None): 39 | print parser_usage 40 | exit(0) 41 | else: 42 | zname = options.zname 43 | dname = options.dname 44 | zFile = zipfile.ZipFile(zname) 45 | 46 | passFile = open( dname ) 47 | for lines in passFile.readlines(): 48 | password = line.strip('\n') 49 | t= Thread( target = extractFile, args=(zFile, password)) 50 | t.start() 51 | if __name__ == '__main__' : 52 | main() 53 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ###Hacking with Python 2 | This is the collection of various python hacking tools. The repo was basically created to learn a thing or two about Hacking with Python and CTFs 3 | 4 | I would also include some basic tips for python as I get them in Basic Tips folder 5 | 6 | Tools covered till now: 7 | - Simple port scans with and without nmap 8 | - Zip and UNIX password crackers 9 | - XOR Encryption 10 | - Scapy Introduction (sr and sr1 connect) 11 | --------------------------------------------------------------------------------