我在一个在线程序上工作,在这个程序中我应该做一个缓冲区溢出。
当我运行程序时,我必须完成随机生成的两个数字的和):
>>> 451389913 + 1587598959 =如果我得出正确的结果,我就会得到一个“没关系”的答案。否则,控制台将写入“再试一次”。
我用Ghidra解压缩程序,并在main()函数中获得以下代码:
{
int iVar1;
char local_9 [36];
int local_42;
uint local_6;
uint local_f;
local_f = rand();
local_6 = rand();
local_42 = local_6 + local_f;
printf(">>> %d + %d = ",(ulong)local_f,(ulong)local_6);
fflush(stdout);
fgets(local_9,100,stdin);
iVar1 = atoi(local_9);
if (local_42 == iVar1) {
puts("That's ok");
}
else {
puts("Try it again");
}
return 0;
}我注意到一个fgets函数,它使我假设我可以在和之前执行缓冲区溢出。我还看到local9变量由36个字符组成。所以我想在有效载荷开始的时候,必须有36个字符。
我开始用pwntools Python库编写以下代码片段:
import pwn
offset = 36
payload = b'A'*offset + b'[.....]'
c = pwn.remote("URL",Port)
c.sendline(payload)
c.interactive()问题是,我知道我必须在b'A'*offset之后写一些东西,但我不知道该添加什么。我的困难是把随机数之和加入到有效载荷中。
有可能做到吗?
任何想法都将不胜感激,谢谢。
发布于 2022-05-10 05:11:54
当然,是可能的,pwn是瑞士反恐基金的军刀。
# string = c.recv()
# assuming the string you receive is this
string = b">>> 451389913 + 1587598959 ="
# receive expression as bytes
# convert it into utf8 string for convenience
# split() splits the string at whitespaces and store them as array elements
expression = string.decode("utf8").split()
# covert string to int for to get logical sum instead of literal
solution = int(expression[1])+int(expression[3])
c.sendline(payload)然而,在一个更具挑战性的场景中,服务器可能会用除法或差异问您多个答案,您将不得不根据需要更改操作符。我宁愿使用运算符库,也不愿编写一堆ifs.
import operator
ops = {
'+' : operator.add,
'-' : operator.sub,
'*' : operator.mul,
'/' : operator.truediv
}
string = b">>> 451389913 + 1587598959 ="
expression = string.decode("utf8").split()
solution = ops[expression[2]](int(expression[1]), int(expression[3]))
c.sendline(solution)https://stackoverflow.com/questions/72131714
复制相似问题