首页 > 其他分享 >第一届“长城杯”信息安全铁人三项赛初赛-第四场-pwn-all

第一届“长城杯”信息安全铁人三项赛初赛-第四场-pwn-all

时间:2024-04-02 15:15:10浏览次数:35  
标签:第四场 gift libc elf 初赛 pop pd debug 铁人三项

第一届“长城杯”信息安全铁人三项赛初赛-第四场-pwn-all

这次打了个第二。

onetime

逆向分析

经典菜单堆,free分支存在uaf,然后第五个分支和第一个分支可以达成fastbin attack

漏洞利用

利用fastbin attack申请0x60208d,然后修改分支判断变量与p指针,做到利用show分支泄露和修改atoisystem进行getshell

EXP

运行:./exp.py re ./onetime 192.168.17.127 7777攻击远程

#!/usr/bin/env python3
'''
Author:7resp4ss
Date:2024-03-31 14:50:42
Usage:
    Debug : python3 exp.py debug elf-file-path -t -b malloc
    Remote: python3 exp.py remote elf-file-path ip:port
    flag{606e1f4dfd993eb94675ac02e6e39541}

'''

from pwncli import *
cli_script()


io: tube = gift.io
elf: ELF = gift.elf
libc: ELF = gift.libc

filename  = gift.filename # current filename
is_debug  = gift.debug # is debug or not 
is_remote = gift.remote # is remote or not
gdb_pid   = gift.gdb_pid # gdb pid if debug

if gift.remote:
    libc = ELF("./onetime.so")
    gift[libc] = libc


def cmd(i, prompt='your choice >>'):
    sla(prompt, str(i))

def add():
    cmd('1')
    #......

def edit(pd):
    cmd('2')
    sa('l content:',pd)
    #......

def show():
    cmd('3')
    #......

def dele():
    cmd('4')
    #......

def magic(pd):
    cmd('5')
    sa('e your name:',pd)


add()
dele()
edit(flat(
    {
        0x0:0x60208d
    }
))
add()
#0x6020a0
pd = b'aaa'
pd+=flat(
    {
        0x0:[
            0,
            elf.got.atoi,
            0,0
            ]

    }
)
magic(pd)
'''
pwndbg> tele 0x6020a0
00:0000│  0x6020a0 (has2) ◂— 0xdeadbeef
01:0008│  0x6020a8 (p) —▸ 0x60209d ◂— 0xdeadbeef616161
02:0010│  0x6020b0 (has4) ◂— 0x1
03:0018│  0x6020b8 (has1) ◂— 0x100000001
04:0020│  0x6020c0 ◂— 0x0
... ↓     3 skipped
pwndbg> 
08:0040│  0x6020e0 ◂— 0x0
... ↓     7 skipped

'''
show()
lb = recv_current_libc_addr(libc.sym.atoi,0x10)
leak_ex2(lb)
libc.address = lb
edit(flat(
    {
        0:libc.sym.system
    }
))
sl('$0')


ia()


FLAG

flag{606e1f4dfd993eb94675ac02e6e39541}

guess_game

逆向分析

进去对main函数按p,然后把地址0x4015340x401546的垃圾数据都nop掉,就可以看出程序就是玩游戏,玩对给一个栈溢出。但是4次机会是猜不对的。因此我们可以输入6泄露rand函数的返回值值,然后利用rand函数的缺陷。如下:

● 参考Peter Selinger: The GLIBC pseudo-random number generator (dal.ca) 
o[n] == o[n-31] + o[n-3]
o[n] == o[n-31] + o[n-3] + 1
 
如果能多次泄露,将产生的数记录在数组leaknum中,可通过leaknum[i ] = leaknum[i-31] + leaknum[i-3] / leaknum[i ] = leaknum[i-31] + leaknum[i-3] + 1预测。(i为数组下标,从0开始) 

来预测rand的返回值,从而触发栈溢出

漏洞利用

栈溢出,但是发现gadget只有:

0x000000000040125d : pop rbp ; ret
0x0000000000401540 : pop rbx ; ret
0x0000000000401543 : pop rdx ; ret
0x000000000040153d : pop rsi ; ret

由此联想到利用magic gadget修改got然后执行ogg

magic gadget如下:

pwndbg> x/10i 0x000000000040125c
   0x40125c:	add    DWORD PTR [rbp-0x3d],ebx
   0x40125f:	nop
   0x401260:	ret    

EXP

运行:./exp.py re ./pwn 192.168.17.127 8888,跑不通多跑几次

#!/usr/bin/env python3
'''
Author:7resp4ss
Date:2024-03-31 14:06:41
Usage:
    Debug : python3 exp.py debug elf-file-path -t -b malloc
    Remote: python3 exp.py remote elf-file-path ip:port
    flag{f68dad953b9708da575d07faf43f77db}

'''

from pwncli import *
cli_script()


io: tube = gift.io
elf: ELF = gift.elf
libc: ELF = gift.libc

filename  = gift.filename # current filename
is_debug  = gift.debug # is debug or not 
is_remote = gift.remote # is remote or not
gdb_pid   = gift.gdb_pid # gdb pid if debug

