nginx 反代 tomcat 后, url 带斜杠出现源码下载漏洞

2022-02-08 15:42:36 +08:00
 FONG2

百度搜了一遍,tomcat 有类似的漏洞,但是我的版本已经修复。 实测直接访问 tomcat 地址 xxx.jsp/报 404 , 访问 nginx 地址 xxx.jsp/弹出下载请求,能把这个 jsp 源码下回来, 怎么破? 百度没找到相应漏洞说明, 我尝试用 rewire 屏蔽后斜杠,但是导致 xxx.com/aa/打不开了。

6066 次点击
所在节点    NGINX
44 条回复
learningman
2022-02-08 15:44:36 +08:00
把你 nginx 配置发出来吧
themostlazyman
2022-02-08 15:44:39 +08:00
贴下 nginx 配置吧,感觉没配置对。
julyclyde
2022-02-08 15:48:27 +08:00
你确定是反代?是不是 nginx 直接 root 到同一个目录去了?
undeflife
2022-02-08 15:50:36 +08:00
看起来是直接把 root 设置到了 tomcat 的 webapps 目录
FONG2
2022-02-08 16:02:17 +08:00
location /abc {
proxy_set_header CLIENTIP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://1.1.1.1:8080/abc;
}
FONG2
2022-02-08 16:03:37 +08:00
learningman
2022-02-08 16:05:12 +08:00
不是这里,问题可能处在上面的 root 那里
FONG2
2022-02-08 16:06:43 +08:00
访问 nginx http://host/abc/a.jsp/ 弹下载提示 能下载源码
访问 tomcat http://host:8080/abc/a.jsp/ 显示 404
nginx 版本 1.21.6
tomcat 8.5.63
FONG2
2022-02-08 16:10:35 +08:00
@learningman 这个 Server 没有配 root
server {
listen 80;
server_name localhost;
client_body_timeout 60s;
client_header_timeout 60s;
send_timeout 600s;
location / {
proxy_set_header MyClientIP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://1.1.1.1:8080/abc/;
}
ThirdFlame
2022-02-08 16:24:42 +08:00
能下到 a.jsp 的源代码? 你确实不是 html 而是源代码?
FONG2
2022-02-08 16:28:47 +08:00
@ThirdFlame yes
<%@ page...
<% request.setxxxxx%>
都能看到,就是 jsp 源码
skiy
2022-02-08 16:48:25 +08:00
在服务器直接 curl 一下看看是 404 ,还是下载?按理不应该出现这个问题才对。

我有个配置

index index.html index.htm default.htm default.html;
root /data/wwwroot/default;

location / {
log_not_found on;
proxy_pass http://127.0.0.1:8081/api/;

proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
FONG2
2022-02-08 17:07:35 +08:00
@skiy curl 是下载 也可以看到<%代码%>
eason1874
2022-02-08 17:18:25 +08:00
a.jsp 是文件名?如果是,这种情况应该是 Nginx 没把 a.jsp/ 请求转发给 Tomcat 处理,而是当作文件下载请求返回文件内容
FONG2
2022-02-08 17:22:31 +08:00
@eason1874 那怎么解决?而且我在 access.log localhost_xxlog 查不到访问记录
qq1340691923
2022-02-08 17:26:04 +08:00
jsp 而已,有什么慌的
skiy
2022-02-08 17:41:08 +08:00
@FONG2 若在你服务器中 CURL 实际地址也是下载,那就不是 NGINX 的问题了吧。若是只有反代的地址是下载,才是 NGINX 的问题。反代没涉及到下载的,是不是你 NGINX 的配置问题?可以试试的上面发的那串(需要重启 NGINX )
eason1874
2022-02-08 17:48:24 +08:00
@FONG2 让后端给请求打日志,然后访问了看日志就知道请求有没有到后端了。请求没有到后端就是反代配置问题
Chism
2022-02-08 17:50:14 +08:00
我的 nginx 把版本从 1.21 换到 1.19 ,竟然导致 domain 前端调用 domain/的 api 报跨域
gengchun
2022-02-08 18:36:41 +08:00
见过太多离谱的部署了,不评价 OP 。

@Chism 确认一下 ngx 编译参数,可能是配置路径问题导致用了不正确的配置。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/832466

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX