运行一下,输入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. android 自定义权限管理

    在Android6.0后有些权限就需要进行询问,虽然可以将targetSdkVersion设置成小于等于23,但是这样可能有些东西无法使用,所以要进行权限的管理. 实现逻辑:打开页面就询问权限,如果没 ...

  2. Vagrant 构建 Linux 开发环境

    Vagrant 是一个简单易用的部署工具,用英文说应该是 Orchestration Tool .它能帮助开发人员迅速的构建一个开发环境,帮助测试人员构建测试环境, Vagrant 基于 Ruby 开 ...

  3. pod command

    pod 基础使用命令 创建Podfile文件 1 pod init 使用命令打开Podfile文件 1 open -a Xcode Podfile 搜索pod 库 1 pod search 库名 更新 ...

  4. vue2.0 日历日程表 ,可进行二次开发.

    由于工作业务需求,要写一个日程表,日程表写之前 要先生成日历,废话不多说,直接 上代码: <!DOCTYPE html> <html lang="zh-CN"&g ...

  5. java.lang.ClassNotFoundException: org.I0Itec.zkclient.IZkStateListener异常解决

    在启动Dubbo项目时,出现该异常 java.lang.ClassNotFoundException: org.I0Itec.zkclient.IZkStateListener 解决,引入 <d ...

  6. ansible基础-Jinja2模版 | 过滤器

    Jinja2模版介绍 注:本文demo使用ansible2.7稳定版 在ansible基础-变量的「8.2 模版使用变量」章节中关于模版与变量也有所提及,有兴趣的同学可以去回顾一下. ansible通 ...

  7. Python爬虫入门教程 51-100 Python3爬虫通过m3u8文件下载ts视频-Python爬虫6操作

    什么是m3u8文件 M3U8文件是指UTF-8编码格式的M3U文件. M3U文件是记录了一个索引纯文本文件, 打开它时播放软件并不是播放它,而是根据它的索引找到对应的音视频文件的网络地址进行在线播放. ...

  8. 【Git之旅】1.Git常用命令

    1.创建初始化版本库 git init 2.将文件添加到版本库中 git add index.html (添加到暂存区) git add . 命令让Git把当前目录及目录中的文件都添加到版本库里 gi ...

  9. pandas操作

    python中使用了pandas的一些操作,特此记录下来: 生成DataFrame import pandas as pd data = pd.DataFrame({ 'v_id': ["v ...

  10. Spring Boot 2.x :通过 spring-boot-starter-hbase 集成 HBase

    摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! 本文内容 HBase 简介和应用场景 spring-boot- ...