程序可信任路径代码执行漏洞

来源:互联网 发布:酷炫的js特效 编辑:程序博客网 时间:2024/06/06 02:10


转自:http://www.2cto.com/Article/201305/208951.html

时间:2012-09-26

 

【漏洞描述】

      在使用CreateProcess函数时,当第一个参数lpApplicationName为NULL,而第二个参数lpCommandLine中包含有空格,且未加双引号时,会导致在执行函数时会被截断,比如:c:\program files\sub dir\program name,程序将会以下列顺序来搜索程序:

 

c:\program.exe files\sub dir\program name

c:\programfiles\sub.exe dir\program name

c:\programfiles\sub dir\program.exe name

c:\programfiles\sub dir\program name.exe

 

演示代码:

 

#include <stdio.h>

#include <windows.h>

 

int main()

{

         char cmd[] = "C:\\Program Files\\test.exe";                  // test.exe为命令控制台cmd.exe,而C:\Program.exe为计算器calc.exe

         STARTUPINFO si = { sizeof(si) };

         PROCESS_INFORMATION pi;

         si.dwFlags = STARTF_USESHOWWINDOW;

         si.wShowWindow = TRUE;

         CreateProcess(NULL,cmd,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);  

         return 0;

 

}

 

执行后会打开计算器calc.exe,而不是cmd.exe:

 
 

 点击查看原始尺寸

 

【漏洞修复】

 

主要有以下两种修复方式:

1、  将执行命令字符串放置在第1个参数lpApplicationName中:

 

         CreateProcess(cmd,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);  

 

2、当将命令字符串放置在第2个参数时,应用双引号包括进来:

 

        char cmd[] = "\”C:\\Program Files\\test.exe\”";


0 0
原创粉丝点击