From 4f8544cfca8e40ab11090e4f3097a4a080bc0382 Mon Sep 17 00:00:00 2001 From: OJ Date: Thu, 23 Apr 2020 15:32:52 +1000 Subject: [PATCH] Slight make tweak and removal of some verbose debug stuff --- c/meterpreter/make-cmake.bat | 8 +++---- c/meterpreter/source/screenshot/bmp2jpeg.c | 13 ------------ c/meterpreter/source/screenshot/screenshot.c | 22 -------------------- 3 files changed, 4 insertions(+), 39 deletions(-) diff --git a/c/meterpreter/make-cmake.bat b/c/meterpreter/make-cmake.bat index 8512a2e3..75c979a2 100644 --- a/c/meterpreter/make-cmake.bat +++ b/c/meterpreter/make-cmake.bat @@ -80,12 +80,12 @@ IF "%BUILD_64%" == "Y" ( @ECHO ==================================================================================== @ECHO == Generating "%VS_TITLE%" w/ %PTS_VER% on x64 ^(Trace: %TRACE_MSG%^) @ECHO ==================================================================================== - cmake -G "%VS_TITLE%" -A x64 -T %PTS_VER% -S workspace -B workspace\build\%VS_VER%\x64 -Wno-dev -DBUILD_SNIFFER=%SNIFFER% -DDBGTRACE=%DBGTRACE% -DDBGTRACE_VERBOSE=%DBGTRACE_VERBOSE% + cmake -G "%VS_TITLE%" -A x64 -T %PTS_VER% -S workspace -B workspace\build\%VS_VER%_%PTS_VER%\x64 -Wno-dev -DBUILD_SNIFFER=%SNIFFER% -DDBGTRACE=%DBGTRACE% -DDBGTRACE_VERBOSE=%DBGTRACE_VERBOSE% if "%DO_BUILD%" == "Y" ( @ECHO ==================================================================================== @ECHO == Building "%VS_TITLE%" w/ %PTS_VER% on x64 @ECHO ==================================================================================== - cmake --build workspace\build\%VS_VER%\x64 --config Release --clean-first -- /p:XPDeprecationWarning=false + cmake --build workspace\build\%VS_VER%_%PTS_VER%\x64 --config Release --clean-first -- /p:XPDeprecationWarning=false ) ) @@ -93,12 +93,12 @@ IF "%BUILD_86%" == "Y" ( @ECHO ==================================================================================== @ECHO == Generating "%VS_TITLE%" w/ %PTS_VER% on x86 ^(Trace: %TRACE_MSG%^) @ECHO ==================================================================================== - cmake -G "%VS_TITLE%" -A Win32 -T %PTS_VER% -S workspace -B workspace\build\%VS_VER%\Win32 -Wno-dev -DBUILD_SNIFFER=%SNIFFER% -DDBGTRACE=%DBGTRACE% -DDBGTRACE_VERBOSE=%DBGTRACE_VERBOSE% + cmake -G "%VS_TITLE%" -A Win32 -T %PTS_VER% -S workspace -B workspace\build\%VS_VER%_%PTS_VER%\Win32 -Wno-dev -DBUILD_SNIFFER=%SNIFFER% -DDBGTRACE=%DBGTRACE% -DDBGTRACE_VERBOSE=%DBGTRACE_VERBOSE% if "%DO_BUILD%" == "Y" ( @ECHO ==================================================================================== @ECHO == Building "%VS_TITLE%" w/ %PTS_VER% on x86 @ECHO ==================================================================================== - cmake --build workspace\build\%VS_VER%\Win32 --config Release --clean-first -- /p:XPDeprecationWarning=false + cmake --build workspace\build\%VS_VER%_%PTS_VER%\Win32 --config Release --clean-first -- /p:XPDeprecationWarning=false ) ) diff --git a/c/meterpreter/source/screenshot/bmp2jpeg.c b/c/meterpreter/source/screenshot/bmp2jpeg.c index dffbd46d..0190197b 100644 --- a/c/meterpreter/source/screenshot/bmp2jpeg.c +++ b/c/meterpreter/source/screenshot/bmp2jpeg.c @@ -745,8 +745,6 @@ int bmp2jpeg(HBITMAP hBmp, HDC hDC, int quality, BYTE ** buf_jpeg, DWORD * buf_j cClrBits = 24; else cClrBits = 32; - dprintf("[SCREENSHOT bmptojpeg] Debug 1"); - // Allocate memory for the BITMAPINFO structure. (This structure // contains a BITMAPINFOHEADER structure and an array of RGBQUAD // data structures.) @@ -800,7 +798,6 @@ int bmp2jpeg(HBITMAP hBmp, HDC hDC, int quality, BYTE ** buf_jpeg, DWORD * buf_j return 0; } - dprintf("[SCREENSHOT bmptojpeg] Debug 2"); hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M" // Compute the size of the entire file. hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + @@ -837,7 +834,6 @@ int bmp2jpeg(HBITMAP hBmp, HDC hDC, int quality, BYTE ** buf_jpeg, DWORD * buf_j * We need to provide some value for jpeg_set_defaults() to work. */ - dprintf("[SCREENSHOT bmptojpeg] Debug 3"); cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ @@ -850,7 +846,6 @@ int bmp2jpeg(HBITMAP hBmp, HDC hDC, int quality, BYTE ** buf_jpeg, DWORD * buf_j /* Read the input file header to obtain file size & colorspace. */ start_input_bmp(&cinfo, src_mgr); - dprintf("[SCREENSHOT bmptojpeg] Debug 4"); jpeg_default_colorspace(&cinfo); @@ -858,18 +853,14 @@ int bmp2jpeg(HBITMAP hBmp, HDC hDC, int quality, BYTE ** buf_jpeg, DWORD * buf_j /* Go GRAYSCALE */ //jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE); /* Quality */ - dprintf("[SCREENSHOT bmptojpeg] Debug 4A"); jpeg_set_quality(&cinfo, quality, FALSE); // Write the compressed JPEG to memory: bug_jpeg - dprintf("[SCREENSHOT bmptojpeg] Debug 4B"); jpeg_mem_dest(&cinfo, buf_jpeg, buf_jpeg_size); /* Start compressor */ - dprintf("[SCREENSHOT bmptojpeg] Debug 4C"); jpeg_start_compress(&cinfo, TRUE); - dprintf("[SCREENSHOT bmptojpeg] Debug 5"); /* Process data */ while (cinfo.next_scanline < cinfo.image_height) { num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); @@ -877,13 +868,9 @@ int bmp2jpeg(HBITMAP hBmp, HDC hDC, int quality, BYTE ** buf_jpeg, DWORD * buf_j } /* Finish compression and release memory */ - dprintf("[SCREENSHOT bmptojpeg] Debug 6"); (*src_mgr->finish_input) (&cinfo, src_mgr); - dprintf("[SCREENSHOT bmptojpeg] Debug 7"); jpeg_finish_compress(&cinfo); - dprintf("[SCREENSHOT bmptojpeg] Debug 8"); jpeg_destroy_compress(&cinfo); - dprintf("[SCREENSHOT bmptojpeg] Debug 9"); // Free memory. GlobalFree((HGLOBAL)lpBits); diff --git a/c/meterpreter/source/screenshot/screenshot.c b/c/meterpreter/source/screenshot/screenshot.c index ece08e2e..dcd262f9 100644 --- a/c/meterpreter/source/screenshot/screenshot.c +++ b/c/meterpreter/source/screenshot/screenshot.c @@ -83,9 +83,7 @@ DWORD screenshot(int quality, DWORD dwPipeName) do { - dprintf("[SCREENSHOT] Debug 1"); _snprintf_s(cNamedPipe, sizeof(cNamedPipe), MAX_PATH, "\\\\.\\pipe\\%08X", dwPipeName); - dprintf("[SCREENSHOT] Debug 2"); os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); @@ -93,7 +91,6 @@ DWORD screenshot(int quality, DWORD dwPipeName) { BREAK_ON_ERROR("[SCREENSHOT] screenshot: GetVersionEx failed") } - dprintf("[SCREENSHOT] Debug 3"); // On NT we cant use SM_CXVIRTUALSCREEN/SM_CYVIRTUALSCREEN. if (os.dwMajorVersion <= 4) @@ -102,15 +99,12 @@ DWORD screenshot(int quality, DWORD dwPipeName) ymetric = SM_CYSCREEN; } - dprintf("[SCREENSHOT] Debug 4"); // open the WinSta0 as some services are attached to a different window station. hWindowStation = OpenWindowStationA("WinSta0", FALSE, WINSTA_ALL_ACCESS); - dprintf("[SCREENSHOT] Debug 5"); if (!hWindowStation) { if (RevertToSelf()) { - dprintf("[SCREENSHOT] Debug 6"); hWindowStation = OpenWindowStationA("WinSta0", FALSE, WINSTA_ALL_ACCESS); } } @@ -123,44 +117,36 @@ DWORD screenshot(int quality, DWORD dwPipeName) // get the current process's window station so we can restore it later on. hOrigWindowStation = GetProcessWindowStation(); - dprintf("[SCREENSHOT] Debug 7"); // set the host process's window station to this sessions default input station we opened if (!SetProcessWindowStation(hWindowStation)) BREAK_ON_ERROR("[SCREENSHOT] screenshot: SetProcessWindowStation failed"); // grab a handle to the default input desktop (e.g. Default or WinLogon) - dprintf("[SCREENSHOT] Debug 8"); hInputDesktop = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED); if (!hInputDesktop) BREAK_ON_ERROR("[SCREENSHOT] screenshot: OpenInputDesktop failed"); // get the threads current desktop so we can restore it later on - dprintf("[SCREENSHOT] Debug 9"); hOrigDesktop = GetThreadDesktop(GetCurrentThreadId()); // set this threads desktop to that of this sessions default input desktop on WinSta0 - dprintf("[SCREENSHOT] Debug 10"); SetThreadDesktop(hInputDesktop); // and now we can grab a handle to this input desktop - dprintf("[SCREENSHOT] Debug 11"); hDesktopWnd = GetDesktopWindow(); // and get a DC from it so we can read its pixels! - dprintf("[SCREENSHOT] Debug 12"); hdc = GetDC(hDesktopWnd); if (!hdc) BREAK_ON_ERROR("[SCREENSHOT] screenshot. GetDC failed"); // back up this DC with a memory DC - dprintf("[SCREENSHOT] Debug 13"); hmemdc = CreateCompatibleDC(hdc); if (!hmemdc) BREAK_ON_ERROR("[SCREENSHOT] screenshot. CreateCompatibleDC failed"); // calculate the width and height - dprintf("[SCREENSHOT] Debug 14"); sx = GetSystemMetrics(xmetric); sy = GetSystemMetrics(ymetric); @@ -168,20 +154,17 @@ DWORD screenshot(int quality, DWORD dwPipeName) // prevent breaking functionality on <= NT 4.0 if (os.dwMajorVersion >= 4) { - dprintf("[SCREENSHOT] Debug 14"); sxpos = GetSystemMetrics(SM_XVIRTUALSCREEN); sypos = GetSystemMetrics(SM_YVIRTUALSCREEN); } // and create a bitmap - dprintf("[SCREENSHOT] Debug 15"); hbmp = CreateCompatibleBitmap(hdc, sx, sy); if (!hbmp) BREAK_ON_ERROR("[SCREENSHOT] screenshot. CreateCompatibleBitmap failed"); // this bitmap is backed by the memory DC - dprintf("[SCREENSHOT] Debug 16"); if (!SelectObject(hmemdc, hbmp)) BREAK_ON_ERROR("[SCREENSHOT] screenshot. SelectObject failed"); @@ -189,11 +172,9 @@ DWORD screenshot(int quality, DWORD dwPipeName) // screenshot all available monitors by default HMODULE user32 = NULL; - dprintf("[SCREENSHOT] Debug 17"); if ((user32 = LoadLibraryA("user32"))) { - dprintf("[SCREENSHOT] Debug 18"); FARPROC SPDA = GetProcAddress(user32, "SetProcessDPIAware"); if (SPDA) { @@ -201,16 +182,13 @@ DWORD screenshot(int quality, DWORD dwPipeName) } FreeLibrary(user32); } - dprintf("[SCREENSHOT] Debug 19"); if (!StretchBlt(hmemdc, 0, 0, sx, sy, hdc, sxpos, sypos, GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN), SRCCOPY)) BREAK_ON_ERROR("[SCREENSHOT] screenshot. StretchBlt failed"); // finally convert the BMP we just made into a JPEG... - dprintf("[SCREENSHOT] Debug 20"); if (bmp2jpeg(hbmp, hmemdc, quality, &pJpegBuffer, &dwJpegSize) != 1) BREAK_WITH_ERROR("[SCREENSHOT] screenshot. bmp2jpeg failed", ERROR_INVALID_HANDLE); - dprintf("[SCREENSHOT] Debug 21"); // we have succeded dwResult = ERROR_SUCCESS;