Python 找不到我在 EIP 溢出中看到的子字符串

Python cannot find substring that I can see in EIP overflow

我有一个脚本,用于自动化和理解应用程序模糊测试。 我正在 运行ning vulnserver 和 fuzzing 以找到堆栈溢出的点,然后生成一个唯一的字符串,然后将再次发送该字符串以定位 EIP 被覆盖的点。

我遇到的问题是,我确定在发送 A 的初始集合 2100 时发生溢出。从那里我用下面的脚本生成一串连续的字符,摘录...

Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2

问题是当 EIP 被下面覆盖时,我无法在生成的模式中找到 EIP 字符串

正在寻找字符串...

pattern.find(eip_string) 

EIP asciie 值:8qC7

当 运行 在 IDLE 中时,我可以看到它找到了现有的字符串,但是 returns -1 对于那些它不能 find/do 不存在的字符串。

str.find('Aa0')
0
str.find('8qC7')
-1
str.find('foo bar')
-1

问题是我生成字符串的方式还是 Python 机制的其他问题? 我该如何解决这个问题,以便在主字符串中找到 EIP 模式?

生成模式的方法... Link 到 Github

上的 project/method
def create_pattern(self, length):
    index_up, index_down, int_index = 0, 0, 0

    int_list = list(range(0, 10))
    int_limit = len(int_list)-1 # 9

    char_list = string.ascii_lowercase
    char_limit = len(char_list)-1 # 25

    pattern = ''

while len(pattern) < length:
    if int_index <= int_limit:
        new_sequence = char_list[index_up].capitalize() + char_list[index_down] + str(int_list[int_index])
        pattern = pattern + new_sequence
        int_index += 1

    else:
        int_index = 0

        if index_down <= char_limit:
            index_down += 1

        if index_down >= char_limit:
            index_down = 0
            index_up += 1

        if index_up > char_limit:
            index_up = 0

self.pattern = pattern
return pattern

问题总结

  1. 我生成了一个长的非连续字符串。
  2. 我已经使用主字符串的子字符串覆盖了 EIP,并且可以在调试器中看到它
  3. 搜索时,在主串中找不到子串

所以我想出了问题所在。显然 EIP 值是小端。因此,我所要做的就是反转生成的字符串,这解决了我的问题。

基本PICNIC错误!

>> s = bytearray.fromhex(eip_query).decode()
>> s
'8oC7'
>> s[::-1]
'7Co8'
>> pattern.find_offset(s[::-1])
1943