^ 不支持的操作数类型:'bytes' 和 'bytes' 与 XOR
unsupported operand type(s) for ^: 'bytes' and 'bytes' with XOR
我在这个问题作为副本关闭之前问过我尝试了副本 link 但没有任何效果。
完整代码:
import requests
import base64
import urllib.parse
import operator
username = "badministrator"
password = "Password1"
URL = "http://url/login.php"
values = {'username' : username, 'password' : password}
def first_login(url_login, value):
with requests.Session() as c:
c.post(url_login, data = value)
response = c.get(url_login, verify=False, allow_redirects=True)
Cookie = [value for key,value in c.cookies.get_dict().items()]
cookie, IV = Cookie
return cookie, IV
def base64_decode():
cookie, IV = first_login(URL, values)
decode_cookie = base64.b64decode(urllib.parse.unquote_to_bytes(cookie))
decode_IV = base64.b64decode(urllib.parse.unquote_to_bytes(IV))
return decode_cookie, decode_IV
def xor_exp():
decoded_cookie, decoded_IV = base64_decode()
decoded_IV[0] = bytes(map(operator.xor, b'a', b'b', decoded_IV[0]))
decoded_cookie[0] = b'a'
return decoded_IV, decoded_cookie
print(xor_exp())
我不能以字节为单位进行迭代,也不能将三口异或在一起[=13=]
bytes
是不可变的,所以如果你想改变它们的内容,你可以构造一个新的 bytes
对象(就像你对字符串或元组所做的那样)或者创建一个 bytearray
.我将在下面展示它们:
def xor_exp():
decoded_cookie, decoded_IV = base64_decode()
decoded_IV = bytes([3 ^ decoded_IV[0]]) + decoded_IV[1:]
decoded_cookie = b'a' + decoded_cookie[1:]
return decoded_IV, decoded_cookie
def xor_exp():
decoded_cookie, decoded_IV = base64_decode()
decoded_cookie = bytearray(decoded_cookie)
decoded_IV = bytearray(decoded_IV)
decoded_IV[0] = 3 ^ decoded_IV[0]
decoded_cookie[:1] = b'a'
return bytes(decoded_IV), bytes(decoded_cookie)
尝试 2:
如果您知道 bytes
对象将只包含一个字符,我会简单地调用它们 ord
:
decoded_IV[0] = ord(b'a') ^ ord(b'b') ^ decoded_IV[0]
其中,给定这些特定值等于
decoded_IV[0] = 3 ^ decoded_IV[0]
尝试 1:
你不能直接异或Python中的对象bytes
,但是你可以异或int
对象,并且bytes
实现Iterable[int]
,这意味着你可以做:
import operator
...
decoded_IV[0] = bytes(map(operator.xor, b'a', b'b', decoded_IV[0]))
这里使用标准库函数operator.xor
and the builtin function map
。
我在这个问题作为副本关闭之前问过我尝试了副本 link 但没有任何效果。
完整代码:
import requests
import base64
import urllib.parse
import operator
username = "badministrator"
password = "Password1"
URL = "http://url/login.php"
values = {'username' : username, 'password' : password}
def first_login(url_login, value):
with requests.Session() as c:
c.post(url_login, data = value)
response = c.get(url_login, verify=False, allow_redirects=True)
Cookie = [value for key,value in c.cookies.get_dict().items()]
cookie, IV = Cookie
return cookie, IV
def base64_decode():
cookie, IV = first_login(URL, values)
decode_cookie = base64.b64decode(urllib.parse.unquote_to_bytes(cookie))
decode_IV = base64.b64decode(urllib.parse.unquote_to_bytes(IV))
return decode_cookie, decode_IV
def xor_exp():
decoded_cookie, decoded_IV = base64_decode()
decoded_IV[0] = bytes(map(operator.xor, b'a', b'b', decoded_IV[0]))
decoded_cookie[0] = b'a'
return decoded_IV, decoded_cookie
print(xor_exp())
我不能以字节为单位进行迭代,也不能将三口异或在一起[=13=]
bytes
是不可变的,所以如果你想改变它们的内容,你可以构造一个新的 bytes
对象(就像你对字符串或元组所做的那样)或者创建一个 bytearray
.我将在下面展示它们:
def xor_exp():
decoded_cookie, decoded_IV = base64_decode()
decoded_IV = bytes([3 ^ decoded_IV[0]]) + decoded_IV[1:]
decoded_cookie = b'a' + decoded_cookie[1:]
return decoded_IV, decoded_cookie
def xor_exp():
decoded_cookie, decoded_IV = base64_decode()
decoded_cookie = bytearray(decoded_cookie)
decoded_IV = bytearray(decoded_IV)
decoded_IV[0] = 3 ^ decoded_IV[0]
decoded_cookie[:1] = b'a'
return bytes(decoded_IV), bytes(decoded_cookie)
尝试 2:
如果您知道 bytes
对象将只包含一个字符,我会简单地调用它们 ord
:
decoded_IV[0] = ord(b'a') ^ ord(b'b') ^ decoded_IV[0]
其中,给定这些特定值等于
decoded_IV[0] = 3 ^ decoded_IV[0]
尝试 1:
你不能直接异或Python中的对象bytes
,但是你可以异或int
对象,并且bytes
实现Iterable[int]
,这意味着你可以做:
import operator
...
decoded_IV[0] = bytes(map(operator.xor, b'a', b'b', decoded_IV[0]))
这里使用标准库函数operator.xor
and the builtin function map
。