DC-7靶场

DC-7靶场

信息收集

  • nmap扫描,发现IP为192.168.137.137,开放端口22、80

    image-20250417104139529

  • 访问80,并扫描网站使用的框架。使用的内容管理系统是Drupal 8

    image-20250417104350648

  • While this challenge isn't all that technical, if you need to resort to brute forcing or a dictionary attacks, you probably won't succeed.即暴力破解是行不通的。

  • 发现网站存在robots.txt文件,包含一些网站的路径

    User-agent: *
    # CSS, JS, Images
    Allow: /core/*.css$
    Allow: /core/*.css?
    Allow: /core/*.js$
    Allow: /core/*.js?
    Allow: /core/*.gif
    Allow: /core/*.jpg
    Allow: /core/*.jpeg
    Allow: /core/*.png
    Allow: /core/*.svg
    Allow: /profiles/*.css$
    Allow: /profiles/*.css?
    Allow: /profiles/*.js$
    Allow: /profiles/*.js?
    Allow: /profiles/*.gif
    Allow: /profiles/*.jpg
    Allow: /profiles/*.jpeg
    Allow: /profiles/*.png
    Allow: /profiles/*.svg
    # Directories
    Disallow: /core/
    Disallow: /profiles/
    # Files
    Disallow: /README.txt
    Disallow: /web.config
    # Paths (clean URLs)
    Disallow: /admin/
    Disallow: /comment/reply/
    Disallow: /filter/tips
    Disallow: /node/add/
    Disallow: /search/
    Disallow: /user/register/
    Disallow: /user/password/
    Disallow: /user/login/
    Disallow: /user/logout/
    # Paths (no clean URLs)
    Disallow: /index.php/admin/
    Disallow: /index.php/comment/reply/
    Disallow: /index.php/filter/tips
    Disallow: /index.php/node/add/
    Disallow: /index.php/search/
    Disallow: /index.php/user/password/
    Disallow: /index.php/user/register/
    Disallow: /index.php/user/login/
    Disallow: /index.php/user/logout/
  • 虽然/core目录下的文件都允许爬取,但是直接访问core目录是被拒绝的,又不知道具体文件名,这个线索只能暂时先放着了。

    image-20250417153402089

  • 然后再找找cms的漏洞,发现CVE-2019-6340,这是一个反序列化漏洞,通过构造序列化字符串实现远程命令执行。

    image-20250417142934178

尝试利用漏洞

  • 使用kali的msfconsole工具进行利用

    image-20250417143137306

    image-20250417145440655

  • 没有成功。网上搜索发现网站必须开启RESTful Web服务才能利用,这个服务可以返回 JSON、XML 等格式的响应,用来与其他应用程序或服务进行交互,方便与其他系统集成。没有成功可能说明dc-7没有开这个服务。

其他尝试

  • 登录页面sql注入,试了很多方法但都尝试失败

  • 然后就看了看README.txt,发现core目录下有这些文件

    More about configuration:
    * Install, update, and maintain Drupal:
     See INSTALL.txt and UPDATE.txt in the "core" directory.
  • 继续看/core/INSTALL.txt

    Run the following command for a list of available options that you may need to
    configure quick-start:
    - php core/scripts/drupal quick-start --help
  • /core/secipts/drupal:

    #!/usr/bin/env php
    <?php
    
      
    
      /**
    
       * @file
    
       * Provides CLI commands for Drupal.
    
       */
    
      
    
      use Drupal\Core\Command\QuickStartCommand;
    
      use Drupal\Core\Command\InstallCommand;
    
      use Drupal\Core\Command\ServerCommand;
    
      use Symfony\Component\Console\Application;
    
      
    
      if (PHP_SAPI !== 'cli') {
    
        return;
    
      }
    
      
    
      $classloader = require_once __DIR__ . '/../../autoload.php';
    
      
    
      $application = new Application('drupal', \Drupal::VERSION);
    
      
    
      $application->add(new QuickStartCommand());
    
      $application->add(new InstallCommand($classloader));
    
      $application->add(new ServerCommand($classloader));
    
      
    
      $application->run();
  • 说明存在/autoload.php文件,但是依旧没有权限访问

