Live data from Hacker News

Named Pipes in .NET 6 with Tray Icon and Service

erikengberg.com

31–40 of 54 posts

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

#31
post #24

Earlier quoted context omitted.

Good to address the security aspects of named pipe. However none of those describes how to secure the server. The server needs to call ImpersonateNamedPipeClient() on the incoming client connection to assume the client’s security token, that would lower the server’s privilege to the level of the client. That’s it! A guest level client can connect to the server. The server’s privilege becomes guest, and cannot access…

FWIW, the project in the article is explicitly intended to allow privilege elevation: "You have an application which runs in user context, without any administrative rights, and you need to perform some tasks which requires higher privileges."

The server can do whatever it needs to do in its higher privilege. Just when it interacts with the client connection, it lowers its privilege to the client's level. It gets the incoming data, sanitizes it, and reverts back to higher privilege to do the work. This minimizes the attack surface to the area dealing with client interaction, not the whole server. The server might link in a 3rd party XML library to sanitizes the incoming data and you don't know what the library can do. Running that in the client privilege level ensures that whatever it does only under the client's privilege.

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

#32
post #24

Earlier quoted context omitted.

Good to address the security aspects of named pipe. However none of those describes how to secure the server. The server needs to call ImpersonateNamedPipeClient() on the incoming client connection to assume the client’s security token, that would lower the server’s privilege to the level of the client. That’s it! A guest level client can connect to the server. The server’s privilege becomes guest, and cannot access…

FWIW, the project in the article is explicitly intended to allow privilege elevation: "You have an application which runs in user context, without any administrative rights, and you need to perform some tasks which requires higher privileges."

[deleted]

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

#33
post #31

Earlier quoted context omitted.

FWIW, the project in the article is explicitly intended to allow privilege elevation: "You have an application which runs in user context, without any administrative rights, and you need to perform some tasks which requires higher privileges."

The server can do whatever it needs to do in its higher privilege. Just when it interacts with the client connection, it lowers its privilege to the client's level. It gets the incoming data, sanitizes it, and reverts back to higher privilege to do the work. This minimizes the attack surface to the area dealing with client interaction, not the whole server. The server might link in a 3rd party XML library to sanitize…

That thread still has higher privilege write access to it's process's state, including the stacks of other threads that haven't impersonated that client. ImpersonateNamedPipeClient is a very leaky security barrier, and far from the only thing you need to know about when it comes to named pipe security.

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

#34
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…

So, the parent comment I replied to was in relation to needing VS 2022 for .NET 6, to which I replied that you could use Jetbrains Rider EAP, obviously for .NET 6, to accomplish the task in the linked post.

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

Obviously, they are competing with a 20+yo product.

But atleast I can get all my .NET work done on Linux without needing slow bloated VS with a ton of useless features like 'unit testing for poor code choices or legacy codebases', or 'integration with the 2nd worst collaborative tool after Jira'.

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

#35
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…

So, the parent comment I replied to was in relation to needing VS 2022 for .NET 6, to which I replied that you could use Jetbrains Rider EAP, obviously for .NET 6, to accomplish the task in the linked post. > They will ever play catch-up with platform capabilities and only offer a subset of the package. Obviously, they are competing with a 20+yo product. But atleast I can get all my .NET work done on Linux without ne…

Sure when it all boils down to the tiny .NET Core subset of ASP.NET MVC applications, instead of those 20 years of history.

Looking forward to see how they deal with MAUI and Blazor integration.

What others call bloat I call productivity features.

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

#36
post #16

Earlier quoted context omitted.

Is there a reason you do this? Curious, I havent had to setup SQL Server myself in a while so I don't know what a reasonable reason would be.

Named pipes are fast when the database is on the same box, but slower than a normal tcp connection when the database is remote. Something to do with PeekNamedPipe calls having to prepend reads.

Yeah one of my favorite SE posters talks a little more about it, generally the benefits are only there if you have app/db/sql server all on the same box.

https://dba.stackexchange.com/a/24176/15642

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

#37

I think this is the first NamedPipes tutorial in C# that I've ever seen that doesn't do things completely wrong by using a StreamWriter or StreamReader. Of course, that's because it uses another library that wraps all the tricky bits of NamedPipes that everybody always does wrong -> https://github.com/HavenDV/H.Pipes NamedPipes are sweet for doing same-machine IPC on Windows, that is for sure, but the built-in API is…

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.

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

#38
post #27

Earlier quoted context omitted.

Been using them since 1992 but at this point I would naturally turn to sockets, even on the same machine. I can't even really say why though. Named pipes are nice because they are really more like a file but at this point sockets feel more natural because they exist and are supported everywhere.

TCP server cannot assume the security context of the client, thus privilege elevation attack can easily happen.

More importantly in a lot of cases, you can ask the kernel for the client's SID as the server, and make decisions knowing that the client couldn't forge it.

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

#39

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...

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

#40

I think this is the first NamedPipes tutorial in C# that I've ever seen that doesn't do things completely wrong by using a StreamWriter or StreamReader. Of course, that's because it uses another library that wraps all the tricky bits of NamedPipes that everybody always does wrong -> https://github.com/HavenDV/H.Pipes NamedPipes are sweet for doing same-machine IPC on Windows, that is for sure, but the built-in API is…

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...

Post reply on HN