Last active
December 11, 2023 17:55
-
-
Save terremoth/22f9b8312ca0ed01e6bec3bd0c88533a to your computer and use it in GitHub Desktop.
Check the MBR or GPT content from the Disk. Works for cli and web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$is_terminal = php_sapi_name() == "cli"; | |
$td_tag_init = "\t".'<td>'; | |
$td_tag_end = '</td>'.PHP_EOL; | |
$tr_tag_init = '<tr>'.PHP_EOL; | |
$tr_tag_end = '</tr>'.PHP_EOL; | |
$to_html_init = '&#'; | |
$to_html_end = ';'; | |
$new_line_code = '<br>'.PHP_EOL; | |
if ($is_terminal) { | |
$new_line_code = PHP_EOL; | |
$td_tag_init = null; | |
$td_tag_end = null; | |
$tr_tag_init = null; | |
$tr_tag_end = PHP_EOL; | |
$to_html_init = null; | |
$to_html_end = null; | |
} | |
if (!$is_terminal) { | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Your MBR</title> | |
<meta charset="utf-8"> | |
<style>html {font-size:1.3em;font-family: monospace;}table{white-space: pre;}</style> | |
</head> | |
<body> | |
<h1>Your MBR</h1> | |
<table border="1"> | |
<?php | |
} | |
$disk = fopen('\\\\.\\C:', 'rb+'); //escaping the escape | |
// 512 for mbr, 16384 for GPT itself | |
$bin_data = fread($disk, 16384); // you can resize to 2048/4096/8192/16384/32768/65536/131072/262144... | |
//$character_set = mb_detect_encoding($bin_data); | |
//$bin_data = mb_convert_encoding($bin_data, 'Windows-1252', $character_set); | |
$hex_data = bin2hex($bin_data); | |
$splitted_bin = str_split($bin_data, 2); | |
$splitted_hex = str_split($hex_data, 2); | |
$chunk_size = 16; // from 0 to 15 (16 bytes) | |
$data_size = count($splitted_hex); | |
$number_of_chunks = $data_size / $chunk_size; | |
$raw_string = ''; | |
fclose($disk); | |
for ($chunk_counter = 0; $chunk_counter < $number_of_chunks; $chunk_counter++) { | |
echo $tr_tag_init; | |
echo $td_tag_init; | |
$until = $chunk_counter * $chunk_size; | |
for ($data_counter = $until; $data_counter < $until + $chunk_size; $data_counter++) { | |
echo $splitted_hex[$data_counter].' '; | |
} | |
echo $td_tag_end; | |
echo $td_tag_init; | |
for ($data_counter_ascii = $until; $data_counter_ascii < $until + $chunk_size; $data_counter_ascii++) { | |
$raw_string = $bin_data[$data_counter_ascii]; | |
$ascii_code = ord($raw_string); | |
$dec_bin = $ascii_code < 32 ? '.' : $to_html_init.($is_terminal ? $raw_string : $ascii_code).$to_html_end; | |
echo $dec_bin; | |
} | |
echo $td_tag_end; | |
echo $tr_tag_end; | |
} | |
if (!$is_terminal) { | |
?> | |
</table> | |
</body> | |
</html> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since it access some sensitive area from your disk, Windows requires elevation, so execute it through a powershell or cmd with admin rights