if gift.remote:
    libc = ELF("./libc.so.6")
    gift[libc] = libc

def magic():
    sla('guess number?[y/n]','6')
    sla('Give Up? [y/n]','y')
    ru('you are a loser,the number is ')
    leak_num = int(rl()[:-1],16)
    sla('continue guess?','y')
    return leak_num

def game():
    sla('guess number?[y/n]','y')
    for i in range(5):
        sla(':',str(i))
num = []

for i in range(31):
    game()
    num.append(magic())

magic_num = num[0]+num[31-3]
print(magic_num)
sla('guess number?[y/n]','y')
sla(':',str(magic_num))
CG.set_find_area(1,0)

'''
pwndbg> x/10i 0x000000000040125c
   0x40125c:	add    DWORD PTR [rbp-0x3d],ebx
   0x40125f:	nop
   0x401260:	ret    

0x000000000040125d : pop rbp ; ret
0x0000000000401540 : pop rbx ; ret
0x0000000000401543 : pop rdx ; ret
0x000000000040153d : pop rsi ; ret

0xeacec execve("/bin/sh", r15, r12)
constraints:
  [r15] == NULL || r15 == NULL
  [r12] == NULL || r12 == NULL

0xeacef execve("/bin/sh", r15, rdx)
constraints:
  [r15] == NULL || r15 == NULL
  [rdx] == NULL || rdx == NULL

0xeacf2 execve("/bin/sh", rsi, rdx)
constraints:
  [rsi] == NULL || rsi == NULL
  [rdx] == NULL || rdx == NULL


'''
pop_rbp = 0x000000000040125d
pop_rbx = 0x0000000000401540
pop_rdx = 0x0000000000401543
pop_rsi = 0x000000000040153d

ogg = 0xeacf2
offset = ogg - libc.sym.puts if ogg > libc.sym.puts else ogg - libc.sym.puts + 0x100000000

null_ptr = elf.bss()+0x800
pd = flat(
    {
        72:[pop_rbp,
            elf.got.puts+0x3d,
            pop_rbx,
            offset,
            0x000000000040125c,
            pop_rsi,
            null_ptr,
            pop_rdx,
            null_ptr,
            elf.plt.puts]
    }
)

sla('get it,you win!',pd)
'''cyc = 0
for i in num:
    print("The " + str(cyc) + "Num :" + str(i))
    cyc = cyc + 1
    '''
ia()
'''leaknum[32] = leaknum[1] + leaknum[32-3]'''

FLAG

flag{f68dad953b9708da575d07faf43f77db}

thread_pwn

逆向分析

我在上一年buuoj-2023六月挑战赛做过一样的,叫A dream,我还写过wp在我的博客园里。。。

程序在开启沙箱前打开了一个线程,劫持该线程即可:

__int64 __fastcall main(__int64 a1, char **a2, char **a3)
{
  pthread_t newthread; // [rsp+8h] [rbp-8h] BYREF

  sub_401256(a1, a2, a3);
  puts("Welcome ,do you know threads?");
  pthread_create(&newthread, 0LL, start_routine, 0LL);
  sub_4014AD();
  return 0LL;
}

漏洞利用

  • 首先栈迁移泄露libc地址,详细点击这里
  • 利用magic_read0x4014BE)和ret2csu,获得布置栈空间的能力
  • 利用系统调用构造循环read不断往线程栈输入payload

EXP

运行./exp.py re ./thread_pwn 192.168.17.127 9999即可

#!/usr/bin/env python3
'''
Author:7resp4ss
Date:2024-03-31 13:08:15
Usage:
    Debug : python3 exp.py debug elf-file-path -t -b malloc
    Remote: python3 exp.py remote elf-file-path ip:port
'''
#flag{c79f2facb69cc53d6ca2b3de7957a827}

from pwncli import *
cli_script()


io: tube = gift.io
elf: ELF = gift.elf
libc: ELF = gift.libc

filename  = gift.filename # current filename
is_debug  = gift.debug # is debug or not 
is_remote = gift.remote # is remote or not
gdb_pid   = gift.gdb_pid # gdb pid if debug

CG.set_find_area(1,0)
pd = flat(
    {
        72-0x8:[
            0x4041c0,
            0x4014BE]
    }
)
s(pd)

sleep(1)
pd = flat(
    {
        0:[
            0x40158A,
            0,1,0,0x4041c0,0x100,elf.got.read,0x401570
        ],
        0x50-0x10:[
            0x404180-8,
            CG.leave_ret()]
    }
)
s(pd)
sleep(1)


pd = flat(
    {
        56:[
            0x0000000000401593,
            1,
            0x0000000000401591,
            elf.got.read,
            0,
            elf.plt.write,
            #0x404230
            0x0000000000401593,
            0,
            0x0000000000401591,
            0x404230-0x20+0x48,
            0,
            elf.plt.read,

        ]
    }
)
sl(pd)
lb = recv_current_libc_addr(0x205380,0x10)
leak_ex2(lb)

