有人可以解释一下jjencode是如何工作的,如果在我的代码上使用它是好的

时间:2011-04-04 04:40:00

标签: javascript xss obfuscation encode

有人可以解释我http://utf-8.jp/public/jjencode.html如何工作,如果在我的代码上使用它是好的,我第一次尝试它时我需要在我的代码中使用一些算法才能使用它但是它有效在每个网站上,都在发生什么?

我已经看到了源代码,但我不明白。

2 个答案:

答案 0 :(得分:10)

这是评论过的脚本 http://corkami.googlecode.com/svn-history/r399/trunk/misc/jjencode.txt

// this is a commented source of a jjencode script
// jjencode, http://utf-8.jp/public/jjencode.html

// reference: Peter Ferrie, 2011, http://pferrie2.tripod.com/papers/jjencode.pdf

// for reference,
// alert("Hello, JavaScript" )
// is encoded as 

// $=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")[$],_$_:++$,$_$$:({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$$_:(!""+"")[$],$__:++$,$_$:++$,$$__:({}+"")[$],$$_:++$,$$$:++$,$___:++$,$__$:++$};$.$_=($.$_=$+"")[$.$_$]+($._$=$.$_[$.__$])+($.$$=($.$+"")[$.__$])+((!$)+"")[$._$$]+($.__=$.$_[$.$$_])+($.$=(!""+"")[$.__$])+($._=(!""+"")[$._$_])+$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+(!""+"")[$._$$]+$.__+$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];$.$($.$($.$$+"\""+$.$_$_+(![]+"")[$._$_]+$.$$$_+"\\"+$.__$+$.$$_+$._$_+$.__+"(\\\"\\"+$.__$+$.__$+$.___+$.$$$_+(![]+"")[$._$_]+(![]+"")[$._$_]+$._$+",\\"+$.$__+$.___+"\\"+$.__$+$.__$+$._$_+$.$_$_+"\\"+$.__$+$.$$_+$.$$_+$.$_$_+"\\"+$.__$+$._$_+$._$$+$.$$__+"\\"+$.__$+$.$$_+$._$_+"\\"+$.__$+$.$_$+$.__$+"\\"+$.__$+$.$$_+$.___+$.__+"\\\"\\"+$.$__+$.___+")"+"\"")())();


// preliminary points

// (a + "") gives the string representation of a

// [] = empty array. 0 by value, -1 with ~ => ~[] = -1
// as a string, ![] gives  'false'

// {} = empty object.
// as a string, {} gives '[object Object]'

// if a is a x-long array, a[x] is 'undefined' as a string. same for absent properties.

// "" is an empty string. !"" returns 'true' as it is indeed 'null'


// now let's start with the actual code

// creating $ variable with a value.
 $=~[]; // $ = -1

 // defining properties of a $ object.
 $ =
 {
   ___:++$,             // 0, $ = 0

   $$$$:(![] + ””)[$],        // 0th char of 'false',           => 'f'

   __$:++$,             // 1, $ = 1 now...

   $_$_:(![] + ””)[$],        // 1st char of 'false'            => 'a'

   _$_:++$,             // 2...

   $_$$:({} + ””)[$],         // 2nd char of '[object Object]'  => 'b'

   $$_$:($[$] + ””)[$],       // 2nd char of 'undefined'        => 'd'

   _$$:++$,             // 3...

   $$$_:(!”” + ””)[$],        // 3rd char of 'true'             => 'e'

   $__:++$,             // 4

   $_$:++$,             // 5

   $$__:({} + ””)[$],         // 5th char of '[object Object]'  => 'c'

   $$_:++$,             // 6

   $$$:++$,             // 7

   $___:++$,            // 8

   $__$:++$             // 9
 };

// => in order, ___, __$, _$_, _$$, $__, $_$, $$_, $$$, $___, $__$, $_$_, $_$$, $$__, $$_$, $$$_, $$$$ are now equal to 0...F,
// note they are just binary numbers with character substitution

$.$_ =
    ($.$_ = $ + ””)[$.$_$] +              // 5th character of '[object Object]'  => $.$_ = 'c'
    ($._$ = $.$_[$.__$]) +                // 1st character of ...                => $._$ = 'o'
    ($.$$ = ($.$ + ””)[$.__$]) +          // 1st char of 'undefined'             => $.$$ = 'n'
    ((!$) + ””)[$._$$] +                  // 3rd char of 'false'                 => 's'         // poor s, we don't save it...
    ($.__ = $.$_[$.$$_]) +                // 6th char of '[object Object]'       => $.__ = 't'
    ($.$ = (!”” + ””)[$.__$]) +           // 1st char of 'true'                  => $.$  = 'r'
    ($._ = (!”” + ””)[$._$_]) +           // 2nd char of 'true'                  => $._  = 'u'
    $.$_[$.$_$] +                         // 5th char of '[object Object]']      => 'c'         // hey, we already have a c !
    $.__ +                                // 't'
    $._$ +                                // 'o'
    $.$;                                  // 'r'

