密码学笔记——eval(function(p,a,c,k,e,d) 加密破解
?密碼學筆記——eval(function(p,a,c,k,e,d) 的加密破解
例題:
小明某天在看js的時候,突然看到了這么一段代碼,發現怎么也理不出代碼邏輯,你能幫幫他嗎?
格式:SimCTF{}
eval(function(p,a,c,k,e,d){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--)d[e(c)]=k[c]||e(c);k=[function(e){return d[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;}('<1 8="7/a">9(\'\\6\\3\\2\\5\\4\\b\\i\\h\\k\\j\\0\\g\\d\\c\\f\\0\\e\')</1>',21,21,'u0065|script|u006d|u0069|u0054|u0043|u0053|text|type|alert|javascript|u0046|u006f|u0063|u007d|u0064|u006e|u006a|u007b|u005f|u0073'.split('|'),0,{}))
?
1、其實這個eval(function(p,a,c,k,e,d){}))中自帶解碼函數e(),“while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p”? while循環產生的每個p就是解碼后的函數代碼,我們刪掉源碼中的“return p”,不用將結果返回, 而是直接輸出在一個文本區域中,如“document.getElementById(”textareaID”).innerText=p”
?
2、
原代碼:
eval(function(p,a,c,k,e,d){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--)d[e(c)]=k[c]||e(c);k=[function(e){return d[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;}('<1 8="7/a">9(\'\\6\\3\\2\\5\\4\\b\\i\\h\\k\\j\\0\\g\\d\\c\\f\\0\\e\')</1>',21,21,'u0065|script|u006d|u0069|u0054|u0043|u0053|text|type|alert|javascript|u0046|u006f|u0063|u007d|u0064|u006e|u006a|u007b|u005f|u0073'.split('|'),0,{}))
修改后的代碼:
eval(function(p,a,c,k,e,d){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--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);document.getElementById('textareaID').innerText=p;}('<1 8="7/a">9(\'\\6\\3\\2\\5\\4\\b\\i\\h\\k\\j\\0\\g\\d\\c\\f\\0\\e\')</1>',21,21,'u0065|script|u006d|u0069|u0054|u0043|u0053|text|type|alert|javascript|u0046|u006f|u0063|u007d|u0064|u006e|u006a|u007b|u005f|u0073'.split('|'),0,{}))
?
代碼如下:
<!DOCTYPE html P LIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title> Crack Baidu統計構造函數</title><meta http-equiv="content-type" content="text/html; charset=UTF-8" /><meta http-equiv="X- -Compatible" content="IE=EmulateIE7" /><meta name="Author" content=www.gemingcao.com/><meta name="Keywords" content="" /><meta name="Description" content="" /> </head><body><textarea id="textareaID" rows="25" cols="50"></textarea><script type="text/javascript">eval(function(p,a,c,k,e,d){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--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);document.getElementById('textareaID').innerText=p;}('<1 8="7/a">9(\'\\6\\3\\2\\5\\4\\b\\i\\h\\k\\j\\0\\g\\d\\c\\f\\0\\e\')</1>',21,21,'u0065|script|u006d|u0069|u0054|u0043|u0053|text|type|alert|javascript|u0046|u006f|u0063|u007d|u0064|u006e|u006a|u007b|u005f|u0073'.split('|'),0,{}))</script></body></html>?
?3、保存為html文件,其結果為
?
4、發現是Unicode編碼,用 http://tool.chinaz.com/tools/unicode.aspx?
?
?5、另一種方法是,用在線的js混淆還原工具
??????? http://tool.lu/js
?
?
?
?
?
? ? ???????? 注:本筆記參考http://www.cnblogs.com/wangchunming/archive/2012/04/01/2429455.html
----------------------------------------------------------------分割線---------------------------------------------------------
? ? ? ? ? ? ? ps:萌新一枚,本文純為學習筆記,以防某日犯傻忘記--。如有不妥處,望大佬們賜教~
?
轉載于:https://www.cnblogs.com/xdjun/p/7467981.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的密码学笔记——eval(function(p,a,c,k,e,d) 加密破解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: qq邮箱app如何添加附件(登录QQ邮箱
- 下一篇: Selenium-键盘操作