在Asp.net MVC和Knockout js应用程序中解析IDOR



我们有一个已经投入生产的应用程序,在端点& CustomerKey&quot中检测到IDOR漏洞。这包含客户ID,当使用暴力时允许在我们的应用程序中会话接管。

现在我们不能加密这个,因为它可能会使应用程序变慢,因为CustomerKey在JS和后端被多次使用。我们的应用程序允许许多用户同时登录,我们也在应用程序中使用signalR。

使用CustomerKey的后端代码示例:

[HttpPost]
[AllowAnonymous]
public JsonResult UpLoadLog(string CustomerKey, string message)
{
try
{
var log = message.Split(new string[] { "rn" }, 
StringSplitOptions.RemoveEmptyEntries);
foreach (string s in log)
{
Logger.Write(LogType.Info, this.GetType(), "UpLoadLog", CustomerKey + ": " 
+ s.TrimStart('r', 'n'), null);
}
}
catch (Exception ex)
{
Logger.Write(LogType.Fatal, this.GetType(), "UpLoadLog", ex.Message, ex);
}
HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
return null;
} 
[AuthorizeUser]
public ActionResult Customer(string CustomerKey, string FeedData, string FeedInfo)
{
if (string.IsNullOrEmpty(CustomerKey))
{
var owinContext = Request.GetOwinContext();
CustomerKey = owinContext.Get<string>("CustomerKey");
FeedData = owinContext.Get<string>("FeedData");
FeedInfo = owinContext.Get<string>("FeedInfo");
}
ViewBag.CustomerKey = CustomerKey;
ViewBag.FeedData = FeedData;
ViewBag.FeedInfo = FeedInfo;
ViewBag.UseSignalR = true;
ViewBag.isOffline = true;
return View("Offline", "CustomerLayout");

}

使用CustomerKey的js代码示例:

var UpLoadLog = function (log, isAsync) {
if (isAsync== null || isAsync== undefined)
isAsync= true;   
jQuery.ajax({
type: "POST",
async: isAsync,
contentType: "application/json;charset=utf-8",
url: rooturl + "Authentication/UpLoadLog",
data: JSON.stringify({ CustomerKey: jQuery("#customerKey").val(), message: "rnrn" + log + "rnrn" }),
dataType: "json",
success: function (response, status, jqXHR) {           
},
error: function (jqXHR, status, error) {
}
});

LogMessages = "rnrn";
};

应用程序在布局中还包含一个隐藏字段,其中使用CustomerKey的值

<input type="hidden" id="customerkey" value="@ViewBag.CustomerKey"/>

我需要帮助的是如何在不对应用程序进行巨大更改的情况下解决这个漏洞?

如果我正确理解了这个问题,那么问题在于任何人都可以使用任何CustomerKey发送请求,并通过CustomerKey获得响应,即使他们没有获得接收此类信息的授权。如果关于CustomerKey的信息与授权过滤器(AuthorizeUser)相关联,那么,在我看来,解决这个问题最节省时间的方法是将CustomerKey与授权用户的相应属性进行比较。如果键不匹配,抛出异常。要讨论特定的代码行,实际上,我需要与项目一起工作,并且可以访问所有的源代码。

您可以输入第三个参数,即CustomerKey参数的md5()。这样,当联系该方法时,它会检查md5参数是否真的是CustomerKey参数的md5,如果是,则写入日志。这是对第一个参数进行的一种校验和,它保证只有知道该规则的人才能保存日志。这可以作为新方法签名

的一个示例
[HttpPost]
[AllowAnonymous]
public JsonResult UpLoadLog(string CustomerKey, string message, string md5)

这是一种计算md5的方法:

using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
string calculatedMd5 = Convert.ToHexString(hashBytes);
}