The Command Pattern is widely used to create a robust, salable applications. However I see guidance in this MSDN article that could allow a caller to invoke a late-bound command... enabling the caller to call any assembly, class, and method available to the running process:
[Serializable()]
public class LateBoundCommand : ICommand
{
protected string AssemblyName;
protected string ClassName;
protected string MethodName;
protected object[] Parameters;
protected LateBoundCommand()
{
}
public LateBoundCommand(string assemblyName, string className,
string methodName)
{
AssemblyName = assemblyName;
ClassName = className;
MethodName = methodName;
}
// sets all parameter values
public void SetParameters(params object[] myParameters)
{
Parameters = myParameters;
}
public virtual void Execute()
{
Console.WriteLine("LateBoundCommand.Execute starting");
Assembly a = Assembly.LoadWithPartialName(AssemblyName);
Type TargetType = a.GetType(ClassName);
MethodInfo TargetMethod = TargetType.GetMethod(MethodName);
TargetMethod.Invoke(null, Parameters);
Console.WriteLine("LateBoundCommand.Execute complete");
}
}
Since this article was published in 2004, and the underlying pattern was developed in 1995, there must be a lot of software developed this way. Outside of SDLC what is the right way to protect IT Infrastructure from software developed this way?
Is there any .NET or Java specific auditing that can be done to identify late bound execution... atypical of the running service?
Can I scan the MSIL (or Java equivalent) for this type of invocation?