c - 如何获取c程序的操作码

标签 c linux assembly x86 opcode

我知道如何使用 gdb 获取程序的汇编代码,但如何获取操作码? 我需要它来破解 Linux 服务器(别担心它是我正在学习的类(class)的一部分,所以不会损害真正的服务器)。其实我在读this文章,我想知道如何从汇编中获得:

[aleph1]$ gcc -o shellcodeasm -g -ggdb shellcodeasm.c
[aleph1]$ gdb shellcodeasm

(gdb) disassemble main
Dump of assembler code for function main:
0x8000130 <main>:       pushl  %ebp
0x8000131 <main+1>:     movl   %esp,%ebp
0x8000133 <main+3>:     jmp    0x800015f <main+47>
0x8000135 <main+5>:     popl   %esi
0x8000136 <main+6>:     movl   %esi,0x8(%esi)
0x8000139 <main+9>:     movb   $0x0,0x7(%esi)
0x800013d <main+13>:    movl   $0x0,0xc(%esi)
0x8000144 <main+20>:    movl   $0xb,%eax
0x8000149 <main+25>:    movl   %esi,%ebx
0x800014b <main+27>:    leal   0x8(%esi),%ecx
0x800014e <main+30>:    leal   0xc(%esi),%edx
0x8000151 <main+33>:    int    $0x80
0x8000153 <main+35>:    movl   $0x1,%eax
0x8000158 <main+40>:    movl   $0x0,%ebx
0x800015d <main+45>:    int    $0x80
0x800015f <main+47>:    call   0x8000135 <main+5>
0x8000164 <main+52>:    das
0x8000165 <main+53>:    boundl 0x6e(%ecx),%ebp
0x8000168 <main+56>:    das
0x8000169 <main+57>:    jae    0x80001d3 <__new_exitfn+55>
0x800016b <main+59>:    addb   %cl,0x55c35dec(%ecx)
End of assembler dump.

以下内容:

testsc.c
------------------------------------------------------------------------------
char shellcode[] =
    "\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\x0c\x00\x00\x00"
    "\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80"
    "\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\xe8\xd1\xff\xff"
    "\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\xc3";

系统是 linux x86,我将使用 C 语言。我真的很喜欢自动化的方式,但手动解决方案也可以。

我的意思是如何转换 %ebp、%esi、%esp 等。有我可以使用的 map 吗?还是自动化程序?

最佳答案

给你:

Disassembly of section .data:

00000000 <shellcode>:
   0:       eb 2a                   jmp    2c <shellcode+0x2c>
   2:       5e                      pop    %esi
   3:       89 76 08                mov    %esi,0x8(%esi)
   6:       c6 46 07 00             movb   $0x0,0x7(%esi)
   a:       c7 46 0c 00 00 00 00    movl   $0x0,0xc(%esi)
  11:       b8 0b 00 00 00          mov    $0xb,%eax
  16:       89 f3                   mov    %esi,%ebx
  18:       8d 4e 08                lea    0x8(%esi),%ecx
  1b:       8d 56 0c                lea    0xc(%esi),%edx
  1e:       cd 80                   int    $0x80
  20:       b8 01 00 00 00          mov    $0x1,%eax
  25:       bb 00 00 00 00          mov    $0x0,%ebx
  2a:       cd 80                   int    $0x80
  2c:       e8 d1 ff ff ff          call   2 <shellcode+0x2>
  31:       2f                      das
  32:       62 69 6e                bound  %ebp,0x6e(%ecx)
  35:       2f                      das
  36:       73 68                   jae    a0 <shellcode+0xa0>
  38:       00 89 ec 5d c3 00       add    %cl,0xc35dec(%ecx)

请注意 add %cl 指令中的最后一个 00 是如何来自字符串空终止符字节的;这不是明确的。

我是如何得到这个的,我只是简单地编译了你的声明

gcc testsc.c -c

然后

objdump -D testsc.o

关于c - 如何获取c程序的操作码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813027/

相关文章:

linux - Eclipse 不使用 .bashrc 中设置的路径

assembly - mov si, offset msg 中的 FASM vc MASM 转换问题

c - 在较大的字符串中查找子字符串 (C)

c - Scanf() 与格式说明符中提供的\n 和 '\n' 的工作方式不同

c - POSIX 计时器以预期频率的两倍运行

assembly - 操作码 FF350E204000 有什么作用?

linux - 在我的代码末尾进行系统调用后出现程序集段错误

c - 条件递归中的段错误

c - 我如何使用结构?

linux - 如何使用 cut 以不同格式输出初始行?