湯圓
    • 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
    資訊安全暑訓營 === ## 高階網站安全 ###### 2019/07/16 > [講義](https://drive.google.com/file/d/1E6m7Nm-2ONeyBRjyw62eGzRi8rYpYQP-/view?usp=sharing) > 由於上課沒有把講義上完,筆記目前只整理出前半的部分,後半正在趕工中。 ### URL 構成 ::: success <scheme>://<netloc>/<path>?<query>#<fragment> http://kaibro.tw/a.php?gg=in#yo ::: - scheme : http - netloc : baibro.tw - path : a.php - query : gg=in - fragment : yo ### HTTP Protocol #### HTTP Method - 表示Request的目的 - GET / POST / PUT / DELETE / OPTIONS ... - GET - 跟server要東西 - 參數會出現在網址上 - POST - 送東西給server - 參數不會出現在網址 - 常用於登入, 上傳檔案 #### Request - 讓瀏覽器打kaibro.tw, 送出的Request: :::info GET / HTTP/1.1 Host: kaibro.tw User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0) Gecko/20100101 Firefox/56.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3 Connection: close Upgrade-Insecure-Requests: 1 ::: ###### 詳細內容介紹請看講義16~36頁 #### Statuus Code - Server回傳狀態代碼 - 1xx : **有收到請求,但仍要繼續處理** - 2xx : **成功,好棒棒** - 3xx : **重導向相關的訊息** - 4xx : **Client端發生錯誤** - 5xx : **Server端發生錯誤** #### Cookie - 網站用來紀錄資料 > 存放在Client小檔案 - 紀錄帳號資訊 - session id - 使用者是否登入 > 用在投放廣告 ### 資訊蒐集( Information Leak ) - robots.txt - .git / .svn - .DS_Store - .index.php.swp - index.php~ #### robots.txt - 顯示隱藏路徑 - 有時可找到一些較難猜的目錄、檔案 - CTF老梗 #### git / svn - 版本管理系統 - 常見線上部署環境忘記砍掉 - 還原 source code - 工具 - [scrabble](https://github.com/denny0223/scrabble) - [GitHack](https://github.com/lijiejie/GitHack) #### .DS_Store - Apple系統常見隱藏檔 - 能洩漏目錄資訊,如資料夾文件名等 - 工具 - [ds_store_exp](https://github.com/lijiejie/ds_store_exp) - [原理分析](https://0day.work/parsing-the-ds_store-file-format/) #### Google Hacking > 利用 Google search - site : - 指定特定網站 - intext : - 搜索網頁正文出現的字串 - intitle : - 搜索網頁標題 - filetype : / ext : - 搜索特定類型副檔名 #### GitHub Hacking > Search前人破解的東西 #### 其他 (CTF使用請注意規則) - 掃 Port - [Nmap](https://nmap.org/), [masscan](https://github.com/robertdavidgraham/masscan) - 掃目錄/檔案 - [dirsearch](https://github.com/maurosoria/dirsearch), [DirBuster](https://www.owasp.org/index.php/Category:OWASP_DirBuster_Project), ... - 掃子域名 - [subDomainBrute](https://github.com/lijiejie/subDomainsBrute), [Sublist3r](https://github.com/aboul3la/Sublist3r), ... #### 社工庫( Social Engineering Database ) - 由洩漏的資料庫組成 - [Have I Been Pwned](https://haveibeenpwned.com/) ### PHP #### PHP Feature - Hacker-friendly language - 早期CTF常出現 #### 弱型別 - '123' == 123 ? - True - 'kaibro' == 0 ? - True - '0010e2' == '1e3' ? - True - 0 == false ? - True #### Array 特性 - strcmp([],[]) - NULL - shal([]) - NULL - strlen([]) - NULL ### 前端安全 #### 同源政策 - 同域要求同協議、同域名、同端口 ##### 跨域 - JSONP - 透過script可以跨域的特性載入資料 - CORS - 添加一些HTTP Header來標示跨域請求 #### XSS (Cross Site Scripting) > 輸入被當Javascript執行 - 反射型 XSS - 儲存型 XSS - DOM XSS #### CSRF (Cross-site request forgery) > 觸發非預期 Request > #### 瀏覽器層面防禦 - IE/Edge: XSS Filter - Chrome/Safari: XSS Auditor - CSP (Content Security Policy) ### Command Injection > 常出現在網頁直接跑 System Command 的狀況 #### 基本招式 ### SQL Injection > 一種資料庫查詢語言 ### 資料補充 - [http](https://notfalse.net/http-series) - [php-1](https://www.php.net/manual/zh/index.php) - [php-2](https://github.com/w181496/Web-CTF-Cheatsheet) - [CORS](https://developer.mozilla.org/zh-TW/docs/Web/HTTP/CORS) ## Crypto *~~自己加油...666~~* ###### 2019/07/17 > [講義](https://drive.google.com/file/d/1guWxIBm22TnpzR_CUR0UnnozF0oKBmZP/view?usp=sharing) > [共筆](https://hackmd.io/a42SAsXjRdmIDSsT1TQQgg?view#Mode) > ***被擊倒 =.= 自己看ㄅ*** ### pwntools r.send("XXX") ###### 沒Enter r.sendline("XXX") ###### 有Enter r.sendlineafter('a',"XXX") ###### 接收到a才傳XXX r.recv() R.recvline() ###### \n r.recvuntil('\n') ###### 接收到哪裡 r.recvrepeat(0.3) ###### 0.3秒後不接收 A xor B = C A xor C = B B xor C = A 打RSA好用的自動化工具 [RsaCtfTool](https://github.com/Ganapati/RsaCtfTool) ## 逆向工程 Reverse ###### 2019/07/18 [講義](https://drive.google.com/file/d/1tzTPKLIVcdg2g3yiBGikTdfPxUUmEp9e/view?usp=sharing) ### 起手式 #### 指令 - file :::info 用途 : 用來查看檔案類型 ::: :::success shell : file binary > binary在這為檔案名 ::: :::warning output : binary: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 2.6.32, BuildID[sha1]=89e53b704c36245e1ab38a71c9f1349898e373ea, stripped ::: #### 指令 - strings :::info 用途 : 印出檔案中的可視字串 ::: :::success shell : strings binary > binary在這為檔案名 ::: :::warning output : /lib/ld-linux.so.2 ;pL6$^ libc.so.6 ... ::: --- :::info 進階用法 : 印出檔案中的可視字串,長度大於等於10 ::: :::success shell : strings -n 10 binary > binary在這為檔案名 ::: :::warning output : /lib/ld-linux.so.2 _IO_stdin_used __stack_chk_fail ... ::: --- :::info 進階用法 : 印出檔案中的可視字串,且結果中包含"name" ::: :::success shell : strings binary | grep "name" > binary在這為檔案名 ::: :::warning output : Out of list name (0 <= index < 10)!!! Input this name: Input new name:l ... ::: #### 指令 - strace :::info 用途 : 查看程式執行時的system call 和 signal ::: :::success shell : strace ./binary > binary在這為檔案名 ::: :::warning output : execve("./hexedit", ["./hexedit"], 0x7ffd6c827460 /* 38 vars */) = 0 brk(NULL) = 0xe37000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) ... ::: #### 指令 - ltrace :::info 用途 : 查看程式執行時的library call ::: :::success shell : ltrace ./binary > binary在這為檔案名 ::: :::warning output : __libc_start_main(0x40052d, 1, 0x7ffc83150168, 0x400550 <unfinished ...>) puts("Find the flag!") +++ exited (status 0) +++ ::: #### 指令 - objdump :::info 用途 : 查看反組譯資訊 ::: :::success shell : objdump -d ./binary > binary在這為檔案名 ::: :::warning output : adder: file format elf64-x86-64 Disassembly of section .init: 0000000000400778 <_init>: 400778: 48 83 ec 08 sub $0x8,%rsp 40077c: 48 8b 05 75 18 20 00 mov 0x201875(%rip),%rax # 601ff8 <__gmon_start__> 400783: 48 85 c0 test %rax,%rax ... ::: --- :::info 進階用法 : 查看反組譯資訊,並以intel格式導向less方便閱讀 ::: :::success shell : objdump -M intel -d ./binary | less > binary在這為檔案名 ::: :::warning output : adder: file format elf64-x86-64 Disassembly of section .init: 0000000000400778 <_init>: 400778: 48 83 ec 08 sub rsp,0x8 40077c: 48 8b 05 75 18 20 00 mov rax,QWORD PTR [rip+0x201875] # 601ff8 <__gmon_start__> 400783: 48 85 c0 test rax,rax ... ::: ### 組合語言 #### Intel vs. AT&T syntax > 一般通常是用Intel syntax > 詳細差異請看講義18頁 #### [General Purpose Register](https://en.wikibooks.org/wiki/X86_Assembly/X86_Architecture) > 老師只丟wiki給我們 > 圖片我放不上去 > 講義19~20頁 #### RIP - instruction pointer - 指向下一個要執行的指令 #### RSP - stack pointer - 指向stack的頂端 #### 編譯組合語言 :::info shell: ```= nasm -f elf64 test.asm #編譯 ld -m elf_x86_64 -o test test.o #鏈結 ./test #執行 ``` ::: #### 函式呼叫 > 講義25~31 > 全部圖解 - 條件判斷式 > 32頁自己看八 - 迴圈 > 33頁自己看八 ### 程式在記憶體中的樣子 #### 原始碼 :::success C : ```cpp= #include <iostream> int main() { int a = 0x17, b = 0x4, c; c = a + b; printf("%d\n", c); } ``` ::: :::success assembly : ```= ... mov DWORD PTR [rbp-0x1c],0x17 mov DWORD PTR [rbp-0x18],0x4 mov edx,DWORD PTR [rbp-0x1c] mov eax,DWORD PTR [rbp-0x18] add eax,edx mov DWORD PTR [rbp-0x14],eax ``` ::: #### 編譯&執行 :::success shell : ```shell= gcc test.c -o test # 編譯 ./test # 執行 ``` ::: #### 程式在記憶體長怎樣 - 開兩個terminal,來看一下程式跑起來在記憶體中長甚麼樣子 :::danger shell : ```shell= ./test ``` ::: --- :::danger shell : ```shell= cat /proc/$(pidof test)/maps ``` ::: > 講義38~39有漂亮的圖片自己看吧 ### 動態除錯 - gdb #### gdb - 使用介紹 ::: info 下斷點 : **B**reak **main** **B**reak ***0x4004da** ::: --- :::info 執行程式 : **r**un ::: --- :::info 繼續執行 : **c**ontinue ::: --- :::info 執行完該函式 : **fin**ish ::: --- :::info 執行一條 instruction (不會追進函式) : **ni** ::: --- :::info 執行一條 instruction ( 會追進函式 ) : **si** ::: --- :::info 離開 : **q**uit ::: --- :::info 列出變數的值 : **p**rint **$rsp** ::: --- :::info 印出變數指向的記憶體的值 : **x/[length][format] [address expression]** **x/10gx $rsp x/20wx 0x7fffffffe5f0 x/s 0x7fffffffe8d0** > [使用介紹](http://visualgdb.com/gdbreference/commands/x) ::: --- :::info 查看記憶體 : **vm**map ::: --- :::info 查看保護機制 **checks**ec ::: #### gdb - 套件安裝 - [peda](https://github.com/longld/peda) - [Pwngdb](https://github.com/scwuaptx/Pwngdb) - 裝這兩個套件可以讓 gdb 更好用 :::info 安裝 : shell ```shell= git clone https://github.com/longld/peda.git ~/peda git clone https://github.com/scwuaptx/Pwngdb.git cp ~/Pwngdb/.gdbinit ~/ ``` ::: - 介面展示 > 講義47頁\ #### 工具推薦 ##### 反編譯 - [IDA Pro](https://www.hex-rays.com/products/ida/support/download.shtml) > 要錢 - [Ghidra](https://ghidra-sre.org/) > 免費 ## PWN ###### 2019/07/19 ### 工具使用 - pwntools #### 介紹 - python 套件 - 專門給打 pwn 的人用的 - [介紹文](https://github.com/Gallopsled/pwntools) - [教學資源-1](http://docs.pwntools.com/en/stable/intro.html) - [教學資源-2](https://github.com/Gallopsled/pwntools-tutorial) #### 安裝 - [Github](https://github.com/arthaud/python3-pwntools) :::info shell : ```shell= sudo apt-get update sudo apt-get install python3 python3-dev python3-pip git sudo pip3 install --upgrade git+https://github.com/arthaud/python3-pwntools.git ``` ::: #### 與server連線 :::info python : ```python= from pwn import * r = remote('127.0.0.1',20000) r.interactive() ``` > r.interactive()為互動模式,使用起來跟 nc 差不多 ::: #### 常用函式 ::: info ```python= # 從伺服器接收所有 '\n' 之前的 data r.recvline() # 發送 data 給伺服器 r.send('hello') # 發送 data + '\n' 給伺服器 r.sendline('hello') # 從伺服器接收所有 hello 之前的 data r.recvuntil('hello') # 從伺服器接收所有 hello 之前的 data 後發送 world r.sendlineafter('hello', 'world') ``` ::: --- :::info ```python= # 將數字轉成 32 bits = 4 bytes 的字串 ( little endian ) p32(0xdeadbeef) # 將數字轉成 64 bits = 8 bytes 的字串 ( little endian ) p64(0xdeadbeef) # 將 32 bits = 4 bytes 的字串轉成數字 ( little endian ) u32(b'\xef\xbe\xad\xde') # 將 64 bits = 8 bytes 的字串轉成數字 ( little endian ) u64(b'\xef\xbe\xad\xde\x00\x00\x00\x00') ``` ::: --- :::info ```python= # load libc libc = ELF('./libc') # libc base address libc.address # libc functions libc.symbols[b'system'] ``` ::: #### 本地端 debug :::info ```python= from pwn import * context.arch = 'amd64' context.terminal = ['tmux', 'splitw', '-h'] r = process('./test') gdb.attach(proc.pidof(r)[0]) ``` > tmux 要先安裝 ::: ### 攻擊技巧 - butter overflow #### 用C寫一個簡單的程式 :::info ```cpp= #include<stdio.h> void magic() { system("/bin/sh") } int main() { char buffer[8]; scanf("%s",buffer); // 讀取使用者輸入 printf("%s\n",buffer); // 印出使用者輸入 return 0; } ``` ::: --- 站存檔 : > ubuntu > ubuntu linux --- > 編輯器 > ZSH (oh my zsh) --- - [NTHU](https://hackmd.io/PBaX-EWYROC-UuQKlwhDnA)

    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