exit的shellcode

在linux下输入man 3 exit

[root@localhost ~]# man 3 exit


得到

 

NAME
       exit - cause normal process termination

SYNOPSIS
       #include <stdlib.h>

       void exit(int status);

DESCRIPTION
       The exit() function causes normal process termination and the value of status & 0377 is returned to the parent (see wait(2)).

       All functions registered with atexit(3) and on_exit(3) are called, in the reverse order of their registration.  (It is possible for one of these
       functions to use atexit(3) or on_exit(3) to register an additional function to be executed during exit processing; the new registration is added
       to  the  front of the list of functions that remain to be called.)  If one of these functions does not return (e.g., it calls _exit(2), or kills
       itself with a signal), then none of the remaining functions is called, and further exit processing (in particular, flushing of stdio(3) streams)
       is  abandoned.  If a function has been registered multiple times using atexit(3) or on_exit(3), then it is called as many times as it was regis-
       tered.

       All open stdio(3) streams are flushed and closed.  Files created by tmpfile(3) are removed.

       The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE, that may be passed to exit() to indicate successful or unsuccessful  ter-
       mination, respectively.

RETURN VALUE
       The exit() function does not return.


exit只有一个参数,那就是状态。我一般设置状态为0 ,在C语言中调用就是

exit(0);


上面用linux汇编语言实现:

;exit.asm
[SECTION .text]
global _start
_start:
        xor eax, eax       ;exit is syscall 1
        mov al, 1       ;exit is syscall 1
        xor ebx,ebx     ;zero out ebx
        int 0x80


exit的系统调用号是1,状态是0,于是eax设置为1,ebx设置为0,再调用0x80号中断。

在linux上编译:

[root@localhost shellcode]# nasm -f elf exit.asm 


连接:

[root@localhost shellcode]# ld -o exiter exit.o 


生成了exiter,然后对exiter进行反汇编:

[root@localhost shellcode]# objdump -d exiter


显示:

exiter:     file format elf32-i386


Disassembly of section .text:

08048060 <_start>:
 8048060:       31 c0                   xor    %eax,%eax
 8048062:       b0 01                   mov    $0x1,%al
 8048064:       31 db                   xor    %ebx,%ebx
 8048066:       cd 80                   int    $0x80


于是,shellcode就是\x31\xc0\xb0\x01\x31\xdb\xcd\x80

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值