{"id":13840393,"url":"https://github.com/codewhitesec/HandleKatz","last_synced_at":"2025-07-11T07:33:39.193Z","repository":{"id":38280804,"uuid":"414175478","full_name":"codewhitesec/HandleKatz","owner":"codewhitesec","description":"PIC lsass dumper using cloned handles","archived":false,"fork":false,"pushed_at":"2022-10-18T08:55:13.000Z","size":1370,"stargazers_count":568,"open_issues_count":2,"forks_count":103,"subscribers_count":12,"default_branch":"main","last_synced_at":"2024-08-05T17:25:03.376Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codewhitesec.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-06T10:59:15.000Z","updated_at":"2024-07-24T08:40:14.000Z","dependencies_parsed_at":"2022-07-13T04:51:41.159Z","dependency_job_id":null,"html_url":"https://github.com/codewhitesec/HandleKatz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewhitesec%2FHandleKatz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewhitesec%2FHandleKatz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewhitesec%2FHandleKatz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codewhitesec%2FHandleKatz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codewhitesec","download_url":"https://codeload.github.com/codewhitesec/HandleKatz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225705403,"owners_count":17511288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T17:00:47.226Z","updated_at":"2024-11-21T09:31:27.259Z","avatar_url":"https://github.com/codewhitesec.png","language":"C","readme":"# HandleKatz\n\nThis tool was implemented as part of our Brucon2021 conference talk and demonstrates the usage of **cloned handles to Lsass** in order to create an obfuscated memory dump of the same.\n\nIt compiles down to an executable **living fully in its text segment**. Thus, the extracted .text segment of the PE file is fully position independent code (=PIC), meaning that it can be treated like any shellcode.\n\nThe execution of HandleKatz in memory has a very small footprint, as itself does not allocate any more executable memory and can therefore efficiently be combined with concepts such as (Phantom)DLL-Hollowing as described by [@_ForrestOrr](https://www.forrest-orr.net/post/malicious-memory-artifacts-part-i-dll-hollowing). This is in contrast to PIC PE loaders, such as Donut, SRDI or Reflective Loaders which, during PE loading, allocate more executable memory.\nAdditionally, it makes use of a modified version of ReactOS MiniDumpWriteDumpA and bypasses userlandhooks using [RecycledGate](https://github.com/thefLink/RecycledGate).     \n\nFor detailed information please refer to the PDF file **PICYourMalware.pdf** in this repository.\n\n## Usage\n\n- **make all** to build HandleKatzPIC.exe, HandleKatz.bin and loader.exe\n\n**Please note** that different compiler (versions) yield different results. This might produce a PE file with relocations.\n\nAll tests were carried out using ```x86_64-w64-mingw32-gcc mingw-gcc version 11.2.0 (GCC)```. The produced PIC was successfully tested on: Windows 10 Pro 10.0.17763. On other versions of windows, API hashes might differ.\n\nTo use the PIC, cast a pointer to the shellcode in executable memory and call it according to the definition:\n```\nDWORD handleKatz(BOOL b_only_recon, char* ptr_output_path, uint32_t pid, char* ptr_buf_output);\n```\n\n- **b_only_recon** If set, HandleKatz will only enumerate suitable handles without dumping\n- **ptr_output_path** Determines where the obfuscated dump will be written to\n- **pid** What PID to clone a handle from\n- **ptr_buf_output** A char pointer to which HandleKatz writes its internal output\n\nFor deobfuscation of the dump file, the script **Decoder.py** can be used.\n\n**Loader** implements a sample loader for HandleKatz:\n```\nloader.exe --pid:7331 --outfile:C:\\Temp\\dump.obfuscated\n```\n![Usage of HandleKatz PIC](imgs/HandleKatz.png)\n\n## Detection\n\nAs cloned handles are used along with modified ReactOS code, no ProcessAccess events can be observed on Lsass. However, ProcessAccess events on programs which hold a handle to Lsass can be observed.\n\nDefenders can monitor for ProcessAccess masks with set **PROCESS_DUP_HANDLE (0x0040)** to identify the usage of this tool.\n\n## Credits\n\n- Implementation by our [@thefLinkk](https://twitter.com/thefLinkk), see [C-To-Shellcode-Examples](https://github.com/thefLink/C-To-Shellcode-Examples) for more PIC examples.\n- [@Hasherezade](https://twitter.com/hasherezade) for [tutorials](https://vxug.fakedoma.in/papers/VXUG/Exclusive/FromaCprojectthroughassemblytoshellcodeHasherezade.pdf) on the C-To-Shellcode concept\n- [@ParanoidNinja](https://twitter.com/NinjaParanoid) for [tutorials](https://github.com/paranoidninja/PIC-Get-Privileges) on the C-To-Shellcode concept\n- [@_ForrestOrr](https://twitter.com/_ForrestOrr) for his amazing [blogpost series](https://www.forrest-orr.net/post/malicious-memory-artifacts-part-i-dll-hollowing) on memory artifacts\n- [@rookuu_](https://twitter.com/rookuu_) for the idea to use ReactOS MiniDumpWriteDump\n- [Outflank](https://outflank.nl/) for documenting direct syscalls and their [InlineWhispers](https://github.com/outflanknl/InlineWhispers) project\n- [React OS](https://reactos.org/) for the implementation of MiniDumpWriteDump\n- [Hilko Bengen](https://github.com/hillu) for improving the makefile\n","funding_links":[],"categories":["Operating Systems","C"],"sub_categories":["Windows"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewhitesec%2FHandleKatz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewhitesec%2FHandleKatz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewhitesec%2FHandleKatz/lists"}