카테고리 없음

시보 11/21

eunGI 2022. 11. 21. 15:38

[exec_shell2.s]

BITS 32                     ; Tell nasm this is 32-bit code.

; int execve(const char *filename, char *const argv[], char *const envp[]) 

  xor eax, eax               ; Zero out eax.

  push eax                    ; Push some nulls for string termination.

  push 0x68732f2f         ; Push “//sh” to the stack.

  push 0x6e69622f         ; Push “/bin” to the stack.

  mov ebx, esp              ; Put the address of “/bin//sh” into ebx, via esp.

  push eax                    ; Push 32-bit null terminator to the stack.

  mov edx, esp              ; This is an empty array for envp.

  push ebx                    ; Push string address to stack above null terminator.

  mov ecx, esp              ; This is the argv array with string ptr.

  mov al, 11                  ; Syscall #11.   

  int 0x80                     ; Do it

 

여기 파일에서 push //sh, push/bin을 push ohw/ -> push nib/ -> push rsu/ 로 바꾸고 who.s 파일의 이름으로 저장

 

nasm who.s

ndisasm -b32 who > dump_w

perl convert.pl dump_w out_w

하고 cat out_w 하고 나온 쉘코드 복사해서 who.c에 shellcodes[] 배열에 있는 값 지우고 복사

 

그리고 gcc -z execstack -o whoS who.c

./whoS 하면 whoS로 usr/bin/who와 같은 기능을 하는 파일 완성