下载附件拿到源码。

#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. kubernetes的网络代理模式

    在k8s中,如果想ping svc以及ip,发现无法ping通,使用测试环境为k8s 1.6,后来k8s升级到1.12版本,发现ping svc以及ip可以ping通,这里分析一下原因. 后来发现是由 ...

  2. AcWing 1303. 斐波那契前 n 项和

    输出斐波那契数列前 n 项和 对m取摸的结果 #include<bits/stdc++.h> #define LL long long #define N 3 using namespac ...

  3. Java实验项目三——平面图形和立体图形抽象类

    Program:按照下面要求完成类的设计 (1)设计一个平面图形抽象类和一个立体图形抽象类,提供该类对象公共的方法和属性. (2)修改项目三中第2题中所设计的球类.圆柱类,圆锥类.矩形类.三角形类.圆 ...

  4. java面向对象的理解(个人)

    面向对象是Java的基本特征,在程序开发的过程中基于面向过程的一种思维,将功能封装进对象,强调具备这些功能的对象和调用结果,不关注具体的实现过程. 面向对象的特点:是一种更符合人们思考习惯的思想,可以 ...

  5. XML技术

    XML是一种可扩展标记语言,用来标记数据.定义数据类型,1998年由W3W发布1.0.版本,与HTML语言相比,可以自定义可扩展标签格式,但是语法严格. XML可以用来存储数据,可移植性强,主要充当配 ...

  6. Linux- RPM与yum软件包安装

    Linux安装及管理程序一.Linux应用程序基础1)应用程序与系统命令的关系2)典型应用程序的目录结构3)常见的软件包封装类型二.RPM包管理工具① RPM软件包管理器Red-Hat Package ...

  7. C语言:进制转化

    16进制数4321转10进制:原来方法 =4*16^3+3*16^2+2*16^1+1*16^0 =4*16^3+3*16^2+2*16^1+1 =16*(4*16^2+3*16^1+2)+1 =16 ...

  8. 1.在配置XML文件时出现reference file contains errors (http://www.springframework.org/schema/beans/...解决方案

    解决方案: 第一步:将 Preferences > XML > XML Files > Validation中"Honour all XML schema location ...

  9. final修饰符(3)-基本类型变量和引用类型变量的区别

    final修饰基本类型变量 当使用final修饰基本类型变量时,不能对基本类型变量重新赋值,因此基本类型变量不能被改变 final修饰引用类型变量 当使用final修饰引用类型变量时,它保存的仅仅是一 ...

  10. [刘阳Java]_MyBatis_注解基本用法_第10讲

    MyBatis注解提出,可以说是非常好简化了MyBatis配置文件的使用.下面我们简单地来告诉大家如何使用MyBatis的注解 定义接口 package com.gxa.dao; import jav ...