LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 722|回复: 4

shellcode编译有语法问题,找了很久没找出来

[复制链接]
发表于 2005-4-3 12:23:39 | 显示全部楼层 |阅读模式

  1. void main()
  2. {
  3. 3          __asm__("              
  4. 4                jmp     0x0
  5. 5                popl    %esi
  6. 6                movl    %esi,0x8(%esi)
  7. 7                movb    $0x0,0x7(%esi)
  8. 8                movl    $0x0,0xc(%esi)
  9. 9                movl    $0xb,%eax
  10. 10              movl    %esi,%ebx
  11. 11              leal    0x8(%esi),%ecx
  12. 12              leal    0xc(%esi),%edx
  13. 13              int     $0x80
  14. 14              movl    $0x1, %eax
  15. 15              movl    $0x0, %ebx
  16. 16              int     $0x80
  17. 17              call    0x0
  18. 18              .string "/bin/sh"
  19. 19        ");
  20. }
复制代码

$gcc shellcode.c
shellcode.c: 3:18 missing terminating " character
shellcode.c: in function `main`:
shellcode.c: 4 error: parse before jmp
shellcode.c: 19:17 missing terminating " character
发表于 2005-4-3 12:35:51 | 显示全部楼层
双引号不能跨行,你可以在行尾加上反斜杠,或者每一行都打上一对双引号。

也不能嵌套,你的 __asm__("...") 有一对双引号,.string "/bin/sh" 又有一对双引号。
回复 支持 反对

使用道具 举报

发表于 2005-4-3 19:35:59 | 显示全部楼层
这种简单程序,直接写成汇编不就行了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-3 23:03:53 | 显示全部楼层

  1. void main()
  2. {
  3. 3          __asm__(            
  4. 4                "jmp     0x0"
  5. 5                "popl    %esi"
  6. 6                "movl    %esi,0x8(%esi)"
  7. 7                "movb    $0x0,0x7(%esi)"
  8. 8                "movl    $0x0,0xc(%esi)"
  9. 9                "movl    $0xb,%eax"
  10. 10              "movl    %esi,%ebx"
  11. 11              "leal    0x8(%esi),%ecx"
  12. 12              "leal    0xc(%esi),%edx"
  13. 13              "int     $0x80"
  14. 14              "movl    $0x1, %eax"
  15. 15              "movl    $0x0, %ebx"
  16. 16              "int     $0x80"
  17. 17              "call    0x0"
  18. 18              ".string "/bin/sh""
  19. 19        );
  20. }
复制代码

很感谢楼上各位特别是doubleelec的回帖
每行加引号后
$gcc shellcode.c
/tmp/ccz89qcn.s Assembler messages:
/tmp/ccz89qcn.s: 13: Error: junk `popl %esimovl %esi` after expression
/tmp/ccz89qcn.s: 13: Error: too many memory references for `jmp`

请问/tmp/ccz89qcn.s是什么东西?编译过程怎么会出现?什么作用?该怎么解决
小弟第一次接触C中嵌入汇编,问得很菜,请见谅.
回复 支持 反对

使用道具 举报

发表于 2005-4-4 11:30:21 | 显示全部楼层
那是一个gcc在编译时生成的临时文件。
置顶的论坛索引中有linux汇编的链接,你先看看,然后再修改你的代码。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表