├── Svc.rc ├── SvcEventLog.rc ├── Svc.aps ├── MSG00001.bin ├── images ├── Eventvwr.PNG └── Eventvwr2.PNG ├── SvcEventManifest.res ├── SvcEventManifest.rc ├── SvcEventManifestTEMP.BIN ├── Manifestcompile.bat ├── stdafx.cpp ├── Engine.h ├── EventLogging.h ├── Svc.h ├── .gitignore ├── Install.bat ├── SvcEventLog.mc ├── WindowsMemPageDelta.sln ├── EventLogging.cpp ├── SvcEventManifest.h ├── stdafx.h ├── WindowsMemPageDelta.cpp ├── WindowsPBI.h ├── WindowsMemPageDelta.vcxproj.filters ├── SvcEventManifest.man ├── README.md ├── Svc.cpp ├── WindowsMemPageDelta.vcxproj ├── Engine.cpp └── LICENSE /Svc.rc: -------------------------------------------------------------------------------- 1 | LANGUAGE 0x9,0x1 2 | 1 11 "MSG00409.bin" 3 | -------------------------------------------------------------------------------- /SvcEventLog.rc: -------------------------------------------------------------------------------- 1 | LANGUAGE 0x9,0x1 2 | 1 11 "MSG00409.bin" 3 | -------------------------------------------------------------------------------- /Svc.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/HEAD/Svc.aps -------------------------------------------------------------------------------- /MSG00001.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/HEAD/MSG00001.bin -------------------------------------------------------------------------------- /images/Eventvwr.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/HEAD/images/Eventvwr.PNG -------------------------------------------------------------------------------- /SvcEventManifest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/HEAD/SvcEventManifest.res -------------------------------------------------------------------------------- /images/Eventvwr2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/HEAD/images/Eventvwr2.PNG -------------------------------------------------------------------------------- /SvcEventManifest.rc: -------------------------------------------------------------------------------- 1 | LANGUAGE 0x9,0x1 2 | 1 11 "MSG00001.bin" 3 | 1 WEVT_TEMPLATE "SvcEventManifestTEMP.BIN" 4 | -------------------------------------------------------------------------------- /SvcEventManifestTEMP.BIN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/HEAD/SvcEventManifestTEMP.BIN -------------------------------------------------------------------------------- /Manifestcompile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Compiling manifest 3 | mc.exe SvcEventManifest.man 4 | echo Resouring manifest 5 | rc.exe SvcEventManifest.rc 6 | echo Linking manifest 7 | link.exe /dll /noentry /machine:x64 SvcEventManifest.res /OUT:NCCGroup-WMPD-EvtLog.dll 8 | echo Finished manifest -------------------------------------------------------------------------------- /stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // NCCGroupWindowsPatchDetector.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /Engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | #pragma once 14 | 15 | void EnumerateProcesses(); 16 | -------------------------------------------------------------------------------- /EventLogging.h: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | #pragma once 14 | #include "stdafx.h" 15 | 16 | void RegisterEvent(); 17 | void WriteEvent(LPWSTR strMessage); 18 | void WriteTotal(LPWSTR strMessage); 19 | void UnRegisterEvent(); 20 | -------------------------------------------------------------------------------- /Svc.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | A Microsoft Windows memory page delta tool 4 | 5 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 6 | 7 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 8 | 9 | https://github.com/nccgroup/WindowsMemPageDelta 10 | 11 | Released under AGPL see LICENSE for more information 12 | */ 13 | 14 | #pragma once 15 | 16 | #define LOGNAME TEXT("NCC Group Mem Delta") 17 | #define SVCNAME TEXT("NCC Group Mem Delta") 18 | 19 | VOID SvcInstall(void); 20 | VOID WINAPI SvcCtrlHandler(DWORD); 21 | VOID WINAPI SvcMain(DWORD, LPTSTR*); 22 | 23 | VOID ReportSvcStatus(DWORD, DWORD, DWORD); 24 | VOID SvcInit(DWORD, LPTSTR*); 25 | VOID SvcReportEvent(LPTSTR); 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ####################### 2 | # Visual Studio files # 3 | ####################### 4 | *.suo 5 | *.user 6 | *.sdf 7 | ipch/ 8 | .vs/ 9 | 10 | ################## 11 | # Python Ness # 12 | ################## 13 | __pycache__/ 14 | env/ 15 | *.pyc 16 | 17 | ################## 18 | # Compiled files # 19 | ################## 20 | linux/ 21 | bin/ 22 | obj/ 23 | Release/ 24 | Debug/ 25 | *.dll 26 | *.exe 27 | *.pdb 28 | *.obj 29 | *.log 30 | *.tlog 31 | *.htm 32 | *.pch 33 | watchlist.db 34 | 35 | ##################### 36 | # OS-specific files # 37 | ##################### 38 | .DS_Store 39 | .DS_Store? 40 | ._* 41 | .Spotlight-V100 42 | .Trashes 43 | Icon? 44 | ehthumbs.db 45 | Thumbs.db 46 | *.pyproj 47 | *.pyd 48 | ip2asn-v4.tsv 49 | *.tsv 50 | -------------------------------------------------------------------------------- /Install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Run this from an elevated command prompt 3 | 4 | REM ------------------------------------------- 5 | REM This is the installation 6 | REM ------------------------------------------- 7 | REM Copy the Eventlog DLL to the Windows directory 8 | copy NCCGroup-WMPD-EvtLog.dll c:\Windows\NCCGroup-WMPD-EvtLog.dll 9 | REM Copy the Main Binary 10 | copy WindowsMemPageDelta.exe c:\Windows\WindowsMemPageDelta.exe 11 | 12 | REM Create the service 13 | sc create NCCMemDelta displayname= "NCC Group Memory Delta" binpath= "\"c:\Windows\WindowsMemPageDelta.exe\" -s" start= auto 14 | REM Start the service 15 | net start NCCMemDelta 16 | 17 | REM ------------------------------------------- 18 | REM This is the Eventlog manifest 19 | REM ------------------------------------------- 20 | wevtutil install-manifest SvcEventManifest.man -------------------------------------------------------------------------------- /SvcEventLog.mc: -------------------------------------------------------------------------------- 1 | MessageIdTypedef=DWORD 2 | 3 | SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS 4 | Informational=0x1:STATUS_SEVERITY_INFORMATIONAL 5 | Warning=0x2:STATUS_SEVERITY_WARNING 6 | Error=0x3:STATUS_SEVERITY_ERROR 7 | ) 8 | 9 | 10 | FacilityNames=(System=0x0:FACILITY_SYSTEM 11 | Runtime=0x2:FACILITY_RUNTIME 12 | Stubs=0x3:FACILITY_STUBS 13 | Io=0x4:FACILITY_IO_ERROR_CODE 14 | ) 15 | 16 | LanguageNames=(English=0x409:MSG00409) 17 | 18 | ; // The following are message definitions. 19 | 20 | MessageId=0x1 21 | Severity=Error 22 | Facility=Runtime 23 | SymbolicName=SVC_ERROR 24 | Language=English 25 | An error has occurred (%2). 26 | . 27 | 28 | MessageId=0x1 29 | Severity=Informational 30 | Facility=System 31 | SymbolicName=SVC_LOG 32 | Language=English 33 | %2. 34 | . 35 | 36 | ; // A message file must end with a period on its own line 37 | ; // followed by a blank line. -------------------------------------------------------------------------------- /WindowsMemPageDelta.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30011.22 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsMemPageDelta", "WindowsMemPageDelta.vcxproj", "{6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Debug|x64.ActiveCfg = Debug|x64 17 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Debug|x64.Build.0 = Debug|x64 18 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Debug|x86.ActiveCfg = Debug|Win32 19 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Debug|x86.Build.0 = Debug|Win32 20 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Release|x64.ActiveCfg = Release|x64 21 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Release|x64.Build.0 = Release|x64 22 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Release|x86.ActiveCfg = Release|Win32 23 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {F8B71A88-D0E2-42D7-8B9C-3143EC419278} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /EventLogging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | // https://www.developer.com/net/cplus/article.php/3624581/Programming-the-Windows-Vista-Event-Log.htm 14 | // https://kallanreed.wordpress.com/2016/05/28/creating-an-etw-provider-step-by-step/ 15 | 16 | #include "stdafx.h" 17 | 18 | //first step - register the event 19 | REGHANDLE hPub = NULL; 20 | 21 | void RegisterEvent() { 22 | ULONG res = EventRegister(&NCCGROUP_MEMPAGEDELTA_PUBLISHER, NULL, NULL, &hPub); 23 | if (ERROR_SUCCESS != res) { 24 | _tprintf(_T("Could not register event\n")); 25 | } 26 | } 27 | 28 | void WriteEvent(LPWSTR strMessage) { 29 | 30 | EVENT_DATA_DESCRIPTOR opEventDesc; 31 | 32 | EventDataDescCreate(&opEventDesc, strMessage, ((ULONG)wcslen(strMessage) + 1) * sizeof(WCHAR)); 33 | 34 | ULONG res = EventWrite(hPub, &DNP_OP_EVENT, 1, &opEventDesc); 35 | if (ERROR_SUCCESS != res) { 36 | _tprintf(_T("Could not raise operational event Error = %i\n"), res); 37 | } 38 | } 39 | 40 | void WriteTotal(LPWSTR strMessage) { 41 | 42 | EVENT_DATA_DESCRIPTOR opEventDesc; 43 | 44 | EventDataDescCreate(&opEventDesc, strMessage, ((ULONG)wcslen(strMessage) + 1) * sizeof(WCHAR)); 45 | 46 | ULONG res = EventWrite(hPub, &DNP_TOT_EVENT, 1, &opEventDesc); 47 | if (ERROR_SUCCESS != res) { 48 | _tprintf(_T("Could not raise operational event Error = %i\n"), res); 49 | } 50 | } 51 | 52 | void UnRegisterEvent() { 53 | EventUnregister(hPub); 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /SvcEventManifest.h: -------------------------------------------------------------------------------- 1 | //**********************************************************************` 2 | //* This is an include file generated by Message Compiler. *` 3 | //* *` 4 | //* Copyright (c) Microsoft Corporation. All Rights Reserved. *` 5 | //**********************************************************************` 6 | #pragma once 7 | 8 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 | // Provider "NCC Group-Mem Page Delta" event count 3 10 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 11 | 12 | // Provider GUID = 9cde86c9-dfb9-463f-b2c5-71eec232a69c 13 | EXTERN_C __declspec(selectany) const GUID NCCGROUP_MEMPAGEDELTA_PUBLISHER = {0x9cde86c9, 0xdfb9, 0x463f, {0xb2, 0xc5, 0x71, 0xee, 0xc2, 0x32, 0xa6, 0x9c}}; 14 | 15 | #ifndef NCCGROUP_MEMPAGEDELTA_PUBLISHER_Traits 16 | #define NCCGROUP_MEMPAGEDELTA_PUBLISHER_Traits NULL 17 | #endif // NCCGROUP_MEMPAGEDELTA_PUBLISHER_Traits 18 | 19 | // 20 | // Channel 21 | // 22 | #define MEMPAGEDELTAOP 0x10 23 | #define MEMPAGEDELTATOT 0x11 24 | #define MEMPAGEDELTADEBUG 0x12 25 | 26 | // 27 | // Event Descriptors 28 | // 29 | EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR DNP_OP_EVENT = {0x1, 0x0, 0x10, 0x4, 0x0, 0x0, 0x8000000000000000}; 30 | #define DNP_OP_EVENT_value 0x1 31 | EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR DNP_DEBUG_EVENT = {0x2, 0x0, 0x12, 0x4, 0x0, 0x0, 0x2000000000000000}; 32 | #define DNP_DEBUG_EVENT_value 0x2 33 | EXTERN_C __declspec(selectany) const EVENT_DESCRIPTOR DNP_TOT_EVENT = {0x3, 0x0, 0x11, 0x4, 0x0, 0x0, 0x4000000000000000}; 34 | #define DNP_TOT_EVENT_value 0x3 35 | 36 | #define MSG_SimpleMessage 0xB0000001L 37 | -------------------------------------------------------------------------------- /stdafx.h: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | #pragma once 14 | 15 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later. 16 | // 0x0501 17 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 18 | #endif 19 | 20 | #include "stdafx.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "Svc.h" 33 | #include "SvcEventManifest.h" 34 | #include "EventLogging.h" 35 | #include "Engine.h" 36 | 37 | 38 | // 39 | extern bool bFirstRun; 40 | extern bool bConsole; 41 | extern bool bService; 42 | 43 | // Reimplement from Winternal.h 44 | typedef NTSTATUS (WINAPI *_NtQueryInformationProcess)( 45 | IN HANDLE ProcessHandle, 46 | IN PROCESSINFOCLASS ProcessInformationClass, 47 | OUT DWORD_PTR* ProcessInformation, 48 | IN ULONG ProcessInformationLength, 49 | OUT PULONG ReturnLength OPTIONAL 50 | ); 51 | 52 | // http://downloads.securityfocus.com/vulnerabilities/exploits/26556.c 53 | typedef PIMAGE_NT_HEADERS(NTAPI *RTLIMAGENTHEADER)(DWORD_PTR); 54 | 55 | 56 | // http://uninformed.org/index.cgi?v=6&a=3&p=2 57 | //typedef struct _IMAGE_BASE_RELOCATION { 58 | // ULONG VirtualAddress; 59 | // ULONG SizeOfBlock; 60 | // USHORT TypeOffset[1]; 61 | //} IMAGE_BASE_RELOCATION, *PIMAGE_BASE_RELOCATION; -------------------------------------------------------------------------------- /WindowsMemPageDelta.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | // Includes 14 | #include "stdafx.h" 15 | 16 | bool bService = false; 17 | bool bConsole = false; 18 | 19 | // Globals 20 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 21 | 22 | /// 23 | int _tmain(int argc, _TCHAR* argv[]) 24 | { 25 | RegisterEvent(); 26 | 27 | if (lstrcmpi(argv[1], TEXT("-i")) == 0) 28 | { 29 | fwprintf(stdout,L"Installing service\n"); 30 | SvcInstall(); 31 | return 0; 32 | } 33 | else if (lstrcmpi(argv[1], TEXT("-c")) == 0) 34 | { 35 | bConsole = true; 36 | 37 | fwprintf(stdout, L"Running ... \n"); 38 | 39 | // Loop 40 | while (true) { 41 | EnumerateProcesses(); 42 | if (bFirstRun == true) bFirstRun = false; 43 | Sleep(30000); 44 | } 45 | } 46 | else if (lstrcmpi(argv[1], TEXT("-s")) == 0) 47 | { 48 | 49 | bService = true; 50 | 51 | WriteEvent((LPWSTR)TEXT("Service Starting..")); 52 | 53 | // TO_DO: Add any additional services for the process to this table. 54 | SERVICE_TABLE_ENTRY DispatchTable[] = 55 | { 56 | { (LPWSTR)SVCNAME, (LPSERVICE_MAIN_FUNCTION)SvcMain }, 57 | { NULL, NULL } 58 | }; 59 | 60 | // This call returns when the service has stopped. 61 | // The process should simply terminate when the call returns. 62 | 63 | if (!StartServiceCtrlDispatcher(DispatchTable)) 64 | { 65 | fwprintf(stdout, L"Error doing dispatch\n"); 66 | } 67 | 68 | WriteEvent((LPWSTR)TEXT("Shutting down")); 69 | fwprintf(stdout, L"Finished service\n"); 70 | 71 | } 72 | 73 | UnRegisterEvent(); 74 | return 0; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /WindowsPBI.h: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | // http://stackoverflow.com/questions/7446887/get-command-line-string-of-64-bit-process-from-32-bit-process 14 | 15 | #pragma once 16 | #include "stdafx.h" 17 | 18 | // NtQueryInformationProcess for pure 32 and 64-bit processes 19 | typedef NTSTATUS(NTAPI *_NtQueryInformationProcess)( 20 | IN HANDLE ProcessHandle, 21 | ULONG ProcessInformationClass, 22 | OUT PVOID ProcessInformation, 23 | IN ULONG ProcessInformationLength, 24 | OUT PULONG ReturnLength OPTIONAL 25 | ); 26 | 27 | typedef NTSTATUS(NTAPI *_NtReadVirtualMemory)( 28 | IN HANDLE ProcessHandle, 29 | IN PVOID BaseAddress, 30 | OUT PVOID Buffer, 31 | IN SIZE_T Size, 32 | OUT PSIZE_T NumberOfBytesRead); 33 | 34 | // NtQueryInformationProcess for 32-bit process on WOW64 35 | typedef NTSTATUS(NTAPI *_NtWow64ReadVirtualMemory64)( 36 | IN HANDLE ProcessHandle, 37 | IN PVOID64 BaseAddress, 38 | OUT PVOID Buffer, 39 | IN ULONG64 Size, 40 | OUT PULONG64 NumberOfBytesRead); 41 | 42 | // PROCESS_BASIC_INFORMATION for pure 32 and 64-bit processes 43 | //typedef struct _PROCESS_BASIC_INFORMATION { 44 | // PVOID Reserved1; 45 | // PVOID PebBaseAddress; 46 | // PVOID Reserved2[2]; 47 | // ULONG_PTR UniqueProcessId; 48 | // PVOID Reserved3; 49 | //} PROCESS_BASIC_INFORMATION; 50 | 51 | // PROCESS_BASIC_INFORMATION for 32-bit process on WOW64 52 | // The definition is quite funky, as we just lazily doubled sizes to match offsets... 53 | typedef struct _PROCESS_BASIC_INFORMATION_WOW64 { 54 | PVOID Reserved1[2]; 55 | PVOID64 PebBaseAddress; 56 | PVOID Reserved2[4]; 57 | ULONG_PTR UniqueProcessId[2]; 58 | PVOID Reserved3[2]; 59 | } PROCESS_BASIC_INFORMATION_WOW64; 60 | 61 | //typedef struct _UNICODE_STRING { 62 | // USHORT Length; 63 | // USHORT MaximumLength; 64 | // PWSTR Buffer; 65 | //} UNICODE_STRING; 66 | 67 | typedef struct _UNICODE_STRING_WOW64 { 68 | USHORT Length; 69 | USHORT MaximumLength; 70 | PVOID64 Buffer; 71 | } UNICODE_STRING_WOW64; -------------------------------------------------------------------------------- /WindowsMemPageDelta.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;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 | {531c7a41-ee64-4cb8-bf10-6c56b6304b53} 18 | 19 | 20 | {0239c586-5244-4c31-9123-ea8a529b57b0} 21 | 22 | 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | PreBuild 63 | 64 | 65 | Install 66 | 67 | 68 | -------------------------------------------------------------------------------- /SvcEventManifest.man: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 13 | 14 | 15 | 16 | 21 | 26 | 31 | 32 | 33 | 34 | 35 | 43 | 44 | 45 | 46 | 53 | 60 | 61 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Windows Executable Memory Page Delta Reporter 2 | ====================== 3 | 4 | A Windows Service to performantly produce telemetry on new or modified Windows memory pages that are now executable every 30 seconds. 5 | 6 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 7 | 8 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 9 | 10 | https://github.com/nccgroup/WindowsMemPageDelta 11 | 12 | Released under AGPL see LICENSE for more information 13 | 14 | Blog 15 | ------------- 16 | https://research.nccgroup.com/2020/10/03/tool-windows-executable-memory-page-delta-reporter/ 17 | 18 | Hypothesis 19 | ------------- 20 | Collect enough telemetry from a Windows host or an entire estate on which processes create and change memory so its executable along with their size and you’ll be able to spot the anomalies. These anomalies may be malicious activity. 21 | 22 | Compatibility 23 | ------------- 24 | Only Windows 10 is supported / tested 25 | 26 | What it does 27 | ------------- 28 | Simply: 29 | * rapidly scans Windows processes every 30 seconds 30 | * enumerates their memory pages, protection and state 31 | * identifies differences - noting those that are now executable that were not on the previous run 32 | 33 | Performant in that 34 | * consumes a constant of about 95MB of RAM 35 | * takes about 8 seconds to run 36 | 37 | History 38 | ------------- 39 | Part of this code is based on a project I wrote back in 2014 called WindowsPatchDetector - https://github.com/olliencc/WindowsPatchDetector . This project detected changes in the .text section compared to that on disk. 40 | 41 | To do 42 | ------------- 43 | - [X] Add eventlog output 44 | - [X] Make a Windows service 45 | 46 | Command Line Options 47 | ------------- 48 | 49 | Run it as a console app 50 | ``` 51 | WindowsMemPageDelta.exe -c 52 | ``` 53 | 54 | Run it as a Windows service 55 | ``` 56 | WindowsMemPageDelta.exe -s 57 | ``` 58 | 59 | Installation 60 | ------------- 61 | The below is a batch file which can be used to install the service. 62 | 63 | ``` 64 | REM ------------------------------------------- 65 | REM This is the installation 66 | REM ------------------------------------------- 67 | REM Copy the Eventlog DLL to the Windows directory 68 | copy NCCGroup-WMPD-EvtLog.dll c:\Windows\NCCGroup-WMPD-EvtLog.dll 69 | REM Copy the Main Binary 70 | copy WindowsMemPageDelta.exe c:\Windows\WindowsMemPageDelta.exe 71 | REM Create the service 72 | sc create NCCMemDelta displayname= "NCC Group Memory Delta" binpath= "\"c:\Windows\WindowsMemPageDelta.exe\" -s" start= auto 73 | REM Start the service 74 | net start NCCMemDelta 75 | 76 | REM ------------------------------------------- 77 | REM This is the Eventlog manifest 78 | REM ------------------------------------------- 79 | wevtutil install-manifest SvcEventManifest.man 80 | ``` 81 | 82 | Logs are in Event Logging 83 | ------------- 84 | There are two buckets 85 | - Individual executable page deltas - to detect specific anomalies 86 | - Totals of executable memory per process - to aid longitudal monitoring and variance detection 87 | 88 | Individual deltas: 89 | ![Eventvwr Example for Deltas](https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/master/images/Eventvwr.PNG) 90 | 91 | Totals: 92 | ![Eventvwr Example for Totals](https://raw.githubusercontent.com/nccgroup/WindowsMemPageDelta/master/images/Eventvwr2.PNG) 93 | 94 | Output schema 95 | ------------- 96 | The schema for New delta events is: 97 | ``` 98 | TYPE,PID,Process Name,Address,Size,Protection 99 | ``` 100 | 101 | Example 102 | ``` 103 | New,32068,ServiceHub.DataWarehouseHost.exe,7ffd5b9d0000,53248,XRW.... 104 | New,32068,ServiceHub.DataWarehouseHost.exe,7ffd93f51000,69632,XR.... 105 | New,32068,ServiceHub.DataWarehouseHost.exe,7ffd97241000,1015808,XR.... 106 | New,12692,ScriptedSandbox64.exe,1e247250000,20480,X..... 107 | New,12692,ScriptedSandbox64.exe,1e2475f0000,4096,X..... 108 | New,12692,ScriptedSandbox64.exe,1e247770000,32768,X..... 109 | New,12692,ScriptedSandbox64.exe,1e2477b0000,12288,X..... 110 | New,12692,ScriptedSandbox64.exe,1e2477f0000,16384,X..... 111 | New,12692,ScriptedSandbox64.exe,1e247af0000,40960,X..... 112 | ... 113 | ``` 114 | 115 | The schema for Change delta events is: 116 | 117 | ``` 118 | TYPE,PID,Process Name,Address,Size,Protection,Previous Protection 119 | ``` 120 | 121 | ``` 122 | Changed,16008,Teams.exe,cc86df04000,503808,XR....,.RW.... 123 | Changed,16008,Teams.exe,cc86e004000,86016,XR....,.RW.... 124 | Changed,16008,Teams.exe,cc86e084000,86016,XR....,.RW.... 125 | Changed,16008,Teams.exe,cc86e104000,86016,XR....,.RW.... 126 | Changed,16008,Teams.exe,cc86e284000,503808,XR....,.RW.... 127 | Changed,16008,Teams.exe,cc86e604000,503808,XR....,.RW.... 128 | Changed,16008,Teams.exe,cc86e984000,503808,XR....,.RW.... 129 | Changed,16008,Teams.exe,cc86ea04000,503808,XR....,.RW.... 130 | Changed,16008,Teams.exe,cc86ec84000,503808,XR....,.RW.... 131 | ``` 132 | 133 | The schema for Total events is: 134 | ``` 135 | TYPE,PID,Process Name,Total Executable Memory Bytes 136 | ``` 137 | 138 | ``` 139 | Total,36904,chrome.exe,451309568 140 | Total,38772,chrome.exe,324202496 141 | Total,9508,conhost.exe,95203328 142 | Total,38808,mspdbsrv.exe,31637504 143 | Total,5292,SearchProtocolHost.exe,434233344 144 | Total,31036,chrome.exe,268713984 145 | Total,25940,chrome.exe,262905856 146 | Total,1184,Teams.exe,259481600 147 | Total,36984,conhost.exe,154443776 148 | ``` -------------------------------------------------------------------------------- /Svc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | 14 | // https://www.codeproject.com/Articles/4166/Using-MC-exe-message-resources-and-the-NT-event-lo 15 | // https://docs.microsoft.com/en-us/windows/win32/services/sample-mc 16 | // https://stackoverflow.com/questions/3026855/configure-the-message-compiler-mc-exe-as-a-custom-compiler-step-in-vc-2010 17 | 18 | #include "stdafx.h" 19 | 20 | #pragma comment(lib, "advapi32.lib") 21 | 22 | SERVICE_STATUS gSvcStatus; 23 | SERVICE_STATUS_HANDLE gSvcStatusHandle; 24 | HANDLE ghSvcStopEvent = NULL; 25 | 26 | VOID SvcInstall(void); 27 | VOID WINAPI SvcCtrlHandler(DWORD); 28 | VOID WINAPI SvcMain(DWORD, LPTSTR*); 29 | 30 | VOID ReportSvcStatus(DWORD, DWORD, DWORD); 31 | VOID SvcInit(DWORD, LPTSTR*); 32 | 33 | // 34 | // Purpose: 35 | // Installs a service in the SCM database 36 | // 37 | // Parameters: 38 | // None 39 | // 40 | // Return value: 41 | // None 42 | // 43 | VOID SvcInstall() 44 | { 45 | SC_HANDLE schSCManager; 46 | SC_HANDLE schService; 47 | TCHAR szPath[MAX_PATH]; 48 | 49 | if (!GetModuleFileName(NULL, szPath, MAX_PATH)) 50 | { 51 | printf("Cannot install service (%d)\n", GetLastError()); 52 | return; 53 | } 54 | 55 | // Get a handle to the SCM database. 56 | 57 | schSCManager = OpenSCManager( 58 | NULL, // local computer 59 | NULL, // ServicesActive database 60 | SC_MANAGER_ALL_ACCESS); // full access rights 61 | 62 | if (NULL == schSCManager) 63 | { 64 | printf("OpenSCManager failed (%d)\n", GetLastError()); 65 | return; 66 | } 67 | 68 | // Create the service 69 | 70 | schService = CreateService( 71 | schSCManager, // SCM database 72 | SVCNAME, // name of service 73 | SVCNAME, // service name to display 74 | SERVICE_ALL_ACCESS, // desired access 75 | SERVICE_WIN32_OWN_PROCESS, // service type 76 | SERVICE_DEMAND_START, // start type 77 | SERVICE_ERROR_NORMAL, // error control type 78 | szPath, // path to service's binary 79 | NULL, // no load ordering group 80 | NULL, // no tag identifier 81 | NULL, // no dependencies 82 | NULL, // LocalSystem account 83 | NULL); // no password 84 | 85 | if (schService == NULL) 86 | { 87 | printf("CreateService failed (%d)\n", GetLastError()); 88 | CloseServiceHandle(schSCManager); 89 | return; 90 | } 91 | else printf("Service installed successfully\n"); 92 | 93 | CloseServiceHandle(schService); 94 | CloseServiceHandle(schSCManager); 95 | } 96 | 97 | // 98 | // Purpose: 99 | // Entry point for the service 100 | // 101 | // Parameters: 102 | // dwArgc - Number of arguments in the lpszArgv array 103 | // lpszArgv - Array of strings. The first string is the name of 104 | // the service and subsequent strings are passed by the process 105 | // that called the StartService function to start the service. 106 | // 107 | // Return value: 108 | // None. 109 | // 110 | VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR* lpszArgv) 111 | { 112 | // Register the handler function for the service 113 | gSvcStatusHandle = RegisterServiceCtrlHandler( 114 | SVCNAME, 115 | SvcCtrlHandler); 116 | 117 | if (!gSvcStatusHandle) 118 | { 119 | // TODO Logging TEXT("RegisterServiceCtrlHandler")); 120 | return; 121 | } 122 | 123 | // These SERVICE_STATUS members remain as set here 124 | 125 | gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; 126 | gSvcStatus.dwServiceSpecificExitCode = 0; 127 | 128 | // Report initial status to the SCM 129 | 130 | ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000); 131 | 132 | // Perform service-specific initialization and work. 133 | 134 | SvcInit(dwArgc, lpszArgv); 135 | 136 | // Loop 137 | while (true) { 138 | 139 | } 140 | 141 | } 142 | 143 | // 144 | // Purpose: 145 | // The service code 146 | // 147 | // Parameters: 148 | // dwArgc - Number of arguments in the lpszArgv array 149 | // lpszArgv - Array of strings. The first string is the name of 150 | // the service and subsequent strings are passed by the process 151 | // that called the StartService function to start the service. 152 | // 153 | // Return value: 154 | // None 155 | // 156 | VOID SvcInit(DWORD dwArgc, LPTSTR* lpszArgv) 157 | { 158 | // TO_DO: Declare and set any required variables. 159 | // Be sure to periodically call ReportSvcStatus() with 160 | // SERVICE_START_PENDING. If initialization fails, call 161 | // ReportSvcStatus with SERVICE_STOPPED. 162 | 163 | // Create an event. The control handler function, SvcCtrlHandler, 164 | // signals this event when it receives the stop control code. 165 | 166 | ghSvcStopEvent = CreateEvent( 167 | NULL, // default security attributes 168 | TRUE, // manual reset event 169 | FALSE, // not signaled 170 | NULL); // no name 171 | 172 | if (ghSvcStopEvent == NULL) 173 | { 174 | ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); 175 | return; 176 | } 177 | 178 | // Report running status when initialization is complete. 179 | 180 | ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); 181 | 182 | // TO_DO: Perform work until service stops. 183 | 184 | while (1) 185 | { 186 | // Check whether to stop the service. 187 | 188 | EnumerateProcesses(); 189 | if (bFirstRun == true) bFirstRun = false; 190 | Sleep(30000); 191 | 192 | // We need to finish 193 | if (WaitForSingleObject(ghSvcStopEvent, 0) == WAIT_OBJECT_0) { 194 | ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); 195 | return; 196 | } 197 | 198 | } 199 | } 200 | 201 | // 202 | // Purpose: 203 | // Sets the current service status and reports it to the SCM. 204 | // 205 | // Parameters: 206 | // dwCurrentState - The current state (see SERVICE_STATUS) 207 | // dwWin32ExitCode - The system error code 208 | // dwWaitHint - Estimated time for pending operation, 209 | // in milliseconds 210 | // 211 | // Return value: 212 | // None 213 | // 214 | VOID ReportSvcStatus(DWORD dwCurrentState, 215 | DWORD dwWin32ExitCode, 216 | DWORD dwWaitHint) 217 | { 218 | static DWORD dwCheckPoint = 1; 219 | 220 | // Fill in the SERVICE_STATUS structure. 221 | 222 | gSvcStatus.dwCurrentState = dwCurrentState; 223 | gSvcStatus.dwWin32ExitCode = dwWin32ExitCode; 224 | gSvcStatus.dwWaitHint = dwWaitHint; 225 | 226 | if (dwCurrentState == SERVICE_START_PENDING) 227 | gSvcStatus.dwControlsAccepted = 0; 228 | else gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; 229 | 230 | if ((dwCurrentState == SERVICE_RUNNING) || 231 | (dwCurrentState == SERVICE_STOPPED)) 232 | gSvcStatus.dwCheckPoint = 0; 233 | else gSvcStatus.dwCheckPoint = dwCheckPoint++; 234 | 235 | // Report the status of the service to the SCM. 236 | SetServiceStatus(gSvcStatusHandle, &gSvcStatus); 237 | } 238 | 239 | // 240 | // Purpose: 241 | // Called by SCM whenever a control code is sent to the service 242 | // using the ControlService function. 243 | // 244 | // Parameters: 245 | // dwCtrl - control code 246 | // 247 | // Return value: 248 | // None 249 | // 250 | VOID WINAPI SvcCtrlHandler(DWORD dwCtrl) 251 | { 252 | // Handle the requested control code. 253 | 254 | switch (dwCtrl) 255 | { 256 | case SERVICE_CONTROL_STOP: 257 | ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0); 258 | 259 | // Signal the service to stop. 260 | 261 | SetEvent(ghSvcStopEvent); 262 | ReportSvcStatus(gSvcStatus.dwCurrentState, NO_ERROR, 0); 263 | 264 | return; 265 | 266 | case SERVICE_CONTROL_INTERROGATE: 267 | break; 268 | 269 | default: 270 | break; 271 | } 272 | 273 | } 274 | -------------------------------------------------------------------------------- /WindowsMemPageDelta.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 | {6AD7A22E-E4C9-4E0A-AFCF-C52A2057D741} 24 | Win32Proj 25 | WindowsMemPageDelta 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | Static 48 | 49 | 50 | Application 51 | false 52 | v142 53 | true 54 | Unicode 55 | Static 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 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 | 104 | 105 | Level3 106 | true 107 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 108 | false 109 | MultiThreadedDLL 110 | 111 | 112 | Console 113 | true 114 | Wtsapi32.lib;Psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 115 | 116 | 117 | Manifestcompile.bat 118 | 119 | 120 | Manifest compilation 121 | 122 | 123 | 124 | 125 | 126 | 127 | Level3 128 | true 129 | true 130 | true 131 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 132 | true 133 | 134 | 135 | Console 136 | true 137 | true 138 | true 139 | 140 | 141 | 142 | 143 | 144 | 145 | Level3 146 | true 147 | true 148 | true 149 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 150 | true 151 | 152 | 153 | Console 154 | true 155 | true 156 | true 157 | Wtsapi32.lib;Psapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) 158 | 159 | 160 | Manifestcompile.bat 161 | 162 | 163 | Manifest compilation 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | true 183 | true 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /Engine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | A Microsoft Windows memory page delta tool 3 | 4 | Released as open source by NCC Group Plc - http://www.nccgroup.com/ 5 | 6 | Developed by Ollie Whitehouse, ollie dot whitehouse at nccgroup dot com 7 | 8 | https://github.com/nccgroup/WindowsMemPageDelta 9 | 10 | Released under AGPL see LICENSE for more information 11 | */ 12 | 13 | // Includes 14 | #include "stdafx.h" 15 | 16 | bool bFirstRun = true; 17 | bool bVerbose = false; 18 | TCHAR strErrMsg[1024]; 19 | DWORD dwModuleRelocs = 0; 20 | HANDLE event_log = NULL; 21 | 22 | // 23 | #pragma pack(push, 1) 24 | struct procNfoStuct { 25 | DWORD PID; 26 | TCHAR Name[MAX_PATH]; 27 | unsigned long long TotalExecMem = 0; 28 | }; 29 | #pragma pack(pop) 30 | 31 | // 32 | #pragma pack(push, 1) 33 | struct procStuct 34 | { 35 | DWORD PID; 36 | unsigned long long address; 37 | unsigned long allocprotection; 38 | unsigned long long size; 39 | unsigned long protection; 40 | unsigned long state; 41 | unsigned long type; 42 | }; 43 | #pragma pack(pop) 44 | 45 | procStuct megaStruc[1000000]; 46 | procStuct megaStruc2[1000000]; 47 | unsigned long long lastEntry = 0; 48 | unsigned long long lastEntry2 = 0; 49 | 50 | procNfoStuct Procs[4098]; 51 | DWORD NumOfProcs = 0; 52 | 53 | // Manual imports 54 | _NtQueryInformationProcess __NtQueryInformationProcess = (_NtQueryInformationProcess)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQueryInformationProcess"); 55 | typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 56 | LPFN_ISWOW64PROCESS fnIsWow64Process = fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); 57 | 58 | 59 | // 60 | BOOL putinMegaStruc(DWORD dwPID, TCHAR* cProcess, ULONG64 BaseAddress, DWORD AllocationProtect, SIZE_T RegionSize, DWORD Protect, DWORD State, DWORD Type) { 61 | 62 | megaStruc[lastEntry].PID = dwPID; 63 | megaStruc[lastEntry].address = BaseAddress; 64 | megaStruc[lastEntry].allocprotection = AllocationProtect; 65 | megaStruc[lastEntry].size = RegionSize; 66 | megaStruc[lastEntry].protection = Protect; 67 | megaStruc[lastEntry].state = State; 68 | megaStruc[lastEntry].type = Type; 69 | lastEntry++; 70 | return TRUE; 71 | } 72 | 73 | // 74 | BOOL putinMegaStrucAlt(DWORD dwPID, TCHAR* cProcess, ULONG64 BaseAddress, DWORD AllocationProtect, SIZE_T RegionSize, DWORD Protect, DWORD State, DWORD Type) { 75 | 76 | megaStruc2[lastEntry2].PID = dwPID; 77 | megaStruc2[lastEntry2].address = BaseAddress; 78 | megaStruc2[lastEntry2].allocprotection = AllocationProtect; 79 | megaStruc2[lastEntry2].size = RegionSize; 80 | megaStruc2[lastEntry2].protection = Protect; 81 | megaStruc2[lastEntry2].state = State; 82 | megaStruc2[lastEntry2].type = Type; 83 | lastEntry2++; 84 | 85 | return TRUE; 86 | } 87 | 88 | CONST TCHAR* Protection(DWORD Protection) 89 | { 90 | switch (Protection) { 91 | case PAGE_EXECUTE: 92 | return L"X....."; 93 | 94 | case PAGE_EXECUTE_READ: 95 | return L"XR...."; 96 | 97 | 98 | case PAGE_EXECUTE_READWRITE: 99 | return L"XRW...."; 100 | 101 | case PAGE_NOACCESS: 102 | return L"......."; 103 | 104 | case PAGE_READONLY: 105 | return L".R....."; 106 | 107 | case PAGE_READWRITE: 108 | return L".RW...."; 109 | 110 | case PAGE_WRITECOPY: 111 | return L"..WC..."; 112 | 113 | case PAGE_GUARD: 114 | return L"....G.."; 115 | 116 | case PAGE_NOCACHE: 117 | return L".....c."; 118 | 119 | case PAGE_WRITECOMBINE: 120 | return L".....Cw"; 121 | 122 | default: 123 | return L"UKNOWN."; 124 | 125 | } 126 | 127 | 128 | 129 | } 130 | 131 | // 132 | // This calculates the total executable memory for a process 133 | // and then logs it 134 | // 135 | void calcTotals() { 136 | 137 | DWORD dwCount = 0; 138 | TCHAR logLine[4098]; 139 | 140 | while (Procs[dwCount].PID != 0) { 141 | 142 | for (DWORD dwCountInner = 0; dwCountInner < lastEntry2; dwCountInner++) { 143 | 144 | if (megaStruc2[dwCountInner].PID == Procs[dwCount].PID) { 145 | Procs[dwCount].TotalExecMem += megaStruc2[dwCountInner].size; 146 | } 147 | else if(megaStruc2[dwCountInner].PID == 0) 148 | { 149 | continue; 150 | } 151 | 152 | } 153 | 154 | _stprintf_s(logLine, TEXT("Total,%u,%s,%llu\n"), Procs[dwCount].PID, Procs[dwCount].Name, Procs[dwCount].TotalExecMem); 155 | if (bConsole == true) { 156 | _ftprintf(stdout, logLine); 157 | } 158 | WriteTotal(logLine); 159 | 160 | 161 | dwCount++; 162 | } 163 | 164 | } 165 | 166 | // 167 | // This diffs the new exec pages 168 | // and then logs it 169 | // 170 | BOOL diffMegaStrucAlt() { 171 | 172 | bool bBoing = false; 173 | TCHAR logLine[4098]; 174 | 175 | 176 | for (int count = 0; count < lastEntry2; count++) { 177 | 178 | bBoing = false; 179 | 180 | unsigned int dwPIDMatch = 0; 181 | for (dwPIDMatch = 0; dwPIDMatch < 4098; dwPIDMatch++) { 182 | if (Procs[dwPIDMatch].PID == megaStruc2[count].PID) { // this code assumes likelihood of a process being created and assuming a previous PID within 30 seconds is low 183 | break; 184 | } 185 | } 186 | 187 | // noise reduction 188 | if (dwPIDMatch == 0 || dwPIDMatch == 4098) { // New process not seen before so don't report 189 | continue; 190 | } 191 | 192 | // optimization 193 | if (megaStruc2[count].protection != PAGE_EXECUTE && megaStruc2[count].protection != PAGE_EXECUTE_READ && megaStruc2[count].protection != PAGE_EXECUTE_READWRITE) { 194 | continue; 195 | } 196 | 197 | // then fall back methods 198 | if (count < lastEntry2 && count < lastEntry && megaStruc2[count].PID == megaStruc[count].PID && megaStruc2[count].address == megaStruc[count].address && megaStruc2[count].allocprotection == megaStruc[count].allocprotection && megaStruc2[count].type == megaStruc[count].type && megaStruc2[count].state == megaStruc[count].state && megaStruc2[count].protection == megaStruc[count].protection) 199 | { 200 | 201 | continue; 202 | } 203 | else // then slow way 204 | { 205 | 206 | for (int count2 = 0; count2 < lastEntry; count2++) { 207 | 208 | if (megaStruc2[count].PID == megaStruc[count2].PID && megaStruc2[count].address == megaStruc[count2].address && megaStruc2[count].allocprotection == megaStruc[count2].allocprotection && megaStruc2[count].type == megaStruc[count2].type && megaStruc2[count].state == megaStruc[count2].state && megaStruc2[count].protection == megaStruc[count2].protection) { 209 | bBoing = true; 210 | break; // present 211 | } 212 | else if (megaStruc2[count].PID == megaStruc[count2].PID && megaStruc2[count].address == megaStruc[count2].address && megaStruc2[count].size == megaStruc[count2].size) 213 | { 214 | bBoing = true; 215 | 216 | _stprintf_s(logLine, TEXT("Changed,%u,%s,%I64x,%llu,%s,%s\n"), megaStruc2[count].PID, Procs[dwPIDMatch].Name, megaStruc2[count].address, megaStruc2[count].size, Protection(megaStruc2[count].protection), Protection(megaStruc[count2].protection)); 217 | 218 | if (bConsole == true) { 219 | _ftprintf(stdout, logLine); 220 | } 221 | 222 | WriteEvent(logLine); 223 | 224 | break; 225 | } 226 | } 227 | 228 | if (bBoing == false) { 229 | 230 | _stprintf_s(logLine, TEXT("New,%u,%s,%I64x,%llu,%s\n"), megaStruc2[count].PID, Procs[dwPIDMatch].Name, megaStruc2[count].address, megaStruc2[count].size, Protection(megaStruc2[count].protection)); 231 | 232 | if (bConsole == true) { 233 | _ftprintf(stdout, logLine); 234 | } 235 | 236 | WriteEvent(logLine); 237 | } 238 | } 239 | } 240 | 241 | // Copy across 242 | memcpy(megaStruc, megaStruc2, sizeof(megaStruc)); 243 | lastEntry = lastEntry2; 244 | 245 | // Clean up 246 | memset(megaStruc2, 0x00, sizeof(megaStruc2)); 247 | lastEntry2 = 0; 248 | 249 | return TRUE; 250 | } 251 | 252 | // 253 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms684139(v=vs.85).aspx 254 | // 255 | BOOL IsWow64() 256 | { 257 | BOOL bIsWow64 = FALSE; 258 | 259 | if (NULL != fnIsWow64Process) 260 | { 261 | if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) 262 | { 263 | return false; 264 | } 265 | } 266 | return bIsWow64; 267 | } 268 | 269 | /// 270 | /// Analyze the process and its memory regions 271 | /// 272 | /// Process ID 273 | void AnalyzeProc(DWORD dwPID) 274 | { 275 | DWORD dwRet, dwMods; 276 | HANDLE hProcess; 277 | HMODULE hModule[4096]; 278 | TCHAR cProcess[MAX_PATH]; // Process name 279 | SYSTEM_INFO sysnfoSysNFO; 280 | BOOL bIsWow64 = FALSE; 281 | BOOL bIsWow64Other = FALSE; 282 | DWORD dwRES = 0; 283 | 284 | 285 | 286 | hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwPID); 287 | if (hProcess == NULL) 288 | { 289 | if (GetLastError() == 5) { 290 | hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwPID); 291 | if (hProcess == NULL) { 292 | //fprintf(stderr, "Failed to OpenProcess(%d),%d\n", dwPID, GetLastError()); 293 | return; 294 | } 295 | } 296 | else { 297 | //fprintf(stderr, "Failed to OpenProcess(%d),%d\n", dwPID, GetLastError()); 298 | return; 299 | } 300 | } 301 | 302 | 303 | if (EnumProcessModules(hProcess, hModule, 4096 * sizeof(HMODULE), &dwRet) == 0) 304 | { 305 | if (GetLastError() == 299) { 306 | //fprintf(stderr, "64bit process and we're 32bit - sad panda! skipping PID %d\n", dwPID); 307 | } 308 | else { 309 | //fprintf(stderr, "Error in EnumProcessModules(%d),%d\n", dwPID, GetLastError()); 310 | } 311 | return; 312 | } 313 | dwMods = dwRet / sizeof(HMODULE); 314 | 315 | GetModuleBaseName(hProcess, hModule[0], cProcess, MAX_PATH); 316 | Procs[NumOfProcs].PID = dwPID; 317 | _tcscpy_s(Procs[NumOfProcs].Name, MAX_PATH, cProcess); 318 | NumOfProcs++; 319 | 320 | //PrintProcessInfo(cProcess, dwPID); 321 | 322 | if (IsWow64Process(GetCurrentProcess(), &bIsWow64)) { 323 | GetNativeSystemInfo(&sysnfoSysNFO); 324 | 325 | if (bIsWow64) 326 | { 327 | //fwprintf(stdout,L"[i] Running under WOW64 - Page Size %d\n",sysnfoSysNFO.dwPageSize); 328 | } 329 | else 330 | { 331 | //fwprintf(stdout,L"[i] Not running under WOW64 - Page Size %d\n",sysnfoSysNFO.dwPageSize); 332 | } 333 | } 334 | else { 335 | //fwprintf(stderr, L"Error in IsWow64Process(%d),%d\n", dwPID, GetLastError()); 336 | return; 337 | } 338 | 339 | // 340 | // Walk the processes address space 341 | // 342 | unsigned char* pString = NULL; 343 | 344 | ULONG_PTR addrCurrent = 0; 345 | ULONG_PTR lastBase = (-1); 346 | 347 | unsigned int iInserted = 0; 348 | 349 | for (;;) 350 | { 351 | #ifdef WIN64 352 | MEMORY_BASIC_INFORMATION64 memMeminfo; 353 | #endif 354 | #ifdef WIN32 355 | MEMORY_BASIC_INFORMATION memMeminfo; 356 | #endif 357 | VirtualQueryEx(hProcess, reinterpret_cast(addrCurrent), reinterpret_cast(&memMeminfo), sizeof(memMeminfo)); 358 | 359 | if (lastBase == (ULONG_PTR)memMeminfo.BaseAddress) { 360 | break; 361 | } 362 | 363 | lastBase = (ULONG_PTR)memMeminfo.BaseAddress; 364 | 365 | //_ftprintf(stdout, TEXT("%u,%s,%p,%lld,%u,%u\n"), dwPID, cProcess, memMeminfo.BaseAddress, memMeminfo.RegionSize, memMeminfo.Protect, memMeminfo.State); 366 | 367 | if (bFirstRun == true && memMeminfo.State == MEM_COMMIT) { 368 | putinMegaStruc(dwPID, cProcess, (ULONG64)memMeminfo.BaseAddress, memMeminfo.AllocationProtect, memMeminfo.RegionSize, memMeminfo.Protect, memMeminfo.State, memMeminfo.Type); 369 | } 370 | else if (memMeminfo.State == MEM_COMMIT) 371 | { 372 | putinMegaStrucAlt(dwPID, cProcess, (ULONG64)memMeminfo.BaseAddress, memMeminfo.AllocationProtect, memMeminfo.RegionSize, memMeminfo.Protect, memMeminfo.State, memMeminfo.Type); 373 | } 374 | else 375 | { 376 | // Skip 377 | } 378 | 379 | addrCurrent += memMeminfo.RegionSize; 380 | } 381 | 382 | CloseHandle(hProcess); 383 | } 384 | 385 | /// 386 | /// Enumerate all the processes on the system and 387 | /// pass off to the analysis function 388 | /// 389 | void EnumerateProcesses() 390 | { 391 | DWORD dwPIDArray[4096], dwRet, dwPIDS, intCount; 392 | NumOfProcs = 0; 393 | 394 | // Be clean to ensure no stale data 395 | memset(Procs, 0x00, sizeof(Procs)); 396 | 397 | // 398 | // Enumerate 399 | // 400 | if (EnumProcesses(dwPIDArray, 4096 * sizeof(DWORD), &dwRet) == 0) 401 | { 402 | DWORD dwRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, strErrMsg, 1023, NULL); 403 | if (dwRet != 0) { 404 | _ftprintf(stderr, TEXT("[!] EnumProcesses() failed - %s"), strErrMsg); 405 | } 406 | else 407 | { 408 | _ftprintf(stderr, TEXT("[!] EnumProcesses() - Error: %d\n"), GetLastError()); 409 | } 410 | return; 411 | } 412 | 413 | dwPIDS = dwRet / sizeof(DWORD); 414 | 415 | // 416 | // Analyze 417 | // 418 | for (intCount = 0; intCount < dwPIDS; intCount++) 419 | { 420 | AnalyzeProc(dwPIDArray[intCount]); 421 | } 422 | 423 | // Do the diff calc the totals 424 | // and log 425 | if (bFirstRun == false) 426 | { 427 | calcTotals(); 428 | diffMegaStrucAlt(); 429 | } 430 | 431 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------