├── .gitattributes ├── .gitignore ├── AppGame.sln ├── InjectAssembly ├── ExecuteAssembly.h ├── InjectAssembly.cpp ├── InjectAssembly.vcxproj ├── InjectAssembly.vcxproj.filters ├── LHCommon.cpp └── LHCommon.h ├── README.md └── TragetAssembly2 ├── App.config ├── AppEnvironment.cs ├── MainForm.Designer.cs ├── MainForm.cs ├── MainForm.resx ├── Program.cs ├── Properties └── AssemblyInfo.cs └── TragetAssembly2.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /AppGame.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32421.90 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InjectAssembly", "InjectAssembly\InjectAssembly.vcxproj", "{679C01AF-C56D-49E2-A823-FA17A7F6A979}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TragetAssembly2", "TragetAssembly2\TragetAssembly2.csproj", "{27DEE685-15F5-44AF-9A55-BD61D7535553}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Debug|Any CPU.ActiveCfg = Debug|x64 21 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Debug|Any CPU.Build.0 = Debug|x64 22 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Debug|x64.ActiveCfg = Debug|x64 23 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Debug|x64.Build.0 = Debug|x64 24 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Debug|x86.ActiveCfg = Debug|Win32 25 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Debug|x86.Build.0 = Debug|Win32 26 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Release|Any CPU.ActiveCfg = Release|x64 27 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Release|Any CPU.Build.0 = Release|x64 28 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Release|x64.ActiveCfg = Release|x64 29 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Release|x64.Build.0 = Release|x64 30 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Release|x86.ActiveCfg = Release|Win32 31 | {679C01AF-C56D-49E2-A823-FA17A7F6A979}.Release|x86.Build.0 = Release|Win32 32 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Debug|x64.Build.0 = Debug|Any CPU 36 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Debug|x86.Build.0 = Debug|Any CPU 38 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Release|x64.ActiveCfg = Release|Any CPU 41 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Release|x64.Build.0 = Release|Any CPU 42 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Release|x86.ActiveCfg = Release|Any CPU 43 | {27DEE685-15F5-44AF-9A55-BD61D7535553}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {E6F22F6F-A63B-4481-AD55-A1E9FFA500FC} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /InjectAssembly/ExecuteAssembly.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mudebug77/InjectAssembly/96ad549b81397f8d44b0ffadce5f192bdb736bb7/InjectAssembly/ExecuteAssembly.h -------------------------------------------------------------------------------- /InjectAssembly/InjectAssembly.cpp: -------------------------------------------------------------------------------- 1 | // InjectAssembly.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include "LHCommon.h" 6 | #include "ExecuteAssembly.h" 7 | 8 | 9 | BOOL InjectRometeDll(DWORD dwProcessId,LPCTSTR szFilePath, LPCTSTR szArg) 10 | { 11 | BOOL bResult = FALSE; 12 | HANDLE hProcess = NULL; 13 | HANDLE hThread = NULL; 14 | HANDLE hFile = NULL; 15 | PSTR pRemoteMemory = NULL; 16 | SIZE_T cch; 17 | __try 18 | { 19 | printf("dwProcessId:%08X\n", dwProcessId); 20 | // 获得想要注入代码的进程的句柄. 21 | hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId); 22 | printf("OpenProcess:%p\n", hProcess); 23 | if (hProcess == NULL) 24 | { 25 | printf("[错误] OpenProcess(%d) 调用失败!错误代码: [%d]\n", dwProcessId, GetLastError()); 26 | __leave; 27 | } 28 | 29 | HANDLE hFile = CreateFileW(szFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL); 30 | if (hFile == NULL) 31 | { 32 | printf("[错误] CreateFile(%ls) 调用失败!错误代码: [%d]\n", szFilePath, GetLastError()); 33 | __leave; 34 | } 35 | DWORD FileSize = GetFileSize(hFile, NULL); 36 | intptr_t FunctionSize = GetFunctionSize(ExecuteAssembly); 37 | printf("FunctionSize:%lld [%ls] FileSize:%ld\n", FunctionSize, szFilePath, FileSize); 38 | if ((FileSize == 0)||(FileSize==-1)) 39 | { 40 | printf("[错误] GetFileSize NULL 调用失败!错误代码: [%d]\n", GetLastError()); 41 | __leave; 42 | } 43 | LPBYTE FileData = new BYTE[FileSize + 1]; 44 | DWORD filetemp; 45 | if (ReadFile(hFile, FileData, FileSize, &filetemp, NULL)==0) 46 | { 47 | printf(("[错误] ReadFile:[%ld]%ls error:%d\n"), FileSize, szFilePath, GetLastError()); 48 | __leave; 49 | } 50 | 51 | 52 | cch = FunctionSize + sizeof(PARAMX) + FileSize + 0x100; 53 | // 在远程线程中为路径名分配空间. 54 | pRemoteMemory = (PSTR)VirtualAllocEx(hProcess, NULL, cch, MEM_COMMIT | MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE); 55 | if (pRemoteMemory == NULL) 56 | { 57 | printf("[错误] VirtualAllocEx(%d) size:%lld 调用失败!错误代码: [%d]\n", dwProcessId,cch, GetLastError()); 58 | __leave; 59 | } 60 | 61 | HMODULE NTDLL = GetModuleHandleA("ntdll"); 62 | if (NTDLL == 0) __leave; 63 | PARAMX param; 64 | RtlZeroMemory(¶m, sizeof(PARAMX)); 65 | 66 | param.lpFileData = pRemoteMemory + FunctionSize + sizeof(PARAMX); 67 | param.DataLength = FileSize; 68 | wcscpy_s(param.szArgument,512, szArg); 69 | 70 | 71 | param.LdrGetProcedureAddress = (LdrGetProcedureAddressT)GetProcAddress(NTDLL, "LdrGetProcedureAddress");; 72 | param.NtAllocateVirtualMemory = (NtAllocateVirtualMemoryT)GetProcAddress(NTDLL, "NtAllocateVirtualMemory"); 73 | param.LdrLoadDll = (LdrLoadDllT)GetProcAddress(NTDLL, "LdrLoadDll"); 74 | param.RtlInitAnsiString = (RtlInitAnsiStringT)GetProcAddress(NTDLL, "RtlInitAnsiString"); 75 | param.RtlFreeAnsiString = (RtlFreeAnsiStringT)GetProcAddress(NTDLL, "RtlFreeAnsiString"); 76 | param.RtlAnsiStringToUnicodeString = (RtlAnsiStringToUnicodeStringT)GetProcAddress(NTDLL, "RtlAnsiStringToUnicodeString"); 77 | param.RtlFreeUnicodeString = (RtlFreeUnicodeStringT)GetProcAddress(NTDLL, "RtlFreeUnicodeString"); 78 | param.RtlInitUnicodeString = (RtlInitUnicodeStringT)GetProcAddress(NTDLL, "RtlInitUnicodeString"); 79 | 80 | 81 | //写入shellcode 82 | if (!WriteProcessMemory(hProcess, pRemoteMemory, (PVOID)ExecuteAssembly, FunctionSize, &cch)) 83 | { 84 | printf("[错误] WriteProcessMemory A (%d) 调用失败!错误代码: [%d]\n", dwProcessId, GetLastError()); 85 | __leave; 86 | } 87 | if (!WriteProcessMemory(hProcess, pRemoteMemory + FunctionSize, (PVOID)¶m, sizeof(PARAMX), &cch)) 88 | { 89 | printf("[错误] WriteProcessMemory B (%d) 调用失败!错误代码: [%d]\n", dwProcessId, GetLastError()); 90 | __leave; 91 | } 92 | if (!WriteProcessMemory(hProcess, pRemoteMemory + FunctionSize + sizeof(PARAMX), (PVOID)FileData, FileSize, &cch)) 93 | { 94 | printf("[错误] WriteProcessMemory C (%d) 调用失败!错误代码: [%d]\n", dwProcessId, GetLastError()); 95 | __leave; 96 | } 97 | 98 | // 创建远程线程,并通过远程线程调用用户的DLL文件. 99 | hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)(pRemoteMemory), pRemoteMemory + FunctionSize, 0, NULL); 100 | if (hThread == NULL) 101 | { 102 | printf("[错误] CreateRemoteThread( %p ) 失败!错误代码: [%d]\n", pRemoteMemory + FileSize, GetLastError()); 103 | __leave; 104 | } 105 | 106 | // 等待远程线程终止. 107 | if (WAIT_FAILED == WaitForSingleObject(hThread, INFINITE)) 108 | { 109 | printf("CreateRemoteThread() : WaitForSingleObject() 调用失败!错误代码: [%d]\n", GetLastError()); 110 | __leave; 111 | } 112 | 113 | cch = FileSize + FunctionSize + sizeof(PARAMX) + 0x100; 114 | //清空DLL路径以免被侦测 115 | LPBYTE zBuffer = new BYTE[cch + 1]; 116 | memset(zBuffer, 0, cch + 1); 117 | //WriteProcessMemory(hProcess, (PVOID)pRemoteMemory, (PVOID)zBuffer, cch, NULL); 118 | delete[] zBuffer; 119 | bResult = TRUE; 120 | } 121 | __finally 122 | { 123 | // 关闭句柄. 124 | if (pRemoteMemory != NULL) 125 | { 126 | //VirtualFreeEx(hProcess, (PVOID)pRemoteMemory, 0, MEM_RELEASE); 127 | } 128 | if (hThread != NULL) CloseHandle(hThread); 129 | if (hProcess != NULL) CloseHandle(hProcess); 130 | if (hFile != NULL) CloseHandle(hFile); 131 | } 132 | return bResult; 133 | } 134 | 135 | 136 | DWORD EnablePrivilege(LPCTSTR name) 137 | { 138 | BOOL rv; 139 | HANDLE hToken; 140 | 141 | TOKEN_PRIVILEGES priv = { 1,{0,0,SE_PRIVILEGE_ENABLED} }; 142 | 143 | LookupPrivilegeValue(0, name, &priv.Privileges[0].Luid); 144 | 145 | OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken); 146 | 147 | AdjustTokenPrivileges(hToken, FALSE, &priv, sizeof priv, 0, 0); 148 | 149 | rv = GetLastError(); 150 | printf(("EnablePrivilege GetLastError:%d \n"), rv); 151 | 152 | CloseHandle(hToken); 153 | return rv; 154 | } 155 | 156 | 157 | #define PROCESSFLAG 20210822 158 | 159 | int main(int argc, char* argv[]) 160 | { 161 | if (argc != 4) 162 | { 163 | printf("arg count error"); 164 | return -1; 165 | } 166 | list ProcessList; 167 | wstring sProcessName; 168 | wstring sLibraryPath; 169 | wstring sLibraryArg; 170 | Utf8ToUnicode(argv[1], sProcessName); 171 | Utf8ToUnicode(argv[2], sLibraryPath); 172 | Utf8ToUnicode(argv[3], sLibraryArg); 173 | printf("3FindProcessName:%ls [%ls]\n", sProcessName.c_str(), sLibraryPath.c_str()); 174 | //%08d 175 | const WCHAR szB08d[] = { 0x0025,0x0030,0x0038,0x0064,0x0000 }; 176 | BYTE szTempBuff[0x100]; 177 | 178 | printf("argv:%ls\n", sLibraryArg.c_str()); 179 | const WCHAR szSE_DEBUG_NAME[] = { 0x0053,0x0065,0x0044,0x0065,0x0062,0x0075,0x0067,0x0050,0x0072,0x0069,0x0076,0x0069,0x006C,0x0065,0x0067,0x0065,0x0000 }; 180 | EnablePrivilege(szSE_DEBUG_NAME); 181 | 182 | try 183 | { 184 | for (int i = 0; i < 60 * 4 * 5; i++) 185 | { 186 | ProcessList.clear(); 187 | if (GetProcessIdByName(sProcessName.c_str(), ProcessList)) 188 | { 189 | for (list::iterator it = ProcessList.begin(); it != ProcessList.end(); it++) 190 | { 191 | DWORD nProcessId = *it; 192 | 193 | printf("InjectRometeDll:%d\n", nProcessId); 194 | swprintf_s((wchar_t*)szTempBuff,128, szB08d, nProcessId ^ PROCESSFLAG); 195 | HANDLE m_hMutex = CreateMutex(NULL, TRUE, (wchar_t*)szTempBuff); 196 | int nError = GetLastError(); 197 | if (nError == ERROR_ALREADY_EXISTS) 198 | { 199 | if (m_hMutex) CloseHandle(m_hMutex); 200 | return FALSE; 201 | } 202 | if (m_hMutex) CloseHandle(m_hMutex); 203 | if (!InjectRometeDll(nProcessId, sLibraryPath.c_str(), sLibraryArg.c_str())) 204 | { 205 | printf("注入失敗:%d\n", nProcessId); 206 | } 207 | Sleep(100); 208 | return 0; 209 | } 210 | } 211 | Sleep(200); 212 | } 213 | } 214 | catch (...) 215 | { 216 | 217 | } 218 | } 219 | 220 | // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 221 | // 调试程序: F5 或调试 >“开始调试”菜单 222 | 223 | // 入门使用技巧: 224 | // 1. 使用解决方案资源管理器窗口添加/管理文件 225 | // 2. 使用团队资源管理器窗口连接到源代码管理 226 | // 3. 使用输出窗口查看生成输出和其他消息 227 | // 4. 使用错误列表窗口查看错误 228 | // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 229 | // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 230 | -------------------------------------------------------------------------------- /InjectAssembly/InjectAssembly.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {679c01af-c56d-49e2-a823-fa17a7f6a979} 25 | InjectAssembly 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | ..\Bin\ 82 | $(ProjectName)_$(Platform) 83 | 84 | 85 | false 86 | ..\Bin\ 87 | $(ProjectName)_$(Platform) 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 94 | true 95 | 96 | 97 | Console 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | false 106 | false 107 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 108 | true 109 | Size 110 | false 111 | 112 | 113 | Console 114 | true 115 | true 116 | true 117 | 118 | 119 | 120 | 121 | Level3 122 | false 123 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | Default 125 | ProgramDatabase 126 | false 127 | Disabled 128 | 129 | 130 | Console 131 | true 132 | 133 | 134 | 135 | 136 | Level3 137 | true 138 | false 139 | false 140 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 141 | Default 142 | ProgramDatabase 143 | false 144 | MaxSpeed 145 | 146 | 147 | Console 148 | true 149 | true 150 | true 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /InjectAssembly/InjectAssembly.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {fdd4580f-511c-4858-ab8f-0d60bf493568} 18 | 19 | 20 | 21 | 22 | 源文件 23 | 24 | 25 | LHCommon 26 | 27 | 28 | 29 | 30 | 头文件 31 | 32 | 33 | LHCommon 34 | 35 | 36 | -------------------------------------------------------------------------------- /InjectAssembly/LHCommon.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mudebug77/InjectAssembly/96ad549b81397f8d44b0ffadce5f192bdb736bb7/InjectAssembly/LHCommon.cpp -------------------------------------------------------------------------------- /InjectAssembly/LHCommon.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mudebug77/InjectAssembly/96ad549b81397f8d44b0ffadce5f192bdb736bb7/InjectAssembly/LHCommon.h -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InjectAssembly 2 | 注入c#控制台到非托管进程 3 | 4 | 注入部分 5 | OpenProcess -> VirtualAllocEx -> 写入shellcode 和 c# 程序 ->CreateRemoteThread 6 | 7 | shellcode 部分 8 | CLRCreateInstance v4.0.30319 9 | 通过pDefaultAppDomain->raw_Load_3接口调用加载byte[] 内存中加载c# dll ExecuteAssembly 10 | 11 | 12 | https://bbs.pediy.com/thread-272660.htm 13 | -------------------------------------------------------------------------------- /TragetAssembly2/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /TragetAssembly2/AppEnvironment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mudebug 8 | { 9 | //主要负责储存启动时需要的参数 10 | public static class AppEnvironment 11 | { 12 | public static string AppArgs; 13 | public static string AppDirectory; 14 | } 15 | } -------------------------------------------------------------------------------- /TragetAssembly2/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace TragetAssembly2 2 | { 3 | partial class MainForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.button1 = new System.Windows.Forms.Button(); 32 | this.SuspendLayout(); 33 | // 34 | // button1 35 | // 36 | this.button1.Location = new System.Drawing.Point(116, 71); 37 | this.button1.Name = "button1"; 38 | this.button1.Size = new System.Drawing.Size(99, 48); 39 | this.button1.TabIndex = 0; 40 | this.button1.Text = "button1"; 41 | this.button1.UseVisualStyleBackColor = true; 42 | this.button1.Click += new System.EventHandler(this.button1_Click); 43 | // 44 | // MainForm 45 | // 46 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 47 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 48 | this.ClientSize = new System.Drawing.Size(800, 450); 49 | this.Controls.Add(this.button1); 50 | this.Name = "MainForm"; 51 | this.Text = "MainForm"; 52 | this.ResumeLayout(false); 53 | 54 | } 55 | 56 | #endregion 57 | 58 | private System.Windows.Forms.Button button1; 59 | } 60 | } -------------------------------------------------------------------------------- /TragetAssembly2/MainForm.cs: -------------------------------------------------------------------------------- 1 | using Mudebug; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | 12 | namespace TragetAssembly2 13 | { 14 | public partial class MainForm : Form 15 | { 16 | public MainForm() 17 | { 18 | InitializeComponent(); 19 | } 20 | 21 | private void button1_Click(object sender, EventArgs e) 22 | { 23 | MessageBox.Show("Test box by mudebug\n" + AppEnvironment.AppArgs); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TragetAssembly2/MainForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /TragetAssembly2/Program.cs: -------------------------------------------------------------------------------- 1 | using Mudebug; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace TragetAssembly2 11 | { 12 | internal class Program 13 | { 14 | #if DEBUG 15 | [DllImport("kernel32.dll")] 16 | [return: MarshalAs(UnmanagedType.Bool)] 17 | static extern bool AllocConsole(); 18 | #endif 19 | 20 | public static MainForm MainForm; 21 | static void Main(string[] args) 22 | { 23 | #if DEBUG 24 | AllocConsole(); 25 | Console.WriteLine($"{DateTime.UtcNow} 啟動:{string.Join("\n", args)}"); 26 | #endif 27 | AppEnvironment.AppArgs = args[0]; 28 | 29 | var LibarayArg = AppEnvironment.AppArgs.Split('\t'); 30 | AppEnvironment.AppDirectory = LibarayArg[0]; 31 | Console.WriteLine($"AppDirectory:{AppEnvironment.AppDirectory}"); 32 | 33 | Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + AppEnvironment.AppDirectory); 34 | 35 | 36 | var MainThread = new Thread(() => 37 | { 38 | MainForm = new MainForm(); 39 | MainForm.ShowDialog(); 40 | }); 41 | MainThread.Start(); 42 | 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /TragetAssembly2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("TragetAssembly2")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TragetAssembly2")] 13 | [assembly: AssemblyCopyright("Copyright © 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("27dee685-15f5-44af-9a55-bd61d7535553")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TragetAssembly2/TragetAssembly2.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {27DEE685-15F5-44AF-9A55-BD61D7535553} 8 | Exe 9 | TragetAssembly2 10 | TragetAssembly2 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | ..\Bin\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | ..\Bin\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Form 51 | 52 | 53 | MainForm.cs 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | MainForm.cs 62 | 63 | 64 | 65 | --------------------------------------------------------------------------------