Tuesday, June 03, 2008

汇编语言的艺术

Linux下使用汇编语言 有很多选择:内联汇编,as或者nasm/yasm,下面是使用 as的例子:
.text
.globl _start
_start:
jmp get_string
print_string:
movl $4, %eax /* __NR_write */
movl $1, %ebx
popl %ecx
movl $6, %edx
int $0x80

movl %eax, %ebx
movl $1, %eax /* __NR_exit */
int $0x80

get_string:
call print_string
.string "hello\n"

这 段汇编使用了传统的int $0x80系统调用,这里最重要的窍门是怎样获取字符串的首地址(call/popl)。这个小技巧使得生成的代码是位置无关的(PIC - Position Independent Code)。这在code injection中注入shellcode非常普遍。

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home