├── README.md ├── modified └── obfuscator.php └── original ├── Docs - Please read!.txt ├── HunterObfuscator.php └── index.php /README.md: -------------------------------------------------------------------------------- 1 | # Hunter - PHP Javascript Obfuscator 2 | > :lock: Protect your JavaScript source code with the simplest and fastest way. 3 | 4 | ### :squirrel: [Investigate the live demo](https://damidev.000webhostapp.com/) 5 | 6 | ## Requirement 7 | ```php 8 | require_once 'HunterObfuscator.php'; //Include the class 9 | ``` 10 | 11 | ## Simple usage to obfuscate JS code: 12 | ```php 13 | $jsCode = "alert('Hello world!');"; //Simple JS code 14 | $hunter = new HunterObfuscator($jsCode); //Initialize with JS code in parameter 15 | $obsfucated = $hunter->Obfuscate(); //Do obfuscate and get the obfuscated code 16 | echo ""; 17 | ``` 18 | 19 | ## Simple usage to obfuscate HTML code: 20 | 21 | ```php 22 | $htmlCode = "

Title

Hello world!

"; //Simple HTML code 23 | $hunter = new HunterObfuscator($htmlCode, true); //Initialize with HTML code in first parameter and set second one to TRUE 24 | $obsfucated = $hunter->Obfuscate(); //Do obfuscate and get the obfuscated code 25 | echo ""; 26 | ``` 27 | 28 | > **Note**: If your HTML code contains any JS codes please remove any comments in that js code to prevent issues. 29 | 30 | ## Set expiration time: 31 | 32 | ```php 33 | $hunter->setExpiration('+10 day'); //Expires after 10 days 34 | $hunter->setExpiration('Next Friday'); //Expires next Friday 35 | $hunter->setExpiration('tomorrow'); //Expires tomorrow 36 | $hunter->setExpiration('+5 hours'); //Expires after 5 hours 37 | $hunter->setExpiration('+1 week 3 days 7 hours 5 seconds'); //Expires after +1 week 3 days 7 hours and 5 seconds 38 | ``` 39 | 40 | ## Domain name lock: 41 | 42 | ```php 43 | $hunter->addDomainName('google.com'); //the generated code will work only on google.com 44 | ``` 45 | 46 | > **Note**: you can add multiple domains by adding one by one. 47 | 48 | #### See the included demo (/original/index.php) for more. 49 | 50 | #### Happy Coding :) 51 | 52 | 53 | ## CHANGE LOG (YYYY/MM/DD) 54 | 55 | * v1.2 - **2018-01-11** 56 | * fixed utf8 characters 57 | 58 | * v1.1 - **2017-11-20** 59 | * Some improvments 60 | * Added expiration time 61 | * Added domain name lock 62 | * Added ability to obfuscate HTML code 63 | * New demo script 64 | 65 | * v1.0 - **2017-07-27** 66 | * Initial release 67 | -------------------------------------------------------------------------------- /modified/obfuscator.php: -------------------------------------------------------------------------------- 1 | [^\S ]+/s','/[^\S ]+\/'),$replace=array('>','<','\\1',''); 5 | 6 | static function getMask(){ return substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),0,9); } 7 | 8 | static function hashIt($s){ 9 | for($i=0;$i 0) { 15 | $code = "if(window.location.hostname==='".self::$domainNames[0]."' "; 16 | for ($i=1;$i 0) 21 | self::$code = 'if((Math.round(+new Date()/1000)) < '.self::$expireTime.'){'.self::$code.'}'; 22 | } 23 | 24 | static function encodeIt(){ 25 | self::prepare(); 26 | for ($i=0,$s='',$l=strlen(self::$code);$i<$l;++$i) 27 | $s .= self::hashIt(base_convert(ord(self::$code[$i]) + self::$interval, 10, self::$option)) . self::$mask[self::$option]; 28 | return $s; 29 | } 30 | 31 | static function Obfuscate($c,$h=0,$t=0,$d=0){ 32 | self::$code = $h ? self::html2Js(self::cleanHtml($c)) : self::cleanJS($c); 33 | if($t) self::setExpiration(is_numeric($t) ? $t : strtotime($t)); 34 | if ($d){ 35 | if (is_array($d)){ 36 | foreach($d as $a) self::addDomainName($a); 37 | }else{ 38 | self::addDomainName($d); 39 | } 40 | } 41 | self::$mask = self::getMask(); 42 | self::$interval = rand(1,50); 43 | self::$option = rand(2,8); 44 | $r = rand(0,99); 45 | $z = rand(0,99); 46 | return "var _0xc{$r}e=[\"\",\"\x73\x70\x6C\x69\x74\",\"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x2B\x2F\",\"\x73\x6C\x69\x63\x65\",\"\x69\x6E\x64\x65\x78\x4F\x66\",\"\",\"\",\"\x2E\",\"\x70\x6F\x77\",\"\x72\x65\x64\x75\x63\x65\",\"\x72\x65\x76\x65\x72\x73\x65\",\"\x30\"];function _0xe{$z}c(d,e,f){var g=_0xc{$r}e[2][_0xc{$r}e[1]](_0xc{$r}e[0]);var h=g[_0xc{$r}e[3]](0,e);var i=g[_0xc{$r}e[3]](0,f);var j=d[_0xc{$r}e[1]](_0xc{$r}e[0])[_0xc{$r}e[10]]()[_0xc{$r}e[9]](function(a,b,c){if(h[_0xc{$r}e[4]](b)!==-1)return a+=h[_0xc{$r}e[4]](b)*(Math[_0xc{$r}e[8]](e,c))},0);var k=_0xc{$r}e[0];while(j>0){k=i[j%f]+k;j=(j-(j%f))/f}return k||_0xc{$r}e[11]}eval(function(h,u,n,t,e,r){r=\"\";for(var i=0,len=h.length;i/','',$c); } 68 | static function cleanJS($c){ return preg_replace(self::$search,self::$replace,preg_replace('/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?Obfuscate(); //Do obfuscate and get the obfuscated code 12 | echo ""; 13 | 14 | ##Simple usage to obfuscate HTML code: 15 | 16 | $htmlCode = "

Title

Hello world!

"; //Simple HTML code 17 | $hunter = new HunterObfuscator($htmlCode, true); //Initialize with HTML code in first parameter and set second one to TRUE 18 | $obsfucated = $hunter->Obfuscate(); //Do obfuscate and get the obfuscated code 19 | echo ""; 20 | 21 | Note: If your HTML code contains any JS codes please remove any comments in that js code to prevent issues. 22 | 23 | 24 | ##Set expiration time: 25 | $hunter->setExpiration('+10 day'); //Expires after 10 days 26 | $hunter->setExpiration('Next Friday'); //Expires next Friday 27 | $hunter->setExpiration('tomorrow'); //Expires tomorrow 28 | $hunter->setExpiration('+5 hours'); //Expires after 5 hours 29 | $hunter->setExpiration('+1 week 3 days 7 hours 5 seconds'); //Expires after +1 week 3 days 7 hours and 5 seconds 30 | 31 | ##Domain name lock: 32 | $hunter->addDomainName('google.com'); //the generated code will work only on google.com 33 | Note: you can add multiple domains by adding one by one. 34 | 35 | See the included demo for more. 36 | 37 | Happy Coding :) 38 | 39 | 40 | ******* CHANGE LOG ******* 41 | 42 | v1.0 2017-07-27 43 | #Initial release 44 | 45 | v1.1 2017-11-20 46 | #Some improvments 47 | #Added expiration time 48 | #Added domain name lock 49 | #Added ability to obfuscate HTML code 50 | #New demo script -------------------------------------------------------------------------------- /original/HunterObfuscator.php: -------------------------------------------------------------------------------- 1 | cleanHtml($Code); 17 | $this->code = $this->html2Js($Code); 18 | } else { 19 | $Code = $this->cleanJS($Code); 20 | $this->code = $Code; 21 | } 22 | 23 | $this->mask = $this->getMask(); 24 | $this->interval = rand(1, 50); 25 | $this->option = rand(2, 8); 26 | } 27 | 28 | private function getMask() 29 | { 30 | $charset = str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); 31 | return substr($charset, 0, 9); 32 | } 33 | 34 | private function hashIt($s) 35 | { 36 | for ($i = 0; $i < strlen($this->mask); ++$i) 37 | $s = str_replace("$i", $this->mask[$i], $s); 38 | return $s; 39 | } 40 | 41 | private function prepare() 42 | { 43 | if (count($this->domainNames) > 0) { 44 | $code = "if(window.location.hostname==='" . $this->domainNames[0] . "' "; 45 | for ($i = 1; $i < count($this->domainNames); $i++) 46 | $code .= "|| window.location.hostname==='" . $this->domainNames[$i] . "' "; 47 | $this->code = $code . "){" . $this->code . "}"; 48 | } 49 | if ($this->expireTime > 0) 50 | $this->code = 'if((Math.round(+new Date()/1000)) < ' . $this->expireTime . '){' . $this->code . '}'; 51 | } 52 | 53 | private function encodeIt() 54 | { 55 | $this->prepare(); 56 | $str = ""; 57 | for ($i = 0; $i < strlen($this->code); ++$i) 58 | $str .= $this->hashIt(base_convert(ord($this->code[$i]) + $this->interval, 10, $this->option)) . $this->mask[$this->option]; 59 | return $str; 60 | } 61 | 62 | public function Obfuscate() 63 | { 64 | $rand = rand(0,99); 65 | $rand1 = rand(0,99); 66 | return "var _0xc{$rand}e=[\"\",\"\x73\x70\x6C\x69\x74\",\"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x2B\x2F\",\"\x73\x6C\x69\x63\x65\",\"\x69\x6E\x64\x65\x78\x4F\x66\",\"\",\"\",\"\x2E\",\"\x70\x6F\x77\",\"\x72\x65\x64\x75\x63\x65\",\"\x72\x65\x76\x65\x72\x73\x65\",\"\x30\"];function _0xe{$rand1}c(d,e,f){var g=_0xc{$rand}e[2][_0xc{$rand}e[1]](_0xc{$rand}e[0]);var h=g[_0xc{$rand}e[3]](0,e);var i=g[_0xc{$rand}e[3]](0,f);var j=d[_0xc{$rand}e[1]](_0xc{$rand}e[0])[_0xc{$rand}e[10]]()[_0xc{$rand}e[9]](function(a,b,c){if(h[_0xc{$rand}e[4]](b)!==-1)return a+=h[_0xc{$rand}e[4]](b)*(Math[_0xc{$rand}e[8]](e,c))},0);var k=_0xc{$rand}e[0];while(j>0){k=i[j%f]+k;j=(j-(j%f))/f}return k||_0xc{$rand}e[11]}eval(function(h,u,n,t,e,r){r=\"\";for(var i=0,len=h.length;iencodeIt() . "\"," . rand(1, 100) . ",\"" . $this->mask . "\"," . $this->interval . "," . $this->option . "," . rand(1, 60) . "))"; 67 | } 68 | 69 | public function setExpiration($expireTime) 70 | { 71 | if (strtotime($expireTime)) { 72 | $this->expireTime = strtotime($expireTime); 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | public function addDomainName($domainName) 79 | { 80 | if ($this->isValidDomain($domainName)) { 81 | $this->domainNames[] = $domainName; 82 | return true; 83 | } 84 | return false; 85 | } 86 | 87 | private function isValidDomain($domain_name) 88 | { 89 | return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) 90 | && preg_match("/^.{1,253}$/", $domain_name) 91 | && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)); 92 | } 93 | 94 | private function html2Js($code) 95 | { 96 | $search = array( 97 | '/\>[^\S ]+/s', // strip whitespaces after tags, except space 98 | '/[^\S ]+\/' // Remove HTML comments 101 | ); 102 | $replace = array( 103 | '>', 104 | '<', 105 | '\\1', 106 | '' 107 | ); 108 | $code = preg_replace($search, $replace, $code); 109 | $code = "document.write('" . addslashes($code . " ") . "');"; 110 | return $code; 111 | } 112 | 113 | private function cleanHtml($code) 114 | { 115 | return preg_replace('//', '', $code); 116 | } 117 | 118 | private function cleanJS($code) 119 | { 120 | $pattern = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?[^\S ]+/s', // strip whitespaces after tags, except space 124 | '/[^\S ]+\/' // Remove HTML comments 127 | ); 128 | $replace = array( 129 | '>', 130 | '<', 131 | '\\1', 132 | '' 133 | ); 134 | return preg_replace($search, $replace, $code); 135 | } 136 | } -------------------------------------------------------------------------------- /original/index.php: -------------------------------------------------------------------------------- 1 | setExpiration($_POST['code_exp']); 11 | if(!empty($_POST['code_dn'])) 12 | { 13 | $domains = explode(',', $_POST['code_dn']); 14 | foreach ($domains as $domain) 15 | $hunter->addDomainName($domain); 16 | } 17 | $code = $hunter->Obfuscate(); 18 | } 19 | ?> 20 | 21 | 22 | PHP Javascript Obfuscator 23 | 24 | 25 | 26 | 27 | 34 | 39 | 40 | 41 | 42 |
43 |
44 |
45 |

PHP JavaScript Obfuscator

46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | Your code 55 |
56 |
57 | 58 |

59 |
60 | 63 |
64 | 65 |
66 |
67 | Your obfuscated code 68 |
69 |
70 | 71 |
72 |
73 | 74 |
75 |
76 |
77 |
78 | Options 79 |
80 |
81 |
82 | 83 |
    84 |
  • 85 |
  • 86 |
87 |
88 |
89 |
90 |
91 |
92 | Example: +1 day, +2 week, next Thursday, etc... 93 |
94 |
95 |
96 |
97 |
98 | Example: example1.com,example2.com... 99 |
100 |
101 |
102 |
103 |
104 | Please note... 105 |
106 |
107 |

Although this can provide a high security level, a potentially thief can try to de-obfuscate and reach a closer code to the original one due to the public and open architecture of JavaScript.

108 |

So it's not recommended to use this to protect sensible information.

109 |
110 |
111 |
112 |
113 |
114 | 115 | 116 |
117 | 118 | --------------------------------------------------------------------------------