Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False Positive on DllBaseChecker[32|64] #31

Open
akhribfarouk opened this issue Jan 11, 2021 · 0 comments
Open

False Positive on DllBaseChecker[32|64] #31

akhribfarouk opened this issue Jan 11, 2021 · 0 comments

Comments

@akhribfarouk
Copy link

as i said before you can avoid the False positive of the scanners by forcing the allocated memory and it worked (everytime)
this is the fix (maybe it is not sofisticated but it works like a charm):


#include <windows.h>
#include <tchar.h>
#include <winbase.h>
#include <stdio.h>
#include <stdbool.h> 
// bitness check courtesy of http://stackoverflow.com/a/12338526
// Check windows
#if _WIN32 || _WIN64
#if _WIN64
#define ENV64BIT
#else
#define ENV32BIT
#endif
#endif
// Check GCC
#if __GNUC__
#if __x86_64__ || __ppc64__
#define ENV64BIT
#else
#define ENV32BIT
#endif
#endif
#define AllotOff_MEM 100000000
int main() {
	DWORD written_b = 0;
	HANDLE hStdOut = 0;
	HINSTANCE hDllBase = 0;
	LPWSTR* szArglist;
	char buffer[50];
	int nArgs;
	hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
	if (nArgs > 1) {
		GetFileAttributesW(szArglist[1]); // from winbase.h
		if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(szArglist[1]) && GetLastError() == ERROR_FILE_NOT_FOUND)
		{
			char cFileNotFound[] = "DLL not found?\n";
			WriteFile(hStdOut, cFileNotFound, strlen(cFileNotFound), &written_b, 0);
			return 0;
		}
		else {
			// suppress output of popups (Entry Point not found etc.)
			UINT oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
			SetErrorMode(oldErrorMode | SEM_FAILCRITICALERRORS);
			hDllBase = LoadLibraryW(szArglist[1]);

		}
	}
	else {
		char output[] = "Usage: DllBaseChecker[32|64].exe <dll_to_load>";
		WriteFile(hStdOut, output, strlen(output), &written_b, 0);
		return 0;
	}
#if defined(ENV64BIT)
	bool a = true;
	bool b = false;
	int	s, l = 0;
	char * memdmp = NULL;
	//ByPassing the False Positive here because it is to much for the memory but not the CPU.
	memdmp = (char *)malloc(AllotOff_MEM);
	if (a != false)
	{
		goto zone_two;
		for (s = 0; s < 100000; s++)
		{
			l += s;
		}
	}
zone_three:
	if (memdmp != NULL)
	{
	if (sizeof(void*) != 8)
	{
		wprintf(L"ENV64BIT: Error: pointer should be 8 bytes. Exiting.");
		return 0;
		b = true;
	}
	else {
		sprintf(buffer, "DLL loaded at: 0x%llx\n", hDllBase);
		WriteFile(hStdOut, buffer, strlen(buffer), &written_b, 0);
		b = true;
	}
	}
zone_two:
	if (b != true)
	{
		for (s = 0; s < 100000; s++)
		{
			l += s;
		}
		goto zone_three;
	}
	return 0;
#elif defined (ENV32BIT)
	bool a = true;
	bool b = false;
	int	s,l = 0;
	char * memdmp = NULL;
	memdmp = (char *)malloc(AllotOff_MEM);
	if (a!=false)
	{
		goto zone_two;
		for (s=0;s<100000;s++)
		{
			l += s;
		}
	}
	zone_three:
	if (memdmp != NULL)
	{
		if (sizeof(void*) != 4)
		{
			wprintf(L"ENV32BIT: Error: pointer should be 4 bytes. Exiting.");
			b = true;
			return 0;
		}
		else {
			sprintf(buffer, "DLL loaded at: 0x%x\n", (unsigned int)hDllBase);
			WriteFile(hStdOut, buffer, strlen(buffer), &written_b, 0);
			b = true;
		}
	}
zone_two:
	if (b!=true)
	{
		for (s = 0; s < 100000; s++)
		{
			l += s;
		}
		goto zone_three;
	}
#else
#error "Must define either ENV32BIT or ENV64BIT".
#endif
	return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant