張耀東
    • 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
    --- title: ghidra tags: malware --- [TOC] # WannaCry [ghidra.ninja](https://www.ghidra.ninja/posts/03-wannacry-1/) ## 修改data type(Edit Function Signature) - 找不到main -> 從entry開始看 - entry是microsoft的default - [csdn - OEP](https://blog.csdn.net/kkfd1002/article/details/79832269) - ![](https://i.imgur.com/DzwhLqv.png) - GetModuleHandleA 是啟動函數 - exit(WinMain) - 所以 local_6c 就是 WinMain -> [MSDN](https://docs.microsoft.com/zh-tw/windows/win32/learnwin32/winmain--the-application-entry-point) - ```int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);``` - 去掉預設跟 c -> ```int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)``` ## Kill Switch - WinMain 裡面可以看到,奇怪的 URL -> 這就是 kill switch 了 - change var name,fix data type - ![](https://i.imgur.com/ZXwlX9q.png) - 這邊可以看到 只有兩行指令 -> 直接讀assembly的意思是重複的將一個var讀到記憶體區段 -> strcpy ## InterNetOpenA、InternetOpenUrlA :::success ```c= HINTERNET InternetOpenA( LPCSTR lpszAgent, DWORD dwAccessType, LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags ); ``` ::: - 沒有對應的function type時,在data type自己新增 - ![](https://i.imgur.com/OuDqje2.png) - fix data type :::success ```c= HINTERNET InternetOpenUrlA( HINTERNET hInternet, LPCSTR lpszUrl, LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext ); ``` ::: - fix data type ==**有時候MSDN上會有錯的 Function type 要注意!!!**== ## GetModuleFileNameA :::info GetModuleFileNameA ```cpp= DWORD GetModuleFileNameA ( HMODULE hModule, LPSTR lpFilename, DWORD nSize ); ``` ![](https://i.imgur.com/Y6ZjaED.png) lpFilename -> ExecutablePath ::: ## (int *)__p___argc(); ![](https://i.imgur.com/x8i6WaL.png) ![](https://i.imgur.com/Dr9q5xX.png) ![](https://i.imgur.com/PWwHjfh.png) ![](https://i.imgur.com/ZYrQAB0.png) | | Release | Debug | | --------| -------- | -------- | | x64 | __p___argc() | j___p___argc | | x86 | _get_wide_winmain_command_line | j__get_wide_winmain_command_line | [stackoverflow](https://stackoverflow.com/questions/54655387/assembly-return-value-of-p-argv) ![](https://i.imgur.com/cyxQw17.png) ![](https://i.imgur.com/iz3sALz.png) - 這邊可以 fix function type -> ```int * __p___argc (void)``` ## Create_wannacry_service :::success ![](https://i.imgur.com/3U3wo8w.png) - sprintf -> 格式化字串 ```c= int sprintf( char *buffer, const char *format [, argument] ... ); ``` e.g:檔案路徑是 C:\Users\Dung\Desktop\Malware\test\wannacry.exe buffer 會存 C:\Users\Dung\Desktop\Malware\test\wannacry.exe -m security ::: :::info ![](https://i.imgur.com/1ge3f8h.png) - OpenSCManagerA ![](https://i.imgur.com/zl7FVIZ.png) - 0x0 - the function connects to the service control manager on the local computer. - 0x0 - If it is NULL, the SERVICES_ACTIVE_DATABASE database is opened by default. - 0xf003f - ![](https://i.imgur.com/aTeRHLJ.png) - ![](https://i.imgur.com/uadSrGh.png) ::: :::success - 如果SCManager有被成功打開並返回SC_HANDLE - CreateServiceA ```c= SC_HANDLE CreateServiceA( SC_HANDLE hSCManager, LPCSTR lpServiceName, LPCSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCSTR lpBinaryPathName, LPCSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCSTR lpDependencies, LPCSTR lpServiceStartName, LPCSTR lpPassword ); ``` - s_mssecsvc2.0_004312fc - lpServiceName - s_Microsoft_Security_Center_(2.0)_S_00431308 - Microsoft Security Center(2.0)Service - 0xf01ff - ![](https://i.imgur.com/gonRh2X.png) - 0x10 - ![](https://i.imgur.com/o7rJrhN.png) - 0x2 - SERVICE_AUTO_START - ![](https://i.imgur.com/eHJeqgX.png) - 0x1 - SERVICE_ERROR_NORMAL - ![](https://i.imgur.com/kziygsT.png) - buffer_exec_with_path - ![](https://i.imgur.com/Ip2w1ho.png) - 0x0 - Specify NULL or an empty string if the service does not belong to a group. - 0x0 - pecify NULL if you are not changing the existing tag. - 0x0 - Specify NULL or an empty string if the service has no dependencies. - 0x0 - If this parameter is NULL, CreateService uses the LocalSystem account. If the service type specifies SERVICE_INTERACTIVE_PROCESS, the service must run in the LocalSystem account. -> 基本上是已經使用拿到 administrator 的權限創造的 service 後面幾項都是填 null。創建的 service 會 auto run ::: ## 第二個func ![](https://i.imgur.com/yMqQkuh.png) - 接著可以看到hModule在kernel32.dll - 然後抓func的address - 修參數名稱 ![](https://i.imgur.com/UEBiYl8.png) ![](https://i.imgur.com/9NEXd8z.png) ## memset -> 待研究 - 這邊兩個 for loop 做的事情跟 memset 一樣 ## sprintf - ![](https://i.imgur.com/ya8HuPt.png) - 這邊兩個 sprintf 的參數其實有多個 -> 修改 ghidra - ![](https://i.imgur.com/q2zsSkj.png) - ![](https://i.imgur.com/SserNQj.png) ## MoveFileExA :::success BOOL MoveFileExA( LPCSTR lpExistingFileName, LPCSTR lpNewFileName, DWORD dwFlags ); ::: - 先看dwFlags - ![](https://i.imgur.com/qNMJtqs.png) - MOVEFILE_REPLACE_EXISTING # wannacry -> 無聊想修改的地方 ## entry - STARTUPINFOA - ![](https://i.imgur.com/IrBUObf.png) ## SERVICE_TABLE_ENTRYA - ![](https://i.imgur.com/8X6aHCB.png) - retype Variable - ![](https://i.imgur.com/ilzi2GL.png) - ![](https://i.imgur.com/9bJugmU.png) - service在撰寫的時候就規定最後一個要填 null - ![](https://i.imgur.com/FitbJmL.png) ## ChangeServiceConfig2A - ![](https://i.imgur.com/0yq5T1A.png) - 位置接在這邊 -> 應該是sevice沒辦法open的時候做的事情 - ![](https://i.imgur.com/ON3jTtX.png) [msdn](https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-changeserviceconfig2a)

    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