-
[System Security] 7.3 쉘 코드 작성Security/System Security 2021. 5. 11. 14:30
1. "/bin/sh" 문자열을 임의의 메모리에 위치시킴
.string "/bin/sh"
2. NULL문자(0)를 "bin/sh"뒤에 붙인다. ("/bin/sh\0")
movb $0x0, [0x0 1바이트에 대한 주소]
3. /bin/sh 문자열 주소값을 불러와서 name[0]에 할당한다
movl [/bin/sh 문자열이 저장된 주소], [name[0]의 주소]
4. null값을 name[1]에 해당하는 주소에 할당한다
movl $0x0, [name[1]에 대한 주소]
5. 0xb를 EAX 레지스터에 저장한다
movl $0xb, %eax
6. /bin/sh 문자열의 주소를 EBX 레지스터에 저장한다
movl [/bin/sh 문자열의 주소], %ebx
7. /bin/sh 문자열 주소를 저장한 곳의 주소를 ECX 레지스터에 저장한다
leal [/bin/sh 문자열의 주소]. %ecx
8. 0x0값을 EDX 레지스터에 저장한다
movl $0x0, %edx
9. int $0x80 명령을 실행한다
int $0x80
컴파일과 실행
gcc -o asmshell1 asmshell.c -fno-stack-protector -mpreferred-stack-boundary=2
코드 세그먼트 내에 write 권한을 추가하기 위한 링킹 옵션 추가
gcc -o asmshell2 asmshell.c -fno-stack-protector -mpreferred-stack-boundary=2 -static -W1,--omagic
섹션 헤더 확인하기
readelf -S asmshell1
'Security > System Security' 카테고리의 다른 글
[System Security] 실습 정리 (0) 2021.05.11 [System Security] 명령어 정리 (0) 2021.05.11 [System Security] 7.2 쉘 코드 획득 (0) 2021.05.10 [System Security] 7.1 시스템콜 원리 (0) 2021.05.10 [System Security] 6.5 Lena's Crackme : Ollydbg (0) 2021.05.10