[BUUCTF]REVERSE——[WUSTCTF2020]level4

[WUSTCTF2020]level4

附件

步骤

  1. elf文件,虚拟机试运行一下看看大概的情况,根据提示字符Typing....Struct.....char....*left....*right............emmmmm...OK!猜测存在二叉树
    在这里插入图片描述
    看到type1和type2里的字符串有点像flag,但是顺序被打乱了
  2. 64位ida载入
    在这里插入图片描述
    type1(byte_601290), 二叉树中序遍历:2f0t02T{hcsiI_SwA__r7Ee}
    在这里插入图片描述
    type2(byte_601290),二叉树后序遍历:20f0Th{2tsIS_icArE}e7__w
    在这里插入图片描述
    关于二叉树的介绍,了解了二叉树的原理后就可以求出前序了。一开始手动的,写到一半发现太多了就换脚本了

python3的exp
来源:https://blog.csdn.net/weixin_41287060/article/details/99400963

#使用中序后序求前序遍历
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def reConstructBinaryTree(self, post, tin):
        if len(post) == 0:
            return None
        root = TreeNode(post[-1])
        TinIndex = tin.index(post[-1])
        root.left = self.reConstructBinaryTree(post[0:TinIndex], tin[0:TinIndex])
        root.right = self.reConstructBinaryTree(post[TinIndex:len(post) - 1], tin[TinIndex + 1:])
        return root

    def PreTraversal(self, root):
        if root != None:
            print(root.val,end="")
            self.PreTraversal(root.left)
            self.PreTraversal(root.right)

strm="2f0t02T{hcsiI_SwA__r7Ee}"
stre="20f0Th{2tsIS_icArE}e7__w"
post = list(stre)#后序
tin = list(strm)#中序

S = Solution()
root = S.reConstructBinaryTree(post, tin)
S.PreTraversal(root)

wctf2020{This_IS_A_7reE}
flag{This_IS_A_7reE}

猜你喜欢

转载自blog.csdn.net/mcmuyanga/article/details/114382440
今日推荐