import requests import re def script(url): proxy={ 'http': 'http://127.0.0.1:8080', 'https': 'http://127.0.0.1:8080', } try: data=['Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0'] http=requests.post(url=url,data=data,proxies=proxy) if re.search('Error-Based Fields',http): print('存在sql注入,路径遍历漏洞') elif re.search('Debugging Information',http): print('存在敏感信息泄露或代码执行漏洞') elif re.search('Injection Echo',http): print('存在sql注入,或命令注入漏洞') else: print('没有找到漏洞') except Exception as f: print(f'错误{f}') script('https://www.zhihu.com/')这代码运行时提示too many values to unpack (expected 2)怎么办?
时间: 2024-04-22 13:28:16 浏览: 17
这个错误通常是由于你的 `data` 列表中只有一个元素,而 `requests.post()` 函数期望传递两个参数,即 `data` 和 `json`。你可以将 `data` 参数改为 `json` 参数来解决这个问题。
另外,注意在发送 POST 请求时,应该使用 `json` 参数传递 JSON 数据,而不是使用 `data` 参数传递字符串数据。
以下是修正后的代码:
```python
import requests
import re
def script(url):
proxy = {
'http': 'http://127.0.0.1:8080',
'https': 'http://127.0.0.1:8080',
}
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0',
}
data = {
'user_agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0',
}
http = requests.post(url=url, headers=headers, proxies=proxy, json=data)
if re.search('Error-Based Fields', http.text):
print('存在 SQL 注入、路径遍历漏洞')
elif re.search('Debugging Information', http.text):
print('存在敏感信息泄露或代码执行漏洞')
elif re.search('Injection Echo', http.text):
print('存在 SQL 注入、命令注入漏洞')
else:
print('没有找到漏洞')
except Exception as e:
print(f'错误:{e}')
script('https://www.zhihu.com/')
```
请注意,我还将 `requests.post()` 返回的响应数据 `http` 的内容从 `http` 改为 `http.text`,以便对其进行正则表达式匹配。希望能解决你的问题!