ROP4
实验程序:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
char exec_string[20];
void exec_the_string() {
execlp(exec_string, exec_string, NULL);
}
void call_me_with_cafebabe(int cafebabe) {
if (cafebabe == 0xcafebabe) {
strcpy(exec_string, "/sh");
}
}
void call_me_with_two_args(int deadbeef, int cafebabe) {
if (cafebabe == 0xcafebabe && deadbeef == 0xdeadbeef) {
strcpy(exec_string, "/bin");
}
}
void vulnerable_function() {
char buf[128];
read(STDIN_FILENO, buf, 512);
}
void be_nice_to_people() {
// /bin/sh is usually symlinked to bash, which usually drops privs. Make
// sure we don't drop privs if we exec bash, (ie if we call system()).
gid_t gid = getegid();
setresgid(gid, gid, gid);
}
int main(int argc, char** argv) {
exec_string[0] = '\0';
be_nice_to_people();
vulnerable_function();
}
实验要求:
关闭ASLR
思路:
1、首先利用read()函数,将从键盘中输入的数据流(这里指“/bin/sh”字符串)读入到栈空间所在地址。
read(0,地址,9)从输入流读取9个字符到地址处。0表示输入流,1表示输出流。
为什么是9个?因为可以读入/bin/bash
2、利用pop pop pop ret Gadgets使read()读完后执行system()函数
因此,构造格式:
payload=填充字符+read地址+Gadgets地址+read参数+execl地址+4个填充字符+execl参数
实验步骤:
1、 找到read和execl的plt地址
2、找到栈中可用的地址
3、找到Gadgets,
这里选用0x080495b9,因为只需要3个pop就到达execl地址处了
4、构造exp
备注:data2和data3是其他方法
5、运行exp。不知道什么原因输入“/bin/bash和/bin/date”都可以,但是输入”/bin/sh”却不行