XCTF-open-source
下载附件拿到源码。
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
if (argc != 4) {
printf("what?\n");
exit(1);
}
unsigned int first = atoi(argv[1]);
if (first != 0xcafe) {
printf("you are wrong, sorry.\n");
exit(2);
}
unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) {
printf("ha, you won't get it!\n");
exit(3);
}
if (strcmp("h4cky0u", argv[3])) {
printf("so close, dude!\n");
exit(4);
}
printf("Brr wrrr grr\n");
unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv[3]) - 1615810207;
printf("Get your key: ");
printf("%x\n", hash);
return 0;
}
这是段C语言的源码。拿到变量hash的值就是flag。一共四个if条件。
第一个if:argc为表示传参的个数,这里判断是不是四个参数
if (argc != 4) {
printf("what?\n");
exit(1);
}
第二个if:atoi函数把字符串转成整型(int型)。oxcafe转成整型为:
unsigned int first = atoi(argv[1]);
if (first != 0xcafe) {
printf("you are wrong, sorry.\n");
exit(2);
}
第三个if:||运算符只要前一部分成立就不会看后一部分,满足条件会输出“"ha, you won't get it!”,我们让second=25,不满足这个if条件。
unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) {
printf("ha, you won't get it!\n");
exit(3);
}
第四个if:strcmp会根据 ASCII 编码依次比较 str1 和 str2 的每一个字符,直到出现不到的字符,或者到达字符串末尾(遇见\0)
如果返回值 < 0,则表示 str1 小于 str2。
如果返回值 > 0,则表示 str2 小于 str1。
如果返回值 = 0,则表示 str1 等于 str2。
让argv[3]='h4cky0u',则if判断为假,不进入if后的运算。
if (strcmp("h4cky0u", argv[3])) {
printf("so close, dude!\n");
exit(4);
}
最后求hash的值:
first =0xcafe,
second=25
strlen(argv[3])=7
unsigned int hash = 0xcafe * 31337 + (25% 17) * 11 + 7 - 1615810207;
最后以16进制输出
printf("%x\n", hash);
用python写解题脚本:
a = int('0xcafe',16) #把16进制的0xcafe转成int型
hash = a * 31337 + (25% 17) * 11 + 7 - 1615810207;
print(hex(hash))
得到0xc0ffee,flag为c0ffee
XCTF-open-source的更多相关文章
- AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...
- mysql-5.6.34 Installation from Source code
Took me a while to suffer from the first successful souce code installation of mysql-5.6.34. Just pu ...
- source /etc/profile报错-bash: id:command is not found
由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...
- eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过
问题描述 使用Eclipse调试代码的时候,打了断点,经常出现Source not found,网上找了半天,大部分提示点击Edit Source Lookup Path,添加被调试的工程,然而往往没 ...
- Oracle使用java source调用外部程序
需求 Oracle调用第三方外部程序.Oracle使用sqluldr2快速导出大批量数据,然后用winrar压缩后发送邮件. 本文档主要实现前两步需求,发送邮件程序这里不再说明. 原码 授权 begi ...
- Perforce 与Source Insight, Visual Studio集成
转自:http://shashanzhao.com/archives/837.html 1.Perforce 首先需要为perforce设置系统环境变量,以便perforce命令行可以正常使用. 环境 ...
- Linux下Source Insight的安装和汉化
原创文章,转载请注明出处. 工欲善其事,必先利其器.Source Insight绝对是阅读C和C++代码的利器,另外,Source Insight的体量很小,安装便捷,显示直观,比vim+cscope ...
- pip apt source images
~/.pip/pip.conf [global] index-url = https://pypi.douban.com/simple download_cache = ~/.cache/pip [i ...
- WPF 中的image控件的Source如何赋值
Image image=new Image();image.Source = new BitmapImage(new Uri(@"daw\adw.jpg",UriKind.Rela ...
- A Complete List of .NET Open Source Developer Projects
http://scottge.net/2015/07/08/a-complete-list-of-net-open-source-developer-projects/?utm_source=tuic ...
随机推荐
- Python的字符串和编码
1. 字符编码 字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit) ...
- C语言:C99 中的37个关键字
一.数据类型关键字(12个): 1.char [tʃɑ:]:声明字符型变量或函数 2.double [ˈdʌbəl] :声明双精度变量或函数 3.enum :声明枚举类型 4.float [fləut ...
- 台达PLC开发笔记(二):台达PLC设置主机通讯参数为RTU并成功通讯
前言 前面使用485和网口与台达成功建立通讯,但是485是使用用的ASICC模式,多数情况下是使用RTU模式提升通讯效率. 下载安装台达ISPSoft软件 官网下载地址:https://d ...
- ABP Framework V4.4 RC 新增功能介绍
目录 新增功能概述 启动模板删除 EntityFrameworkCore.DbMigrations 项目 CMS-Kit 动态菜单管理 Razor引擎对文本模板的支持 DbContext/Entiti ...
- 从S3中拷贝或同步文件
p.p1 { margin: 0; font: 16px "Helvetica Neue"; color: rgba(53, 53, 53, 1) } p.p2 { margin: ...
- Python使用笔记005-文件操作(二)
1.1 打开文件模式 # r r+ r+读是没问题的,写的话,会覆盖原来的内容,文件不存在时会报错# w w+ w+用来新的文件没问题,旧的文件会覆盖原来的内容# a a+ a+写是追加,读不到是因为 ...
- if语句 条件测试 shell编程之条件语句
shell 编程之条件语句一.条件测试 ① test命令 测试 ② 文件测试 ③ 整数值比较 ④ 字符串比较 ⑤ 逻辑测试二.if语句的结构 单分支结构 双分支结构 多分支结构三.ca ...
- Spring Boot(一):如何使用Spring Boot搭建一个Web应用
Spring Boot Spring Boot 是Spring团队旗下的一款Web 应用框架 其优势可以更快速的搭建一个Web应用 从根本上上来讲 Spring Boot并不是什么新的框架技术 而是在 ...
- C语言typedef的用法详解
C语言允许为一个数据类型起一个新的别名,就像给人起"绰号"一样. 起别名的目的不是为了提高程序运行效率,而是为了编码方便.例如有一个结构体的名字是 stu,要想定义一个结构体变量就 ...
- Gradle入门第一集【下载,安装和测试】
参考:https://www.cnblogs.com/panchanggui/p/9394760.html 1,http://services.gradle.org/distributions/链接下 ...