Awwwolf
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # SQL injection [TOC] ![](https://hackmd.io/_uploads/rJG1Sr1Bh.png) 資料來源 : https://portswigger.net/web-security/sql-injection ### Database type and version ![](https://hackmd.io/_uploads/rJhpVryH3.png) ### Second-order SQL injection ![](https://hackmd.io/_uploads/SyeiYDJBh.png) ### Retrieving multiple values within a single column 如果查詢只返回單個列 可以透過將多個值連接在此單個列中,輕鬆檢索多個值,最好使用合適的分隔符來區分這些組合值。例如,在 Oracle 上,您可以提交以下輸入: ```' UNION SELECT username || '~' || password FROM users--``` 這使用了在 Oracle 上是字符串連接運算符的雙管符號 ||。注入的查詢將用 ~ 字符分隔的用戶名和密碼字段的值連接在一起。 ## APPRENTICE ### Lab: SQL injection vulnerability in WHERE clause allowing retrieval of hidden data --2023/05/02 題目就說是 SQL injection 順便給範例 XD ![](https://i.imgur.com/SxmTvm4.png) 一開始進來長這樣(除了congratulation那行),可以點下面的物品來觀察 URL 的變化,便於接下來做 injection 的動作 ![](https://i.imgur.com/9QfwvJF.png) 如果直接點下面的 "view details",顯示這樣 ```URLs/product?productId=10``` ![](https://i.imgur.com/qWIT77B.png) 接著試試看點擊 Refine your search 中的一個選項,可以看到 ```URLs/filter?category=Food+%26+Drink``` ![](https://i.imgur.com/21DVEXw.png) 在隨意選擇一個食物點進去看 URL,诶,又變回 ```URLs/product?productId=7``` ![](https://i.imgur.com/W7cSEEi.png) 試著輸入 ```'+OR+1=1--'``` 在 URL 上,看來能夠注入的地方不是這裡 ![](https://i.imgur.com/5HFSWcc.png) 回到選擇 Food&Drink 的那一頁,嘗試注入 ```URLs/filter?category=Food+%26+Drink'+OR+1=1--'```,成功出現除了食物以外的項目啦 ![](https://i.imgur.com/QgBGxfE.png) ### Lab: SQL injection vulnerability allowing login bypass --2023/05/02 題目就直接說在 login 頁面,想辦法用 administrator 去登入 ![](https://i.imgur.com/Euhjsao.png) 一樣熟悉的頁面,但是這次多了紅色框起來的 "My account" 看來目標在這裡啦 ![](https://i.imgur.com/4RPjCp8.jpg) Login 頁面長這樣很陽春,我們在 username 注入 ```adminstrator' OR 1=1 --``` password 就隨便打 ![](https://i.imgur.com/c0ceTkQ.png) 進來了 OUO ![](https://i.imgur.com/6gcCwrO.png) ## PRACTITIONER ### Lab: SQL injection UNION attack, determining the number of columns returned by the query --2023/05/15 透過 SQL injection 中的 UNION 攻擊將 NULL 塞入欄位中(應該是這樣吧 ![](https://hackmd.io/_uploads/r1QMaDyr2.png) 戳三次就出來了,我也很驚訝 OAO ![](https://hackmd.io/_uploads/SJW41dJr2.png) ### Lab: SQL injection UNION attack, finding a column containing text --2023/05/15 痾,題目要使用 UNION 來攻擊和檢索資料,然後要得到一個隨機的字串,放入 UNION 之中 (大概是這樣吧 ![](https://hackmd.io/_uploads/r1U1KuJS3.png) 戳出欄位有三個 ![](https://hackmd.io/_uploads/HkuTdukS2.png) 將第一個欄位改成 ```'abc'``` ![](https://hackmd.io/_uploads/HJtZFd1H3.png) 將 abc 換到中間的 NULL 就跑出這樣 ![](https://hackmd.io/_uploads/r17iFdJrh.png) 將 abc 改成 Make the database retrieve the string: 'mkFd70' 後面的字串,就 successful ![](https://hackmd.io/_uploads/HkPk5u1Sh.png) ### Lab: SQL injection UNION attack, retrieving data from other tables --2023/05/15 透過 SQL injection UNION 攻擊取得 admin 的帳號密碼 ![](https://hackmd.io/_uploads/HyYzhdyr3.png) 戳出來有兩個欄位 ![](https://hackmd.io/_uploads/ryQSauJB3.png) ```'UNION SELECT username, password FROM users--``` admin 的帳密都出來了 OUO ![](https://hackmd.io/_uploads/rkVcpOkB2.png) successful ![](https://hackmd.io/_uploads/Sk3X0ukrn.png) ### Lab: SQL injection UNION attack, retrieving multiple values in a single column --2023/05/16 透過 SQL injection UNION 攻擊並取得 admin 的帳密 ![](https://hackmd.io/_uploads/SkGi1t1Bn.png) 一樣戳出欄位為二 ![](https://hackmd.io/_uploads/HkdNxFySn.png) 塞入 ```'UNION SELECT username, password FROM users--``` 失敗 ![](https://hackmd.io/_uploads/S1H7xYJB2.png) 塞入 ```'UNION SELECT username || ':' || password FROM users--``` 也失敗 ![](https://hackmd.io/_uploads/HyttltkB3.png) 看了一下解答,搞錯了將一個欄位合併,所以是 ```UNION SELECT NULL, username || ':' || password FROM users--``` ![](https://hackmd.io/_uploads/SyuH-KJr2.png) successful ![](https://hackmd.io/_uploads/B1QwfK1Bn.png) ### Lab: SQL injection with filter bypass via XML encoding --2023/05/16 這題呢是結合 SQL injection 和 XML 攻擊,透過 UNION 攻擊後端 database 取得 admin 的帳號密碼登入 ![](https://hackmd.io/_uploads/SkU2PBySh.png) 首先這是最初的 request,尚未對它進行任何更動,Response 是 474 units ![](https://hackmd.io/_uploads/B1ai5B1rh.png) 接著試試看 ```1+1```,發現 response 中的 units 增加了 ![](https://hackmd.io/_uploads/B1_jqByS3.png) 試試看用 UNION 去戳,ㄟ~ Attack detected,被擋住了 ![](https://hackmd.io/_uploads/HJEWwDyr2.png) 既然被擋住了,那麼就 encode 成其他形式,有個東西叫做 Hackvertor,從 Extensions -> BApp Store -> Search "Hackvertor" -> 點擊 "install" ![](https://hackmd.io/_uploads/B1TNNDyHn.png) 對著需要轉換的那行點擊右鍵 -> Extensions -> Hackvertor -> Encode -> hex_entities ![](https://hackmd.io/_uploads/BJWDPwkS3.png) 回傳了所有的 username ![](https://hackmd.io/_uploads/ByLJ_vyrn.png) 加上 password 卻失敗了,需要找其他方法 ![](https://hackmd.io/_uploads/HJ37_wyrh.png) 在中間加上兩個 | 去隔開就行了,最後輸入為 ```1 UNION SELECT user || ':' || password FROM users``` ![](https://hackmd.io/_uploads/ryyduPJSn.png) successful ![](https://hackmd.io/_uploads/HyyTCHJH2.png)

    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