Perché non è possibile trovare una stringa codificata nel programma disassemblato?
Oct 17 2020
Ho scritto un semplice programma per stampare qualcosa sullo schermo come di seguito:
ebra@him:/tmp/tuts$ cat sample.c #include <stdio.h> int main() { puts("Sample!"); } ebra@him:/tmp/tuts$ gcc sample.c -o sample
ebra@him:/tmp/tuts$ ebra@him:/tmp/tuts$ ./sample
Sample!
E poi ho smontato l'eseguibile per vedere cosa sta succedendo sotto il cofano:
ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep "<main>:" -A 10
0000000000001149 <main>:
1149: f3 0f 1e fa endbr64
114d: 55 push rbp
114e: 48 89 e5 mov rbp,rsp
1151: 48 8d 3d ac 0e 00 00 lea rdi,[rip+0xeac] # 2004 <_IO_stdin_used+0x4>
1158: e8 f3 fe ff ff call 1050 <puts@plt>
115d: b8 00 00 00 00 mov eax,0x0
1162: 5d pop rbp
1163: c3 ret
1164: 66 2e 0f 1f 84 00 00 nop WORD PTR cs:[rax+rax*1+0x0]
116b: 00 00 00
Come vedi sopra, subito prima di chiamare la putsfunzione, abbiamo lea rdi,[rip+0xeac]. Presumo che [rip+0xeac]sia l'indirizzo del testo codificato (ad esempio "Sample!").
Poiché ripè uguale a 0x1151mentre esegui la movlinea, il valore di [rip + 0xeac]sarà 0x1151 + 0xeac = 0x1ffd.
Ma non riesco a trovare questo indirizzo nel programma smontato:
ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep -i 1ffd
ebra@him:/tmp/tuts$ objdump -M intel --disassemble-all sample | grep -i "Sample!" ebra@him:/tmp/tuts$
Perché?
Risposte
4 blabb Oct 17 2020 at 15:24
per cercare String non puoi utilizzare disassemble-all
look at the bytes in both commands if you disassemble how can you find the string
objdump -s sample.exe |grep -i sample
sample.exe: file format pei-i386
404040 00000000 53616d70 6c652100 20634000 ....Sample!. c@.
objdump -M intel --disassemble-all sample.exe --start-address=0x404044 --stop-address=0x40404f
sample.exe: file format pei-i386
Disassembly of section .rdata:
00404044 <.rdata>:
404044: 53 push ebx
404045: 61 popa
404046: 6d ins DWORD PTR es:[edi],dx
404047: 70 6c jo 4040b5 <.rdata+0x45>
404049: 65 21 00 and DWORD PTR gs:[eax],eax
0040404c <_GS_ExceptionPointers>:
40404c: 20 63 40 and BYTE PTR [ebx+0x40],ah