我已经为填充 oracle CTF 编写了这个小函数,但在此过程中迷路了,有人可以帮忙吗?
我正在尝试从后面逐字节更新字节串。但是,当我运行它时,它是从前面的 newbyte 执行的:看起来像 b"x00/x00..." iv[0:x] 不会以某种方式变小
def test_new_bytes(stringX, stringRest, c0, x):
print("iv 0:x", iv[0 : x - 2])
if x > 1:
for i in range(0, 256):
if i < 16:
HEX_I = hex(i)[2:]
# print(HEX_I)
newbyte = bytes.fromhex("0" + HEX_I) + stringRest
print(i, newbyte)
iv_new = stringX + newbyte
print("check", stringX, newbyte, stringRest)
print(iv_new)
if checkPadding(xor(iv_new, c0) + c0):
print("Correckt padding woohoo", xor(iv_new, c0))
test_new_bytes(iv[0 : x - 1], newbyte, c0, x=x - 1)
print("your i is ", i)
# return iv_new
else:
HEX_I = hex(i)[2:]
# print(HEX_I)
newbyte = bytes.fromhex(HEX_I) + stringRest
print(i, newbyte)
iv_new = stringX + newbyte
print(iv_new)
if checkPadding(xor(iv_new, c0) + c0):
print(
"Correckt padding woohoo at i, x", i, x, xor(iv_new, c0)
)
print("check", stringX, newbyte)
test_new_bytes(iv[0 : x - 1], newbyte, c0, x=x - 1)
print("your i is ", i) # return iv_new
print(iv[0:16], b"", c0)
test_new_bytes(iv[0:15], b"", c0, 15)
test_new_bytes(c0[0:15], b"", c1, 15)