XMRHRX
    • 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
    • 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
    • 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 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
  • 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 ###### ~~本簡報僅限學術用途,不要拿來用來搞事(怒)~~ ---- ### 前言 ##### *所有的天才,只不過是學會了你自己認為你不可能學會的東西而已* --- ## What is database ? #### something that you can store data. ---- ### the data in database ### (always called "row") ![](https://i.imgur.com/yUalKh7.png =500x400) ---- ### would look like excel. ![](https://i.imgur.com/xBaP09r.png) NOTE: 應用? --- ## What is SQL ? #### ***S*** tructured ***Q*** uery ***L*** anguage > a domain-specific language > designed for managing data NOTE: 簡單說就是跟資料庫溝通的語言 ---- you sent a query to database, and it take action. (and maybe return result) --- ## Basic query https://steve-lab.eu.org/superdatabase/ ---- ## search the column from table SELECT \<column\[,col...\]\> FROM \<table_name\>; ![](https://i.imgur.com/xBaP09r.png) ---- ![](https://i.imgur.com/EC4vxAQ.png) ---- SELECT 1; ![](https://i.imgur.com/v6xVWEY.png) ---- SELECT "ABC"; ![](https://i.imgur.com/McfUs87.png) ---- SELECT * FROM \`user\` ![](https://i.imgur.com/RkrxCKj.png) ---- ##### SELECT 1 FROM \`user\`; ##### SELECT 1; NOTE: What different and what would happen. ---- ![](https://i.imgur.com/U7TQV68.png) ---- ## WHERE ##### condition in SQL ---- ##### SELECT * FROM Customers WHERE CustomerID=2; ![](https://i.imgur.com/2ekcDlB.png) ---- Basic condition: >AND, OR Basic compare: > \>, <, =, >=, <= ---- Compare wit less restrict: >IS, IS NOT, LIKE function: >SUBSTRING(str/col, pos, len) ---- ##### WHERE LIKE ![](https://i.imgur.com/EHgvImx.png) ---- ### example of LIKE ---- > WHERE username LIKE "abc%" would match all string start with abc ---- > WHERE username LIKE "123__" would match all string start with 123 and followed by two any char NOTE:%可以符合任意數量的字元(包含數量0),\_一定要是任意一個字元 ---- ##### SELECT in SELECT ![](https://i.imgur.com/rqvDRUh.png) NOTE: why 8 rows? --- ## A tool ## b4 we start h4cKI!NG.. NOTE:講慢一點 ---- #### Intall Burpsuite https://portswigger.net/burp/communitydownload Choose the ***community edition*** and your OS ![](https://i.imgur.com/1jQFLSL.png =1250x170) ---- #### Install Firefox Because chrome is alway limit... You need a fox to set proxy, bro. > a useful firefox add-on > "Proxy SwitchOmega" ---- #### Start a burpsuite project ![](https://i.imgur.com/Rj1xNe8.png =440x180) Next ---- ![](https://i.imgur.com/CDoUOOE.png =440x200) Start Burp ---- ![](https://i.imgur.com/O2j3vBK.png =600x300) Check the "Intercept is off" ---- #### set up your firefox ##### 1. ![](https://i.imgur.com/3Lz3Ttv.png) ##### 2. Click Preference ---- ##### 3. ![](https://i.imgur.com/RO5gLLV.png) ##### 4. ![](https://i.imgur.com/6XH8LAw.png) ---- #### download CA Certificate http://burpsuite ![](https://i.imgur.com/kX6US9h.png) Click the "CA Certificate" to download. ---- #### install the CA Certificate ![](https://i.imgur.com/5xC6Czg.png) ![](https://i.imgur.com/8kpeC19.png) Click "view certificate" => "import..." => select the CA your downloaded. ---- #### an overview 1. install & start burpsuite (with "intercept is off") 2. install firefox 3. set up firefox proxy 4. download CA Certificate 5. install CA Certificate 6. try it --- ## basic burpsuite ---- ### watch HTTP history ![](https://i.imgur.com/AgFsruv.png) Select one request in histroy and press Ctrl+r. Then ... ---- ### Repeater Then you can see it in Repeater. and you can edit and click the send ![](https://i.imgur.com/YCS5RYX.png) ---- ###### different request content with different response ![](https://i.imgur.com/zHdFBQ0.png =800x80) ![](https://i.imgur.com/K5eId11.png =800x80) --- ## It is time 2 inj3ct! # IT IS TIME 4 H4CKING!! ------ #### Have you ever think?... ##### How password be stored? ##### What heppen when you click "login"? ---- 1. Click login 2. server receive the password and username you sent NOTE:講慢一點 ---- 4. query to get the DB_password with your username > SELECT \`DB_password\` FROM \`user\` WHERE \`username\` = "%s" 5. compare the password and DB_password ---- ### Is there something wrong?? ---- > 「Never trust user input」 SELECT \`DB_password\` FROM \`user\` WHERE \`username\` = "\\""+ username +"\\"" What could happen? ---- example.com/?username=Jhon > WHERE \`username\` = "Jhon" example.com/?username=hello > WHERE \`username\` = "hello" ---- example.com/?username=" > WHERE \`username\` = """ ---- `「資料庫不是應該都要有奇數個引號嗎!?」` `by 某人` ![](https://i.imgur.com/lIu6dtR.png) ---- ### So... #### if there someone called: ### Robert";DROP TABLE \`user\`# ---- ?username=Robert";DROP TABLE \`user\`# > WHERE \`username\` = "Robert";DROP TABLE \`user\`#" ---- ![](https://i.imgur.com/HidjgwG.png =1300x400) ---- ## And the table be droped(delete). #### all the data in the table is deleted. ~~Sound interesting, right?~~ ---- ## Any question? :D --- # Practice time!! > Don't try it on internet without the permission of target ---- ### The baby SQLi https://www.wechall.net/challenge/training/mysql/auth_bypass1/index.php ---- 1. Read code source > How it work? > The logic of target? NOTE:講慢一點 ---- 2. try it > Prove your idea and modify it with results. ---- #### a stange way to use SQLi https://www.wechall.net/challenge/training/mysql/auth_bypass2/index.php ---- #### Where to inject? ##### You need tool! https://www.wechall.net/challenge/guestbook/index.php NOTE: X-Forwarded-For: 3333', (SELECT `gbu_password` FROM `gbook_user` WHERE gbu_name="admin"))# --- ![](https://i.imgur.com/K0wwVr7.png) --- ## END NOTE:提醒復原,問他們都會嗎?

    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