카테고리 없음

시보 11/28

eunGI 2022. 11. 28. 15:16

쉘코드 연습문제 - 마지막 문제

[link]

https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md

link의 시스템 콜 번호: 9

https://man7.org/linux/man-pages/man2/link.2.html

link 시스템 콜의 인자 확인
- 여기서 link는 하드링크를 의미
- oldpath (=/root/a)는 ebx에
- newpath (=/root/b)는 ecx에
- link의 시스템 콜 번호는 eax에 저장해야함

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.
  cdq                         ; edx가 0이 됨 이거 하면
  mov al, 9                  ; 링크 시스템 콜 번호
  push edx                  ; insert null

  push 0x612F2F74         ; Push “a//t” to the stack.
  push 0x6F6F722F         ; Push “oor/” to the stack.
  mov ebx, esp              ; /root/a (=oldpath)를 ebx에 저장
  push edx                    ; insert null
  push 0x622F2F74         ; Push “b//t” to the stack.
  push 0x6F6F722F         ; Push “oor/” to the stack.
  mov ecx, esp              ; Put the address of “/root/b” into ebx, via esp. 
  int 0x80                     ; Do it

[chmod]

https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md
https://man7.org/linux/man-pages/man2/chmod.2.html

chmod의 시스템 콜 번호랑 인자 확인
chmod("/root/a", 메뉴얼 페이지에 있는 권한 값 아무거나 넣기 (8진수로 나와있는거 10진수로 바꿔서만 넣으면 됨)
/root/a => ebx에 넣기
권한 => ecx에 넣기 (read by group 40 = 10진수로 32를 넣어줄 것임), 32는 2바이트라서 cl에 넣어야함

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.
  cdq                         ; edx가 0이 됨 이거 하면
  xor ecx ecx                  ; ecx 0으로 만들기
  mov cl, 32                  ; read by group 권한 번호 (null 생기면 안되니까 cl 에 ㄴ넣어야함
  push edx                    ; insert null
  push 0x612F2F74         ; Push “a//t” to the stack.
  push 0x6F6F722F         ; Push “oor/” to the stack.
  mov ebx, esp              ; /root/a 를 ebx에 저장
  mov al, 15                  ; chmod 시스템 콜 번호
  int 0x80                     ; Do it