SECURITY/System

[시스템보안] 11주차_ Shellcode(2)

2022. 11. 14. 17:02
목차
  1. 1 Shellcode
  2. 2 shell-spawning Shellcode
  3. 3 Shellcode 연습문제

1 Shellcode

(1) Helloworld2.c

  - 2의 보수를 이용한 접근법

  - 역 방향으로  Call 명령어를 수행하여  Call 명령어에 null byte가 존재하지 않도록 함

  - nasm을 이용해서 helloworld2.s을 어셈블(assemble), Hexdump로 쉘코드 생성

 

  - call 명령어의 널바이트 제거됨

  - mov 명령어의 널바이트는 여전히 제거되지 않음

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

jmp short one          ; Jump down to a call at the end.

two:
; ssize_t write(int fd, const void *buf, size_t count);
pop ecx                  ; Pop the return address (string ptr) into ecx.
mov eax, 4             ; Write syscall #4
mov ebx, 1             ; STDOUT file descriptor
mov edx, 15           ; Length of the string
int 0x80                 ; Do syscall: write(1, string, 14)

; void _exit(int status);
mov eax, 1              ; Exit syscall #1
mov ebx, 0              ; Status = 0
int 0x80                  ; Do syscall: exit(0)

one:
call two                                       ; Call back upwards to avoid null bytes
db "Hello, World!", 0x0a, 0x0d       ; with newline and carriage return bytes

 

(2) Helloworld3.c

  - mov 명령어에서 Null 바이트 제거하기

  - 8byte 레지스터를 사용함 (al, bl, cl, dl)

 

  - mov 명령어 널바이트 제거됨

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

jmp short one            ; Jump down to a call at the end.

two:
; ssize_t write(int fd, const void *buf, size_t count);
pop ecx                     ; Pop the return address (string ptr) into ecx.
xor eax, eax               ; Zero out full 32 bits of eax register.
mov al, 4                   ; Write syscall #4 to the low byte of eax.
xor ebx, ebx               ; Zero out full 32 bits of ebx register.
inc ebx                      ; Increment ebx to 1, STDOUT file descriptor.
xor edx, edx               ; Zero out full 32 bits of edx register.
mov dl, 15                 ; Length of the string
int 0x80                     ; Do syscall: write(1, string, 14)

; void _exit(int status);
mov al, 1                   ; Exit syscall #1, the top 3 bytes are still zeroed.
dec ebx                     ; Decrement ebx back down to 0 for Status = 0
int 0x80                     ; Do syscall: exit(0)

one:
call two                                       ; Call back upwards to avoid null bytes
db "Hello, World!", 0x0a, 0x0d       ; with newline and carriage return bytes

 

2 shell-spawning Shellcode

(1) exec_shell1.c

  - exec_shell2.s의 쉘코드 생성

 

(2) exec_shell2.c

  - exec_shell2.s의 쉘코드 생성

  - 1과 달리 스텍을 사용하여 생성함 > Shell code의 크기 줄어듬

  - 공격에 유리함

 

3 Shellcode 연습문제

(1) 쉘 코드를 작성하여 /usr/bin/who와 동일한 출력 만들어내기

 

 

 

  1. 1 Shellcode
  2. 2 shell-spawning Shellcode
  3. 3 Shellcode 연습문제
'SECURITY/System' 카테고리의 다른 글
  • [시스템보안] 13주차 버퍼오버플로우 공격(2)
  • [시스템보안] 12주차_ Shellcode(3)
  • [시스템보안] 10주차_ Shellcode
  • [시스템보안] 10주차_ Bufferoverflow2
yuujoeng
yuujoeng
IT and Information Security
yuujoeng
알감자는 공부중
yuujoeng
전체
오늘
어제
  • 🎁 (201)
    • SECURITY (80)
      • 관리보안 (27)
      • System (10)
      • System | Wargame (30)
      • Android (9)
      • Reversing (3)
      • AWS (1)
    • BLOCKCHAIN (45)
      • BlockChain (22)
      • Ethereum (23)
    • PROGRAMMING (30)
      • Web (16)
      • Android (6)
      • Spring (8)
    • IT (0)
      • Article (40)
      • RaspberryPi (5)

블로그 메뉴

  • HOME
  • TIKKLE

인기 글

hELLO · Designed By 정상우.
yuujoeng
[시스템보안] 11주차_ Shellcode(2)
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.