Yuawn Pwn1 casino Writeup

kazma 成大資安社 創辦人/社長

casino

先執行看一下:

casino

一樣假裝沒有 source code 來用 r2 分析一下 main 先:

r2

首先 name 是全域變數,可以輸入 0x100 個 bytes,位址是 0x6020f0,age 也是全域變數,位址是 0x602104,再來 jg 是 jump is greater 的意思,大於 19 就可以進 casino 了,接下來 r2 看一下 casino:

casino_casino

看到 seed 了,位址是 0x602100,我們再四處看看會發現 guess[ ] 的 index 是沒有限制輸入的:

chose

guess[] 的位置是在 0x6020d0,完整的計畫如下:
首先透過 overflow name 去蓋掉 seed 跟 age 接著蓋上 shellcode,再來隨便輸入一個大於 19 的 age 進到 casino,透過分析流程可以發現只要猜對樂透,最後就會 call 一個 puts 來輸出勝利訊息,輸的話會用 printf 來輸出失敗訊息,這裡我們決定用沒有限制輸入的 index 來改 puts 的 got,因為整數只有 4 個 bytes,所以需要兩次來改成想要控成的 rip 也就是剛剛 shellcode 的位址,至於為什麼不是改 printf 的 got 是因為第二次改數字還會用到 printf,那樂透要怎麼猜對並且走到勝利訊息呢?就是從剛剛控的 seed 來固定隨機種子,接著可以寫一個 lottery.c 來直接透視號碼。
lottery.c:

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
#include <stdlib.h>

int main () {
int lottery[6] = {0};
srand(0);
for (int i = 0; i < 6; i++) {
lottery[i] = rand() % 100;
printf("%d ", lottery[i]);
}
}
// 83 86 77 15 93 35

exploit.py:

1

代編輯

  • Title: Yuawn Pwn1 casino Writeup
  • Author: kazma
  • Created at : 2023-12-13 23:05:16
  • Updated at : 2023-12-18 16:11:23
  • Link: https://kazma.tw/2023/12/13/Yuawn-Pwn1-casino-Writeup/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments
On this page
Yuawn Pwn1 casino Writeup