文件上传功能是 Web 应用中非常重要且敏感的部分,如果缺乏完善的安全控制,极易成为攻击者利用的突破口。本文通过对 .NET 某 ERP 系统的两个文件上传功能进行代码审计与漏洞分析,揭示了潜在的任意文件上传风险及其危害。
01. 漏洞代码审计
在渗透测试中,通过分析提供的代码,可以看到系统中存在两个文件上传接口:Upload***File 和 Upload***PlanFile。这两个方法分别负责上传文件到 \In***Files\ 和 \In***PlanFile\ 目录下。
1.1 Upload***File 方法
该方法在代码中,文件扩展名仅通过以下代码获取,并未对其进行任何安全校验,具体代码如下所示。
public UploadResult Upload***File()
{
UploadResult uploadResult = new UploadResult();
try
{
HttpPostedFile httpPostedFile = HttpContext.Current.Request.Files[0];
string str = HostingEnvironment.MapPath("~/");
string text = str + "\\In***Files\\";
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);