运行一下,输入flag;

用ida打开:



input_lengthinput_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的更多相关文章

  1. 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 ...

  2. Everything You Wanted to Know About Machine Learning

    Everything You Wanted to Know About Machine Learning 翻译了理解机器学习的10个重要的观点,增加了自己的理解.这些原则在大部分情况下或许是这样,可是 ...

  3. 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 ...

  4. 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? ...

  5. Device Tree Usage( DTS文件语法)

    http://elinux.org/Device_Tree_Usage Device Tree Usage     Top Device Tree page This page walks throu ...

  6. Computer skills one can learn within one day

    Computer related technical skills are usually thought as complicated and difficult to understand. It ...

  7. [DEEP LEARNING An MIT Press book in preparation]Deep Learning for AI

    动人的DL我们有六个月的时间,积累了一定的经验,实验,也DL有了一些自己的想法和理解.曾经想扩大和加深DL相关方面的一些知识. 然后看到了一个MIT按有关的对出版物DL图书http://www.iro ...

  8. Device Tree Usage(理解DTS文件语法)

    Basic Data Format The device tree is a simple tree structure of nodes and properties. Properties are ...

  9. Markdown 尝试

    目录 简介 参数模型 vs. 非参数模型 创新点 at the modeling level at the training procedure 模型结构 attention kernel Full ...

  10. 在windows环境初步了解tuxedo

    最近换了一份工作,新公司使用tuxedo来简化应用的开发,而我参加工作这么多年,虽说略懂c++的开发,但是也没有用过tuxedo这种古老的东西.既然没有接触过,那就学学吧.先描述一下道路的曲折性吧. ...

随机推荐

  1. 使用CAS实现无锁列队-链表

    #include <stdlib.h> #include <stdio.h> #include <pthread.h> #include <iostream& ...

  2. Java中Map和Object的互相转换方式

    一.使用Apache中的BeanUtils类,导入commons-beanutils包. Jar包Maven下载地址:https://mvnrepository.com/artifact/common ...

  3. mongo connections url string 的问题

    摘要 driver 连接Mongo DB的url其实很简单,就是几个变量拼接成一个url,和关系型数据库没什么不同.但是因为mongo有单个instance和replicaSet不同的部署策略,还有m ...

  4. 使用 Moq 测试.NET Core 应用 -- Mock 方法

    第一篇文章, 关于Mock的概念介绍: https://www.cnblogs.com/cgzl/p/9294431.html 本文介绍使用Moq来Mock方法. 使用的代码: https://git ...

  5. TabTopAutoLayout【自定义顶部选项卡区域(带下划线)(动态选项卡数据且可滑动)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 自定义顶部选项卡布局LinearLayout类,实现带下划线且可滑动效果.[实际情况中建议使用RecyclerView] 备注:如果 ...

  6. SpringSecurity自定义AuthenticationProvider和AuthenticationFilter

    AuthenticationProvider 默认实现:DaoAuthenticationProvider 授权方式提供者,判断授权有效性,用户有效性,在判断用户是否有效性,它依赖于UserDetai ...

  7. 简述java接口和C++虚类的相同和不同之处

    C++虚类相当于java中的抽象类,与接口的不同处是: 1.一个子类只能继承一个抽象类(虚类),但能实现多个接口 2.一个抽象类可以有构造方法,接口没有构造方法 3.一个抽象类中的方法不一定是抽象方法 ...

  8. 微信公众号开发C#系列-4、获取接口调用凭证

    概述 获取接口调用凭证实质就是获取access_token.在微信接口开发中,许多服务的使用都离不开Access Token,Access Token相当于打开这些服务的钥匙,正常情况下会在7200秒 ...

  9. 了解一下 - Base64

    Base64编码是最常见的编码方式(使用64个字符表示任意8bit字节序列),是一种基于64个可打印字符来表示任意二进制数据的方法,是从二进制转换到可见字符的过程. 使用场景 数据加密后通过Base6 ...

  10. python 正则验证 IP地址与MAC地址

    #coding=utf-8 import re def isValidIp(ip): if re.match(r"^\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} ...