Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /* ### OBF ### */ include_once dirname(__FILE__) . "\x2f\56\56\57\151\156\143\154..

Decoded Output download

<?php 
/* ### OBF ### */ 
 include_once dirname(__FILE__) . "/../include/check.php"; set_time_limit(600); function message($text) { echo "{$text}"; } function checkUpdateFile($filename) { $error = "Wrong filename"; if (!preg_match("/(\d+)-(\d+)-(\d+)-(\d+)/", $filename, $m)) { goto aIFhq; } return $m; goto kpckR; aIFhq: message($error); return false; kpckR: } $update = $ARGUMENTS[0]; $crc = $ARGUMENTS[1]; $stage = $ARGUMENTS[2]; if (!($stage == '')) { goto qNbv8; } $stage = 0; qNbv8: $target_dir = ''; $decr_tool = "update_decrypt"; $update_name = basename($update); if (preg_match("/^http.?:\/\//", $update)) { goto I8P2W; } message("Wrong upgrade URL"); exit; I8P2W: if (!(($m = checkUpdateFile($update_name)) === false)) { goto D9l6Q; } message("Wrong upgrade description"); exit; D9l6Q: $update_dir = "/tmp/_update-{$update_name}"; $file_list = "{$update_dir}/files.list"; $file_list_remove = "{$update_dir}/remove.list"; $files_list_new = "{$update_dir}/files_new.json"; $links_list_new = "{$update_dir}/links_new.json"; $update_device = $m[1]; $update_fw = $m[2]; $update_base_build = $m[3]; $update_new_build = $m[4]; mkdir($update_dir, 0777, TRUE); if (file_exists($update_dir)) { goto Obx3U; } message("Can't create temp dir"); exit; Obx3U: switch ($stage) { case 0: shell_exec("cget '{$update}' | {$decr_tool} | tar -C {$update_dir} -xj"); if (!file_exists($file_list)) { goto cWGjd; } message("OK"); goto Bupav; cWGjd: message("Wrong upgrade format"); Bupav: exit; case 1: stop_services(true); $files_new = []; $links_new = []; foreach (file($file_list) as $idx => $file) { $file = preg_split("/\s+/", trim($file)); if (!preg_match("/link:\s*\[([^\]]+)\]/", $file[0], $m)) { goto oIQfb; } $links_new[$m[1]] = $file[1]; goto r342G; oIQfb: $crc = $file[0]; $file_target = preg_replace("/\.upgrade$/", '', $file[1]); if (!(file_exists($file_target) && md5_file($file_target) == $crc)) { goto WNXhP; } goto r342G; WNXhP: $files_new[] = array($crc, $file[1]); $file = $update_dir . $file[1]; if (!($crc != 0 && (!file_exists($file) || md5_file($file) != $crc))) { goto Pc67M; } message("File CRC missmatch@#{$idx}"); exit; Pc67M: r342G: } Xkawj: file_put_contents($files_list_new, json_encode($files_new)); file_put_contents($links_list_new, json_encode($links_new)); message("OK"); exit; case 2: if (!file_exists($file_list_remove)) { goto RhY7t; } foreach (file($file_list_remove) as $file) { $file = $target_dir . $file; if (!file_exists($file)) { goto c3W_F; } unlink($file); c3W_F: hUERO: } DdTqu: RhY7t: message("OK"); exit; case 3: $files_new = @json_decode(file_get_contents($files_list_new), true); if (!($files_new == '' || !count($files_new))) { goto kDoEd; } message("No files for upgrading"); exit; kDoEd: foreach ($files_new as $idx => $file) { $target = $target_dir . $file[1]; @unlink($file); @mkdir(dirname($target), 0777, true); rename($update_dir . $file[1], $target); if (!($file[0] != 0 && !file_exists($target))) { goto JXAkX; } message("File update error@#{$idx}"); exit; JXAkX: if (!($file[0] != 0)) { goto oB26V; } $crc = md5_file($target); if (!($crc != $file[0])) { goto CUIoK; } message("File update: file crc missmatch@#{$idx}/{$file[1]}"); exit; CUIoK: oB26V: KVB4L: } YB4mT: message("OK"); exit; case 4: $links_new = @json_decode(file_get_contents($links_list_new), true); if (!($links_new == '')) { goto KweQt; } $links_new = array(); KweQt: foreach ($links_new as $target => $link) { $target = $target_dir . $target; $link = $target_dir . $link; if (!(strlen($link) && strlen($target) && file_exists($target))) { goto I8UT1; } @unlink($link); @mkdir(dirname($link), 0777, true); symlink($target, $link); if (is_link($link)) { goto h81lv; } message("Upgrade error: symlink"); exit; h81lv: I8UT1: At7Kz: } Qaxt3: message("OK"); exit; } Psm0O: ZV83v: function stop_services() { global $update_dir; $services = array("media-proxy-daemon", "ntp-server", "epg-server"); foreach ($services as $service) { shell_exec("/etc/init.d/{$service} stop"); AfjLx: } KvH5V: } ?>

Did this file decode correctly?

Original Code

<?php
/* ### OBF ### */
 include_once dirname(__FILE__) . "\x2f\56\56\57\151\156\143\154\x75\144\145\x2f\x63\x68\x65\143\153\56\160\x68\160"; set_time_limit(600); function message($text) { echo "{$text}"; } function checkUpdateFile($filename) { $error = "\x57\162\157\x6e\147\40\146\151\x6c\145\x6e\141\x6d\145"; if (!preg_match("\57\x28\x5c\x64\x2b\51\x2d\50\134\144\x2b\51\x2d\50\134\144\53\x29\x2d\x28\x5c\x64\53\x29\x2f", $filename, $m)) { goto aIFhq; } return $m; goto kpckR; aIFhq: message($error); return false; kpckR: } $update = $ARGUMENTS[0]; $crc = $ARGUMENTS[1]; $stage = $ARGUMENTS[2]; if (!($stage == '')) { goto qNbv8; } $stage = 0; qNbv8: $target_dir = ''; $decr_tool = "\165\160\x64\141\x74\145\x5f\x64\145\x63\162\171\160\x74"; $update_name = basename($update); if (preg_match("\x2f\136\x68\x74\164\x70\x2e\x3f\72\x5c\x2f\134\x2f\x2f", $update)) { goto I8P2W; } message("\127\x72\x6f\x6e\147\40\165\160\x67\162\x61\x64\x65\40\x55\x52\x4c"); exit; I8P2W: if (!(($m = checkUpdateFile($update_name)) === false)) { goto D9l6Q; } message("\x57\x72\x6f\x6e\x67\x20\x75\160\147\x72\141\x64\145\x20\x64\x65\x73\x63\162\151\160\x74\151\x6f\156"); exit; D9l6Q: $update_dir = "\57\x74\x6d\x70\57\137\x75\x70\x64\x61\x74\x65\x2d{$update_name}"; $file_list = "{$update_dir}\57\146\151\154\145\x73\56\154\x69\x73\164"; $file_list_remove = "{$update_dir}\57\x72\x65\155\157\166\145\x2e\x6c\151\x73\164"; $files_list_new = "{$update_dir}\57\x66\x69\x6c\145\163\x5f\156\145\167\56\152\x73\x6f\156"; $links_list_new = "{$update_dir}\57\x6c\151\156\153\x73\137\x6e\145\167\x2e\152\163\x6f\x6e"; $update_device = $m[1]; $update_fw = $m[2]; $update_base_build = $m[3]; $update_new_build = $m[4]; mkdir($update_dir, 0777, TRUE); if (file_exists($update_dir)) { goto Obx3U; } message("\103\x61\156\x27\x74\40\x63\x72\x65\141\164\145\40\164\145\155\160\40\x64\151\162"); exit; Obx3U: switch ($stage) { case 0: shell_exec("\143\147\145\164\40\x27{$update}\47\40\x7c\x20{$decr_tool}\40\x7c\40\x74\141\162\x20\x2d\x43\x20{$update_dir}\40\x2d\170\x6a"); if (!file_exists($file_list)) { goto cWGjd; } message("\117\113"); goto Bupav; cWGjd: message("\x57\x72\x6f\156\147\x20\x75\x70\x67\x72\x61\144\x65\x20\146\x6f\162\x6d\x61\x74"); Bupav: exit; case 1: stop_services(true); $files_new = []; $links_new = []; foreach (file($file_list) as $idx => $file) { $file = preg_split("\x2f\134\163\53\57", trim($file)); if (!preg_match("\57\154\151\x6e\x6b\x3a\134\x73\52\x5c\x5b\50\x5b\x5e\134\x5d\135\53\x29\x5c\x5d\x2f", $file[0], $m)) { goto oIQfb; } $links_new[$m[1]] = $file[1]; goto r342G; oIQfb: $crc = $file[0]; $file_target = preg_replace("\57\x5c\56\165\x70\147\162\141\144\x65\x24\57", '', $file[1]); if (!(file_exists($file_target) && md5_file($file_target) == $crc)) { goto WNXhP; } goto r342G; WNXhP: $files_new[] = array($crc, $file[1]); $file = $update_dir . $file[1]; if (!($crc != 0 && (!file_exists($file) || md5_file($file) != $crc))) { goto Pc67M; } message("\x46\151\154\145\x20\x43\122\x43\x20\x6d\151\163\163\155\141\x74\143\150\100\x23{$idx}"); exit; Pc67M: r342G: } Xkawj: file_put_contents($files_list_new, json_encode($files_new)); file_put_contents($links_list_new, json_encode($links_new)); message("\117\x4b"); exit; case 2: if (!file_exists($file_list_remove)) { goto RhY7t; } foreach (file($file_list_remove) as $file) { $file = $target_dir . $file; if (!file_exists($file)) { goto c3W_F; } unlink($file); c3W_F: hUERO: } DdTqu: RhY7t: message("\x4f\x4b"); exit; case 3: $files_new = @json_decode(file_get_contents($files_list_new), true); if (!($files_new == '' || !count($files_new))) { goto kDoEd; } message("\x4e\157\x20\146\151\154\x65\163\x20\x66\157\x72\40\x75\160\147\162\x61\144\151\156\147"); exit; kDoEd: foreach ($files_new as $idx => $file) { $target = $target_dir . $file[1]; @unlink($file); @mkdir(dirname($target), 0777, true); rename($update_dir . $file[1], $target); if (!($file[0] != 0 && !file_exists($target))) { goto JXAkX; } message("\x46\x69\154\x65\x20\x75\160\144\x61\x74\x65\x20\145\162\x72\157\162\x40\43{$idx}"); exit; JXAkX: if (!($file[0] != 0)) { goto oB26V; } $crc = md5_file($target); if (!($crc != $file[0])) { goto CUIoK; } message("\x46\x69\x6c\x65\40\165\160\144\x61\x74\145\x3a\40\x66\x69\154\x65\x20\x63\162\x63\x20\x6d\x69\x73\163\155\141\x74\x63\150\x40\x23{$idx}\x2f{$file[1]}"); exit; CUIoK: oB26V: KVB4L: } YB4mT: message("\x4f\x4b"); exit; case 4: $links_new = @json_decode(file_get_contents($links_list_new), true); if (!($links_new == '')) { goto KweQt; } $links_new = array(); KweQt: foreach ($links_new as $target => $link) { $target = $target_dir . $target; $link = $target_dir . $link; if (!(strlen($link) && strlen($target) && file_exists($target))) { goto I8UT1; } @unlink($link); @mkdir(dirname($link), 0777, true); symlink($target, $link); if (is_link($link)) { goto h81lv; } message("\125\160\147\162\141\144\x65\40\x65\162\162\157\162\x3a\40\x73\x79\x6d\154\151\156\x6b"); exit; h81lv: I8UT1: At7Kz: } Qaxt3: message("\117\113"); exit; } Psm0O: ZV83v: function stop_services() { global $update_dir; $services = array("\x6d\x65\144\151\141\x2d\x70\162\x6f\x78\171\55\x64\141\145\x6d\x6f\156", "\156\164\160\x2d\163\x65\162\x76\145\162", "\x65\160\x67\55\163\x65\162\166\145\162"); foreach ($services as $service) { shell_exec("\x2f\x65\164\x63\x2f\x69\x6e\x69\x74\56\x64\x2f{$service}\x20\163\x74\157\160"); AfjLx: } KvH5V: }

Function Calls

None

Variables

None

Stats

MD5 b244e4abba4e0f404be807295fc29cf0
Eval Count 0
Decode Time 50 ms