Skip to content

Commit

Permalink
Updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicshann committed May 2, 2020
1 parent 80c6649 commit 9915705
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 122 deletions.
Binary file added GhostBanner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 61 additions & 59 deletions InjectLib/InjectDll.cpp

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions InjectLib/InjectDll.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <intrin.h>
//#include <Windows.h>
#include "Utils.h"
#include "UniHook.hpp"
#include "json.h"
#include "NtDllEx.hpp"
#include "CompileTime.hpp"
#include "InjDllLdr.hpp"
#include "GhostDbg.hpp"
#include "..\..\GlobalInjector\GInjer\LoaderCode.h"

//====================================================================================
Expand All @@ -34,7 +25,7 @@ void _stdcall LoadConfiguration(void);
void _stdcall SaveConfiguration(int BinFmt=-1);
void _stdcall UnInitApplication(void);
bool _stdcall InitApplication(void);
int _fastcall DbgUsrReqCallback(ShMem::CMessageIPC::SMsgHdr* Req, PVOID ArgA, UINT ArgB);
int _fastcall DbgUsrReqCallback(NShMem::CMessageIPC::SMsgHdr* Req, PVOID ArgA, UINT ArgB);
//------------------------------------------------------------------------------------
bool _cdecl ProcExpDispBefore(volatile PVOID ArgA, volatile PVOID ArgB, volatile PVOID ArgC, volatile PVOID ArgD, volatile PVOID RetVal);
bool _cdecl ProcExpDispAfter(volatile PVOID ArgA, volatile PVOID ArgB, volatile PVOID ArgC, volatile PVOID ArgD, volatile PVOID RetVal);
Expand Down
5 changes: 3 additions & 2 deletions InjectLib/InjectDll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ copy /Y "$(OutDir)$(TargetName)$(TargetExt)" "$(SolutionDir)BUILD\RELEASE\$(Solu
<ClCompile Include="InjectDll.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\COMMON\Common.hpp" />
<ClInclude Include="..\COMMON\CompileTime.hpp" />
<ClInclude Include="..\COMMON\FormatPE.h" />
<ClInclude Include="..\COMMON\FormatPE.hpp" />
<ClInclude Include="..\COMMON\GhostDbg.hpp" />
<ClInclude Include="..\COMMON\HDE.h" />
<ClInclude Include="..\COMMON\HDE.hpp" />
<ClInclude Include="..\COMMON\InjDllLdr.hpp" />
<ClInclude Include="..\COMMON\json.h" />
<ClInclude Include="..\COMMON\MiniString.h" />
Expand Down
15 changes: 9 additions & 6 deletions InjectLib/InjectDll.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
<ClInclude Include="..\COMMON\ThirdParty\ntdll\ntdll.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\FormatPE.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\HDE.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\json.h">
<Filter>Common</Filter>
</ClInclude>
Expand Down Expand Up @@ -68,5 +62,14 @@
<ClInclude Include="..\COMMON\NtDllEx.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\Common.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\FormatPE.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\HDE.hpp">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ TODO:
IPC SRW locks
Enable Config files
IDA compatibility
Fix NativeCreateThread on latest Windows 10
Fix extreme slowness on Windows XP (Sync problem? Fix for GhostDrv) // https://communities.vmware.com/thread/466749
GInjer compatibility (Especially WOW64 debugging)
Wait for attach and ignore events until that (GInjer, requires config)

ISSUES:
Software breakpoints is very dangerous to set if not all threads are suspended on a Debug Event
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


<img align="center" hspace="20" src="/GhostBanner.gif">

<p align="center">
<h1 align="center">GhostDbg</h1>
</p>

13 changes: 0 additions & 13 deletions README.txt

This file was deleted.

Binary file added XDbgPlugin/MainIcon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions XDbgPlugin/Resources.rc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32

1 ICON "MainIcon.ico"
5 ICON "LogoIcon.ico"
MAINICON RCDATA "MainIcon.png" // ICON
InjLib RCDATA INJLIBPATH
Expand Down
37 changes: 20 additions & 17 deletions XDbgPlugin/XDbgPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#pragma comment(linker,"/NODEFAULTLIB")


typedef ShMem SHM;
typedef GhDbg XNI;
typedef NShMem SHM;
typedef NGhDbg XNI;

// ---------- SETTINGS ------------------
bool PLogOnly = false; // Just log usage of Debug API
bool PEnabled = false; // Enable the GhostDbg plugin
bool AllowInject = true; // Allow to load inject DLL into a target process(Attach). Else only processes with already injected GhostDbg DLLs will be visible
bool AllowInjNew = true; // Allow to load inject DLL into a target process(Create).
bool SuspendProc = true; // It is safer to keep a target process suspended while IPC and GhostDbg Client initializing but some timeouts may be detected
UINT InjFlags = InjLdr::mfInjMap|InjLdr::mfRunRMTH|InjLdr::mfRawRMTH;
UINT InjFlags = NInjLdr::mfInjMap|NInjLdr::mfRunRMTH|NInjLdr::mfRawRMTH;
UINT WaitForInj = 3000;
//---------------------------------------

