源代码 :

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h> unsigned char submit[]; void play(){ int i;
printf("Submit your 6 lotto bytes : ");
fflush(stdout); int r;
r = read(, submit, ); printf("Lotto Start!\n");
//sleep(1); // generate lotto numbers
int fd = open("/dev/urandom", O_RDONLY);
if(fd==-){
printf("error. tell admin\n");
exit(-);
}
unsigned char lotto[];
if(read(fd, lotto, ) != ){
printf("error2. tell admin\n");
exit(-);
}
for(i=; i<; i++){
lotto[i] = (lotto[i] % ) + ; // 1 ~ 45
}
close(fd); // calculate lotto score
int match = , j = ;
for(i=; i<; i++){
for(j=; j<; j++){
if(lotto[i] == submit[j]){
match++;
}
}
} // win!
if(match == ){
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[]){ // menu
unsigned int menu; while(){ printf("- Select Menu -\n");
printf("1. Play Lotto\n");
printf("2. Help\n");
printf("3. Exit\n"); scanf("%d", &menu); switch(menu){
case :
play();
break;
case :
help();
break;
case :
printf("bye\n");
return ;
default:
printf("invalid menu\n");
break;
}
}
return ;
}

关键程序 :

  int match = , j = ;
for(i=; i<; i++){
for(j=; j<; j++){
if(lotto[i] == submit[j]){
match++;
}
}
} // win!
if(match == ){
system("/bin/cat flag");
}

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

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

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

看一下assic表:

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

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

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

pwnable.kr lotto之write up的更多相关文章

  1. 【pwnable.kr】lotto

    pwnable.好像最近的几道题都不需要看汇编. ssh lotto@pwnable.kr -p2222 (pw:guest) 直接down下来源码 #include <stdio.h> ...

  2. pwnable.kr的passcode

    前段时间找到一个练习pwn的网站,pwnable.kr 这里记录其中的passcode的做题过程,给自己加深印象. 废话不多说了,看一下题目, 看到题目,就ssh连接进去,就看到三个文件如下 看了一下 ...

  3. pwnable.kr bof之write up

    这一题与前两题不同,用到了静态调试工具ida 首先题中给出了源码: #include <stdio.h> #include <string.h> #include <st ...

  4. pwnable.kr col之write up

    Daddy told me about cool MD5 hash collision today. I wanna do something like that too! ssh col@pwnab ...

  5. pwnable.kr brainfuck之write up

    I made a simple brain-fuck language emulation program written in C. The [ ] commands are not impleme ...

  6. pwnable.kr login之write up

    main函数如下: auth函数如下: 程序的流程如下: 输入Authenticate值,并base64解码,将解码的值代入md5_auth函数中 mad5_auth()生成其MD5值并与f87cd6 ...

  7. pwnable.kr详细通关秘籍(二)

    i春秋作家:W1ngs 原文来自:pwnable.kr详细通关秘籍(二) 0x00 input 首先看一下代码: 可以看到程序总共有五步,全部都满足了才可以得到flag,那我们就一步一步来看 这道题考 ...

  8. pwnable.kr simple login writeup

    这道题是pwnable.kr Rookiss部分的simple login,需要我们去覆盖程序的ebp,eip,esp去改变程序的执行流程   主要逻辑是输入一个字符串,base64解码后看是否与题目 ...

  9. pwnable.kr第二天

    3.bof 这题就是简单的数组越界覆盖,直接用gdb 调试出偏移就ok from pwn import * context.log_level='debug' payload='A'*52+p32(0 ...

随机推荐

  1. 51Nod 1094 和为k的连续区间

    #include <iostream> #include <algorithm> #include <cstring> using namespace std; t ...

  2. UWP 剪贴板

    一:剪贴板 一般的复制,用户自己光标选中文本,crtl +c复制就可以了.但是有时候也需求有一个复制的按钮,当用户点击复制按钮,就可以把当前的某些内容复制到剪贴板里. 这里就用到了DataPackag ...

  3. Codeforces Round #261 (Div. 2) D

    Description Parmida is a clever girl and she wants to participate in Olympiads this year. Of course ...

  4. RAID 0、1、5、1+0总结

    RAID(Redundant Array Of Independent Disk,独立磁盘冗余阵列),可以提供比普通磁盘更快的速度.更高的安全性,生产环境中服务器在安装时一般都会做RAID,RAID的 ...

  5. Java-学完一个月总结(javaSe学习路线)

    JavaSe的一个月 第一周 0410 基本数据类型:数据类型的转换:运算符:导入删除项目0411 分支结构if else:switch case ;while0412 do while ;for / ...

  6. LN : leetcode 494 Target Sum

    lc 494 Target Sum 494 Target Sum You are given a list of non-negative integers, a1, a2, ..., an, and ...

  7. let块级引起的闭包思考

    因为es6在node中用的比较频繁,最近在按计划根据阮一峰的es6教程从头开始学习一遍, 第一步遇到的就是“看似非常熟悉”的let小伙伴,核心character如下: 即:let变量的作用域只在块内. ...

  8. Bundle的用法

    一.API文档说明 1.介绍 用于不同Activity之间的数据传递 1.重要方法 clear():清除此Bundle映射中的所有保存的数据. clone():克隆当前Bundle containsK ...

  9. Delphi定时器控件TTimer“一睡不醒”问题研究

    1,试验1—基础代码 1.1页面控件与代码 定时器 Timer1 Timer_work Interval 1000 1500 Enabled True True Ontimer事件 then exit ...

  10. redis集群架构(含面试题解析)

    老规矩,我还是以循序渐进的方式来讲,我一共经历过三套集群架构的演进! Replication+Sentinel 这套架构使用的是社区版本推出的原生高可用解决方案,其架构图如下! 这里Sentinel的 ...