// => $.$_ = 'constructor'


$.$$ =
    $.$ +                       // 'r'
    (!”” + ””)[$._$$] +         // 'true'[3] => 'e'
    $.__ +                      // 't'
    $._ +                       // 'u'
    $.$ +                       // 'r'
    $.$$;                       // 'n'

$.$ =
    ($.___)[$.$_][$.$_];        // (0)[constructor][constructor]


// summary of $ at this point

// $ = {}
// $.___  = '0';
// $.__$  = '1';
// $._$_  = '2';
// $._$$  = '3';
// $.$__  = '4';
// $.$_$  = '5';
// $.$$_  = '6';
// $.$$$  = '7';
// $.$___ = '8';
// $.$__$ = '9';
// $.$_$_ = 'a';
// $.$_$$ = 'b';
// $.$$__ = 'c';
// $.$$_$ = 'd';
// $.$$$_ = 'e';
// $.$$$$ = 'f';

// $.$_ = 'c'
// $._$ = 'o'
// $.$$ = 'n'
// $.__ = 't'
// $.$  = 'r'
// $._  = 'u'

// $.$_ = 'constructor';
// $.$$ = 'return';
// $.$ = (0)[constructor][constructor]



// and finally, the only line of call

$.$(
    $.$(
        $.$$ + ”\”” + ENCODED + ”\””
        )()
    ) ();

//
(0)[constructor][constructor](
    (0)[constructor][constructor](
        return + " + ENCODED + "
        )()
    )()

// 'equivalent' to eval(eval(ENCODED))


// encoding
// !"#$%&’()*+,-./:;<>=?@[]^_`{|}~  as is
// 0123456789abcdeftou => as $ properties. Ex : 'babe' = $.$_$$ + $.$_$_ + $.$_$$ + $.$$$_
// other ascii chars: as \xxx (octal) encoding. Ex: 'A' = char(65) = \101 = "\\" + $.__$ + $.___ + $.__$
// unicode chars as \u????. ex: 'sea', \u6d77 as "\\" + $._ + $.$$_ + $.$$_$ + $.$$$ + $.$$$

// so in the end, it's just defining a $ object and executing an eval on a string, that is built character by character.

// to confirm, here is a small imperfect python decryption script

// import sys
// start = r'$=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")[$],_$_:++$,$_$$:({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$$_:(!""+"")[$],$__:++$,$_$:++$,$$__:({}+"")[$],$$_:++$,$$$:++$,$___:++$,$__$:++$};$.$_=($.$_=$+"")[$.$_$]+($._$=$.$_[$.__$])+($.$$=($.$+"")[$.__$])+((!$)+"")[$._$$]+($.__=$.$_[$.$$_])+($.$=(!""+"")[$.__$])+($._=(!""+"")[$._$_])+$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+(!""+"")[$._$$]+$.__+$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];$.$($.$($.$$+"\""+'
// end = r'+"\"")())();'
// 
// with open(sys.argv[1], "rb") as f:
//     r = f.read()
// 
// r = r.replace(start, "").replace(end, "")
// print r
// 
// subst = [
//     ['$.$___','8'],
//     ['$.$__$','9'],
//     ['$.$_$_','a'],
//     ['$.$_$$','b'],
//     ['$.$$__','c'],
//     ['$.$$_$','d'],
//     ['$.$$$_','e'],
//     ['$.$$$$','f'],
//     ['$.___','0'],
//     ['$.__$','1'],
//     ['$._$_','2'],
//     ['$._$$','3'],
//     ['$.$__','4'],
//     ['$.$_$','5'],
//     ['$.$$_','6'],
//     ['$.$$$','7'],
//     ['$.$_', 'c'],
//     ['$._$', 'o'],
//     ['$.$$', 'n'],
//     ['$.__', 't'],
//     ['$.$', 'r'],
//     ['$._', 'u'],
//     [r'"\\"' , '\\'],
//     ["\"\\\\\\\\\"", "\\\\"],
//     ["+", ""],
//     ]
// 
// for s in subst:
//     r = r.replace(s[0], s[1])
// 
// r = r.replace("+", "")
// print r

// Ange Albertini, BSD Licence 2011

答案 1 :(得分:1)

重度(ab)使用JavaScript的类型转换可能性,意味着例如。数字值1在JavaScript的内容中转换为字符串“1”。其他情况,例如NULL元素的“值”由JavaScript转换为文本字符串“NULL”等。因此,黑客可以使用例如那些字符串作为计算,字符串程序集等的“存储库”。