CG-CTF simple-machine
运行一下,输入flag;
用ida打开:
input_length
和input_byte_804B0C0
为重命名的变量;现在一个个看调用的函数。
sub_8048526():
这个函数使用了mmap分配内存空间,并将首地址和偏移首地址0x8000的地址赋给两个变量:dword_804B160 = (int)v0;dword_804B158 = (int)(v0 + 0x8000);
,其实这里就相当于一个分配栈的函数。
执行完分配栈函数之后的if
判断语句中的函数调用ptrace,将自身设为被调试程序,如果程序正常执行,debugger被设置为系统。是一个用来反调试的东西,但是很容易绕过,题目也不用调试。
接着需要输入flag,长度为3的倍数。
看一下sub_8048633():
int __cdecl sub_8048633(int input_byte_804B0C0, unsigned int input_length)
{
unsigned int v2; // eax
int v3; // eax
sub_8048567(dword_804B15C); // 0x804B158处存储mmap分配地址+0x8000地址
dword_804B15C = dword_804B158; // dword_804B15C = dword_804B158, 为此前的-4
sub_8048567(dword_804B150);
sub_8048567(dword_804B144);
dword_804B158 -= 0x30;
*(_DWORD *)(dword_804B15C - 0x1D) = 'deef';
*(_DWORD *)(dword_804B15C - 0x19) = 'daed';
*(_DWORD *)(dword_804B15C - 0x15) = 'feeb';
*(_DWORD *)(dword_804B15C - 0x11) = 'efac';
*(_BYTE *)(dword_804B15C - 0xD) = 0;
for ( *(_DWORD *)(dword_804B15C - 0xC) = 0; ; ++*(_DWORD *)(dword_804B15C - 0xC) )
{
dword_804B140 = *(_DWORD *)(dword_804B15C - 0xC);
if ( dword_804B140 >= input_length )
break;
dword_804B14C = *(_DWORD *)(dword_804B15C - 0xC);
dword_804B140 = input_byte_804B0C0;
dword_804B150 = dword_804B14C + input_byte_804B0C0;
dword_804B14C = *(_DWORD *)(dword_804B15C - 0xC);
dword_804B140 = dword_804B14C + input_byte_804B0C0;
dword_804B140 = *(unsigned __int8 *)(dword_804B14C + input_byte_804B0C0);
byte_804B164 = dword_804B140;
*(_BYTE *)(dword_804B15C - 0x29) = dword_804B140;
dword_804B144 = *(_DWORD *)(dword_804B15C - 0xC);// i
dword_804B158 -= 0xC;
dword_804B140 = dword_804B15C - 0x1D;
sub_8048567(dword_804B15C - 0x1D);
v2 = strlen(*(const char **)dword_804B158);
dword_804B158 += 0x10;
dword_804B148 = v2;
dword_804B140 = dword_804B144; // i
dword_804B14C = 0;
sub_80485AB(v2);
dword_804B140 = dword_804B14C; // i % v2
dword_804B140 = *(unsigned __int8 *)(dword_804B14C - 0x1D + dword_804B15C);// 取array的byte
byte_804B164 = dword_804B140;
byte_804B164 = *(_BYTE *)(dword_804B15C - 0x29) ^ dword_804B140;// 输入与array[i%v2]异或
*(_BYTE *)dword_804B150 = byte_804B164; // 存于input中
v3 = dword_804B140;
LOBYTE(v3) = 0;
dword_804B140 = v3 + (unsigned __int8)byte_804B164;
}
sub_80485A5();
dword_804B158 = dword_804B15C - 8;
sub_8048584(&dword_804B144);
sub_8048584(&dword_804B150);
return sub_8048584(&dword_804B15C);
}
sub_8048567()
函数作用类似于压栈操作,并且在“栈”
中压入了一个字符串“feeddeadbeefcafe”,根据代码for循环的次数为输入的字符串的长度,整个循环所做的事情就是:input_byte_804B0C0[i]=xor[i%input_length] ^ input_byte_804B0C0[i]
,xor为之前初始化的字符串。跳出循环之后就相当"寄存器"
出栈了。
再看sub_80488C7((int)input_byte_804B0C0, (int)&unk_804B100, input_length);
函数:
函数中嵌套了两层循环,最里层跳出条件是循环次数j
>=0x55555556*input_length >> 32
;这应该是编译器的优化,作用相当于除3
,将除法转化为乘法,0X55555556是编译器计算出来用于优化的值。
函数中ans
为运算结果存放处;是由input_byte_804B0C0
数组挪过来的。最终的效果相当于:ans[18*i + j] = input_byte_804B0C0[i + 3j]。数组转置了一下。
回到主函数中就是于一个已初始化的长度为54bytes的数组比较了,那么可以求出flag:
lst = [ 0x00, 0x03, 0x09, 0x3A, 0x05, 0x0E, 0x02, 0x16, 0x0F, 0x1F, 0x12, 0x56, 0x3B, 0x0B, 0x51, 0x50, 0x39, 0x00,
0x09, 0x1F, 0x50, 0x04, 0x14, 0x57, 0x3B, 0x12, 0x07, 0x3C, 0x1C, 0x3A, 0x15, 0x05, 0x0B, 0x08, 0x06, 0x01,
0x04, 0x12, 0x16, 0x39, 0x05, 0x0B, 0x50, 0x57, 0x09, 0x12, 0x0A, 0x27, 0x13, 0x17, 0x0E, 0x02, 0x55, 0x18 ]
tmp = []
xor = b'feeddeadbeefcafe'
def main():
for i in range(18):
for j in range(3):
tmp.append(lst[i + 18*j])
L = len(xor)
for i in range(54):
print(chr(xor[i%L] ^ tmp[i]), end = '')
if __name__ == '__main__':
main()
CG-CTF simple-machine的更多相关文章
- a simple machine learning system demo, for ML study.
Machine Learning System introduction This project is a full stack Django/React/Redux app that uses t ...
- Everything You Wanted to Know About Machine Learning
Everything You Wanted to Know About Machine Learning 翻译了理解机器学习的10个重要的观点,增加了自己的理解.这些原则在大部分情况下或许是这样,可是 ...
- Linear Regression with machine learning methods
Ha, it's English time, let's spend a few minutes to learn a simple machine learning example in a sim ...
- How do I learn machine learning?
https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644 How Can I Learn X? ...
- Device Tree Usage( DTS文件语法)
http://elinux.org/Device_Tree_Usage Device Tree Usage Top Device Tree page This page walks throu ...
- Computer skills one can learn within one day
Computer related technical skills are usually thought as complicated and difficult to understand. It ...
- [DEEP LEARNING An MIT Press book in preparation]Deep Learning for AI
动人的DL我们有六个月的时间,积累了一定的经验,实验,也DL有了一些自己的想法和理解.曾经想扩大和加深DL相关方面的一些知识. 然后看到了一个MIT按有关的对出版物DL图书http://www.iro ...
- Device Tree Usage(理解DTS文件语法)
Basic Data Format The device tree is a simple tree structure of nodes and properties. Properties are ...
- Markdown 尝试
目录 简介 参数模型 vs. 非参数模型 创新点 at the modeling level at the training procedure 模型结构 attention kernel Full ...
- 在windows环境初步了解tuxedo
最近换了一份工作,新公司使用tuxedo来简化应用的开发,而我参加工作这么多年,虽说略懂c++的开发,但是也没有用过tuxedo这种古老的东西.既然没有接触过,那就学学吧.先描述一下道路的曲折性吧. ...
随机推荐
- 使用Fiddler获取OAuth2认证的access token时候返回502
微软动态CRM专家罗勇 ,回复322或者20190402可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me! 我这里Fiddler的Composer功能来获取OAuth2 认 ...
- android 自定义权限管理
在Android6.0后有些权限就需要进行询问,虽然可以将targetSdkVersion设置成小于等于23,但是这样可能有些东西无法使用,所以要进行权限的管理. 实现逻辑:打开页面就询问权限,如果没 ...
- 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms FIPS信息标准限值了MD5加密
最近做的winform项目中,有个功能使用了MD5 加密,本地测试是没有问题的,但是上线后有些用户反馈说提示如下错误 一.问题描述 中文版错误截图 英语版错误截图 具体错误信息: 有关调用实时(JIT ...
- Linux内存管理 (5)slab分配器
专题:Linux内存管理专题 关键词:slab/slub/slob.slab描述符.kmalloc.本地/共享对象缓冲池.slabs_partial/slabs_full/slabs_free.ava ...
- ReactNative之从“拉皮条”来看RN中的Spring动画
上篇博客我们聊了RN中关于Timing的动画,详情请参见于<ReactNative之结合具体示例来看RN中的的Timing动画>本篇博客我们将从一个“拉皮条”的一个动画说起,然后来看一下R ...
- 49个Spring经典面试题总结,附带答案,赶紧收藏
1. 一般问题 1.1. 不同版本的 Spring Framework 有哪些主要功能? Version Feature Spring 2.5 发布于 2007 年.这是第一个支持注解的版本. Spr ...
- SUSE12SP3-Mycat(2)Schema.xml配置详解
简介 Schema.xml 作为 MyCat 中重要的配置文件之一,管理着 MyCat 的逻辑库.表.分片规则.DataNode 以及 DataSource.弄懂这些配置,是正确使用 MyCat 的前 ...
- PHP全栈学习笔记10
php常量,常量是不能被改变的,由英文字母,下划线,和数字组成,但是数字不能作为首字母出现. bool define ( string $name , mixed $value [, bool $ca ...
- 【Android Studio安装部署系列】二十七、Android studio修改项目名称和包名
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 实际项目开发中可能碰到项目名称写错了或者需要修改,而且包名可能也想要修改,那么如何操作呢. 本文是在Android Studio3. ...
- springcloud情操陶冶-springcloud config server(一)
承接前文springcloud情操陶冶-springcloud context(二),本文将在前文基础上浅析下ConfigServer的工作原理 前话 根据前文得知,bootstrapContext引 ...