From 19b860efd3b00a164979234f85d8884a3e5e6cf1 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Sun, 22 Sep 2019 16:59:05 +0200 Subject: DLL injection from CMD example --- CMD/CMD.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'CMD') diff --git a/CMD/CMD.cpp b/CMD/CMD.cpp index a9e4388..5d40e54 100644 --- a/CMD/CMD.cpp +++ b/CMD/CMD.cpp @@ -129,18 +129,17 @@ int wmain(int argc, wchar_t **argv) PVOID targetAddr = (PVOID)((UINT64)NULL); SIZE_T targetSize = 4096; try { +#if 0 if (!ki.VAlloc(targetPID, &targetAddr, &targetSize, PAGE_EXECUTE_READWRITE)) { std::wcout << L"VAlloc failed" << std::endl; } -#if 0 if (!ki.VUnlink(targetPID, targetAddr)) { std::wcout << L"VUnlink failed" << std::endl; } -#endif if (!ki.VFree(targetPID, targetAddr, targetSize)) { std::wcout << L"VFree failed" << std::endl; } - +#endif static bool map_test_dll = true; if (map_test_dll) { map_test_dll = false; @@ -154,9 +153,22 @@ int wmain(int argc, wchar_t **argv) if (!dll.InitTargetMemory()) { std::wcout << L"DLL InitTargetMemory failed" << std::endl; } - if (!dll.FixImports()) { + if (!dll.HasImports()) + { + std::wcout << L"DLL has no ImportTable" << std::endl; + } + else if (!dll.FixImports()) { std::wcout << L"DLL FixImports failed" << std::endl; } + if (!dll.HasRelocs()) { + std::wcout << L"DLL has no RelocTable" << std::endl; + } + else if (!dll.FixRelocs()) { + std::wcout << L"DLL FixRelocs failed" << std::endl; + } + if (!dll.CopyHeaderAndSections()) { + std::wcout << L"DLL CopyHeaderAndSections failed" << std::endl; + } std::wcout << L"DLL mapping succesful" << std::endl; } } -- cgit v1.2.3