gpt4 book ai didi

linux - shellcode错误段错误(核心转储)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:33:33 27 4
gpt4 key购买 nike

我是 shellcode 的新手,我尝试为 (hello world) 编写 shellcode,所以这是我的第一个带有空字节的代码:

global _start

section .text

_start: ;tell linker entry point

mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel

section .data

msg db 'Hello, world!',0xa ;our dear string
len equ $ - msg ;length of our dear string

这是我删除 null x00 后的第二个代码!!

global _start

section .text

_start:
;tell linker entry point
xor edx,edx
mov dl,len ;message length
mov ecx,msg ;message to write
xor ebx,ebx
mov bl,1 ;file descriptor (stdout)
xor eax,eax
mov al,4 ;system call number (sys_write)
int 0x80 ;call kernel
xor eax,eax
mov al,1 ;system call number (sys_exit)
int 0x80 ;call kernel

section .data

msg db 'Hello, world!',0xa ;our dear string
len equ $ - msg ;length of our dear string

我编译它来测试:

nasm -f elf32 -o hello-without-null.o hello-without-null.asm

ld -o hello-without-null hello-without-null.o

当我运行它时它的工作./hello-without-null

比我用的:objdump -d hello-without-null -M intel

这是结果:

Disassembly of section .text:

08048080 <_start>:
8048080: 31 d2 xor edx,edx
8048082: b2 0e mov dl,0xe
8048084: b9 9c 90 04 08 mov ecx,0x804909c
8048089: 31 db xor ebx,ebx
804808b: b3 01 mov bl,0x1
804808d: 31 c0 xor eax,eax
804808f: b0 04 mov al,0x4
8048091: cd 80 int 0x80
8048093: 31 c0 xor eax,eax
8048095: b0 01 mov al,0x1
8048097: cd 80 int 0x80

然后我通过以下方式将其转换为 shellcode:

objdump -d ./hello-without-null|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'

输出是:

"\x31\xd2\xb2\x0e\xb9\x9c\x90\x04\x08\x31\xdb\xb3\x01\x31\xc0\xb0\x04\xcd\x80\x31\xc0\xb0\x01\xcd\x80"

当我测试它时,我得到了这个错误:

Shellcode Length: 25 Segmentation fault (core dumped)

我用于测试的 C 代码:

#include<stdio.h>
#include<string.h>

unsigned char code[] = \
"\x31\xd2\xb2\x0e\xb9\x9c\x90\x04\x08\x31\xdb\xb3\x01\x31\xc0\xb0\x04\xcd\x80\x31\xc0\xb0\x01\xcd\x80";

int main()
{

printf("Shellcode Length: %d\n", strlen(code));

int (*ret)() = (int(*)())code;

ret();


}

所以问题是什么??我该如何解决?

最佳答案

我通过改变来解决它

char shellcode[]

const char shellcode[]

并使用 JMP/CALL/POP 方法

关于linux - shellcode错误段错误(核心转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53592134/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com