OZ1NG의 뽀나블(Pwnable)

[PWN] [Tools] Pwntools Shellcraft 사용법 본문

Pwn Study

[PWN] [Tools] Pwntools Shellcraft 사용법

OZ1NG 2020. 1. 5. 19:04

[*] Shellcraft란?

pwntools에서 제공하는 엄청난 기능으로, 매우 간단하게 shellcode를 생성할 수 있도록 도와준다.

주로 pwntools의 asm함수와 같이 사용한다.

보통 CTF에서 seccomp를 우회하는 문제가 나왔을 때 사용한다.

 

[*] 간단한 Shellcraft 사용법

기본적인 문법 : shellcraft.[환경].[OS].[syscall 함수](함수 인자)

[!] 주의 : 함수 인자에는 '주소'를 입력할 때, 꼭 레지스터를 사용해야 한다.

[linux 64bit 환경 예시]
1
2
3
4
sc = shellcraft.amd64.linux.open('./flag'# open으로 ./flag라는 이름의 파일을 연다.
sc += shellcraft.amd64.linux.read('rax','rsp',100# ./flag에서 값을 'rsp'에 100만큼 읽어온다. ('rax'는 ./flag의 핸들러)
sc += shellcraft.amd64.linux.write(1,'rsp',100# write함수를 써서 'rsp'에 저장된 값을 출력한다. 
p.send(asm(sc))
 

[+] 추가로 소스코드 맨위에

context(arch='i386', os='linux') or context(arch='amd64', os='linux')

넣어주면 다음과 같이 [환경]과 [OS]를 무시하고 바로 syscall 함수를 사용 할 수 있다.

사용 후 : shellcraft.[syscall 함수](함수 인자)
            ex) shellcraft.read('rax','rsp',100)

 

추가적인 사용법은 아래의 Pwntools docs에서 확인할 수 있다.

참고1 : http://docs.pwntools.com/en/stable/shellcraft/i386.html

 

pwnlib.shellcraft.i386 — Shellcode for Intel 80386 — pwntools 3.12.1 documentation

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

docs.pwntools.com

참고2 : http://docs.pwntools.com/en/stable/shellcraft/amd64.html

 

pwnlib.shellcraft.amd64 — Shellcode for AMD64 — pwntools 3.12.1 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) – Number of by

docs.pwntools.com

 

'Pwn Study' 카테고리의 다른 글

house of force 공부자료  (0) 2020.06.03
[Pwn] Seccomp bypass  (0) 2020.01.05
[PWN] [TIPS] Pwntools로 문자열 찾기  (0) 2019.12.14
[PWN] [TIPS] Pwntools로 ROP Gadget 찾기  (0) 2019.12.14
[Pwn] .dtors 영역을 이용한 exploit  (0) 2019.11.22
Comments