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 ...
随机推荐
- k8s1.20环境搭建部署(二进制版本)
1.前提知识 1.1 生产环境部署K8s集群的两种方式 kubeadm Kubeadm是一个K8s部署工具,提供kubeadm init和kubeadm join,用于快速部署Kubernetes集群 ...
- SQL 小知识笔记
1.自动生成序列号 select row_number() over(order by field1) as row_number,* from t_table
- POJ 3449 Geometric Shapes 判断多边形相交
题意不难理解,给出多个多边形,输出多边形间的相交情况(嵌套不算相交),思路也很容易想到.枚举每一个图形再枚举每一条边 恶心在输入输出,不过还好有sscanf(),不懂可以查看cplusplus网站 根 ...
- Redis 底层数据结构之整数集合
文章参考:<Redis 设计与实现>黄建宏 整数集合 整数集合时集合键的底层实现之一,当一个集合只包含整数值元素,并且这个集合数量不多时,就会使用整数集合 typedef struct i ...
- SpringBoot:SpringBoot项目的配置文件放在Jar包外加载
SpringBoot读取配置文件的优先级为: 第一.项目jar包同级下的config文件夹是优先级最高的,是在执行命令的目录下建config文件夹.(在jar包的同一目录下建config文件夹,执行命 ...
- STM32F103学习进程
软硬件下载程序和程序运行的相关问题和解决方案,以我自身买的STM32F103C8T6为例 (1) 硬件需要 1. 购买一个STM32F103XXX的板子.这是一个操作实践性非常强的一个学习过程,如果没 ...
- android实现计时器(转)
新建布局文件activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Linea ...
- php-18个魔法函数
目录 php魔法函数 介绍 范例 1.__construct() 2.__destruct() 3.__call() 4.__callStatic 5.__get() 6.__set() 7.__is ...
- 阿里云PTS分享-用性能测试工具JMeter实现基于供应链业务上对于WebSocket 协议的压测
性能测试PTS(Performance Testing Service)是面向所有技术相关背景人员的云化性能测试工具,孵化自阿里内部平台.有别于传统工具的繁复,PTS以互联网化的交互,面向分布式和云化 ...
- 【译】.NET 对象分配工具
随着 Visual Studio 16.10 的发布,性能分析器又有了一个新的分析引擎,.NET 对象分配工具是第一个加入的工具.这为该工具提供了一些新特性,并显著提高了 perf 性能.在你的 C# ...