JHWu
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    # Spring4Shell - JianHong,Wu ## Introduction 從2022開始,出現了嚴重 0-day 漏洞 Spring4Shell,Spring4Shell 漏洞的發生原因,是在傳送參數時未能進行安全的反序列化(Deserialization),該錯誤可讓駭侵者遠端執行任意程式碼,且其 CVSS 危險程度評分高達 9.8 分(滿分為 10 分),危險程度評級為最高等級的「嚴重」(critical)等級。 **影響地區及比例**[3] * 在漏洞被發現後的第一個週末,Check Point Research 發現了約 37K 次分配 Spring4Shell 漏洞的嘗試 * 全球 16% 的組織受到 Spring4Shell 漏洞利用的影響 * 軟件供應商是受影響最大的行業,28% 的組織受到影響 * 受影響最嚴重的地區是歐洲,影響為 20% ## 我們可用的Attack Sequence Step 1. 利用 Spring4Shell get Shell Step 2. download and execute agent Step 3. 使用agent進行C&C,並做Persistence Step 4. Exfiltration 其中Step 2~4,我們可透過我們所學的APT3 or APT29達到,相較比較容易 ## Spring4Shell Attack Path [6] ![](https://i.imgur.com/ZSh8IlV.png) 1. 將HTTP Parameters透過Spring轉成Objects 2. 由於CVE-2010-1622有一些保護此RCE漏洞的Module,需要使用JDK 9+的Class.getModule()去存取ClassLoader 3. 又ClassLoader有能力存取處理一些需要高權限的Method,故可以更改logging target去建立revershell ## 漏洞存在條件 * JDK 9+ * 直接或者間接使用了Spring Framework ## Spring Spring Framework 用於在 Java 中開發企業級Application。它是一個提供全面基礎設施的平台,以增強Memory管理而開發的基於model-view-controller or MVC-based applications。它使Code更更易於維護。 Spring Framework 是 Spring 生態系統的一部分,其中包括用於Cloud、Data和Security等。 ## 攻擊行為 如果我們提出了下面請求 ``` get_headers = { "prefix": "<%", "suffix": "%>//", # This may seem strange, but this seems to be needed to bypass some check that looks for "Runtime" in the log_pattern "c": "Runtime", } ``` 則相當於送出以下參數: * class.module.classLoader.resources.context.parent.pipeline.first.pattern =帶有prefix和suffix的[jsp webshell] * class.module.classLoader.resources.context.parent.pipeline.first.suffix =.jsp * class.module.classLoader.resources.context.parent.pipeline.first.directory =shell的文件名(不含suffix) * class.module.classLoader.resources.context.parent.pipeline.first.prefix =shell的儲存路徑(相對路徑,預設為webapps/ROOT) * class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat =(空) 在此漏洞中,攻擊者可以透過綁定的Class屬性進行任意的寫值,可以利用Class屬性來修改Tomcat的Log configuration,向Log寫入Shell 而這些payload可以分開送,也可以合併在一次的請求中 ## Spring4Shell Variation 該漏洞最後會覆寫Tomcat日誌配置進而上傳WebShell Variation 1 - UPX C&C 1. 先製作一個UPX加殼後的C&C agent 2. 在取得shell後,直接透過shell下載C&C agent取名為System software並執行此加殼的C&C agent Variation 2 - Beaconing frequency or Command Timing * WebShell或C&C agent的Beaconing frequency * command 執行的時間間隔 Variation 3 - Non-standard port * 開啟受害者電腦的Non-standard port並植入WebShell進行連線,而非在80 port上 * 下載一個會在Non-standard port上執行的C&C agent,執行後透過此agent進行C&C Variation 4 - Obfuscated Command * 將指令透過Base64編碼後傳過去,並透過解碼指令對Base64指令解碼 ## Seemingly Case * Google drive Backup and Sync Utilities 會定期傳送 sync info * Google Drive Sync 的 C&C Beaconing ## Deserialization 序列化簡單說就是將物件變成資料流,可以將物件儲存成檔案,永久儲存在硬碟中,必且可以在兩台電腦中傳遞物件,是非常實用的功能。 反序列化就是將檔案還原成物件,並拿來使用。 下圖參考為序列化與反序列化的示意圖[4] ![](https://i.imgur.com/uvSYlHT.png) 由於 Spring4Shell 漏洞的發生原因,是在**傳送參數時未能進行安全的反序列化(Deserialization),該錯誤可讓駭侵者遠端執行任意程式碼**。 故接下來將介紹不安全反序列化的弱點成因 ### 不安全的反序列化的弱點成因[5] * 攻擊者在**未過濾使用者輸入的序列化結構**輸入惡意字串 * 導致**伺服器解析**後回傳非預期結果,可能**導致任意指令執行** * 簡而言之就是後端沒有驗證反序列化的字串是否合法,導致攻擊者可以執行任意指令 而在JAVA反序列化中,JAVA是使用binary形式儲存序列化字串,除此之外像是PHP也會做序列化與反序列化的行為。 ## 解決辦法 升級 Spring Framework 至 5.3.18 和 5.2.2 版本,以及 Spring Boot 至 2.5.12 版本,或更高版本。 ## POC: https://github.com/TheGejr/SpringShell https://github.com/craig/SpringCore0day https://github.com/dinosn/spring-core-rce/ ## Reference [1] National Cybersecurity FFRDC,**CVE-2022-22965**,2022 https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-22965 [2] TWCERT/CC,**Spring4Shell 0-day 嚴重漏洞已遭駭侵者濫用,建議立即進行更新**,2022-04-06 https://www.twcert.org.tw/newepaper/cp-67-5993-38dfc-3.html [3] Sumeet Wadhwani,**16% of Organizations Impacted by Spring4Shell Exploitations, Europe Worst Hit**, April 7, 2022 https://www.spiceworks.com/it-security/vulnerability-management/news/spring4shell-impact/ [4] krishankant singhal,**Serialization and Deserialization**,Apr 13, 2020 https://krishankantsinghal.medium.com/serialization-and-deserialization-5046c958c317 [5] REDFOX,**Insecure Deserialization in Java**,September 2, 2022 https://redfoxsec.com/blog/insecure-deserialization-in-java/ [6] Siddhesh Parab ,REDHUNT LABS,**Things You Should Know About the Spring4Shell Vulnerability (CVE-2022-22965)**,April 3, 2022 https://redhuntlabs.com/blog/the-spring4shell-vulnerability.html

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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