源代码 :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>unsigned char submit[6];void play(){int i;printf("Submit your 6 lotto bytes : ");fflush(stdout);int r;r = read(0, submit, 6);printf("Lotto Start!\n");//sleep(1);// generate lotto numbersint fd = open("/dev/urandom", O_RDONLY);if(fd==-1){printf("error. tell admin\n");exit(-1);}unsigned char lotto[6];if(read(fd, lotto, 6) != 6){printf("error2. tell admin\n");exit(-1);}for(i=0; i<6; i++){lotto[i] = (lotto[i] % 45) + 1;        // 1 ~ 45
    }close(fd);// calculate lotto scoreint match = 0, j = 0;for(i=0; i<6; i++){for(j=0; j<6; j++){if(lotto[i] == submit[j]){match++;}}}// win!if(match == 6){system("/bin/cat flag");}else{printf("bad luck...\n");}}void help(){printf("- nLotto Rule -\n");printf("nlotto is consisted with 6 random natural numbers less than 46\n");printf("your goal is to match lotto numbers as many as you can\n");printf("if you win lottery for *1st place*, you will get reward\n");printf("for more details, follow the link below\n");printf("http://www.nlotto.co.kr/counsel.do?method=playerGuide#buying_guide01\n\n");printf("mathematical chance to win this game is known to be 1/8145060.\n");
}int main(int argc, char* argv[]){// menuunsigned int menu;while(1){printf("- Select Menu -\n");printf("1. Play Lotto\n");printf("2. Help\n");printf("3. Exit\n");scanf("%d", &menu);switch(menu){case 1:play();break;case 2:help();break;case 3:printf("bye\n");return 0;default:printf("invalid menu\n");break;}}return 0;
}

关键程序 :

 1  int match = 0, j = 0;
 2     for(i=0; i<6; i++){
 3         for(j=0; j<6; j++){
 4             if(lotto[i] == submit[j]){
 5                 match++;
 6             }
 7         }
 8     }
 9
10     // win!
11     if(match == 6){
12         system("/bin/cat flag");
13     }

题中让输入的Lotto在1-45范围之内,并且当lotto等于submit的时候,match加1,当match回到6的时候得到flag。而lotto是本地生成的,那么看一下它是怎么生成的:

1 for(i=0; i<6; i++){
2         lotto[i] = (lotto[i] % 45) + 1;        // 1 ~ 45
3     }
4     close(fd);

思路是在1-45范围内随机生成。

看一下assic表:

真正符号输入是从33开始的,那我们在这个范围内选择字符输入。

如图选择一个字符一直输入,总能找到相等的字符,达到6个得到flag:

sorry mom... I FORGOT to check duplicate numbers... :(

转载于:https://www.cnblogs.com/liuyimin/p/7337990.html

pwnable.kr lotto之write up相关推荐

  1. pwnable.kr lotto题解

    ssh lotto@pwnable.kr -p2222 (pw:guest) 题目源码: #include <stdio.h> #include <stdlib.h> #inc ...

  2. pwnable.kr 简单题目详细笔记汇总

    文章目录 fd collision bof flag passcode random input leg mistake shellshock coin1 lotto cmd1 cmd2 uaf bl ...

  3. PWN lotto [pwnable.kr]CTF writeup题解系列10

    目录 0x01题目 0x02解题思路 0x03题解 0x01题目 0x02解题思路 下载文件,检查一下情况 root@mypwn:/ctf/work/pwnable.kr# ssh lotto@pwn ...

  4. pwnable.kr之Toddler‘s Bottle 9~16题知识点记录

    文章目录 第九题 mistake 总结 答案: 第十题 shellshock env指令 bash指令 解题 第十一题 coin1 findall(pattern, string, flags=0) ...

  5. 简单易懂的 pwnable.kr 第六题[random]Writeupt

    简单易懂的 pwnable.kr 第六题[random]Writeupt 题目地址: http://pwnable.kr/play.php 题目: peak小知识 异或^ 据有如下几种性质: 2. 恒 ...

  6. 简单易懂的 pwnable.kr 第三题[bof]Writeupt

    简单易懂的 pwnable.kr 第三题[bof]Writeupt 题目地址:http://pwnable.kr/play.php 点开题目发现: 他给了提示覆盖,并且给了两个网址.分别打开,第一个给 ...

  7. 简单易懂的 pwnable.kr 第二题[collision]Writeupt

    简单易懂的 pwnable.kr 第二题[collision]Writeupt 题目地址:http://pwnable.kr/play.php 题目如下: 和第一题一样,题目给了我们一个ssh远程登录 ...

  8. 简单易懂的 pwnable.kr 第一题[fd]Writeupt

    简单易懂的 pwnable.kr 第一题[fd]Writeupt 题目地址http://pwnable.kr/play.php 题目 题目中给出了ssh远程登录的地址以及登录密码我们先连接,输入密码: ...

  9. 【pwnable.kr】passcode

    pwnable从入门到放弃,第六题. ssh passcode@pwnable.kr -p2222 (pw:guest) 完全是'&'的锅. #include <stdio.h> ...

最新文章

  1. 【MM模块】Sub Range 供应商子范围
  2. 历史和现代的碰撞和思考
  3. wsdl文档中的soap:address的生成规则_BAT大牛都在使用的数据库文档生成插件,不来看一下?...
  4. 第D题 把手放在键盘上时,稍不注意就会往右错一位。
  5. 灾难恢复! 关于做过快照的AVHD文件合并成VHD .
  6. Illustrator 教程,如何在 Illustrator 中使用钢笔工具创建作品?
  7. 【PRML 学习笔记】第三章 - 线性回归模型 (Linear Models for Regression)
  8. 基于能量采集的认知无线电时间和功率分配(二)
  9. 基于MPC5748G的以太网展板通信模块解析
  10. 云痕大数据 家长登录_云痕大数据查成绩app
  11. av_rescale_q和av_rescale_q_rnd和av_rescale_rnd
  12. 苏州园林年卡 办理与使用 附 苏州园林门票价格
  13. 周纪一 威烈王二十三年(戊寅、前403)——摘要
  14. 第四方汇聚支付接口对接Php
  15. ijkplayer播放视频
  16. Oracle VM VirtualBox 新建虚拟电脑
  17. python判断两个列表是否相同_如何检查两个元组列表是否相同
  18. mysql数据库 mdf 文件_如何连接到MDF数据库文件?
  19. 驱动及驱动开发的简单理解
  20. 腾讯云成立星星海实验室,聚焦云原生服务器硬件研发

热门文章

  1. DNS域名系统(二)
  2. ASP.NET页面与IIS底层交互和工作原理详解(一)
  3. Android程序的“现场保护”
  4. Delphi 与 DirectX 之 DelphiX(93): TDIB.DrawDarken();
  5. 子组件调用父组件方法
  6. 2018-03-28 Linux学习
  7. Multimodal —— 看图说话(Image Caption)任务的论文笔记(二)引入attention机制
  8. JAVA程序获取Tomcat的运行状态
  9. 《算法图解》之散列表
  10. Uva 10061 进制问题