有人請給我提供幫助,分解下面的shell代碼(在註釋部分),並向我解釋最後一行代碼的作用?逆向工程彙編代碼到C
# include <stdlib .h>
# include <stdio .h>
# include <string .h>
const char code [] =
"\x31\xc0" /* Line 1: xorl %eax, %eax */
"\x50" /* Line 2: pushl %eax */
"\x68""// sh" /* Line 3: pushl $0x68732f2f */
"\x68""/bin" /* Line 4: pushl $0x6e69622f */
"\x89\xe3" /* Line 5: movl %esp, %ebx */
"\x50" /* Line 6: pushl %eax */
"\x53" /* Line 7: pushl %ebx */
"\x89\xe1" /* Line 8: movl %esp, %ecx */
"\x99" /* Line 9: cdq */
"\xb0\x0b" /* Line 10: movb $0x0b, %al */
"\xcd\x80" /* Line 11: int $0x80 */;
int main (int argc , char ** argv) {
char buf [ sizeof (code)];
strcpy (buf , code);
((void (*)()) buf)(); /*I don't understand what this line is for*/
}
我讀了一點關於gdb,但我不知道如何在這種情況下使用它。
P.S:我在一臺x86-32 Ubuntu Linux機器上。
最後一行是在'BUF []'一個函數調用的代碼。如果堆棧內存段的NX位被設置爲安全性,它可能不起作用。 –
最後一行是函數調用:http://cdecl.org/?q=%28+void+%28%2a%29%28+%29%29+buf+。 – kay
@伊恩是對的。 '(void(*)())'是指向一個沒有參數的函數指針的'buf'類型。你可以使用'gdb'。只需使用'ni'和'si'命令即可進入指令級別。 –