输入验证与表示问题是由元字符、交替编码和数字表示引起的。安全问题源于信任输入。这些问题包括:“Buffer Overflows”、“Cross-Site Scripting”攻击、“SQL Injection”等其他问题。
...
String address = request.getParameter("address");
Properties props = new Properties();
props.put(Provider_URL, "rmi://secure-server:1099/");
InitialContext ctx = new InitialContext(props);
ctx.lookup(address);
...
string name = Request["username"];
string template = "Hello @Model.Name! Welcome " + name + "!";
string result = Razor.Parse(template, new { Name = "World" });
...
operation
参数的值为良性值,程序就可以正常运行。例如,当该值为 "John" 时,result
变量被赋予的值将为 "Hello World!Welcome John!"。然而,如果攻击者指定的语言操作既有可能是有效的,又有可能是恶意的,那么,只有在对主进程具有完全权限的情况下才能执行这些操作。如果底层语言提供了访问系统资源的途径或允许执行系统命令,这种攻击甚至会更加危险。例如,Razor 允许调用 C# 对象;如果攻击者计划将 " @{ System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.FileName=\"calc\"; proc.Start(); }" 指定为 name
的值,主机系统就会执行系统命令。
...
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine scriptEngine = scriptEngineManager.getEngineByExtension("js");
userOps = request.getParameter("operation");
Object result = scriptEngine.eval(userOps);
...
operation
参数的值为良性值,程序就可以正常运行。例如,当该值为 "8 + 7 * 2" 时,result
变量被赋予的值将为 22。然而,如果攻击者指定的语言操作既有可能是有效的,又有可能是恶意的,那么,只有在对主进程具有完全权限的情况下才能执行这些操作。如果底层语言提供了访问系统资源的途径或允许执行系统命令,这种攻击甚至会更加危险。例如,JavaScript 允许调用 Java 对象;如果攻击者计划将 " java.lang.Runtime.getRuntime().exec("shutdown -h now")" 指定为 operation
的值,则主机系统就会执行关机命令。
...
userOp = form.operation.value;
calcResult = eval(userOp);
...
operation
参数的值为良性值,程序就可以正常运行。例如,当该值为“8 + 7 * 2”时,calcResult
变量被赋予的值将为 22。然而,如果攻击者指定的语言操作既有可能是有效的,又有可能是恶意的,那么,只有在对主进程具有完全权限的情况下才能执行这些操作。如果底层语言提供了访问系统资源的途径或允许执行系统命令,这种攻击甚至会更加危险。对于 JavaScript,攻击者还可以利用这种漏洞进行 cross-site scripting 攻击。
...
strUserOp = Request.Form('operation')
strResult = Eval(strUserOp)
...
operation
参数为“8 + 7 * 2”的示例中,程序的预期行为是可行的。strResult
变量应返回的值为 22。然而,如果用户打算指定其他有效的语言操作,那么系统不仅会执行这些操作,还会在对主进程具有完全权限的情况下执行。如果底层语言提供了访问系统资源的途径,或者允许执行系统命令,那么执行任意代码会更加危险。例如,如果攻击者打算将 operation
指定为“Shell('C:\WINDOWS\SYSTEM32\TSSHUTDN.EXE 0 /DELAY:0 /POWERDOWN')”,主机系统会执行关机命令。Delegate
字段可能会导致在反序列化该类的过程中或之后产生执行任意代码漏洞。Delegate
类型用于保持引用稍后可在用户代码中调用的方法调用。序列化 Delegate
类型时,.NET 使用自定义序列化,并使用 System.DelegateSerializationHolder
类存储连接到或订阅 Delegate
的方法信息。Delegate
对象的序列化流不适用于永久性存储或将其传递给远程应用程序,因为攻击者可以将方法信息替换为指向恶意对象图的信息,从而导致在反序列化过程中或之后调用时产生执行任意代码漏洞。Delegate
字段,并且将在 Executor
方法中调用:
...
[Serializable]
class DynamicRunnner
{
Delegate _del;
string[] _arg;
public DynamicRunnner(Delegate dval, params string[] arg)
{
_del = dval;
_arg = arg;
}
public bool Executor()
{
return (bool)_del.DynamicInvoke(_arg);
}
}
...
Example 1
中所示类的不可信流进行反序列化,则攻击者可能会将其方法信息替换为指向 Process.Start
的方法信息,从而在调用 Executor
方法时创建任意进程。BeanUtilsHashMapper
反序列化 Redis Hash,这可能允许攻击者控制此类 Hash 来运行任意代码。
HashMapper<Person, String, String> hashMapper = new BeanUtilsHashMapper<Person>(Person.class);
Person p = hashMapper.fromHash(untrusted_map);
EnableViewStateMac
属性的设置,因为它会在应用程序中引入远程代码执行漏洞。但是,开发人员可以使用 aspnet:AllowInsecureDeserialization
设置覆盖此功能,从而使应用程序容易受到远程代码执行的攻击。aspnet:AllowInsecureDeserialization
设置为 true
。
<appSettings>
<add key="aspnet:AllowInsecureDeserialization" value="true" />
</appSettings>
Low
和 Full
。Low
(默认值)会通过仅反序列化与最基本的 Remoting 功能相关的类型(例如,对 Remoting 基础架构类型、系统实现的一组有限的类型和一组基本的自定义类型进行自动反序列化)来防止反序列化攻击。Full
反序列化级别可在所有情况下对 Remoting 支持的所有类型进行自动反序列化。typeFilterLevel
设置为 Full
。
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="2000">
<serverProviders>
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary"/>
</clientProviders>
</channel>
</channels>
</application>
...
</system.runtime.remoting>
TestService
方法的 RMIServiceExporter。示例 2:公开
<bean id="testService" class="example.TestServiceImpl"/>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="TestService"/>
<property name="service" ref="testService"/>
<property name="serviceInterface" value="example.TestService"/>
<property name="registryPort" value="1199"/>
</bean>
TestService
方法的 JMSInvokerServiceExporter。示例 3:公开
<bean id="testService" class="example.TestServiceImpl"/>
<bean class="org.springframework.jms.remoting.JmsInvokerServiceExporter">
<property name="serviceInterface" value="example.TestService"/>
<property name="service" ref="testService"/>
</bean>
TestService
方法的 HTTPInvokerServiceExporter。
<bean id="testService" class="example.TestServiceImpl"/>
<bean class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="serviceInterface" value="example.TestService"/>
<property name="service" ref="testService"/>
</bean>
The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.
__reduce__
方法,允许任意对象声明如何对它们进行反序列化处理。这种方法应该为其返回一个 callable
和多个参数。Pickle 将使用提供的参数调用可调用的对象,以构建允许攻击者执行任意命令的新对象。