easy-team / easywebpack-cli

A Powerful Cross-platform Webpack CLI Tool
https://easyjs.cn/easywebpack
MIT License
122 stars 28 forks source link

easywebpack-cli目录穿越漏洞 #25

Open muxishuihan opened 4 years ago

muxishuihan commented 4 years ago

你好~ 我发现了easywebpack-cli的一个安全问题,在使用easywebpack-cli并使用-d参数指定了生效目录后,使用"../../"会造成目录穿越问题,能够查看主机中的文件(如数据库连接文件等)。 复现方法: 1、执行 npm i -g easywebpack-cli 2、执行 easy server -d mock -p 8009,-d 指向任意一个目录 3、使用postman或其他工具发包,即可查看文件 image

我并没有查看您的代码来定位问题位置,因此我也不太确定是否是easywebpack-cli引入easywebpack的问题,请见谅。 希望您能够确认问题或及时回复哦~ 多谢

Easywebpack-cli directory traversal vulnerability

Hello~ I found a security problem with easywebpack-cli. After using easywebpack-cli and using the -d parameter to specify the effective directory, using "../../" will cause directory traversal problems. You can view the host Files (such as database connection files, etc.). Reproduction method:

1.npm i -g easywebpack-cli 2.easy server -d mock -p 8009, -d points to any directory 3.Use postman or other tools to send the request to view the file (See above for related pictures)

hubcarl commented 4 years ago

这个命令是用于本地开发使用的,需要使用者自己指定目录,目录可以任意指定

muxishuihan commented 4 years ago

你好,这个命令的主要问题并不是”目录可以任意指定”,而是指定目录后,可以跨目录访问到其他目录下的文件。比如,我执行了easy server -d mock -p 8009,-d /Users/kwai/Desktop/test,一个合理的实现是,我通过http请求只应该能够访问到/Users/kwai/Desktop/test目录下的文件及子目录。但我通过http://xxxxx/../../../../../../etc/passwd,却能够跨目录访问到/etc/passwd文件,这个漏洞的威胁是如果开放的server能够被其他机器访问(如局域网或互联网上的其他机器),访问者可以读取本机中的任意文件。当然我只是指出存在的问题,是否进行处理由您把握哈~

hubcarl commented 4 years ago

@muxishuihan 明白了,这个我处理一下,有兴趣也可以提个 PR 修复

hubcarl commented 4 years ago

@muxishuihan 我试了一下, 用 easy server -d test -p 8009 后, 然后访问 http://192.168.1.7:8009/../../easyjs-old/db 并不能访问上层目录内容, 最终获取的 filename 和 filepath 如下:

>>>filepath /easyjs-old/db  /Users/sky/dev/easyteam/easywebpack-cli/test/easyjs-old/db

用 chrome, curl, postman 访问,最终获取文件内容的路径都是上面内容。

看看能够给个完整例子我试试

muxishuihan commented 4 years ago

@hubcarl 嗨~ 请问您有类似postman或者burpsuite的发包器嘛?浏览器或者curl应该是会自动将http://XXX/../../../../转成http://XXX/,这样就达不到跳转目录的目的啦。我自己使用curl和浏览器测试的结果也和您相同。

ok ,我给您录个像吧

muxishuihan commented 4 years ago

你好,我已经发送到了您在github登记的个人邮箱 hubcarl@126.com 。我个人不是很清楚为什么您使用postman也无法复现该问题。

hubcarl commented 4 years ago

你好,我已经发送到了您在github登记的个人邮箱 hubcarl@126.com 。我个人不是很清楚为什么您使用postman也无法复现该问题。

好的,我查看一下

hubcarl commented 4 years ago

@muxishuihan 可以帮忙调试一下,直接修改 node_modules 加一下日志,然后启动项目看看:

目前看可能出现问题是这两个地方:

muxishuihan commented 4 years ago

@hubcarl 抱歉,这个我可能没法帮上忙。。因为我对node_modules完全不了解。。