c# - 是否可以限制远程机器连接到 NamedPipeServerStream?

标签 c# remote-access named-pipes

我想知道是否可以限制远程机器访问服务器中的命名管道。 我正在按如下方式初始化服务器:

 NamedPipeServerStream pipeServer = new NamedPipeServerStream("myPipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances,  PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

远程客户端做:

 using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(serverIP, "myPipe", PipeDirection.InOut))
{
    pipeStream.Connect(2000);
}

当然成功了。 有没有办法限制它? 谢谢!

最佳答案

找到了! 您需要限制 NT AUTHORITY\NETWORK 的使用:

PipeSecurity PipeSecurity = new PipeSecurity();            
        PipeAccessRule AccessRule = new PipeAccessRule(@"NT AUTHORITY\NETWORK", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Deny);
        PipeSecurity.AddAccessRule(AccessRule);
        PipeAccessRule AccessRule2 = new PipeAccessRule(string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName), PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
        PipeSecurity.AddAccessRule(AccessRule2);

然后将其添加到构造函数中:

 NamedPipeServerStream m_PipeServer = new NamedPipeServerStream("myPipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 0, PipeSecurity);

请注意,在使用管道安全性时,仅仅拒绝网络访问是不够的,但您需要允许应该使用该管道的当前用户(或多个用户)访问。

 string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName)

关于c# - 是否可以限制远程机器连接到 NamedPipeServerStream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30079374/

相关文章:

c# - 输入不是有效的 Base64 字符串,因为它包含非 Base 64 字符

c# - .NET DLL/EXE PE 是否符合要求?

mysql - Amazon Web 服务远程 mysql 访问被拒绝 'user' @'localhost' ubuntu 16.04 服务器

c - 使用 select() 和 O_NONBLOCK 从 FIFO 读取两个连续写入

C# c++ 命名管道连接

c# - 如何隐式转换反射方法调用

c# - 如何定期截断 Microsoft Azure 上的 SQL 数据库

r - 如何在远程服务器上轻松执行R命令?

.net - 远程控制/调试 .NET 应用程序的最佳方法是什么?

c++ - 是否有内置机制,以便在缓冲区不足时写入管道的字节可以覆盖较早的字节?