[SYSTEM HACKING] ShellNoob를 이용한 Shellcode 작성 및 활용 (Writing Shell Code with ShellNoob   Install and Using ShellNoob)

shellcode 를 만드는 일은 재미있지만, 생각보다 시간도 투자되고 약간 귀찮은 부분도 존재합니다. 그러한 과정을 조금 줄여줄 수 있는 좋은 툴이 있어 작성하였습니다.

Shellnoob라는 이 툴은 Shellcode를 위한 툴 입니다. Assembly 코드를 쉘코드로 변환하거나 ShellCode 제작에 있어 굉장히 도움되는 기능을 담고 있는 툴이죠.

Shellnoob 설치하기(Install ShellNoob)

ShellNoob(이하 snoob)는 github를 통해 배포되며, Clone를 이용해 쉽게 설치할 수 있습니다.

git clone https://github.com/reyammer/shellnoob.git

cd shelnoob

python shellnoob.py

명령 등록 1 (Add Command)

./shellnoob.py –install

or

명령 등록 2 (Add Command) bashrc 등 shell profile에 정의하기

vim .bashrc

..snip.. alias snoob=’python [shellnoob dir]/shellnoob.py’

사용하기 쉽게 명령으로 등록한 후 실행하시면 아래와 같이 Usage가 나타납니다.

HaHwul #> snoob shellnoob.py [–from-INPUT] (input_file_path | - ) [–to-OUTPUT] [output_file_path | - ] shellnoob.py -c (prepend a breakpoint (Warning: only few platforms/OS are supported!) shellnoob.py –64 (64 bits mode, default: 32 bits) shellnoob.py –intel (intel syntax mode, default: att) shellnoob.py -q (quite mode) shellnoob.py -v (or -vv, -vvv) shellnoob.py –to-strace (compiles it & run strace) shellnoob.py –to-gdb (compiles it & run gdb & set breakpoint on entrypoint)

Standalone “plugins” shellnoob.py -i [–to-asm | –to-opcode ] (for interactive mode) shellnoob.py –get-const shellnoob.py --get-sysnum shellnoob.py --get-strerror shellnoob.py --file-patch (in hex). (Warning: tested only on x86/x86_64) shellnoob.py --vm-patch (in hex). (Warning: tested only on x86/x86_64) shellnoob.py --fork-nopper (this nops out the calls to fork(). Warning: tested only on x86/x86_64)

“Installation” shellnoob.py –install [–force] (this just copies the script in a convinient position) shellnoob.py –uninstall [–force]

Supported INPUT format: asm, obj, bin, hex, c, shellstorm Supported OUTPUT format: asm, obj, exe, bin, hex, c, completec, python, bash, ruby, pretty, safeasm All combinations from INPUT to OUTPUT are supported!

Check out the README file for more info.

ShellNoob를 이용한 Shell code <-> Assembly Code 변환

shellnoob.py [–from-INPUT] (input_file_path | - ) [–to-OUTPUT] [output_file_path | - ]

매우 간단합니다. 옵션 중 –from- 으로 입력 데이터의 형식을 정해줍니다. 예시로 –from-asm 이렇게 옵션을 주면 assembly 형태의 데이터를 입력으로 받습니다.

–to- 로는 결과 포맷을 지정해 줄 수 있습니다. –to-c, –to-bin 등 이 또한 간단하게 수행할 수 있습니다.

snoob에서 포함된 sample 코드로 테스트를 해볼까합니다.

HaHwul #> cat exec-shell.asm


.section .text
xor    %eax,%eax
push   %eax
push   $0x68732f2f
push   $0x6e69622f
mov    %esp,%ebx
push   %eax
push   %ebx
mov    %esp,%ecx
mov    $0xb,%al
int    $0x80

┎ [ 11:28:59 : root ] [ /test ] HaHwul #> ls exec-shell.asm

입력은 asm, out 은 bin으로 하였을 시 exec-shell.bin 파일이 생성됩니다.

┎ [ 11:29:00 : root ] [ /test ] HaHwul #> snoob –from-asm exec-shell.asm –to-bin Converting /test/exec-shell.asm (asm) into /test/exec-shell.bin (bin)

읽어서보면 쉘코드 데이터가 그대로 써진것을 확인할 수 있습니다.

┎ [ 11:29:10 : root ] [ /test ] HaHwul #> cat exec-shell.bin 1�Ph//shh/bin��PS���

ouput 포맷을 좀 바꿔서 c로 나타내면, buffer에 shellcode를 저장한 형태로 파일이 생성됩니다.

┎ [ 11:34:05 : root ] [ /test ] HaHwul #> snoob –from-asm exec-shell.asm –to-c

exec_shell.c


char shellcode[] = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80";

edb 업로드나, 잠깐의 테스트를 위해선 빠르게 결과물을 얻어낼 수 있지요.

ShellNoob 보조기능

–get-sysnum 옵션을 통해 시스템 콜 넘버를 조회할 수 있습니다. 예시로 자주 사용되는 execve에 대해 보면 아래와 같이 32bit, 64bit 모두 확인할 수 있습니다.

HaHwul #> snoob –get-sysnum execve x86_64 ~> 59 i386 ~> 11

비슷한 기능으로 에러 Number에 대해서 역으로 조회가 가능합니다. 예를들어 20번으로 조회를 하였을 때 Not a directory 라는 메시지를 얻어낼 수 있습니다.

HaHwul #> snoob –get-errno 20 20 ~> Not a directory

또한 Interactive mode 및 –to-gdb, –to-strace를 통한 디버깅 모드 등 여러가지 기능을 수행할 수 있습니다.

ShellNoob 지원 Formats

“asm” - standard assembly. ATT syntax by default, use –intel to use Intel syntax. (see “asm as output” section for more details) (asm - Assembly 포맷 / 기본적으로 ATT를 따라가며 옵션으로 Intel 지정 가능) “bin” - raw binary (‘\x41\x42\x43\x44’) (bin - Binary 형태로 생성) “hex” - raw binary encoded in hex (‘41424344’) (hex - Hex 형태로 생성) “obj” - an ELF (obj - ELF/ .o 파일로 생성) “exe” - an executable ELF (exe - ELF/ 실행 가능한 바이너리 생성) “c” - something ready to embed in a C program. (c - c언어 형태 로 생성하며 내부 변수에 shellcode가 삽입되어 나타남) “python”, “bash”, “ruby” - same here. (다른 언어 포맷으로도 지원함) “completec” - compilable C that properly set the memory as RWX (to support self-modifying shellcodes) “safeasm” - assembly that is 100% assemblable: sometimes objdump’s output, from which the “asm” is taken, is not assemblable. This will output the “raw” bytes (in .byte notation) so that it’s assemblable by “as”. “shellstorm” - The –from-shellstorm switch takes as argument a . ShellNoob will grab the selected shellcode from the shell-storm shellcode DB, and it will convert it to the selected format.

Reference

https://github.com/reyammer/shellnoob/