picoctf 2013_rop4

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”却不行
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值