2018年网鼎杯,emmm,好不容易看到个算法题还花了很长时间,太难过了T_T
二叉树
0x01
下载题目后,得到一张红黑树的图片和README.txt. 将readme进行base64解码可以得到hit:
1 | 1.这是一棵红黑树 |
0x02
经过提示,首先需要找一份红黑树的实现,并且按照图片构造一颗红黑树(如果不按图片会出现多解情况,因为这点被坑惨),以下给出一个很好的python版红黑树实现
1 | # -*- coding: utf-8 -*- |
这段红黑树的果子为rbnode对象,整个树根据果子的key构建,果子的value可以可以放我们字符串的字符。
默认的红黑树时通过不断加入节点自动生成的,但是加入果子的顺序不同会造成树以及果子的颜色的不同,可以看到我对标准的红黑树构造函数做了修改,这样我们可以根据给出的图片(1.jpg)构造一个红黑树。
1 | if __name__ == '__main__': |
备注:
这真的是一个红黑树的一个很好的实现,还可以可视化的打印整棵树,这里给出正常的构造树的方法,只需给出果子的key和value:
1 | if __name__ == '__main__': |
0x03
根据提示3,从树上取走第 18,35,53,50,14,28,19,6,54,36 个果子:
1 | for i in [18,35,53,50,14,28,19,6,54,36]: |
0x04
根据提示4和5,获取第[8,56,47,37,52,34,17,8,8,29,7,47,40,57,46,24,34,34,57,29,22,5,16,57,24,29,8,12,57,12,12,21,33,34,55,51,22,45,34,31,1,23]果子的值,并且按照颜色对其ascii+1或-1,即可得到flag
1 | s="" |
算出flag为:
flag{10ff49a7-db11-4e43-b4f6-66ef12ceb19d}
martricks
刚拿到这题就感觉跟符号执行有关系,可惜没有贯彻思想继续做下去,不过解法蛮简单的,这里简单记录一下,也是当学习一下angr吧:
0x01
拿到题目ida打开,大概F5看一下,有一个判断,如果等于0就congrats否则wrong,那么记下这两处字符串的地址。
0x02
接下来就可以用angr调用该文件,根据符号执行让我们执行到400A84地址,其中避免经过400A90地址
1 | import angr |
等待一会后得到flag:
flag{Everyth1n_th4t_kill5_m3_m4kes_m3_fee1_aliv3}
注: 所有程序题目已经上传至GitHub:https://github.com/Anemone95/ctf_wp/tree/master/wangding2018