ret2libc 这种攻击方式主要是针对 动态链接(Dynamic linking) 编译的程序,通过控制执行libc中的函数(通常为‘sysytem(“/bin/sh”)’)。
通常分为:
劫持binary执行system(/bin/sh),一般有一个溢出点需要两次劫持
一是泄露函数地址:控制eip指向,寻找output函数(如puts和write)和待泄露函数
二是控制binary返回到libc执行sysem(/bin/sh)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char *shell = "/bin/sh";
char buf2[100];
void secure(void)
{
int secretcode, input;
srand(time(NULL));
secretcode = rand();
scanf("%d", &input);
if(input == secretcode)
system("shell!?");
}
int main(void)
{
setvbuf(stdout, 0LL, 2, 0LL);
setvbuf(stdin, 0LL, 1, 0LL);
char buf1[100];
printf("RET2LIBC >_<\\n");
gets(buf1);
return 0;
}


shift+f12,发现system和/bin/sh,与ret2text不同,这里system中并不是/bin/sh

shell!?并不是一个真正的shell命令,所以我们需要将其替换为/bin/sh