libc.address = lb
tstack = lb - 0x4110
leak_ex2(tstack)

CG.set_find_area(1,1)
cyc_pd = flat(
    {
        0x0:[
            CG.read_chain(0,tstack-0x10,0x100),
            CG.pop_rbp_ret(),
            0x404258-0x8,
            CG.leave_ret(),
        ]
    }
)
sleep(1)

sl(cyc_pd)
pd = flat(
    {
        0x0:[
            [CG.ret()]*0x10
        ],
        0x80:CG.execve_chain()
    }
)

for i in range(8):
    sleep(0.5)
    sl(pd)

ia()


FLAG

flag{c79f2facb69cc53d6ca2b3de7957a827}

标签:第四场,gift,libc,elf,初赛,pop,pd,debug,铁人三项
From: https://www.cnblogs.com/7resp4ss/p/18110592

相关文章

  • P7137 [THUPC2021 初赛] 切切糕 题解
    题目传送门前置知识博弈论解法由于本题是CF1628D1GameonSum(EasyVersion)的扩展,故先从CF1628D1GameonSum(EasyVersion)讲解。CF1628D1GameonSum(EasyVersion)设\(x_{i}\)表示第\(i\)轮时Alice选择的数。设\(f_{i,j}\)表示已经进行了\(i\)轮,且......
  • 蓝帽杯2022初赛-fastjson复现
    趁热打铁,直接复现一波蓝帽杯2022初赛的一道fastjson。简简单单写了个Dockerfile和docker-compose.yml,网上能找到jar包链接,然后启动服务:importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.parser.ParserConfig;importjava.util.Objects;importjava.util.re......
  • P8844 [传智杯 #4 初赛] 小卡与落叶 题解
    分析乱搞题。$1\len,m\le10^5$的时候就可以考虑乱搞了。发现每次操作$1$都会把上一次的操作$1$覆盖掉,那么第$i$个询问时树的颜色情况就是由前$1$个操作$1$决定。也就是说这个询问的内容变成了:在$x$为根的子树中,深度不小于$x'$的节点数量。$x'$是该操作$1$......
  • CSP 初赛玄学题
    使用g++-std=c++14-O2指令编译以下两份代码,判断哪个运行时会RE,哪个不会:#include<bits/stdc++.h>#definerept(i,a,b)for(inti=a;i<b;++i)usingnamespacestd;signedmain(){ int**a[10]; rept(i,0,10)rept(j,0,10)rept(k,0,10)a[i][j][k]=i+j-k; rept(i,0,10)rept......
  • THUPC2024-初赛
    哈哈,被干爆了。拖了cdqz哥后腿。题目使用协议来自THUPC2024(2024年清华大学学生程序设计竞赛暨高校邀请赛)初赛。以下『本仓库』皆指THUPC2024初赛官方仓库任何单位或个人都可以免费使用或转载本仓库的题目;任何单位或个人在使用本仓库题目时,应做到无偿、公开,严禁使用这......
  • csp2023 初赛退役(you)记
    9.16csp2023初赛AFO记早上我可睡了个大懒觉,早上8点30才起,起来刷了刷水题,就出门了。J组还没进去,就看到了lzh小佬,然后进去就看到[代词使用它的]rty大佬了呵呵呵,没想到跟wzy和xzx大佬一个考场,虽然他们奇菜无比我似乎把手环带进去了。。。前15道选择:我脑瘫忘了哈夫曼,直到晚......
  • 【西湖论剑2024初赛】MISC3-easy_rawraw WriteUp
    easyraw!manypasswords!首先用volatility+mimikatz可以爆出windows账户密码das123admin321vol.py--plugins=./plugins-f./rawraw.raw--profile=Win7SP1x64mimikatz剪贴板中,有另一个密码DasrIa456sAdmIn987,用来解压mysecretfile.rarvol.py--plugins=./plugins-f......
  • 2024 THUPC 初赛
    队伍名:TZOI。队员:yts,zhy,以及我一个拖后腿的。光我TZ义不容辞!Day-1随便点开一个THUPC的讨论或者游记,几乎每个队都有大神。进了比赛的交流群,一进群就看到了几个洛谷里的老面孔,比如gza等。其中很多人还是实力不弱的。可想而知,这会是一场恶战。但我相信我们队绝对还是一支相当......
  • 铁人三项(第五赛区)_2018_rop
    铁人三项(第五赛区)_2018_rop函数参数劫持32位泄露libcfrompwnimport*context.log_level='debug'#io=gdb.debug('./2018_rop','break*0x8048474')io=process('./2018_rop')elf=ELF('./2018_rop')Lib=ELF('......
  • P9970 [THUPC 2024 初赛] 套娃
    题面定义一个集合的\(\operatorname{mex}\)是最小的不在\(S\)中的非负整数。给定一个序列\(a_1,\dots,a_n\),对于每个\(1\leqk\leqn\),我们按照如下方式定义\(b_k\):对于\(a\)的所有长为\(k\)的子区间,求出这个子区间构成的数集的\(\operatorname{mex}\)。对于求出......