pwnable.kr lotto之write up
源代码 :
#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的更多相关文章
- 【pwnable.kr】lotto
pwnable.好像最近的几道题都不需要看汇编. ssh lotto@pwnable.kr -p2222 (pw:guest) 直接down下来源码 #include <stdio.h> ...
- pwnable.kr的passcode
前段时间找到一个练习pwn的网站,pwnable.kr 这里记录其中的passcode的做题过程,给自己加深印象. 废话不多说了,看一下题目, 看到题目,就ssh连接进去,就看到三个文件如下 看了一下 ...
- pwnable.kr bof之write up
这一题与前两题不同,用到了静态调试工具ida 首先题中给出了源码: #include <stdio.h> #include <string.h> #include <st ...
- pwnable.kr col之write up
Daddy told me about cool MD5 hash collision today. I wanna do something like that too! ssh col@pwnab ...
- pwnable.kr brainfuck之write up
I made a simple brain-fuck language emulation program written in C. The [ ] commands are not impleme ...
- pwnable.kr login之write up
main函数如下: auth函数如下: 程序的流程如下: 输入Authenticate值,并base64解码,将解码的值代入md5_auth函数中 mad5_auth()生成其MD5值并与f87cd6 ...
- pwnable.kr详细通关秘籍(二)
i春秋作家:W1ngs 原文来自:pwnable.kr详细通关秘籍(二) 0x00 input 首先看一下代码: 可以看到程序总共有五步,全部都满足了才可以得到flag,那我们就一步一步来看 这道题考 ...
- pwnable.kr simple login writeup
这道题是pwnable.kr Rookiss部分的simple login,需要我们去覆盖程序的ebp,eip,esp去改变程序的执行流程 主要逻辑是输入一个字符串,base64解码后看是否与题目 ...
- pwnable.kr第二天
3.bof 这题就是简单的数组越界覆盖,直接用gdb 调试出偏移就ok from pwn import * context.log_level='debug' payload='A'*52+p32(0 ...
随机推荐
- 给Clouderamanager集群里安装可视化分析利器工具Hue步骤(图文详解)
扩展博客 以下,是我在手动的CDH版本,安装Hue. CDH版本大数据集群下搭建Hue(hadoop-2.6.0-cdh5.5.4.gz + hue-3.9.0-cdh5.5.4.tar.gz)(博主 ...
- 51Nod 1019 逆序数 (归并排序)
#include <iostream> #include <cstring> using namespace std; ; int a[maxn]; int res[maxn] ...
- js、css外部文件的相对路径问题
如果js.css外部文件有使用到相对路径时,需要注意其相对路径的基准是不一样的. 比如说,在index.html中引用到了外部的js和css文件,这两个文件都通过相对路径引用了某一张图片:这些文件所在 ...
- [HNOI2018]毒瘤
Description 从前有一名毒瘤. 毒瘤最近发现了量产毒瘤题的奥秘.考虑如下类型的数据结构题:给出一个数组,要求支持若干种奇奇怪怪的修改操作(比如区间加一个数,或者区间开平方),并支持询问区间和 ...
- 贪心 HDOJ 5090 Game with Pearls
题目传送门 /* 题意:给n, k,然后允许给某一个数加上k的正整数倍,当然可以不加, 问你是否可以把这n个数变成1,2,3,...,n, 可以就输出Jerry, 否则输出Tom. 贪心:保存可能变成 ...
- 题解报告:hihoCoder #1050 : 树中的最长路
描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅仅可以拼凑成一棵二叉树!还可以拼凑成一棵多叉树——好吧,其实就是更为平常的树而已. 但 ...
- Harris角点检测原理及实现
一.原理 二.实现 close all; clear all; I=imread('test.tif'); [posX,posY]=harris(I); figure;imshow(I); hold ...
- 关于提示replication性能
关于GTIDs的二进制日志:gtid_next: 下一个事务的编号,是master传给slave的 如SET @@SESSION.GTID_NEXT= 'c09756b8-a7e7-11e5-9468 ...
- Spring------自动化装配Bean(二)
上一篇是基于 @ComponentScan自动装配Bean的实现,这一篇将通过java手动装配bean来实现. 手动装配相对于自动装配的优点: 可以自行定义Bean的各个属性. 添加额外的方法调度. ...
- MVC:html动态追加行及取值
先一个button id=addRow 点击事件进行添加 $("#addRow").bind("click", function () { var addH ...