破局点

  • 这时候想起来提示说过这个题目不全是技术性的,正确的方式是“跳出盒子”

    While this challenge isn't all that technical

    Way "outside" the box. 🙂

  • 但是只是觉得这两句有别的意思🤔,然而实际上还是没有想到

  • 查攻略,说是搜一下@DC7USER这个账号,这谁能想到,但确实是再box以外😥

    image-20250417160740361

  • Dc7User/staffdb

    image-20250417160950948

  • 把代码全部down下来,查看config.php文件,发现数据库的账号密码,但是dc-7又没有开3306端口。

    <?php
    
      	$servername = "localhost";
    
      	$username = "dc7user";
    
      	$password = "MdR3xOgB7#dW";
    
      	$dbname = "Staff";
    
      	$conn = mysqli_connect($servername, $username, $password, $dbname);
    
      ?>
  • 那就先拿它试一下ssh。登录成功

    image-20250417164019289

提权

  • 查看当前目录下文件发现一个backups目录和mbox文件,继续查看mbox发现root用户创建了一个定时任务执行去/opt/scripts/backups.sh

    dc7user@dc-7:~$ ls -l
    total 12 
    drwxr-xr-x 2 dc7user dc7user 4096 Apr 17 16:15 backups 
    -rw------- 1 dc7user dc7user 7938 Aug 30  2019 mbox
    
    dc7user@dc-7:~$ cat mbox
    From root@dc-7 Thu Aug 29 17:00:22 2019
    Return-path: 
    Envelope-to: root@dc-7
    Delivery-date: Thu, 29 Aug 2019 17:00:22 +1000
    Received: from root by dc-7 with local (Exim 4.89)
          (envelope-from )
          id 1i3EPu-0000CV-5C
          for root@dc-7; Thu, 29 Aug 2019 17:00:22 +1000
    From: root@dc-7 (Cron Daemon)
    To: root@dc-7
    Subject: Cron  /opt/scripts/backups.sh
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    X-Cron-Env: 
    X-Cron-Env: 
    X-Cron-Env: 
    X-Cron-Env: 
    Message-Id: 
    Date: Thu, 29 Aug 2019 17:00:22 +1000
    
    Database dump saved to /home/dc7user/backups/website.sql               [success]
    gpg: symmetric encryption of '/home/dc7user/backups/website.tar.gz' failed: File exists
    gpg: symmetric encryption of '/home/dc7user/backups/website.sql' failed: File exists
  • 查看/opt/script/backups.sh文件具体信息,是一个备份用的脚本。root和www-data组成员都有可写权限。

    dc7user@dc-7:/opt/scripts$ ls -l backups.sh 
    -rwxrwxr-x 1 root www-data 520 Aug 29  2019 backups.sh
    
    dc7user@dc-7:/opt/scripts$ cat backups.sh 
    #!/bin/bash
    rm /home/dc7user/backups/*
    cd /var/www/html/
    drush sql-dump --result-file=/home/dc7user/backups/website.sql
    cd ..
    tar -czf /home/dc7user/backups/website.tar.gz html/
    gpg --pinentry-mode loopback --passphrase PickYourOwnPassword --symmetric /home/dc7user/backups/website.sql
    gpg --pinentry-mode loopback --passphrase PickYourOwnPassword --symmetric /home/dc7user/backups/website.tar.gz
    chown dc7user:dc7user /home/dc7user/backups/*
    rm /home/dc7user/backups/website.sql
    rm /home/dc7user/backups/website.tar.gz
  • 所以现在的思路是先想办法切换到www-data用户,然后再利用这个文件的定时执行来提权。

  • 而脚本文件中的drush命令是drupal8的管理工具,可以用它来更改管理员密码,如下

    drush user-password admin --password="new_pass"
    注意:需要先cd到网站的目录下,即/var/www/html
  • 登录到后台系统中,通过添加扩展来上传文件

    image-20250417173043109

  • 然后就发现被重命名了😭,这样上传是不行的。网上查到需要安装php的插件,然后就可以在创建页面的地方直接写一句话木马了

  • 注意,要选择年份比较老的,新的很可能解析不了,在这试了很长时间,这个链接的是合适的:https://ftp.drupal.org/files/projects/php-8.x-1.0-alpha1.tar.gz

    image-20250417182216874

  • antsword连接,然后更改定时任务的文件反弹shell到kali,等大概几分钟就可以了

    image-20250417182937465

flag

image-20250417183107918

暂无评论

发送评论 编辑评论


				
上一篇
下一篇