본문 바로가기
Stack Overflow/스프링

[스프링] jjencode 파일 decode 하기(실전 개발)

by Lich King 2021. 12. 25.

일본인 Yosuke HASEGAWA 라는 사람이 jjencode라는 코드난독화 기법을 개발했다.
스프링을 개발함에 있어서 개발자모드에서 공개되면 안되는 프론트단위의 Script에서 난독화를 하는 방식으로 개발을 진행하곤 한다.
대부분의 난독화 기법으로는 어셈블리어로 바꾼다거나, 포인터 형식, 변수명 간소화 등 난독화로 사용하곤 한다. 
기법은 여러가지가 있는데 나는 오늘 난독화된 String과 같은 문장을 복호화하여 사용 하는 방법을 기술하려고 한다.

1. 요약
1.1 난독화 진행(https://utf-8.jp/public/jjencode.html)
1.2 복호화 진행

 

2. 난독화

난독화는 긴설명이 필요하지 않다.
https://utf-8.jp/public/jjencode.html 사이트에서 난독화할 소스코드를 입력한다.
이어 global variable name used by jjencode 항목에 난독화를 하고 싶은 코드를 입력하여 난이도를 더 높일 수 있다.
jjencode를 진행한 코드를 jsp script 단에 적용하면 정상적으로 동작하지 않을 것이다. 이것을 복화하 해서 사용해야 한다.

3. 복호화

<%@ include file="js 파일 경로"%>

<input id="src" type='hidden' value = 'jjencode된 소스'></input>
<input id="dst" type='hidden'></input>

 

사용방법은 간단하다

상단에 있는 소스코드를 js로 만들던지 해서 파일경로를 include 해준다.
이어 id = "src"에 jjencode된 소스를 넣고 복호화js만 삽입해주면 dst에서 복호화된 소스코드를 가져올 수 있다.

 

4. 실전 코드 개발 적용

4.1 복호화 js 코드

<
script >
    function _0x2cb7() {
        var _0xc927c4 = ['$_$+', 'length', '9696280lnTyQQ', '\x22\x5c\x22\x22)())()', '9vudjqh', '_$$+', '$___+', 'src', 'value', '._$+', 'charAt', '4tdhkDk', 'indexOf', '\x22\x27\x5c\x22+\x27+\x22,', '$_$$+', 'charCodeAt', '$$__+', 'substring', '561954PARrcG', 'substr', '___+', '2810515KCqrxw', '$$_+', 'replace', '\x5c\x5c\x5c\x22', '2022687STHkxE', '._+', '7UryLNY', '71957qkWZLH', '12TOxbwB', 'dst', 'fromCharCode', 'toString', '\x22\x5c\x22\x22+', '=~[]', '\x5c\x5c\x5c\x5c', '11373110AlcCig', '$__$+', '$_$_+', '__$+', '\x5c\x5c\x22+', '6751512AFzyyQ', 'getElementById', '._$_]+', '$$_$+', '$$$$+', '$$+\x22\x5c\x22\x22+'];
        _0x2cb7 = function() {
            return _0xc927c4;
        };
        return _0x2cb7();
    }(function(_0x558d0d, _0x302b55) {
        var _0x58eb53 = _0x364e,
            _0x2c90ca = _0x558d0d();
        while (!![]) {
            try {
                var _0x57f471 = -parseInt(_0x58eb53(0x131)) / 0x1 * (-parseInt(_0x58eb53(0x132)) / 0x2) + -parseInt(_0x58eb53(0x12e)) / 0x3 * (-parseInt(_0x58eb53(0x120)) / 0x4) + parseInt(_0x58eb53(0x12a)) / 0x5 + parseInt(_0x58eb53(0x127)) / 0x6 + -parseInt(_0x58eb53(0x130)) / 0x7 * (-parseInt(_0x58eb53(0x13e)) / 0x8) + parseInt(_0x58eb53(0x119)) / 0x9 * (-parseInt(_0x58eb53(0x139)) / 0xa) + -parseInt(_0x58eb53(0x117)) / 0xb;
                if (_0x57f471 === _0x302b55) break;
                else _0x2c90ca['push'](_0x2c90ca['shift']());
            } catch (_0x1fd9e5) {
                _0x2c90ca['push'](_0x2c90ca['shift']());
            }
        }
    }(_0x2cb7, 0x8f481));

function out(_0xf0ae19) {
    var _0xb07153 = _0x364e,
        _0x22ad67 = document[_0xb07153(0x13f)](_0xb07153(0x133))[_0xb07153(0x11d)];
    document[_0xb07153(0x13f)](_0xb07153(0x133))[_0xb07153(0x11d)] = _0x22ad67 + _0xf0ae19;
}

function _0x364e(_0x5b26a1, _0x5f2d3f) {
    var _0x2cb762 = _0x2cb7();
    return _0x364e = function(_0x364ea1, _0x533216) {
        _0x364ea1 = _0x364ea1 - 0x113;
        var _0x3290b6 = _0x2cb762[_0x364ea1];
        return _0x3290b6;
    }, _0x364e(_0x5b26a1, _0x5f2d3f);
}

function jjdecode() {
    var _0x39f6ad = _0x364e,
        _0x45f837 = document[_0x39f6ad(0x13f)](_0x39f6ad(0x11c))[_0x39f6ad(0x11d)];
    _0x45f837[_0x39f6ad(0x12c)](/^\s+|\s+$/g, '');
    var _0x5a6cba, _0x485a00, _0x1563b4, _0x420325;
    _0x45f837[_0x39f6ad(0x121)](_0x39f6ad(0x122)) == 0x0 ? (_0x5a6cba = _0x45f837['indexOf'](_0x39f6ad(0x114)) + 0x8, _0x485a00 = _0x45f837[_0x39f6ad(0x121)]('\x22\x5c\x22\x22)())()'), _0x1563b4 = _0x45f837[_0x39f6ad(0x126)](_0x45f837['indexOf']('\x22\x27\x5c\x22+\x27+\x22,') + 0x9, _0x45f837['indexOf'](_0x39f6ad(0x137))), _0x420325 = _0x1563b4[_0x39f6ad(0x116)]) : (_0x1563b4 = _0x45f837[_0x39f6ad(0x128)](0x0, _0x45f837[_0x39f6ad(0x121)]('=')), _0x420325 = _0x1563b4[_0x39f6ad(0x116)], _0x5a6cba = _0x45f837[_0x39f6ad(0x121)](_0x39f6ad(0x136)) + 0x5, _0x485a00 = _0x45f837[_0x39f6ad(0x121)](_0x39f6ad(0x118)));
    if (_0x5a6cba == _0x485a00) return;
    var _0x2dd138 = _0x45f837['substring'](_0x5a6cba, _0x485a00),
        _0x3a6ada = [_0x39f6ad(0x129), _0x39f6ad(0x13c), '_$_+', _0x39f6ad(0x11a), '$__+', _0x39f6ad(0x115), _0x39f6ad(0x12b), '$$$+', _0x39f6ad(0x11b), _0x39f6ad(0x13a), _0x39f6ad(0x13b), _0x39f6ad(0x123), _0x39f6ad(0x125), _0x39f6ad(0x141), '$$$_+', _0x39f6ad(0x113)],
        _0x36c4d6 = '(![]+\x22\x22)[' + _0x1563b4 + _0x39f6ad(0x140),
        _0x51c743 = _0x1563b4 + _0x39f6ad(0x11e),
        _0xef6c7f = _0x1563b4 + '.__+',
        _0x25f473 = _0x1563b4 + '._+',
        _0x51cad9 = _0x1563b4 + '.',
        _0x2d1e1a = '\x22',
        _0x865874 = _0x1563b4 + '.',
        _0x32ebaf = _0x39f6ad(0x12d),
        _0x15ca64 = _0x39f6ad(0x138),
        _0x4218ed = _0x39f6ad(0x13d),
        _0x35b506 = _0x39f6ad(0x13d) + _0x1563b4 + _0x39f6ad(0x12f),
        _0x12de19 = '\x22+';
    while (_0x2dd138 != '') {
        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x36c4d6)) {
            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x36c4d6[_0x39f6ad(0x116)]), out('l');
            continue;
        } else {
            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x51c743)) {
                _0x2dd138 = _0x2dd138['substr'](_0x51c743[_0x39f6ad(0x116)]), out('o');
                continue;
            } else {
                if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0xef6c7f)) {
                    _0x2dd138 = _0x2dd138['substr'](_0xef6c7f['length']), out('t');
                    continue;
                } else {
                    if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x25f473)) {
                        _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x25f473[_0x39f6ad(0x116)]), out('u');
                        continue;
                    }
                }
            }
        }
        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x51cad9)) {
            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x51cad9['length']);
            var _0x1a01f6 = 0x0;
            for (_0x1a01f6 = 0x0; _0x1a01f6 < _0x3a6ada[_0x39f6ad(0x116)]; _0x1a01f6++) {
                if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x3a6ada[_0x1a01f6])) {
                    _0x2dd138 = _0x2dd138['substr'](_0x3a6ada[_0x1a01f6][_0x39f6ad(0x116)]), out(_0x1a01f6[_0x39f6ad(0x135)](0x10));
                    break;
                }
            }
            continue;
        }
        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x2d1e1a)) {
            _0x2dd138 = _0x2dd138['substr'](_0x2d1e1a[_0x39f6ad(0x116)]);
            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x35b506)) {
                _0x2dd138 = _0x2dd138['substr'](_0x35b506[_0x39f6ad(0x116)]);
                var _0x14e52c = '';
                for (j = 0x0; j < 0x2; j++) {
                    if (0x0 == _0x2dd138['indexOf'](_0x865874)) {
                        _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x865874[_0x39f6ad(0x116)]);
                        for (k = 0x0; k < _0x3a6ada['length']; k++) {
                            if (0x0 == _0x2dd138['indexOf'](_0x3a6ada[k])) {
                                _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x3a6ada[k][_0x39f6ad(0x116)]), _0x14e52c += k[_0x39f6ad(0x135)](0x10) + '';
                                break;
                            }
                        }
                    } else break;
                }
                out(String['fromCharCode'](parseInt(_0x14e52c, 0x10)));
                continue;
            } else {
                if (0x0 == _0x2dd138['indexOf'](_0x4218ed)) {
                    _0x2dd138 = _0x2dd138['substr'](_0x4218ed['length']);
                    var _0x14e52c = '',
                        _0x2bfab5 = '',
                        _0x4c22db = '',
                        _0x3720b3 = 0x0;
                    for (j = 0x0; j < 0x3; j++) {
                        if (j > 0x1) {
                            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x36c4d6)) {
                                _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x36c4d6[_0x39f6ad(0x116)]), _0x2bfab5 = 'l';
                                break;
                            } else {
                                if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x51c743)) {
                                    _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x51c743[_0x39f6ad(0x116)]), _0x2bfab5 = 'o';
                                    break;
                                } else {
                                    if (0x0 == _0x2dd138['indexOf'](_0xef6c7f)) {
                                        _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0xef6c7f[_0x39f6ad(0x116)]), _0x2bfab5 = 't';
                                        break;
                                    } else {
                                        if (0x0 == _0x2dd138['indexOf'](_0x25f473)) {
                                            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x25f473[_0x39f6ad(0x116)]), _0x2bfab5 = 'u';
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x865874)) {
                            _0x4c22db = _0x2dd138[_0x39f6ad(0x128)](_0x865874[_0x39f6ad(0x116)]);
                            for (k = 0x0; k < 0x8; k++) {
                                if (0x0 == _0x4c22db[_0x39f6ad(0x121)](_0x3a6ada[k])) {
                                    if (parseInt(_0x14e52c + k + '', 0x8) > 0x80) {
                                        _0x3720b3 = 0x1;
                                        break;
                                    }
                                    _0x14e52c += k + '', _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x865874[_0x39f6ad(0x116)]), _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x3a6ada[k][_0x39f6ad(0x116)]);
                                    break;
                                }
                            }
                            if (0x1 == _0x3720b3) {
                                if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x51cad9)) {
                                    _0x2dd138 = _0x2dd138['substr'](_0x51cad9['length']);
                                    var _0x1a01f6 = 0x0;
                                    for (_0x1a01f6 = 0x0; _0x1a01f6 < _0x3a6ada[_0x39f6ad(0x116)]; _0x1a01f6++) {
                                        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x3a6ada[_0x1a01f6])) {
                                            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x3a6ada[_0x1a01f6][_0x39f6ad(0x116)]), _0x2bfab5 = _0x1a01f6[_0x39f6ad(0x135)](0x10);
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                        } else break;
                    }
                    out(String['fromCharCode'](parseInt(_0x14e52c, 0x8)) + _0x2bfab5);
                    continue;
                } else {
                    var _0x181394 = 0x0,
                        _0xd91865;
                    while (!![]) {
                        _0xd91865 = _0x2dd138[_0x39f6ad(0x124)](0x0);
                        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x32ebaf)) {
                            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x32ebaf[_0x39f6ad(0x116)]), out('\x22'), _0x181394 += 0x1;
                            continue;
                        } else {
                            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x15ca64)) {
                                _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x15ca64['length']), out('\x5c'), _0x181394 += 0x1;
                                continue;
                            } else {
                                if (0x0 == _0x2dd138['indexOf'](_0x12de19)) {
                                    if (_0x181394 == 0x0) return;
                                    _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x12de19['length']);
                                    break;
                                } else {
                                    if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x35b506)) {
                                        if (_0x181394 == 0x0) return;
                                        _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x35b506[_0x39f6ad(0x116)]);
                                        var _0x14e52c = '',
                                            _0x2bfab5 = '';
                                        for (j = 0x0; j < 0xa; j++) {
                                            if (j > 0x1) {
                                                if (0x0 == _0x2dd138['indexOf'](_0x36c4d6)) {
                                                    _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x36c4d6[_0x39f6ad(0x116)]), _0x2bfab5 = 'l';
                                                    break;
                                                } else {
                                                    if (0x0 == _0x2dd138['indexOf'](_0x51c743)) {
                                                        _0x2dd138 = _0x2dd138['substr'](_0x51c743[_0x39f6ad(0x116)]), _0x2bfab5 = 'o';
                                                        break;
                                                    } else {
                                                        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0xef6c7f)) {
                                                            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0xef6c7f[_0x39f6ad(0x116)]), _0x2bfab5 = 't';
                                                            break;
                                                        } else {
                                                            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x25f473)) {
                                                                _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x25f473[_0x39f6ad(0x116)]), _0x2bfab5 = 'u';
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x865874)) {
                                                _0x2dd138 = _0x2dd138['substr'](_0x865874[_0x39f6ad(0x116)]);
                                                for (k = 0x0; k < _0x3a6ada[_0x39f6ad(0x116)]; k++) {
                                                    if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x3a6ada[k])) {
                                                        _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x3a6ada[k][_0x39f6ad(0x116)]), _0x14e52c += k[_0x39f6ad(0x135)](0x10) + '';
                                                        break;
                                                    }
                                                }
                                            } else break;
                                        }
                                        out(String[_0x39f6ad(0x134)](parseInt(_0x14e52c, 0x10)));
                                        break;
                                    } else {
                                        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x4218ed)) {
                                            if (_0x181394 == 0x0) return;
                                            _0x2dd138 = _0x2dd138['substr'](_0x4218ed['length']);
                                            var _0x14e52c = '',
                                                _0x2bfab5 = '',
                                                _0x4c22db = '',
                                                _0x3720b3 = 0x0;
                                            for (j = 0x0; j < 0x3; j++) {
                                                if (j > 0x1) {
                                                    if (0x0 == _0x2dd138['indexOf'](_0x36c4d6)) {
                                                        _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x36c4d6['length']), _0x2bfab5 = 'l';
                                                        break;
                                                    } else {
                                                        if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x51c743)) {
                                                            _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x51c743[_0x39f6ad(0x116)]), _0x2bfab5 = 'o';
                                                            break;
                                                        } else {
                                                            if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0xef6c7f)) {
                                                                _0x2dd138 = _0x2dd138['substr'](_0xef6c7f[_0x39f6ad(0x116)]), _0x2bfab5 = 't';
                                                                break;
                                                            } else {
                                                                if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x25f473)) {
                                                                    _0x2dd138 = _0x2dd138['substr'](_0x25f473[_0x39f6ad(0x116)]), _0x2bfab5 = 'u';
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (0x0 == _0x2dd138['indexOf'](_0x865874)) {
                                                    _0x4c22db = _0x2dd138[_0x39f6ad(0x128)](_0x865874[_0x39f6ad(0x116)]);
                                                    for (k = 0x0; k < 0x8; k++) {
                                                        if (0x0 == _0x4c22db[_0x39f6ad(0x121)](_0x3a6ada[k])) {
                                                            if (parseInt(_0x14e52c + k + '', 0x8) > 0x80) {
                                                                _0x3720b3 = 0x1;
                                                                break;
                                                            }
                                                            _0x14e52c += k + '', _0x2dd138 = _0x2dd138['substr'](_0x865874[_0x39f6ad(0x116)]), _0x2dd138 = _0x2dd138[_0x39f6ad(0x128)](_0x3a6ada[k][_0x39f6ad(0x116)]);
                                                            break;
                                                        }
                                                    }
                                                    if (0x1 == _0x3720b3) {
                                                        if (0x0 == _0x2dd138['indexOf'](_0x51cad9)) {
                                                            _0x2dd138 = _0x2dd138['substr'](_0x51cad9[_0x39f6ad(0x116)]);
                                                            var _0x1a01f6 = 0x0;
                                                            for (_0x1a01f6 = 0x0; _0x1a01f6 < _0x3a6ada[_0x39f6ad(0x116)]; _0x1a01f6++) {
                                                                if (0x0 == _0x2dd138[_0x39f6ad(0x121)](_0x3a6ada[_0x1a01f6])) {
                                                                    _0x2dd138 = _0x2dd138['substr'](_0x3a6ada[_0x1a01f6]['length']), _0x2bfab5 = _0x1a01f6['toString'](0x10);
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                } else break;
                                            }
                                            out(String[_0x39f6ad(0x134)](parseInt(_0x14e52c, 0x8)) + _0x2bfab5);
                                            break;
                                        } else(0x21 <= _0xd91865 && _0xd91865 <= 0x2f || 0x3a <= _0xd91865 && _0xd91865 <= 0x40 || 0x5b <= _0xd91865 && _0xd91865 <= 0x60 || 0x7b <= _0xd91865 && _0xd91865 <= 0x7f) && (out(_0x2dd138[_0x39f6ad(0x11f)](0x0)), _0x2dd138 = _0x2dd138['substr'](0x1), _0x181394 += 0x1);
                                    }
                                }
                            }
                        }
                    }
                    continue;
                }
            }
        }
        break;
    }
} 
</script>

 

4.2 input, output

<input id="src" type='hidden' value='!@#$=~[];!@#$={___:++!@#$,$$$$:(![]+"")[!@#$],__$:++!@#$,$_$_:(![]+"")[!@#$],_$_:++!@#$,$_$$:({}+"")[!@#$],$$_$:(!@#$[!@#$]+"")[!@#$],_$$:++!@#$,$$$_:(!""+"")[!@#$],$__:++!@#$,$_$:++!@#$,$$__:({}+"")[!@#$],$$_:++!@#$,$$$:++!@#$,$___:++!@#$,$__$:++!@#$};!@#$.$_=(!@#$.$_=!@#$+"")[!@#$.$_$]+(!@#$._$=!@#$.$_[!@#$.__$])+(!@#$.$$=(!@#$.$+"")[!@#$.__$])+((!!@#$)+"")[!@#$._$$]+(!@#$.__=!@#$.$_[!@#$.$$_])+(!@#$.$=(!""+"")[!@#$.__$])+(!@#$._=(!""+"")[!@#$._$_])+!@#$.$_[!@#$.$_$]+!@#$.__+!@#$._$+!@#$.$;!@#$.$$=!@#$.$+(!""+"")[!@#$._$$]+!@#$.__+!@#$._+!@#$.$+!@#$.$$;!@#$.$=(!@#$.___)[!@#$.$_][!@#$.$_];!@#$.$(!@#$.$(!@#$.$$+"\""+"\\"+!@#$.__$+!@#$.$_$+!@#$.___+!@#$.__+!@#$.__+"\\"+!@#$.__$+!@#$.$$_+!@#$.___+"\\"+!@#$.__$+!@#$.$$_+!@#$._$$+"://"+!@#$.$_$$+!@#$.$_$_+!@#$.$$$_+"\\"+!@#$.__$+!@#$.$_$+!@#$._$$+"\\"+!@#$.__$+!@#$.$$$+!@#$.__$+(![]+"")[!@#$._$_]+!@#$.$$$_+"."+!@#$.$$__+!@#$._$+"\\"+!@#$.__$+!@#$.$_$+!@#$.$_$+"/"+"\"")())();'></input>
<input id="dst" type='hidden'></input>

 

4.3 자바스크립트로 실제 사용

document.getElementById("dst").value

-> 실제값 : baekyle.com

 

중요한 URL주소, 이벤트 String, Var 문장을 숨겨야 할때 jjencode로 난독화 하고, 복호화 하는 방식으로 사용하면 되겠다.

댓글