[英]How do I loop through every possible value of a byte in python?
I am conducting a Padding Oracle Attack for my Information Security course. 我正在为我的信息安全课程进行Padding Oracle Attack。 Without getting into the details of the attack, I need to have a for loop that loops through all possible 1 byte hex values.
在不深入探讨攻击细节的情况下,我需要有一个for循环,该循环遍历所有可能的1字节十六进制值。
Pseudo-code of what I need to do: 我需要做的伪代码:
for x in range('\x00', '\xFF'):
replace last byte of ciphertext with byte
perform padding check
I cannot figure out how to accomplish this. 我不知道该怎么做。 Any ideas?
有任何想法吗?
Bytes are really just integers in the range 0-255 (inclusive), or in hex, 0 through to FF. 字节实际上只是0-255(含)范围内的整数,或十六进制的0到FF。 Generate the integer, then create the byte value from that.
生成整数,然后从中创建字节值。 The
bytes()
type takes a list of integers, so create a list of length 1: bytes()
类型采用整数列表,因此创建一个长度为1的列表:
for i in range(0xff):
b = bytes([i])
If you store the ciphertext in a bytearray()
object , you could even trivially replace that last byte by using the integer directly: 如果将密文存储在
bytearray()
对象中 ,则甚至可以直接使用整数来简单地替换最后一个字节:
ciphertext_mutable = bytearray(ciphertext)
for i in range(0xff):
ciphertext_mutable[-1] = i # replace last byte
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.