下载附件拿到源码。

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

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

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

  3. source /etc/profile报错-bash: id:command is not found

    由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...

  4. eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过

    问题描述 使用Eclipse调试代码的时候,打了断点,经常出现Source not found,网上找了半天,大部分提示点击Edit Source Lookup Path,添加被调试的工程,然而往往没 ...

  5. Oracle使用java source调用外部程序

    需求 Oracle调用第三方外部程序.Oracle使用sqluldr2快速导出大批量数据,然后用winrar压缩后发送邮件. 本文档主要实现前两步需求,发送邮件程序这里不再说明. 原码 授权 begi ...

  6. Perforce 与Source Insight, Visual Studio集成

    转自:http://shashanzhao.com/archives/837.html 1.Perforce 首先需要为perforce设置系统环境变量,以便perforce命令行可以正常使用. 环境 ...

  7. Linux下Source Insight的安装和汉化

    原创文章,转载请注明出处. 工欲善其事,必先利其器.Source Insight绝对是阅读C和C++代码的利器,另外,Source Insight的体量很小,安装便捷,显示直观,比vim+cscope ...

  8. pip apt source images

    ~/.pip/pip.conf [global] index-url = https://pypi.douban.com/simple download_cache = ~/.cache/pip [i ...

  9. WPF 中的image控件的Source如何赋值

    Image image=new Image();image.Source = new BitmapImage(new Uri(@"daw\adw.jpg",UriKind.Rela ...

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

随机推荐

  1. 低代码开发LCDP,Power Apps系列 - 新建泰勒创新中心门户案例

    低代码简介 上世纪八十年代,美国就有一些公司和实验室开始了可视化编程的研究,做出了4GL"第四代编程语言",到后来衍生成VPL"Visual Programming La ...

  2. 一个SDK给我干懵逼了?大厂的SDK就这?

    活久见 .org.jboss.netty 和 io.netty 你分的清吗? 大家好,我是小猿来也,一个热衷写 bug 的程序猿. 一天我正在专心致志写 Bug 的时候,一个同事跑过来找我. 说有个很 ...

  3. 32、sed命令详解

    32.1.sed介绍: 1.sed(sed软件常称做)是流编辑器,是操作.过滤.和转换文本内容的工具: 2.sed的模式空间和保持空间介绍: (1)模式空间:sed处理文本内容行的一个临时缓冲区,模式 ...

  4. Linux云计算-01_介绍以及Linux操作系统安装

    1 学习目的 兴趣爱好 技能提升 找到满意的工作 2 什么是云计算 云计算(cloud computing)是分布式计算的一种,指的是通过网络"云"将巨大的数据计算处理程序分解成无 ...

  5. javascript数组 (转)

      javascript的Array可以包含任意数据类型,并通过索引来访问每个元素.   要取得Array的长度,直接访问length属性:   var arr = [1,2,3.14,'Hell0' ...

  6. Kotlin Coroutine(协程): 二、初识协程

    @ 目录 前言 一.初识协程 1.runBlocking: 阻塞协程 2.launch: 创建协程 3.Job 4.coroutineScope 5.协程取消 6.协程超时 7.async 并行任务 ...

  7. NSDate小结

    dateFormat用法: y - 年 2013年,yyyy=2013,yy=13 M - 月 3月,M=3,MM=03,MMM=Mar,MMMM=March D - 一年中的第几天 d - 一月中的 ...

  8. 「ARC103D」 Distance Sums

    「ARC103D」 Distance Sums 传送门 水题. 首先如果让你求树上的节点 \(i\) 到其它所有节点的距离和,这是非常简单的,这就是非常常规的换根 \(\texttt{DP}\). 那 ...

  9. PYD应用方法

    1. 'ImportError: No module named xxx' 可能是xxx.pyd所在路径不在sys.path中. 解决方法:import之前用sys.path.append()方法加入 ...

  10. Vue全局弹窗:一次注册,全局可弹

    Vue全局弹窗 今天来搞一个全局弹窗,不用每个文件都引入,只在main.js里作为全局原型引入就好了 先新建弹窗组件 toast.vue <template></template&g ...