Live data from Hacker News

Named Pipes in .NET 6 with Tray Icon and Service

erikengberg.com

41–50 of 54 posts

Re: Named Pipes in .NET 6 with Tray Icon and Service

#41
post #17

Good article, but I wish the author would've addressed securing these named pipes. Consider that if a user-mode application can send messages to a privileged process (like a Windows service). What prevents any user-mode application from doing that? And if your Windows service is running as "NT_AUTHORITY/SYSTEM" and even executes privileged commands, well you might find you've got a simple privilege escalation vuln. R…

I've worked on apps like this, and I didn't know or care which user was going to use the features requiring elevation. So I couldn't manage permissions per user. My approach to security was to simply limit the input (method parameters usually) from the unprivileged process. For example, not letting the client send arbitrary commands to execute, use filesystem path whitelists, only elevate when required, etc. If the p…

This is generally how I've approached this problem as well. I like using the `ServiceController.ExecuteCommand` method and just send some integer value from the client -> server...and the server maps the integer value to a pre-determined command.

https://docs.microsoft.com/en-us/dotnet/api/system.servicepr...

You've definitely outlined the risk clearly of allowing a client to specify anything arbitrarily.

I once wrote a sudo implementation for Windows Vista / Windows 7 and first attempt used named pipes communicating to a windows service that did some token manipulation to execute things as the user (but with elevated token attached as well). There be (security) dragons.

I like using named pipes and they are a great IPC mechanism for communicating amongst processes of the same privilege level. I would not use them for message passing between processes of different privilege levels.

Re: Named Pipes in .NET 6 with Tray Icon and Service

#42
post #21
post #17

Good article, but I wish the author would've addressed securing these named pipes. Consider that if a user-mode application can send messages to a privileged process (like a Windows service). What prevents any user-mode application from doing that? And if your Windows service is running as "NT_AUTHORITY/SYSTEM" and even executes privileged commands, well you might find you've got a simple privilege escalation vuln. R…

Thanks! That’s very valid feedback. Could be my next write up.

You're welcome. An alternative I've used to named pipes among processes of different privilege levels is to build the service to listen for custom commands sent to it. These are just integers, and the service maps those to pre-defined commands.

Then the only thing the user-mode application can send are just flags (integers) that the service has already pre-determined what it will do in response.

Here's an article: https://www.codeproject.com/Articles/24434/How-to-Write-Wind...

And here's a succinct example: https://stackoverflow.com/a/5805700

Re: Named Pipes in .NET 6 with Tray Icon and Service

#43
post #42
post #21

Earlier quoted context omitted.

Thanks! That’s very valid feedback. Could be my next write up.

You're welcome. An alternative I've used to named pipes among processes of different privilege levels is to build the service to listen for custom commands sent to it. These are just integers, and the service maps those to pre-defined commands. Then the only thing the user-mode application can send are just flags (integers) that the service has already pre-determined what it will do in response. Here's an article: ht…

Interesting. Didn't know about it.

Re: Named Pipes in .NET 6 with Tray Icon and Service

#44

This uses the package H.Pipes which seems to use System.Runtime.Serialization.BinaryFormatter by default; isn't this insecure?

Why is BinaryFormatter insecure? Edit: Never mind, see https://docs.microsoft.com/en-us/dotnet/standard/serializati...

It's possible to use different formatters for H.Pipes. I will probably update the post to not mislead.

Re: Named Pipes in .NET 6 with Tray Icon and Service

#45

Earlier quoted context omitted.

Can you elaborate what’s wrong with using StreamReader or StreamWriter with a np? I’ve used them before so wondering what I’m potentially doing wrong here and what’s the alternative.

It becomes an issue if the data you're reading or writing is larger than 1024 bytes and you are in PipeTransmissionMode.Message, because of some implementation details with buffers and how StreamReader/Writer handle Read/Write calls on the underlying NamedPipe(Client/Server)Stream See https://stackoverflow.com/questions/31936100/namedpipeserver...

Thanks for the info, I personally avoid the message mode and just operate on bytes so that could be why I haven't had problems with it.

Re: Named Pipes in .NET 6 with Tray Icon and Service

#47
Honest question - how relevant the skill like that nowadays with all the stuff going Web and Electron?

Are there any apps (except for creating stuff) that are being developed in a way that “server” part is running locally? It seems to me that everything goes web now and if you have a desktop it’s “just” a client for something remote?

Re: Named Pipes in .NET 6 with Tray Icon and Service

#48
I didn't use named pipes since 2010 but last time I checked named pipes are great for Inter Process Communication on the same machine. Great in terms of performance and access to a standard interface. WCF can be configured to use named pipes on local machines. Last time I checked named pipes were also available on the network and visible by other machines with some overhead.

Security can be achieved not at channel level but at message level: If cannot decrypt the message then it's not for you. At the expense of overhead you open the door for flexibility.

Ultimately it's a tool. What it matters is how you use it. Definitely better than using shared memory for IPC. Files are by default not secured either. Anyone can write into it.

Re: Named Pipes in .NET 6 with Tray Icon and Service

#49
post #29

Earlier quoted context omitted.

Pretty sure there isn't anything you can't do in Jetbrains Rider EAP. Edit: would like to know why I'm being downvoted.

- Debugging across .NET and C++ on the same solution. - Create a architecture diagram out of .NET and native compiled code. - Integration with SharePoint and Dynamix SDKs - SQL Server and Azure SDKs - Using the Fakes mocking framework for MSIL rewriting - Debugging the GPU shaders Just a couple of examples, I can take plenty more out of VS enterprise. I really don't get how people can think JetBrains does better than…

> They will ever play catch-up with platform capabilities and only offer a subset of the package.

Having used both Visual Studio and Rider for many years now, one is definitely playing catch up but I’m not convinced it’s Rider.

There is an equally long list of things that Rider does and VS doesn’t. There’s a reason Resharper for Visual Studio is so popular.

I’m fond of Visual Studio but using Rider on macOS instead of VS on Windows is a much nicer experience for my .NET development (and I know it’s subjective).

Also worth bearing in mind Rider’s cost vs VS Enterprise’s eye-watering licence fees.

Re: Named Pipes in .NET 6 with Tray Icon and Service

#50
post #29

Earlier quoted context omitted.

- Debugging across .NET and C++ on the same solution. - Create a architecture diagram out of .NET and native compiled code. - Integration with SharePoint and Dynamix SDKs - SQL Server and Azure SDKs - Using the Fakes mocking framework for MSIL rewriting - Debugging the GPU shaders Just a couple of examples, I can take plenty more out of VS enterprise. I really don't get how people can think JetBrains does better than…

> They will ever play catch-up with platform capabilities and only offer a subset of the package. Having used both Visual Studio and Rider for many years now, one is definitely playing catch up but I’m not convinced it’s Rider. There is an equally long list of things that Rider does and VS doesn’t. There’s a reason Resharper for Visual Studio is so popular. I’m fond of Visual Studio but using Rider on macOS instead o…

All well and good, if .NET was actually 100% 20 years of portable history without Microsoft/Windows specific tooling.

Borland taught me what it means to always being a 2nd class experience versus owning the platform tooling.

People complain about VS bloat and their answers is to put a yet another heavy weight plugin on top.

When my teammates ask me why my VS is so fast versus theirs, well I don't run Resharper.

Post reply on HN