I have written this little function for a padding oracle CTF and gotten lost along the way, could someone help?
I am trying to update a bytestring byte by byte from the back. Howvever when I run it it does it from the front newbyte: looks like b"x00/x00... " iv[0:x] doesnt get smaller somehow
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)