CTF之二进制逆向学习 -- 混淆算法积累
2021/7/19 22:36:47
本文主要是介绍CTF之二进制逆向学习 -- 混淆算法积累,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
混淆算法积累
- 概述
- JSFUCK
- 总结
概述
最近做逆向题,开始遇到代码混淆相关的知识点,这里做一个纪录,一来防止遗忘,二来供大家学习参考。
JSFUCK
jsfuck混淆是基于js的原子性,它可以用6个字符来实现js编程,这6个字符是()[]+!
。如下代码所示,是alert(1)
的混淆代码展示,将下面代码粘贴到控制台即会弹窗1。
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+[+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])()
至于怎么编写这种js代码,此处不多做解释,下面主要介绍如何还原。首先介绍一个在线还原网站 – jsfuck在线还原。如下截图所示,我们将上面的代码示例使用在线网站进行还原。
最后再介绍使用脚本进行还原,主要是ctf做题时的经验,在做题时遇到了大量的jsfuck混淆后的代码,其中还夹杂着正常的代码符号,所以此时需要用正则表达式将其中的jsfuck混淆后的代码提取出来单独还原。如下代码所示,是buuoj上的一道re题目 – equation,其中用于还原的s只选取了部分,这里的代码可用作以后其它题目的参考。
<script> function deEquation(str) { for (let i = 0; i <= 1; i++) { str = str.replace(/l\[(\D*?)\](\+l|-l|==)/g, (m, a, b) => 'l[' + eval(a) + ']' + b); } str = str.replace(/==(\D*?)&&/g, (m, a) => '==' + eval(a) + '&&'); return str; } s = "l[!+[]+!+[]+!+[]+!+[]+[+[]]]+l[!+[]+!+[]+!+[]+[!+[]+!+[]+!+[]+!+[]+!+[]]]+l[!+[]+!+[]+!+[]+[!+[]+!+[]+!+[]+!+[]]]-l[+[]]-l[+!+[]+[!+[]+!+[]+!+[]+!+[]+!+[]]]-l[!+[]+!+[]+!+[]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]+l[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+l[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]-l[!+[]+!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+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]]+l[!+[]+!+[]+!+[]+!+[]]==+(!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+[+!+[]]])&&"; ss=deEquation(s); document.write(ss); </script>
将上面的代码保存为一个文件,后缀使用.html,然后用浏览器打开即可看到还原后的代码。该代码的意思是取数组l中的元素进行四则运算后和常数进行比较。
总结
不忘初心,砥砺前行!
这篇关于CTF之二进制逆向学习 -- 混淆算法积累的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-22怎么通过控制台去看我的页面渲染的内容在哪个文件中呢-icode9专业技术文章分享
- 2024-12-22el-tabs 组件只被引用了一次,但有时会渲染两次是什么原因?-icode9专业技术文章分享
- 2024-12-22wordpress有哪些好的安全插件?-icode9专业技术文章分享
- 2024-12-22wordpress如何查看系统有哪些cron任务?-icode9专业技术文章分享
- 2024-12-21Svg Sprite Icon教程:轻松入门与应用指南
- 2024-12-20Excel数据导出实战:新手必学的简单教程
- 2024-12-20RBAC的权限实战:新手入门教程
- 2024-12-20Svg Sprite Icon实战:从入门到上手的全面指南
- 2024-12-20LCD1602显示模块详解
- 2024-12-20利用Gemini构建处理各种PDF文档的Document AI管道