简体   繁体   English

将此简单的Javascript转换为PHP

[英]Converting this simple Javascript into PHP

var b=new Array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98);
var p=new Array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1);         
function c(b,p) {
    a='';s=String.fromCharCode;
    for(i=0;i<b.length;i++) {if(p[i])a=s(b[i])+a;else a+=s(b[i]);}
    return a;
}

I am trying to convert the above JavaScript code to PHP, but because in some ways it is compressed to make it more confusing, I'm having great difficulty. 我正在尝试将上述JavaScript代码转换为PHP,但是由于在某些方面将其压缩以使其更加混乱,所以我遇到了很大的困难。 Your help is greatly appreciated! 非常感谢您的帮助!

UPDATE: This is what I've tried: 更新:这是我尝试过的:

<?php
          $b=array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98);
          $p=array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1);     
$a='';
class String {
    public static function fromCharCode() {
        return array_reduce(func_get_args(),function($d,$e){$d.=chr($e);return $d;});
    }
}
for($i=0;$i<b.length;$i++) {if($p[$i])$a=String::fromCharCode($b[$i]) . $a;else $a+=String::fromCharCode($b[$i]);}
echo $a; ?>

It returns blank. 它返回空白。

How do I convert this simple Javascript into PHP? 如何将这个简单的Javascript转换为PHP?

Not tested. 未经测试。 Just a literal translation 只是字面翻译

function c($b, $p){
 $a="";
 for ($i=0;$i<strlen($b);$i++){
   if ($p[$i]) $a=chr($b[$i]).$a; else $a.=chr($b[$i]);
 }
 return $a;
}

In PHP 在PHP中

function c($b,$p){
    $a = '';
    $s = chr();
    for($i=0;$i<strlen($b);$i++){
        if($p[$i]){
            $a = chr($b[$i]).$a;
        } else {
            $a .= chr($b[$i]);
        }
    }
    return $a;
}

Note: you ought to give your variables more descriptive names 注意:您应该为变量赋予更多描述性名称

Another approach I used for this kind of hack was to dynamically write javascript script by PHP but echoing it out via http header with content-type identifier. 我用于这种黑客攻击的另一种方法是通过PHP动态编写JavaScript脚本,但通过带有内容类型标识符的http标头将其回显。 See below as an example: 参见以下示例:

index.html: index.html的:

<script type="text/javascript" src="js.php"></script>

js.php js.php

<?php
$js = <<<JS
///BEGIN JS SCRIPT //
var b=new Array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98);

var p=new Array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1);

function c(b,p) {
a='';
s=String.fromCharCode;
for(i=0;i<b.length;i++) {if(p[i])a=s(b[i])+a;else a+=s(b[i]);}
return a;
}

/// END JS SCRIPT //
JS;
header("Content-type: text/javascript");
echo $js;
exit();
?>

One setback I found about this approach is that the script can't be cached if you want to re-access to these variables in later lines of scripts from your html. 我发现有关此方法的一个挫折是,如果您想从html的更高版本的脚本中重新访问这些变量,则无法缓存该脚本。 But, it serves as a great benefit for some implementation of my work "behind the scene". 但是,对于“幕后”工作的某些实施,这是一个很大的好处。

The best way to do it it's to use chr . 最好的方法是使用chr

chr — Return a specific character chr —返回特定字符

 $b = array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98); $p = array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1); function c($b,$p) { $a=''; for($i=0;$i<count($b);$i++){ if($p[$i]){ $a=chr($b[$i]) . $a; }else{ $a.=chr($b[$i]); } } return $a; } echo(c($b,$p)); 

OUTPUT OUTPUT

 bounty.php?hitlist_id=9366558&formNonce=e0d2fe5b7d80c47a1654f29e797d5aed11e6aa14&h=2487f379e63ee6858f64e291c2f6fe3d09600 

Both examples in JS and PHP same output. JS和PHP中的两个示例都输出相同。

working example php: example 工作示例php: 示例

working example js: example 工作示例js: 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM