eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2 7=B;e C(b,c){b.8||(b.8="");b.f||(b.f="\\4[D");b.5||(b.5="");b.3||(b.3="");b.h||(b.h="");2 d=`${b.3}${b.5}┎─\\4[6`;d+=`${b.3}${b.f}${b.8}\\4[6`;d+=`${b.3}${b.5}${"─".j(7-k(b.8||""))}─┒\\4[6`;l.n(d);r(2 o E F){2 s=7-k(o.t(x=>u(x)).t(x=>x.G(/\\4\\[[0-9]*m/g,\'\')).H(\' \'))-1;2 v=`${b.3}${b.5}┃\\4[6${b.3}${b.h}`;2 w=`${b.3}${b.5}${\' \'.j(s)}┃\\4[6`;l.n(v,...o,w)}2 y=`${b.3}${b.5}┖─${"─".j(7)}─┚\\4[6`;l.n(y);e u(a){z(I a==\'J\')p K.L(a)+" ";p a.M()}e k(a){2 q=a.A;r(2 i=0;i<a.A;i++)z(/[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/.N(a[i]))q+=1;p q}}',50,50,'||let|bgColor|x1b|boxColor|0m|maxLen|title|||||header|function|titleColor||fgColor||repeat|size|console||log|line|return|len|for|count|map|tostr|bodyHead|bodyTail||footer|if|length|120|printBox|33m|of|lines|replace|join|typeof|object|JSON|stringify|toString|test'.split('|'),0,{}))
패킹된 js코드를 해석하거나 원본 코드로 바꿔서 블로그에 쓰는게 과제이다. 처음에는 손으로 하나하나 해석해야 되는줄 알고 미뤄두다가 힌트에 eval함수에 대한 공식 문서 링크가 있는걸 보고 console.log로 바꾸면 원본 코드 출력되니까 걍 그렇게 써도 되냐고 물어보니까 된다고 하셨다.
왜 eval을 console.log로 바꾸면 원본 코드가 출력되냐하면
function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2 7=B;e C(b,c){b.8||(b.8="");b.f||(b.f="\\4[D");b.5||(b.5="");b.3||(b.3="");b.h||(b.h="");2 d=`${b.3}${b.5}┎─\\4[6`;d+=`${b.3}${b.f}${b.8}\\4[6`;d+=`${b.3}${b.5}${"─".j(7-k(b.8||""))}─┒\\4[6`;l.n(d);r(2 o E F){2 s=7-k(o.t(x=>u(x)).t(x=>x.G(/\\4\\[[0-9]*m/g,\'\')).H(\' \'))-1;2 v=`${b.3}${b.5}┃\\4[6${b.3}${b.h}`;2 w=`${b.3}${b.5}${\' \'.j(s)}┃\\4[6`;l.n(v,...o,w)}2 y=`${b.3}${b.5}┖─${"─".j(7)}─┚\\4[6`;l.n(y);e u(a){z(I a==\'J\')p K.L(a)+" ";p a.M()}e k(a){2 q=a.A;r(2 i=0;i<a.A;i++)z(/[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/.N(a[i]))q+=1;p q}}',50,50,'||let|bgColor|x1b|boxColor|0m|maxLen|title|||||header|function|titleColor||fgColor||repeat|size|console||log|line|return|len|for|count|map|tostr|bodyHead|bodyTail||footer|if|length|120|printBox|33m|of|lines|replace|join|typeof|object|JSON|stringify|toString|test'.split('|'),0,{})
eval안에 있는 이 함수는 원래 실행할 코드를 문자열로 만들어서 return해주는 함수이다. 그래서 이 함수가 원래 js코드를 return하면 그게 eval인자로 들어가서 패킹되지 않은 원래 js코드가 실행이 되는것이다.
let maxLen=120;function printBox(b,c){b.title||(b.title="");b.titleColor||(b.titleColor="\x1b[33m");b.boxColor||(b.boxColor="");b.bgColor||(b.bgColor="");b.fgColor||(b.fgColor="");let header=`${b.bgColor}${b.boxColor}┎─\x1b[0m`;header+=`${b.bgColor}${b.titleColor}${b.title}\x1b[0m`;header+=`${b.bgColor}${b.boxColor}${"─".repeat(maxLen-size(b.title||""))}─┒\x1b[0m`;console.log(header);for(let line of lines){let count=maxLen-size(line.map(x=>tostr(x)).map(x=>x.replace(/\x1b\[[0-9]*m/g,'')).join(' '))-1;let bodyHead=`${b.bgColor}${b.boxColor}┃\x1b[0m${b.bgColor}${b.fgColor}`;let bodyTail=`${b.bgColor}${b.boxColor}${' '.repeat(count)}┃\x1b[0m`;console.log(bodyHead,...line,bodyTail)}let footer=`${b.bgColor}${b.boxColor}┖─${"─".repeat(maxLen)}─┚\x1b[0m`;console.log(footer);function tostr(a){if(typeof a=='object')return JSON.stringify(a)+" ";return a.toString()}function size(a){let len=a.length;for(let i=0;i<a.length;i++)if(/[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/.test(a[i]))len+=1;return len}}
eval을 console.log로 바꾸면 이렇게 원본 소스코드가 나온다.
let maxLen = 120;
function printBox(b, c) {
b.title || (b.title = "");
b.titleColor || (b.titleColor = "\x1b[33m");
b.boxColor || (b.boxColor = "");
b.bgColor || (b.bgColor = "");
b.fgColor || (b.fgColor = "");
let header = `${b.bgColor}${b.boxColor}┎─\x1b[0m`;
header += `${b.bgColor}${b.titleColor}${b.title}\x1b[0m`;
header += `${b.bgColor}${b.boxColor}${"─".repeat(maxLen-size(b.title||""))}─┒\x1b[0m`;
console.log(header);
for (let line of lines) {
let count = maxLen - size(line.map(x => tostr(x)).map(x => x.replace(/\x1b\[[0-9]*m/g, '')).join(' ')) - 1;
let bodyHead = `${b.bgColor}${b.boxColor}┃\x1b[0m${b.bgColor}${b.fgColor}`;
let bodyTail = `${b.bgColor}${b.boxColor}${' '.repeat(count)}┃\x1b[0m`;
console.log(bodyHead, ...line, bodyTail)
}
let footer = `${b.bgColor}${b.boxColor}┖─${"─".repeat(maxLen)}─┚\x1b[0m`;
console.log(footer);
function tostr(a) {
if (typeof a == 'object') return JSON.stringify(a) + " ";
return a.toString()
}
function size(a) {
let len = a.length;
for (let i = 0; i < a.length; i++)
if (/[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/.test(a[i])) len += 1;
return len
}
}
사람이 보기 좋게 줄바꿈, 개행 등을 추가해줬다.
'Layer7' 카테고리의 다른 글
| Layer7 - SQL Injection + 웹해킹 7차시 과제 (0) | 2022.10.04 |
|---|---|
| Layer7 - 웹해킹 4차시 과제 (0) | 2022.10.04 |
| Layer7 - 웹해킹 3차시 과제 (0) | 2022.10.04 |
| Layer7 - C언어 4차시 과제 (0) | 2022.10.04 |
| Layer7 - C언어 3차시 과제 (0) | 2022.10.04 |