python-js decompile first test
预备知识
- Literacy - Reptile necessary: Python execute JS code - PyExecJS, PyV8, Js2Py
- First test
PyExecJS
- But look, said
PyV8
no additional equipment JS environment, because the environment itself is a V8, but py3, some problems have time to learn about science. . . [ Here accounted pit, back up the link ]
Purpose is python 可以调试 js
, ok, open out.
1、PyExecJS 初试
pip install PyExecJS
# a.js
function add(x, y) { return x + y; }
# learning00.py
import execjs
def function():
print("in function...")
environ = execjs.get().name # 查看调用的环境
print(environ)
ctx = execjs.compile(""" function add(x, y) { return x + y; } """)
result = ctx.call("add", 3, 2)
print('execjs.all', result)
with open('./a.js', 'r') as f:
ctx = execjs.compile(f.read())
result = ctx.call("add", 1, 2)
print('openFile and call', result)result)
When js contains windows, document, use the jsdom
resolve to learn frompython使用execjs执行含有document、window等对象的js代码,使用jsdom解决
Other techniques [ js obfuscated code reduction ]
First posted test code after a confusion:
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("0-6");2 4(){1("0-5")}8 3=2(){1("0-7")};4();3()',9,9,'忧郁的匹格|alert|function|b|a|反混淆测试2|反混淆测试1|反混淆测试3|var'.split('|'),0,{}))
Anti-aliasing method
- Create a new page
xxx.html
- Adding a div container
id="divTest"
- Assignment performed (in code obfuscation above, the contents of () extracted from the assignment eval (or direct printing))
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="divTest"></div>
</body>
</html>
<script>
// 将内容直接提取到页面中
document.getElementById('divTest').innerText = 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("0-6");2 4(){1("0-5")}8 3=2(){1("0-7")};4();3()',9,9,'忧郁的匹格|alert|function|b|a|反混淆测试2|反混淆测试1|反混淆测试3|var'.split('|'),0,{})
// 直接在控制台中打印出来
console.log(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("0-6");2 4(){1("0-5")}8 3=2(){1("0-7")};4();3()',9,9,'忧郁的匹格|alert|function|b|a|反混淆测试2|反混淆测试1|反混淆测试3|var'.split('|'),0,{}))
</script>
- Open xxx.html shows the code after the results :( anti-aliasing has been compressed, remove the newline character, etc.), then on his own js code can be analyzed.