PandaX icon indicating copy to clipboard operation
PandaX copied to clipboard

pandax excel 导出 任意文件覆盖 或 任意文件下载

Open L1nyz-tel opened this issue 11 months ago • 1 comments

pandax excel 导出任意文件覆盖 或 任意文件下载

https://github.com/PandaXGO/PandaX/blob/3d265207b631b30b0826c2b6051588a2ae076d7a/apps/system/router/user.go#L153-L161

https://github.com/PandaXGO/PandaX/blob/3d265207b631b30b0826c2b6051588a2ae076d7a/apps/system/router/role.go#L84-L92

https://github.com/PandaXGO/PandaX/blob/3d265207b631b30b0826c2b6051588a2ae076d7a/apps/system/router/dict.go#L65-L73

这三处路由,之后都会调用 utils.InterfaceToExcel(*list, fileName) 然后 rc.Download(fileName)

选其中一个来看

代码中没有对传入的 filename 做检查,使用 ../ 跨目录指定导出的 excel 文件名及目录位置,可以用来覆盖掉不应该覆盖的文件

https://github.com/PandaXGO/PandaX/blob/3d265207b631b30b0826c2b6051588a2ae076d7a/apps/system/api/user.go#L326-L342

而且,如果该目标文件没有写权限的话,之后 rc.Download(fileName) 又会将这个文件下载下来,就变成了文件读取了

但是调用的是 http.ServeFile,只能用来读取项目目录下的文件,无法读取 /etc/passwd 等系统文件

https://github.com/PandaXGO/PandaX/blob/3d265207b631b30b0826c2b6051588a2ae076d7a/kit/restfulx/restfulx.go#L84-L92

比如这样子去覆盖掉 template 文件

L1nyz-tel avatar Mar 10 '24 03:03 L1nyz-tel

【fix】对设置的的文件名进行验证

PandaX-Go avatar Mar 11 '24 03:03 PandaX-Go