SQL Server 2008 CLR 프로젝트에 저장 프로 시저가 있습니다. 이 함수는 일부 xml을 포함하는 매개 변수로 콘솔 응용 프로그램을 호출합니다.XML로 param을 포함하는 SQL CLR 함수에서 System.Diagnostics.Process.Start를 호출하십시오.
[Microsoft.SqlServer.Server.SqlProcedure()]
public static SqlInt32 ExecuteApp(SqlString utilPath, SqlString arguments, ref SqlString result)
{
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
Process p = new Process();
try
{
//ProcessStartInfo to run the DOS command attrib
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
info.Arguments = string.Format(@"/c ""{0}"" {1}", utilPath, arguments);
SqlContext.Pipe.Send(info.Arguments);
p.StartInfo = info;
p.Start();
String processResults = p.StandardOutput.ReadToEnd();
SqlContext.Pipe.Send(processResults);
result = processResults;
if (String.IsNullOrEmpty((String)result))
result = p.StandardError.ReadToEnd();
return 1;
}
finally
{
p.Close();
}
}
xml이 포함 된 param의 문제점. 이 저장 프로 시저 실행에 대한 표현이다 : 나는이 같은 오류를 가지고있다
declare @Result nvarchar(max)
exec ExecuteApp 'C:\Console.exe', 'send "<messages><message>my message</message></messages>"', @Result out
select @Result
저장 프로 시저를 실행 한 후 :
<이 시간에 예상치 못한합니다.
xml이 모두 제대로 작동하지 않는 것을 알고 싶습니다.
_ 심각한 보안 취약점이 있습니다. – SLaks
왜 'xp_cmdshell'을 사용하지 않습니까? – SLaks
xp_cmdshell도 서버 수준에서 사용하도록 설정 한 다음 주입 공격을위한 완전히 새로운 방법을 엽니 다. – Shiv