{"id":15039348,"url":"https://github.com/monoxgas/srdi","last_synced_at":"2025-05-15T08:05:27.819Z","repository":{"id":39616645,"uuid":"98681339","full_name":"monoxgas/sRDI","owner":"monoxgas","description":"Shellcode implementation of Reflective DLL Injection. Convert DLLs to position independent shellcode","archived":false,"fork":false,"pushed_at":"2023-11-15T10:53:00.000Z","size":424,"stargazers_count":2254,"open_issues_count":15,"forks_count":473,"subscribers_count":62,"default_branch":"master","last_synced_at":"2025-04-07T03:10:02.310Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/monoxgas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-28T19:30:53.000Z","updated_at":"2025-04-06T13:48:16.000Z","dependencies_parsed_at":"2024-08-13T07:18:42.404Z","dependency_job_id":null,"html_url":"https://github.com/monoxgas/sRDI","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/monoxgas%2FsRDI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monoxgas%2FsRDI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monoxgas%2FsRDI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/monoxgas%2FsRDI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/monoxgas","download_url":"https://codeload.github.com/monoxgas/sRDI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248870240,"owners_count":21175002,"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-09-24T20:42:31.443Z","updated_at":"2025-04-14T11:25:30.716Z","avatar_url":"https://github.com/monoxgas.png","language":"PowerShell","funding_links":[],"categories":["\u003ca id=\"89f963773ee87e2af6f9170ee60a7fb2\"\u003e\u003c/a\u003eDLL"],"sub_categories":["\u003ca id=\"3b4617e54405a32290224b729ff9f2b3\"\u003e\u003c/a\u003eDLL注入"],"readme":"# sRDI - Shellcode Reflective DLL Injection\nsRDI allows for the conversion of DLL files to position independent shellcode. It attempts to be a fully functional PE loader supporting proper section permissions, TLS callbacks, and sanity checks. It can be thought of as a shellcode PE loader strapped to a packed DLL.\n\nFunctionality is accomplished via two components:\n- C project which compiles a PE loader implementation (RDI) to shellcode\n- Conversion code which attaches the DLL, RDI, and user data together with a bootstrap\n\nThis project is comprised of the following elements:\n- **ShellcodeRDI:** Compiles shellcode for the DLL loader\n- **NativeLoader:** Converts DLL to shellcode if neccesarry, then injects into memory\n- **DotNetLoader:** C# implementation of NativeLoader\n- **Python\\ConvertToShellcode.py:** Convert DLL to shellcode in place\n- **Python\\EncodeBlobs.py:** Encodes compiled sRDI blobs for static embedding\n- **PowerShell\\ConvertTo-Shellcode.ps1:** Convert DLL to shellcode in place\n- **FunctionTest:** Imports sRDI C function for debug testing\n- **TestDLL:** Example DLL that includes two exported functions for call on Load and after\n\n**The DLL does not need to be compiled with RDI, however the technique  is cross compatiable.**\n\n## Use Cases / Examples\nBefore use, I recommend you become familiar with [Reflective DLL Injection](https://disman.tl/2015/01/30/an-improved-reflective-dll-injection-technique.html) and it's purpose. \n\n#### Convert DLL to shellcode using python\n```python\nfrom ShellcodeRDI import *\n\ndll = open(\"TestDLL_x86.dll\", 'rb').read()\nshellcode = ConvertToShellcode(dll)\n```\n\n#### Load DLL into memory using C# loader\n```\nDotNetLoader.exe TestDLL_x64.dll\n```\n\n#### Convert DLL with python script and load with Native EXE\n```\npython ConvertToShellcode.py TestDLL_x64.dll\nNativeLoader.exe TestDLL_x64.bin\n```\n\n#### Convert DLL with powershell and load with Invoke-Shellcode\n```powershell\nImport-Module .\\Invoke-Shellcode.ps1\nImport-Module .\\ConvertTo-Shellcode.ps1\nInvoke-Shellcode -Shellcode (ConvertTo-Shellcode -File TestDLL_x64.dll)\n```\n\n## Flags\nThe PE loader code uses `flags` argument to control the various options of loading logic:\n\n- `SRDI_CLEARHEADER` [0x1]: The DOS Header and DOS Stub for the target DLL are completley wiped with null bytes on load (Except for e_lfanew). This might cause issues with stock windows APIs when supplying the base address as a psuedo `HMODULE`.\n- `SRDI_CLEARMEMORY` [0x2]: After calling functions in the loaded module (`DllMain` and any exports), the DLL data will be cleared from memory. This is dangerous if you expect to continue executing code out of the module (Threads / `GetProcAddressR`).\n- `SRDI_OBFUSCATEIMPORTS` [0x4]: The order of imports in the module will be randomized before starting IAT patching. Additionally, the high 16 bits of the flag can be used to store the number of seconds to pause before processing the next import. For example, `flags | (3 \u003c\u003c 16)` will pause 3 seconds between every import.\n- `SRDI_PASS_SHELLCODE_BASE` [0x8]: As opposed to passing supplied user data to the exported function, sRDI will instead pass the base address of the currently executing shellcode block. This can be useful for self-cleanup inside more advanced modules.\n\n## Building\nThis project is built using Visual Studio 2019 (v142) and Windows SDK 10. The python script is written using Python 3.\n\nThe Python and Powershell scripts are located at:\n- `Python\\ConvertToShellcode.py`\n- `PowerShell\\ConvertTo-Shellcode.ps1`\n\nAfter building the project, the other binaries will be located at:\n- `bin\\NativeLoader.exe`\n- `bin\\DotNetLoader.exe`\n- `bin\\TestDLL_\u003carch\u003e.dll`\n- `bin\\ShellcodeRDI_\u003carch\u003e.bin`\n\nIf you would like to update the static blobs inside any of the tools:\n```\n\u003e python .\\lib\\Python\\EncodeBlobs.py -h\nusage: EncodeBlobs.py [-h] solution_dir\n\nsRDI Blob Encoder\n\npositional arguments:\n  solution_dir  Solution Directory\n\noptional arguments:\n  -h, --help    show this help message and exit\n\n\u003e python lib\\Python\\EncodeBlobs.py C:\\code\\srdi\n\n[+] Updated C:\\code\\srdi\\Native/Loader.cpp\n[+] Updated C:\\code\\srdi\\DotNet/Program.cs\n[+] Updated C:\\code\\srdi\\Python/ShellcodeRDI.py\n[+] Updated C:\\code\\srdi\\PowerShell/ConvertTo-Shellcode.ps1\n\n```\n\n## Alternatives\nIf you find my code disgusting, or just looking for an alternative memory-PE loader project, check out some of these:\n\n- https://github.com/fancycode/MemoryModule - Probably one of the cleanest PE loaders out there, great reference.\n- https://github.com/TheWover/donut - Want to convert .NET assemblies? Or how about JScript?\n- https://github.com/hasherezade/pe_to_shellcode - Generates a polymorphic PE+shellcode hybrids.\n- https://github.com/DarthTon/Blackbone - Large library with many memory hacking/hooking primitives.\n\n## Credits\nThe basis of this project is derived from [\"Improved Reflective DLL Injection\" from Dan Staples](https://disman.tl/2015/01/30/an-improved-reflective-dll-injection-technique.html) which itself is derived from the original project by [Stephen Fewer](https://github.com/stephenfewer/ReflectiveDLLInjection). \n\nThe project framework for compiling C code as shellcode is taken from [Mathew Graeber's reasearch \"PIC_BindShell\"](http://www.exploit-monday.com/2013/08/writing-optimized-windows-shellcode-in-c.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonoxgas%2Fsrdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmonoxgas%2Fsrdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmonoxgas%2Fsrdi/lists"}