Expand Down Expand Up @@ -94,7 +94,7 @@ wchar_t WorkFolder[MAX_PATH];

//===========================================================================
BOOL APIENTRY DLLMain(HMODULE hModule, DWORD ReasonCall, LPVOID lpReserved)
{
{
switch (ReasonCall)
{
case DLL_PROCESS_ATTACH:
Expand All @@ -110,7 +110,7 @@ BOOL APIENTRY DLLMain(HMODULE hModule, DWORD ReasonCall, LPVOID lpReserved)
NSTR::StrCopy(CfgFilePath, WorkFolder);
NSTR::StrCopy(GetFileExt(CfgFilePath), L"ini");

LoadConfiguration();
LoadConfiguration();
if(LogMode & lmCons){AllocConsole();/*SetWinConsoleSizes(1000, 500, 1000, 500);*/}
LOGMSG("Starting up... (Time=%016llX), Owner='%ls'", SysTimeToTime64(NNTDLL::GetSystemTime()), &StartUpDir);
TrimFilePath(StartUpDir);
Expand All @@ -131,7 +131,7 @@ BOOL APIENTRY DLLMain(HMODULE hModule, DWORD ReasonCall, LPVOID lpReserved)
}
//====================================================================================
void _stdcall LoadConfiguration(void)
{
{
LogMode = INIRefreshValueInt<PWSTR>(CFGSECNAME, L"LogMode", LogMode, CfgFilePath);
PLogOnly = INIRefreshValueInt<PWSTR>(CFGSECNAME, L"PLogOnly", PLogOnly, CfgFilePath);
PEnabled = INIRefreshValueInt<PWSTR>(CFGSECNAME, L"PEnabled", PEnabled, CfgFilePath);
Expand All @@ -140,12 +140,15 @@ void _stdcall LoadConfiguration(void)
SuspendProc = INIRefreshValueInt<PWSTR>(CFGSECNAME, L"SuspendProc", SuspendProc, CfgFilePath);
InjFlags = INIRefreshValueInt<PWSTR>(CFGSECNAME, L"InjectFlags", InjFlags, CfgFilePath);
WaitForInj = INIRefreshValueInt<PWSTR>(CFGSECNAME, L"WaitForInj", WaitForInj, CfgFilePath);

PVOID pNtDll = GetNtDllBaseFast();

LOGMSG("Initializing...");
PVOID pNtDll = NPEFMT::GetNtDllBaseFast();
LOGMSG("SystemNtDllBase: %p", pNtDll);
NtDllSize = GetRealModuleSize(pNtDll);
NtDllBase = VirtualAlloc(NULL,NtDllSize,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
memcpy(NtDllBase,pNtDll,NtDllSize);
LOGMSG("Clean copy of NtDll: %p", NtDllBase);
LOGMSG("CopyNtDllBase=%p, NtDllSize=%08X", NtDllBase, NtDllSize);
CopyValidModuleMem(pNtDll, NtDllBase, NtDllSize); // On Win7 x64 some regions of ntdll.dll are in reserved state
LOGMSG("Done");
}
//------------------------------------------------------------------------------------
void _stdcall SaveConfiguration(void)
Expand Down Expand Up @@ -190,8 +193,8 @@ void _cdecl MenuHandler(CBTYPE Type, PLUG_CB_MENUENTRY *info)
SaveConfiguration();
break;
case MENU_ID_USERAWTHREADS:
if(InjFlags & InjLdr::mfRawRMTH)InjFlags &= ~InjLdr::mfRawRMTH;
else InjFlags |= InjLdr::mfRawRMTH;
if(InjFlags & NInjLdr::mfRawRMTH)InjFlags &= ~NInjLdr::mfRawRMTH;
else InjFlags |= NInjLdr::mfRawRMTH;
SaveConfiguration();
break;
case MENU_ID_ABOUT:
Expand Down Expand Up @@ -274,7 +277,7 @@ extern "C" __declspec(dllexport) void _cdecl plugsetup(PLUG_SETUPSTRUCT* setupSt
plugin_menuentrysetchecked(PluginHandle,MENU_ID_CHK_CANINJ,AllowInject);
plugin_menuentrysetchecked(PluginHandle,MENU_ID_CHK_CANINJNEW,AllowInjNew);
plugin_menuentrysetchecked(PluginHandle,MENU_ID_SUSPPROCESS,SuspendProc);
plugin_menuentrysetchecked(PluginHandle,MENU_ID_USERAWTHREADS,InjFlags & InjLdr::mfRawRMTH);
plugin_menuentrysetchecked(PluginHandle,MENU_ID_USERAWTHREADS,InjFlags & NInjLdr::mfRawRMTH);

ICONDATA ico;
UINT ResSize = 0;
Expand Down Expand Up @@ -418,7 +421,7 @@ int _stdcall InjectProcess(HANDLE hProcess, DWORD ProcessID)
{
CArr<BYTE> DllData;
wchar_t DllPath[MAX_PATH];
UINT Flags = InjFlags|InjLdr::mfRawMod|fmCryHdr|fmCryImp|fmCryExp|fmCryRes; // TODO: Inject method to cfg (Separated)
UINT Flags = InjFlags|NInjLdr::mfRawMod|NPEFMT::fmCryHdr|NPEFMT::fmCryImp|NPEFMT::fmCryExp|NPEFMT::fmCryRes; // TODO: Inject method to cfg (Separated)
UINT ResSize = 0;
PVOID InjLib = NULL;
NSTR::StrCopy(DllPath, StartUpDir);
Expand All @@ -438,7 +441,7 @@ int _stdcall InjectProcess(HANDLE hProcess, DWORD ProcessID)
else InjLib = GetResource(hInst, "InjLib", RT_RCDATA, &ResSize);
if(!InjLib || !ResSize){DBGMSG("No InjLib found!"); return -1;}
bool POpened = (hProcess == NULL);
if(POpened)hProcess = InjLdr::OpenRemoteProcess(ProcessID, Flags, SuspendProc);
if(POpened)hProcess = NInjLdr::OpenRemoteProcess(ProcessID, Flags, SuspendProc);
if(!hProcess)return -2;
if(SuspendProc)
{
Expand All @@ -450,8 +453,8 @@ int _stdcall InjectProcess(HANDLE hProcess, DWORD ProcessID)
}
else hLstProc = hProcess;
}
if(!POpened && NNTDLL::IsWinXPOrOlder())Flags &= ~InjLdr::mfRawRMTH; // On Windows XP this Csr unfriendly thread will catch a process initialization APC! // A DebugApi remote thread will also catch this APC and DebugApi threas is also not registered with Csr // On latest Win10 raw threads can`t be injected in notepad.exe (Access Denied)
int res = InjLdr::InjModuleIntoProcessAndExec(hProcess, InjLib, ResSize, Flags|InjLdr::mfResSyscall, 3, NULL, NULL, NtDllBase, 0x10000); // mfResSyscall is required to avoid self interception // Only .text(Data merged), .bss and .rdata
if(!POpened && NNTDLL::IsWinXPOrOlder())Flags &= ~NInjLdr::mfRawRMTH; // On Windows XP this Csr unfriendly thread will catch a process initialization APC! // A DebugApi remote thread will also catch this APC and DebugApi threas is also not registered with Csr // On latest Win10 raw threads can`t be injected in notepad.exe (Access Denied)
int res = NInjLdr::InjModuleIntoProcessAndExec(hProcess, InjLib, ResSize, Flags|NInjLdr::mfResSyscall, 3, NULL, NULL, NtDllBase, 0x10000); // mfResSyscall is required to avoid self interception // Only .text(Data merged), .bss and .rdata
if(POpened && !SuspendProc)CloseHandle(hProcess); // Close after OpenRemoteProcess
if(res < 0){DBGMSG("InjModuleIntoProcessAndExec failed with %i",res); if(SuspendProc)NtResumeProcess(hProcess); return -3;} // Cannot terminate without a specific permission
for(int ctr=WaitForInj;ctr > 0;ctr-=100)
Expand Down
7 changes: 1 addition & 6 deletions XDbgPlugin/XDbgPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <intrin.h>
#include "Utils.h"
#include "UniHook.hpp"
#include "NtDllEx.hpp"
#include "GhostDbg.hpp"
#include "InjDllLdr.hpp"
#include "Common.hpp"

//====================================================================================
#define CFGSECNAME L"Parameters"
Expand Down
5 changes: 3 additions & 2 deletions XDbgPlugin/XDbgPlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,9 @@ copy /Y "$(OutDir)$(TargetName)$(TargetExt)" "$(SolutionDir)BUILD\RELEASE\$(Solu
<ClCompile Include="XDbgPlugin.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\COMMON\FormatPE.h" />
<ClInclude Include="..\COMMON\HDE.h" />
<ClInclude Include="..\COMMON\Common.hpp" />
<ClInclude Include="..\COMMON\FormatPE.hpp" />
<ClInclude Include="..\COMMON\HDE.hpp" />
<ClInclude Include="..\COMMON\InjDllLdr.hpp" />
<ClInclude Include="..\COMMON\NtDllEx.hpp" />
<ClInclude Include="..\COMMON\ShMemIPC.hpp" />
Expand Down
15 changes: 9 additions & 6 deletions XDbgPlugin/XDbgPlugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@
<ClInclude Include="..\COMMON\ThirdParty\ntdll\ntdll.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\FormatPE.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\ShMemIPC.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\Utils.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\HDE.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\InjDllLdr.hpp">
<Filter>Common</Filter>
</ClInclude>
Expand All @@ -59,6 +53,15 @@
<ClInclude Include="..\COMMON\NtDllEx.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\Common.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\FormatPE.hpp">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\COMMON\HDE.hpp">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resources.rc">
Expand Down

0 comments on commit 9915705

Please sign in to comment.