当前位置:网站首页>【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
2022-07-06 16:50:00 【黑色地带(崛起)】
目录
一、直接内存获取
1.1、简介:
简单的情况,直接查看内存的方式获取flag
即只需要在比较的地方下个断点,然后通过查看内存即可得到flag
伪代码:
input = get_input()
if(input == calc_flag())
{
puts(flag is input)
}
1.2、示例:
main函数(反编译代码):
1.3、分析:
循环计算出了一个dest,然后与输入的参数argv[1]比较,如果相等,则argv[1]就是flag
选择在调用memcmp的地方下断点,然后运行程序。在断点断下之后,RDI寄存器指向的内容
即为flag,在GDB中读取flag
二、对算法进行逆变换操作
2.1、示例:
一个判断过程的代码:
要分析convert的算法,然后分析结果编写出对应的逆算法,通过reverse_convert(stardard)方式求得flag
input = get_input()
if(standard == convert(input))
{
puts(flag is input)
}定位程序比较的地方:
是base64编码的程序
先分析main函数,其中change函数根据输入input得到一个output字符串,然后将output字符串与“ms4otszPhcr7tMmz GMkHyFn=”进行比较--->需要分析change函数
change函数(反编译代码):
变种的base64:
建立了一个to_string(i)与v22[i]的map,然后,将input转化为二进制的字符串,每次取6字节,转化为一个整数,接着查询map,得到对应的输出字节
base64逆变换:
import base64
s1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
s2 = 'ELF8n0BKxOCbj/WU9mwle4cG6hytqD+P3kZ7AzYsag2NufopRSIVQHMXJri51Tdv'
dict = {}
for i in range(len(s1)):
dict[s2[i]] = s1[i]
dict['='] = '='
output = 'ms4otszPhcr7tMmzGMkHyFn='
s3 = ' '
for i in range(len(output)):
s3 += dict[output[i]]
flag = base64.b64decode(s3)
print flag
三、线性变换的求解
3.1、简介:
如果convert是一个线性变换,那么在output=convert(input)中,output的第i位只能由input的第i位决定。通过获取input[i]的所有可能输入对应的输出output[i],即可求出input[i]。
对于这种变换,可以进行单字符爆破
3.2、示例:
提供了一个cipher可执行程序和ciphertext密文数据。运行cipher,会要求输入明文,并将加密后的结果保存到out文件中
cipher程序运行结果
尝试发现当输入只有第1字节不同时,输出也只有第1字节不同
多次尝试,可以确定其为线性变换
采用单字节爆破
代码:
from zio import *
with open('./ciphertext') as f:
d = f.read()
flag = ' '
for i in range(len(d)):
for c in range(0x21, 0x80):
try_input = flag + chr(c)
io = zio('./cipher')
io.writeline(try_input)
io.close()
f = open('./out', 'rb')
d2 = f.read()
if d2[i] == d[i]:
flag += chr(c)
break
print flag
四、约束求解
4.1、简介:
如果output=convert(input)之后,需要output满足多个约束条件
通常会选择约束求解,通常会用到的约束求解器为z3。
4.2、示例:
运行程序,弹出错误对话框
用OD加载,下断点GetWindowsTextA,按下check键,程序成功断下来
调用堆栈,可以知道函数返回地址为0x40bd7b。
在IDA中查看0x40bd7b地址,发现该函数被识别为CWnd::GetWindowTextA,所以还要再回溯一层,最终到达地址0x4017AD。
0x4017AD函数的反编译代码
(除了对长度进行判断,要求小于40字节之外,还调用了3个子函数,对输入进行变换)
定位到程序的主要判断逻辑:
第一个函数sub_401380(反编译代码)
熟悉的base64字符串--->该函数为base64加密
第二个函数sub_401000(反编译代码)
对每个字符做了一个减3的操作
第三个函数sub_401040(反编译代码)
需要满足条件:
a2[i]+a2[i+1] == v5[i]
a2[9]-a2[20]==22
a2[40]==0条件较难直接计算,故采用约束求解的方式进行求解
代码:
from z3 import *
import base64
s2 = [151, 130, 175, 190, 163, 189, 149, 132, 192, 188, 159, 162, 131, 99, 168, 197, 151, 151, 164, 164, 152, 166, 205, 188, 1s1 = [BitVec('s1_%d' % i, 8) for i in range(41)]
s = Solver()
for i in range(39):
s.add(s1[i]+s1[i+1] == s2[i])
s.add(s1[9] - s1[20] == 22)
s.add(s1[40] == 0)
s3 = ' '
if s.check() == z3.sat:
m = s.model()
for i in range(40):
s3 += chr(m[s1[i]].as_long())
s4 = ' '.join([chr(ord(s3[i])+3) for i in range(len(s3))])
flag = base64.b64decode(s4)
print flag
边栏推荐
- Leecode brush questions record sword finger offer 44 A digit in a sequence of numbers
- 一图看懂对程序员的误解:西方程序员眼中的中国程序员
- 2021 SASE integration strategic roadmap (I)
- MIT 6.824 - Raft学生指南
- Cross-entrpy Method
- Core knowledge of distributed cache
- Typescript incremental compilation
- QT tutorial: creating the first QT program
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- Matlab learning notes
猜你喜欢

DAY THREE

量子时代计算机怎么保证数据安全?美国公布四项备选加密算法

2022/2/12 summary
![[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist](/img/53/95ab85bfd99d943f98881596d0aa8c.png)
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist

DAY FOUR

如何判断一个数组中的元素包含一个对象的所有属性值

从外企离开,我才知道什么叫尊重跟合规…

1000字精选 —— 接口测试基础

The programmer resigned and was sentenced to 10 months for deleting the code. Jingdong came home and said that it took 30000 to restore the database. Netizen: This is really a revenge

rancher集成ldap,实现统一账号登录
随机推荐
PXE server configuration
Introduction to GPIO
Supersocket 1.6 creates a simple socket server with message length in the header
St table
三维扫描体数据的VTK体绘制程序设计
DAY FOUR
MIT 6.824 - Raft学生指南
基于GO语言实现的X.509证书
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
Mujoco produces analog video
Jenkins' user credentials plug-in installation
Pdf document signature Guide
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
ldap创建公司组织、人员
Basic information of mujoco
"Latex" Introduction to latex mathematical formula "suggestions collection"
1000 words selected - interface test basis
Three application characteristics of immersive projection in offline display
工程师如何对待开源 --- 一个老工程师的肺腑之言
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools









