v0mit

Untitled

Aug 5th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. import urllib, urllib2, random, sys
  2. from BeautifulSoup import BeautifulSoup
  3. from BeautifulSoup import BeautifulStoneSoup
  4.  
  5. url = "http://dubstep.net"
  6. injection_str = ""
  7. for x in range(0,8):
  8.     injection_str += random.choice("abcdefghi1234567890")
  9.  
  10. encoded_injection_str = urllib.urlencode({"":";!--\"<%s>=&{()}" % injection_str})
  11.    
  12. class _http_handler():
  13.     def __init__(self):
  14.         self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
  15.         urllib2.install_opener(self.opener)
  16.  
  17.     def request(self, url, data=None):
  18.  
  19.         req = urllib2.Request(url)
  20.         req.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.8.1.18) Gecko/20081029 Firefox/2.0.0.18')
  21.        
  22.         if data != None:
  23.             data = urllib.urlencode(data)
  24.             try:
  25.                 response = self.opener.open(req,data)
  26.             except urllib2.URLError, err:
  27.                 print(err)
  28.                 print("Failed to open: {0}\nWith data:{1}".format(url, data))
  29.                
  30.                 return
  31.                
  32.             return response.read()
  33.         else:
  34.             try:
  35.                 response = self.opener.open(req)
  36.             except urllib2.URLError, err:
  37.                 print(err)
  38.                 print("Failed to open {0}".format(url))
  39.                
  40.                 return
  41.            
  42.             return response.read()
  43.            
  44. def get_forms(url):
  45.     h = _http_handler()
  46.     data = h.request(url)
  47.     if data == None:
  48.         return None
  49.    
  50.     soup = BeautifulSoup(data)
  51.     forms = soup.findAll("form", attrs={"method":"get"})
  52.    
  53.     valid_forms = []
  54.     for form in forms:
  55.         action = form.get("action")
  56.         if action != None:
  57.             inputs = form.findAll("input", attrs={"type":"text"})
  58.             names = []
  59.             for input in inputs:
  60.                 name = input.get("name")
  61.                 if input != None:
  62.                     names.append(str(name))
  63.                    
  64.             valid_forms.append([str(action), names])
  65.                    
  66.     return valid_forms
  67.    
  68. def generate_links(forms):pass
  69.    
  70.  
  71. forms =  get_forms(url)
  72. if forms == None:
  73.     print("Cannot continue, could not open site to parse.")
  74.     sys.exit(0)
  75.    
  76. h = _http_handler()
  77. for form in forms:
  78.     for para in form[1]:
  79.         if form[0] != "#":
  80.             if form[0].startswith("http://"):
  81.                 new_url = "{0}?{1}={2}".format(form[0], para, encoded_injection_str)
  82.                 print(new_url)
  83.                 data = h.request(new_url)
  84.                 if data == None:
  85.                     continue
  86.                 if injection_str in data:
  87.                     print("[!]Possible XSS found!")
  88.                     print("[i]URL:{0}".format(new_url))
  89.                     print("[i]Para:{0}\n".format(para))
  90.             else:
  91.                 new_url = "{0}/{1}?{2}={3}".format( url, form[0],
  92.                                                     para, encoded_injection_str)
  93.                 print(new_url)
  94.                 data = h.request(new_url)
  95.                 if data == None:
  96.                     continue
  97.                 if injection_str in data:
  98.                     print("[!]Possible XSS found!")
  99.                     print("[i]URL:{0}".format(new_url))
  100.                     print("[i]Para:{0}\n".format(para))
Advertisement
Add Comment
Please, Sign In to add comment