攻防世界逆向Reversing-x64Elf-100

文章讲述了对一个64位可执行文件的逆向工程分析,主要涉及在IDAPro64中查找关键函数,理解了一个模数计算器式的字符串匹配逻辑。通过分析字符串数组和字符偏移,作者推断出flag的计算方法并给出了逆向脚本实现。


很明显是个64位可执行文件,用IDA Pro 64打开,找到main

此处打草稿分析一下该伪代码功能,可以直接略过:

然后顺便提一嘴,在IDA里面基本养成一个习惯,你看到的几乎所有东西都是指针,指向某个地址的,然后从中取值

和平常看c代码不太一样,平常看c代码是直接看到变量名字,想它里面存什么值,现在是看到一串符号或者变量,先想它指向哪个地址,从中取出什么值


满足sub_4006FD条件输出“Incorrect Password!”不满足则输出“Nice!”
所以我们进入关键函数,其输出只有两种return 1LL和return 0LL,换句话说,返回1,则满足条件,输出“Incorrect Password!”,返回0,则不满足条件,输出“Nice!”

所以我们需要返回0,而返回0,就需要下面这个for循环,每次循环里面的if语句都不成立,就是每次都返回不了1,循环结束后才能返回0

因此这儿需要搞清楚if里面的条件到底是什么意思,才能写出逆向脚本,先说结论,算法其实就是一个模数计算器,用来循环运算字符串。                                                                                            首先知道a1是个传进来的参数,但是不知道它到底是什么                                                              v3相当于是个数组,里面每个元素都是个字符串,有v3[0]、v3[1]、v3[2]三个字符串                        if里面的条件永远不成立,就是*(char*)(v3[i%3] + 2*(i/3))    -    *(char*)(i+a1)    ==    1    恒成立      v3[i%3]保证i从0循环到11,i%3永远只能等于0、1、2,它的作用类似于汇编中定段地址,先把地址定到v3[0]开头或者v3[1]开头或者v3[2]开头。2*(i/3),保证i从0循环到11,取值永远在0到6,很明显每个元素都是个字符串,每个字符串例如“Dufhbmf”刚好七个字符,索引对应0到6,所以它的作用类似于汇编中的偏移地址,在确定开头的情况下在每一段内再偏移来寻找需要的字符。二者合起来相当于一个二维数组的索引,在这儿个3行7列的矩阵里面寻找需要的字符。

  再来看a1不知道是什么,但根据前面的分析,v3[i%3]+2*(i/3)是字符串型指针,意在寻找3行7列的矩阵中需要的字符的地址,再用个*把地址里存的字符的值取出来,所以我们不妨假设a1也是个字符串的首地址,其中存着字符串的第一个字符,那么i从0循环到11,相当于遍历了这一整个字符串的地址,那么很明显它就是需要逆向出来的目标,很明显推测它就是flag

flag的值怎么球呢,每次循环,*(char *)(v3[i%3]+2*(i/3))代表获得一个字符,或者可以认为获得这个字符的ASCII码值,再把码值-1,就是 *(char *)(i+a1)在这一位的字符的ASCII码值,再把ASCII码值转化成相应的字符,循环12次,就获得了这个flag                                                                    


有以上理解,继续编写逆向的·脚本

网上的借鉴版本:

在这里插入图片描述

再是自己的拆解版本,相互有个对照:

#coding=utf-8


v = ["Dufhbmf", "pG`imos", "ewUglpt"]
s = ''
for i in range(12):
    a = i % 3
    b = 2*int(i/3)
    s += chr(ord(v[a][b])-1)

print(s)

运行后得结果Code_Talkers,就是flag

### CTF Reversing x64 ELF 100 Challenge Solution and Hints For the reversing challenge involving an x64 ELF file, understanding how to interpret hexadecimal strings as ASCII characters is crucial. When faced with a string that appears nonsensical at first glance but contains digits from `0` through `F`, it suggests dealing with hexadecimal encoding. Converting such hex values into their corresponding ASCII representations can reveal hidden messages or flags required by challenges. In this specific case, converting each pair of hexadecimal digits (like `66`) into decimal yields ASCII codes which translate directly into readable text characters; for instance, `66` becomes `102` in decimal, representing 'f' according to the ASCII standard[^1]. Following similar conversions (`6c` -> `110` -> 'n'), one might deduce part of the flag format expected within these types of puzzles—often enclosed between curly braces following "flag". Regarding handling ELF files specifically, knowledge about the structure including headers like `ELF64_Ehdr` and sections described via structures such as `ELF64_Shdr` proves beneficial when attempting reverse engineering tasks on binaries formatted under the Executable and Linkable Format specification used primarily across Unix-like systems[^2]. To tackle this particular level effectively: - Examine any provided binary using tools designed for analyzing ELF executables. - Look out for embedded strings or data segments containing potential clues encoded similarly to what was discussed earlier regarding hexadecimal-to-text conversion. - Utilize debugging utilities alongside disassemblers to trace execution flow while paying attention to operations manipulating input/output streams where flags could be checked against user-supplied answers during runtime. ```bash # Example command line tool usage for inspecting ELF binaries readelf -h your_binary_file # Display the ELF header information strings your_binary_file # Extract printable character sequences possibly hinting towards solutions ``` --related questions-- 1. What are common methods employed in decoding obfuscated texts found inside executable programs? 2. How does one approach decompiling or disassembling different architectures beyond just x86_64? 3. Can you explain more about the significance of various fields present within the ELF header concerning program loading and linking processes?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值