Pwnable.kr_Part_1_15/21

Pwnable.kr-BlackJack-逻辑漏洞

游戏代码在这里:https://cboard.cprogramming.com/c-programming/114023-simple-blackjack-program.html

查看代码发现代码量很多,以为很复杂,但静下心看一下发现其实很简单,大部分代码用来实现游戏逻辑,获取flag的条件是成为百万富翁,就是使自己的余额大于一百万,游戏规则介绍中也说了,不要试着真去赌,因为每一把都是随机的,很可能一夜回到解放前,因此要寻找题目中的漏洞,按照经验,这种题出现漏洞可能是整数溢出或者是数据校验不严格,然后我发现题目中对用户输入赌注的地方缺乏负数校验:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int betting() //Asks user amount to bet
{
printf("\n\nEnter Bet: $");
scanf("%d", &bet);

if (bet > cash) //If player tries to bet more money than player has
{
printf("\nYou cannot bet more money than you have.");
printf("\nEnter Bet: ");
scanf("%d", &bet);
return bet;
}
else return bet;
} // End Function
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×