C# System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe和LowerCodeCharts中存在漏洞。无?
我做了一个,我把这个问题连在了我的意见书上C# System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe和LowerCodeCharts中存在漏洞。无?,c#,asp.net,.net,antixsslibrary,C#,Asp.net,.net,Antixsslibrary,我做了一个,我把这个问题连在了我的意见书上 我正在玩System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe来测试一些东西,我发现了这个 以下代码似乎是正确的: protected void Application_Start(object sender, EventArgs e) { System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe ( LowerCod
我正在玩
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
来测试一些东西,我发现了这个
以下代码似乎是正确的:
protected void Application_Start(object sender, EventArgs e)
{
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
LowerCodeCharts.None,
LowerMidCodeCharts.None,
MidCodeCharts.None,
UpperMidCodeCharts.None,
UpperCodeCharts.None
);
/*2 randoms characters from each pdf linked below */
System.Diagnostics.Debug.WriteLine(
System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(
"%* ܼ aW ?? ?? ??", false));
System.Diagnostics.Debug.WriteLine(
System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(
"%* ܼ aW ?? ?? ??", true));
}
它不能正常工作。上面的字符串未被编码
似乎它仍然在使用LowerCodeCharts.Default
,忽略使用这些字符集的LowerCodeCharts.None
(我找到了每个字符集的列表)
,
在查看了ILSpy的
System.Web.Security.AntiXss.UnicodeCharacterEncoder
我找到了这个代码
public static void MarkAsSafe(....)
{
if (lowerCodeCharts == UnicodeCharacterEncoder.currentLowerCodeChartSettings &&
lowerMidCodeCharts == UnicodeCharacterEncoder.currentLowerMidCodeChartSettings &&
midCodeCharts == UnicodeCharacterEncoder.currentMidCodeChartSettings &&
upperMidCodeCharts == UnicodeCharacterEncoder.currentUpperMidCodeChartSettings &&
upperCodeCharts == UnicodeCharacterEncoder.currentUpperCodeChartSettings)
{
return;
}
/*actual code that does something*/
}
我使用ILSpy进行了查看,对于所有这些工具,默认值都是None
这使得我第一次尝试的MarkAsSafe
无效
当我打电话时,无论是否有我的None
System.Diagnostics.Debug.WriteLine(
System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(
"%* ܼ aW ?? ?? ??", false));
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
LowerCodeCharts.None,
LowerMidCodeCharts.None,
MidCodeCharts.Arrows, /* FAKE VALUE to trigger the proper code */
UpperMidCodeCharts.None,
UpperCodeCharts.None);
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
LowerCodeCharts.None, /* NOW THIS WORK */
LowerMidCodeCharts.None,
MidCodeCharts.None,
UpperMidCodeCharts.None,
UpperCodeCharts.None);
通过查看ILSpy中的System.Web.Security.AntiXss.UnicodeCharacterEncoder
,可以看出
private static void InitialiseSafeList()
{
/*some code */
if (UnicodeCharacterEncoder.characterValues == null)
{
UnicodeCharacterEncoder.InitialiseSafeList();
}
/*some code */
}
因为此时UnicodeCharacterEncoder.characterValues
为空,所以我使用Visual Studio中的监视窗口验证了这一点。UnicodeCharacterEncoder.InitialiseSafeList
方法如下所示
SafeList.PunchUnicodeThrough(ref UnicodeCharacterEncoder.characterValues,
LowerCodeCharts.Default,
LowerMidCodeCharts.None,
MidCodeCharts.None,
UpperMidCodeCharts.None,
UpperCodeCharts.None);
因此,为了使它真正None
,我尝试调用MarkAsSafe两次,一次调用伪值以确保它不会作废,然后调用ALLNone
System.Diagnostics.Debug.WriteLine(
System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(
"%* ܼ aW ?? ?? ??", false));
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
LowerCodeCharts.None,
LowerMidCodeCharts.None,
MidCodeCharts.Arrows, /* FAKE VALUE to trigger the proper code */
UpperMidCodeCharts.None,
UpperCodeCharts.None);
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
LowerCodeCharts.None, /* NOW THIS WORK */
LowerMidCodeCharts.None,
MidCodeCharts.None,
UpperMidCodeCharts.None,
UpperCodeCharts.None);
现在我得到了一个编码字符串
%*ܼąŴƣǼɤʩ˦˿
但是,无法重置内部数组UnicodeCharacterEncoder.characterValues,因此在我的示例中,由于我使用了MidCodeCharts.Arrows,它们现在被视为安全的。无法将其更改回不安全状态
为了好玩,我想找到一种方法让它像应该的那样工作,这让它工作起来
请注意,此代码不用于生产。求你了强>
var assembly = Assembly.GetAssembly(typeof(System.Web.Security.AntiXss.AntiXssEncoder));
var type = assembly.GetType("System.Web.Security.AntiXss.UnicodeCharacterEncoder");
var field = type.GetField("currentLowerCodeChartSettings", BindingFlags.Static | BindingFlags.NonPublic);
field.SetValue(null, -1);
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
System.Web.Security.AntiXss.LowerCodeCharts.None,
System.Web.Security.AntiXss.LowerMidCodeCharts.None,
System.Web.Security.AntiXss.MidCodeCharts.None,
System.Web.Security.AntiXss.UpperMidCodeCharts.None,
System.Web.Security.AntiXss.UpperCodeCharts.None
);
请注意,此代码不用于生产。求你了强>
var assembly = Assembly.GetAssembly(typeof(System.Web.Security.AntiXss.AntiXssEncoder));
var type = assembly.GetType("System.Web.Security.AntiXss.UnicodeCharacterEncoder");
var field = type.GetField("currentLowerCodeChartSettings", BindingFlags.Static | BindingFlags.NonPublic);
field.SetValue(null, -1);
System.Web.Security.AntiXss.AntiXssEncoder.MarkAsSafe
(
System.Web.Security.AntiXss.LowerCodeCharts.None,
System.Web.Security.AntiXss.LowerMidCodeCharts.None,
System.Web.Security.AntiXss.MidCodeCharts.None,
System.Web.Security.AntiXss.UpperMidCodeCharts.None,
System.Web.Security.AntiXss.UpperCodeCharts.None
);
因此,我的问题是,在当前的库实现中,是否有其他方法可以将所有编码标记为不安全?它在一月份被确认为一个bug,而它只是
如果您的计算机被此错误击中,您必须使用我问题中的不推荐的代码
此外,如果必须在运行时多次更改编码,则需要找到手动重置内部数组的方法。否则,编码将包括任何以前的“MarkAsSafe”调用。这可以通过操纵私有/内部变量来实现,这是不推荐的好吧,我想这是静态的
。