gpt4 book ai didi

python - 基本授权凭证不会出现在 Scapy 中?

转载 作者:可可西里 更新时间:2023-11-01 17:24:15 24 4
gpt4 key购买 nike

Note: The scapy layer 'http' is installed with pip install scapy-http

我有以下代码打印 HTTP 请求层中授权值的值:

import sys
from scapy.all import *
from scapy.layers import http
interface = 'wlan0'
def packet(p):
tcp = p.getlayer('TCP')
if tcp:
req = p.getlayer('HTTP Request')
if req:
auth = req.Authorization
if auth:
print(auth)
try:
sniff(iface=interface,store=0,filter="tcp and port 80",prn=packet)
except KeyboardInterrupt:
sys.exit(1)

这应该打印 this wire shark screenshot 中显示的凭证, 但它只打印 b'Basic YWRtaW46RjByZXZlciQ='。这是有原因的吗?

最佳答案

Authorization在您的情况下, header 值恰好是 b'Basic YWRtaW46RjByZXZlciQ=' .这表示使用了基本认证方案,值为<username>:<password> ,base64 编码(在您的情况下为 adminF0rever$)。

你可以这样做:

[...]
auth = req.Authorization
if auth and auth.startswith(b'Basic '):
uname, passw = base64_bytes(auth.split(None, 1)[1]).split(b':', 1)
print("Username: %r, password: %r" % (uname.decode(), passw.decode()))

关于python - 基本授权凭证不会出现在 Scapy 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49620179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com