Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows...

46
using System.NetCore ; var service = CustomWindowsServices.Create ( config ); service.Run (); Christopher Brown Output : CS7036: There is no argument given t Creating Windows Services with .NET Core

Transcript of Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows...

Page 1: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

using System.NetCore;

var service = CustomWindowsServices.Create(config);service.Run();

Christopher Brown

Output:

CS7036: There is no argument given t

Creating Windows Services with .NET Core

Page 2: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Who Am I Who Am I?Developer: Smart Data

IT Support: The Little Woodshop on Main

Former NSA Cyber Intel

Page 3: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

What Are Windows Service?Windows ≈ Daemons

- a process that runs in the background- non interactive - no direct control terminal

Equivalent in other OS- Windows: Service- macOS: Daemon- Linux: Daemon

System Service Management- Windows: Service Control Manager- macOS: launchd- Linux: systemd

Page 4: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Service Control Manager[run] => services.msc

Page 5: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Examples of Services- Updaters- DNS Client Service- System Monitoring- Job Scheduler

- KEY LOGGERS- MALWARE- SPYWARE- VIRUSES

Page 6: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Vista Service HardeningSession 0 Isolation- Prevent Shatter Attacks

Running with Least Privilege

Restricted Network Access

Service Isolation- Service Identity [SID]

Session Isolation prevents malicious services obtaining elevated permissions

Page 7: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

AD

Session 0 Isolation and Shatter Attacks

USER

SERVICE {ADMIN}

SYSTEM

ADMIN

Session 0Message

Loop Shatter Attack

Page 8: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Session 0 Isolation and Shatter Attacks

USER

SERVICE {SYSTEM}

SERVICE {LOCAL}

ADMIN SERVICE {NETWORK}

LOCAL

Session 1Message

Loop Shatter Attack

Def Con 12: Brett Moore – Shoot The Messenger Using Windows Messages to Exploit Local win32

Presenter
Presentation Notes
https://www.youtube.com/watch?v=ElIsSuAZL18
Page 9: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Services in .net Framework

Page 10: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 11: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Services in .net Framework CoreWindows Compatibility Pack- provides access to framework APIs (20,000)- including Windows Services

Worker Service Template [core 3.0]- there was* no service template for core - needs some dependencies *

Page 12: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Rules and Best PracticesNO User Interface / Interaction

Remove Assert Statements

Run with Minimal User Rights- Do NOT CHANGE default logon security policy

Avoid reliance on USER profile settings

Do not bundle unrelated tasks in single service- SOLID – Single Responsibility Principle

Page 13: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Microsoft Compatibility Pack

Page 14: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 15: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 16: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 17: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 18: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 19: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 20: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 21: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 22: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 23: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Installing .net Core Service.net Framework Produces exe.net Core Produces .dll

Publish .dll to .exe- cmd.exe as Admin- Navigate to folder containing csproj- dotnet publish --configuration release

Install Service- cmd.exe as Admin- sc create [serviceName] binPath=“{location of exe}”- sc start [serviceName]

Page 24: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 25: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Uninstalling .net Core Service- sc delete [serviceName]

Page 26: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Presenter
Presentation Notes
PreProcessor Directives
Page 27: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 28: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Presenter
Presentation Notes
IsAttached is a runtime value
Page 29: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Other cmd Service Commands- sc start [serviceName]

- sc stop [serviceName]

- sc query [serviceName]

- sc

Page 30: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 31: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Topshelf

Page 32: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

TopshelfFormerly only Framework

.net Core Compatible- v4.1- 9/19/2018

Requires Compatibility Pack

Page 33: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 34: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 35: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 36: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 37: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Topshelf Installer

Publish .dll to .exe- cmd.exe as Admin- Navigate to folder containing csproj- dotnet publish -r win-x64 -c release

- r: runtime win-x64- c: configuration Release

Install Service- cmd.exe as Admin- Navigate to folder containing published exe- {serviceExe} install- {serviceExe} start- {serviceExe} stop

Page 38: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Worker Service Template

Page 39: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

Worker ServiceCreates ASP.NET Core Worker Service Template- uses IHostedService- need Microsoft.Extensions.Hosting.WindowsServices

- exposes OnStart() OnStop() from ServiceBase

Page 40: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 41: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 42: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 43: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 44: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running
Page 45: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

ReviewWhat a Windows Service is

Service Control Manager

Brief History

.net Framework Template

.net Core Long Hand => Compatibility Pack

.net Core Short Hand => Topshelf

.net Core New Hotness => Worker Service Template

Page 46: Output: Creating Windows Services with .NET Core · Former NSA Cyber Intel. What Are Windows Service? ... Vista Service Hardening Session 0 Isolation - Prevent Shatter Attacks Running

?

Github / LinkedIn: cdbrown0032 Email: [email protected]