Advertisement
gersy

parameth

Nov 12th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.10 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #edited
  3.  
  4. import multiprocessing
  5. import argparse
  6. import requests
  7. import sys
  8. import string
  9. import time
  10. from numpy import array_split
  11.  
  12. requests.packages.urllib3.disable_warnings()
  13. _GETstatus = 0
  14. _GETresponseSize = 0
  15. _POSTstatus = 0
  16. _POSTresponseSize = 0
  17. _POSTdata = {}
  18. _paramValue = 'discobiscuits'
  19.  
  20. def version_info():
  21.     VER = 'parameth v1.337 - \033[033mfind parameters and craic rocks\033[0m'
  22.     AUTH = 'Author: \033[033mCiaran McNally - https://makthepla.net\033[0m'
  23.     print '\033[1;34m                                       |   |'
  24.     print '  __ \\   _` |  __| _` | __ `__ \\   _ \\ __| __ \\'
  25.     print '  |   | (   | |   (   | |   |   |  __/ |   | | |'
  26.     print '  .__/ \\__,_|_|  \\__,_|_|  _|  _|\\___|\\__|_| |_|'
  27.     print '  _|\033[0m'
  28.     print VER
  29.     print AUTH
  30.     print '\033[1;30m================================================\033[0m'
  31.  
  32. def getHeaderObj(header):
  33.     h3 = {}
  34.     h1 = string.split(header, ':')[0]
  35.     h2 = string.split(header, ':')[1]
  36.     h3[h1] = h2
  37.     return h3
  38.  
  39. def getProxyObj(proxy):
  40.     proxies = {}
  41.     if 'https://' in proxy:
  42.         proxies['https'] = string.split(proxy, 'https://')[1]
  43.     else:
  44.         proxies['http'] = string.split(proxy, 'http://')[1]
  45.     return proxies
  46.  
  47. def getCookieObj(cookie):
  48.     cookies = {}
  49.     c1 = string.split(cookie, ':')[1]
  50.     c2 = string.split(c1, ';')
  51.     for i in c2:
  52.         if len(i) >= 2:
  53.             c3 = string.split(i, '=')[0]
  54.             c4 = string.split(i, '=')[1]
  55.             cookies.update({c3:c4})
  56.     return cookies
  57.  
  58. def getParamObj(data):
  59.     newParam = ''
  60.     newValue = ''
  61.     params = []
  62.     requestData = {}
  63.     if data.startswith('?'):
  64.         newParam = data[1:]
  65.     else:
  66.         newParam = data
  67.     if len(data) != 0:
  68.         params = string.split(newParam, '&')
  69.         for i in params:
  70.             newParam = string.split(i, '=')[0] 
  71.             newValue = string.split(i, '=')[1]
  72.             requestData[newParam] = newValue
  73.         return requestData
  74.     else:
  75.         return requestData
  76.  
  77. def getParamStr(data):
  78.     dataString = ''
  79.     if len(data) != 0:
  80.         for i,j in data.iteritems():
  81.             dataString += i + '=' +j
  82.             dataString += '&'
  83.     return dataString[:-1]
  84.  
  85. def split_params(u, t):
  86.     return array_split(u, t)
  87.  
  88. def statusMatch(ignore, status_code):
  89.     if status_code in ignore:
  90.         return False
  91.     else:
  92.         return True
  93.  
  94. def printOut(filename, string):
  95.     f = open(filename,'a')
  96.     f.write(string+'\n')
  97.     f.close()
  98.  
  99. def requestor(url, parameter, header, agent, variance, proxy, ignore,
  100.                 data, out, size, igmeth, cookie, timeout):
  101.     headers = {}
  102.     post = {}
  103.     proxies = {}
  104.     providedData = {}
  105.     cookies = {}
  106.    
  107.     if ':' in cookie:
  108.         cookies = getCookieObj(cookie)
  109.     if ':' in header:
  110.         headers = getHeaderObj(header)
  111.     headers['User-agent'] = agent
  112.     if ':' in proxy:
  113.         proxies = getProxyObj(proxy)
  114.  
  115.     for i in parameter:
  116.         time.sleep(timeout)
  117.         newrl = url
  118.         strvar = ''
  119.         post = {}
  120.         post[i] = _paramValue
  121.         if '?' in url:
  122.             newrl += '&' + i + '=' + _paramValue
  123.         else:
  124.             newrl += '?' + i + '=' + _paramValue
  125.         post.update(_POSTdata)
  126.         try:     
  127.             #GET parameter
  128.             if igmeth != 'g':
  129.                 g = requests.get(newrl, timeout=10, headers=headers,
  130.                     allow_redirects=False, verify=False, proxies=proxies,
  131.                     cookies=cookies)
  132.                 plusvar = len(g.content) + variance
  133.                 subvar = len(g.content) - variance
  134.  
  135.                 if g.status_code != _GETstatus and statusMatch(ignore, str(g.status_code)):
  136.                     print '\033[032mGET(status)\033[0m: '+i+' | '+str(_GETstatus)+'->',
  137.                     print str(g.status_code)+' ( '+newrl+' )'
  138.                     if out != 'out':
  139.                         strvar = 'GET(status) '+i+' '+str(g.status_code)+' '+newrl
  140.                         printOut(out, strvar)
  141.            
  142.                 if statusMatch(ignore, str(g.status_code)):
  143.                     if len(g.content) != _GETresponseSize and len(g.content) != size:
  144.                         if len(g.content) >= plusvar or len(g.content) <= subvar:
  145.                             print '\033[032mGET(size)\033[0m: '+i+' | '+str(_GETresponseSize),
  146.                             print '->' +str(len(g.content))+ ' ( '+newrl+' )'
  147.                             if out != 'out':
  148.                                 strvar = 'GET(size) '+i+' '+str(len(g.content))+' '+newrl
  149.                                 printOut(out, strvar)
  150.            
  151.             #POST parameter
  152.             if igmeth != 'p':
  153.                 p = requests.post(url, timeout=10, headers=headers, data=post,
  154.                     allow_redirects=False, verify=False, proxies=proxies,
  155.                     cookies=cookies)
  156.                 plusvar = len(p.content) + variance
  157.                 subvar = len(p.content) - variance
  158.  
  159.                 if p.status_code != _POSTstatus and statusMatch(ignore, str(p.status_code)):
  160.                     print '\033[032mPOST(status)\033[0m: '+i+' | '+str(_POSTstatus)+'->',
  161.                     print str(p.status_code)+' ( '+url+' )'
  162.                     if out != 'out':
  163.                         strvar = 'POST(status) '+i+' '+str(p.status_code)+' '+url
  164.                         printOut(out, strvar)
  165.            
  166.                 if statusMatch(ignore, str(p.status_code)):
  167.                     if len(p.content) != _POSTresponseSize and len(p.content) != size:
  168.                         if len(p.content) >= plusvar or len(p.content) <= subvar:
  169.                             print '\033[032mPOST(size)\033[0m: '+i+' | '+str(_POSTresponseSize),
  170.                             print '->' +str(len(p.content))+ ' ( '+url+' )'
  171.                             if out != 'out':
  172.                                 strvar = 'POST(size) '+i+' '+str(len(p.content))+' '+url
  173.                                 printOut(out, strvar)
  174.  
  175.         except requests.exceptions.Timeout:
  176.             print 'Request Timed out on parameter "'+i+'"'
  177.         except requests.exceptions.ConnectionError:
  178.             print 'Connection Error on parameter "'+i+'"'
  179.         except requests.exceptions.TooManyRedirects:
  180.             print 'Redirect loop on parameter "'+i+'"'     
  181.    
  182.  
  183. def getBase(url, header, agent, variance, proxy, data, igmeth, cookie):
  184.     headers = {}
  185.     proxies = {}
  186.     cookies = {}
  187.     get = ''
  188.     url_base = ''
  189.     global _GETstatus
  190.     global _GETresponseSize
  191.     global _POSTstatus
  192.     global _POSTresponseSize
  193.     global _POSTdata
  194.    
  195.     if ':' in cookie:
  196.         cookies = getCookieObj(cookie)
  197.     if ':' in header:
  198.         headers = getHeaderObj(header)
  199.     headers['User-agent'] = agent
  200.     if ':' in proxy:
  201.         proxies = getProxyObj(proxy)
  202.     if '?' in url:
  203.         get = string.split(url, '?')[1]
  204.         url_base = string.split(url, '?')[0]
  205.     else:
  206.         url_base = url
  207.    
  208.     _POSTdata = getParamObj(get)
  209.     if len(data) != 0:
  210.         _POSTdata.update(getParamObj(data))
  211.     print 'Establishing base figures...'
  212.     if igmeth != 'p':
  213.         print '\033[031mPOST data: \033[0m'+getParamStr(_POSTdata)
  214.     print '\033[031mOffset value: \033[0m'+str(variance)
  215.     try:
  216.         if igmeth != 'g':
  217.             g = requests.get(url, timeout=10, headers=headers, verify=False,
  218.                                 allow_redirects=False, proxies=proxies,
  219.                                 cookies=cookies)
  220.             _GETstatus = g.status_code
  221.             _GETresponseSize = len(g.content)
  222.             print '\033[031mGET: content-length->\033[0m '+str(len(g.content)),
  223.             print '\033[031m status->\033[0m '+str(g.status_code)
  224.    
  225.         if igmeth != 'p':
  226.             p = requests.post(url_base, timeout=10, headers=headers,
  227.                                 verify=False, allow_redirects=False,
  228.                                 proxies=proxies, data=_POSTdata,
  229.                                 cookies=cookies)
  230.             _POSTstatus = p.status_code
  231.             _POSTresponseSize = len(p.content)
  232.             print '\033[031mPOST: content-length->\033[0m '+str(len(p.content)),
  233.             print '\033[031m status->\033[0m '+str(p.status_code)
  234.        
  235.         if _POSTstatus != _GETstatus and igmeth != 'p' and igmeth != 'g':
  236.             print 'POST and GET are different sizes'
  237.  
  238.     except requests.exceptions.Timeout:
  239.         print 'Request Timed out!'
  240.     except requests.exceptions.ConnectionError:
  241.         print 'Connection Error!'
  242.     except requests.exceptions.TooManyRedirects:
  243.         print 'Redirect loop!'
  244.    
  245.  
  246. if __name__ == '__main__':
  247.     parse = argparse.ArgumentParser()
  248.     parse.add_argument('-v', '--version', action='store_true', default=False,
  249.                         help='Version Information')
  250.     parse.add_argument('-u', '--url', type=str, default='', help='Target URL')
  251.     parse.add_argument('-p', '--params', type=str, default='lists/all.txt',
  252.                         help='Provide a list of parameters to scan for')
  253.     parse.add_argument('-H', '--header', type=str, default='',
  254.                         help='Add a custom header to the requests')
  255.     parse.add_argument('-a', '--agent', type=str, default='parameth v1.0',
  256.                         help='Specify a user agent')
  257.     parse.add_argument('-t', '--threads', type=int, default='2',
  258.                         help='Specify the number of threads.')
  259.     parse.add_argument('-off', '--variance', type=int, default='0',
  260.                         help='The offset in difference to ignore (if dynamic pages)')
  261.     parse.add_argument('-o', '--out', type=str, default='out',help='Specify output file')
  262.     parse.add_argument('-P', '--proxy', type=str, default='',
  263.                         help='Specify a proxy in the form http|s://[IP]:[PORT]')
  264.     parse.add_argument('-x', '--ignore', type=str, default='',
  265.                         help='Specify a status to ignore eg. 404,302...')
  266.     parse.add_argument('-s', '--sizeignore', type=int, default='-1',
  267.                         help='Ignore responses of specified size')
  268.     parse.add_argument('-d', '--data', type=str, default='',
  269.                         help='Provide default post data (also taken from provided url after ?)')
  270.     parse.add_argument('-i', '--igmeth', type=str, default='',
  271.                         help='Ignore GET or POST method. Specify g or p')
  272.     parse.add_argument('-c', '--cookie', type=str, default='', help='Specify Cookies')
  273.     parse.add_argument('-T', '--timeout', type=int, default=0,
  274.                         help='Specify a timeout in seconds to wait between each request')
  275.     args = parse.parse_args()
  276.  
  277.     if len(sys.argv) <= 1:
  278.         parse.print_help()
  279.         sys.exit(0)
  280.    
  281.     if args.version:
  282.         version_info()
  283.  
  284.     if args.url:
  285.         version_info()
  286.         getBase(args.url, args.header, args.agent, args.variance, args.proxy,
  287.                 args.data, args.igmeth, args.cookie)
  288.         print 'Scanning it like you own it...' 
  289.         try:
  290.             with open(args.params, "r") as f:
  291.                 params = f.read().splitlines()
  292.         except IOError:
  293.             print "IOError: Your file is a sex offender."
  294.         threads = []
  295.         splitlist = list(split_params(params, args.threads))
  296.         cok=args.cookie
  297.         if cok=='from_file':
  298.             try:
  299.                 file_path=raw_input('Where is your file')
  300.                 with open(file_path) as reader:
  301.                     cok=reader.read()
  302.             except Exception:
  303.                 cok=args.cookie
  304.         for i in range(0, args.threads):
  305.             p = multiprocessing.Process(target=requestor, args=(args.url,
  306.                 splitlist[i], args.header, args.agent, args.variance,
  307.                 args.proxy, args.ignore, args.data, args.out, args.sizeignore,
  308.                 args.igmeth, cok, args.timeout))
  309.             threads.append(p)
  310.         try:
  311.             for p in threads:
  312.                 p.start()
  313.             for p in threads:
  314.                 p.join()
  315.         except KeyboardInterrupt:
  316.             print 'Scagging out scanner...'
  317.             for p in threads:
  318.                 p.terminate()
  319.             sys.exit(0)
  320.         threads = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement