分段错误,当EXEÇ [英] Segmentation fault error when exe C

查看:147
本文介绍了分段错误,当EXEÇ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,当我编译和执行我的计划,我得到读取以下错误信息:段错误,而strace的错误信息如下:

So after I compile and execute my program I get the following error message that reads: "Segmentation fault", and the strace error message reads:

--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Segmentation fault

问题是,任何想法我怎么能解决这个错误,并显示在shell code中的消息?

Question is, any ideas how I can fix this error and display the message in the shell code?

大会code:

;r3v.asm

;r3v3rs3c - 3x_z3r0
[SECTION .text]

global _start

_start:

jmp short ender

starter:

xor eax, eax    
xor ebx, ebx    
xor edx, edx    
xor ecx, ecx    
mov al, 4   
mov bl, 1   
pop ecx     
mov dl, 18  
int 0x80    
xor ebx, ebx
int 0x80
ender:
call starter    
db 'r3v3rs3c'

与组装起来:NASM -f精灵r3v.asm
与它联系起来:LD -o r3v r3v.o
objdump的-d r3v:用倾倒
提取壳code到一个测试程序:

Assemble it with: nasm -f elf r3v.asm Link it with: ld -o r3v r3v.o Dump it with: objdump -d r3v Extract the shell code into a test program:

/*shelltest.c
r3v3s3c - 3x_z3r0*/
char code[] =
"\xeb\x15\x31\xc0\x31\xdb\x31\xd2\x31\xc9\xb0\x04\xb3\x01\x59\xb2\x12\xcd\x80\31\xdb\xcd\x80\xe8\xe6\xff\xff\xff\x72\x33\x76\x33\x72\x73\x33\x63";
;
int main(int argc, char **argv)
{
int (*exeshell)();
exeshell = (int (*)()) code;
(int)(*exeshell)();
}

然后我编译:GCC shelltest.c -o shelltest
与执行:./shelltest
和输出写着分割的错。

Then I compile with: gcc shelltest.c -o shelltest Execute it with: ./shelltest and the output reads "Segmentation fault".

推荐答案

目前您的字符串code将被放置到被宣布为不可执行,你声明数组是可变的(程序内存的一部分不是常量)。当您尝试运行它作为一个功能,你的操作系统会看到,你正试图在无法执行的内存区域运行code,将与段错误杀死你的程序。

Currently your string code will be placed into a part of the program's memory that is declared to be non executable as you declare the array to be mutable (not const). When you try to run it as a function your OS will see that you are trying to run code in an area of memory that cannot be executed and will kill your program with a segfault.

要解决这个改变你的声明 code 是一个为const char

To fix this change your declaration of code to be a const char

const char code[] = "\xeb......."

这将允许编译器把它转换成可执行存储器,从而允许它被运行

This will allow the compiler put it into executable memory and thus allow it to be run.

这篇关于分段错误,当EXEÇ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