public void Listen(string pipeName) { try { _security = new PipeSecurity(); // Allow Everyone read and write access to the pipe. _security.SetAccessRule(new PipeAccessRule("Authenticated Users", PipeAccessRights.ReadWrite, AccessControlType.Allow)); // Allow the Administrators group full access to the pipe. _security.SetAccessRule(new PipeAccessRule("Administrators", PipeAccessRights.FullControl, AccessControlType.Allow)); // Set to class level var so we can re-use in the async callback method _pipeName = pipeName; // Create the new async pipe var pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.In, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 1024, 1024, _security); // Wait for a connection pipeServer.BeginWaitForConnection(WaitForConnectionCallBack, pipeServer); _started.Set(); } catch (Exception oEx) { Debug.WriteLine(oEx.Message); } }
private PipeSecurity CreateSystemIOPipeSecurity() { var pipeSecurity = new PipeSecurity(); // Allow Everyone read and write access to the pipe. pipeSecurity.SetAccessRule( new PipeAccessRule("Authenticated Users", PipeAccessRights.ReadWrite, AccessControlType.Allow)); // Allow the Administrators group full access to the pipe. pipeSecurity.SetAccessRule( new PipeAccessRule("Administrators", PipeAccessRights.FullControl, AccessControlType.Allow)); return(pipeSecurity); }
/// <summary> /// Create Pipe /// </summary> /// <param name="pipe_name"></param> /// <returns></returns> public static NamedPipeServerStream CreatePipeWithSecurity(string pipe_name = null) { var repository = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository( Assembly.GetExecutingAssembly()); if (!repository.Configured) { throw new Exception("Log4Net repository is not configured, maybe missed file log4net.config"); } if (string.IsNullOrEmpty(pipe_name)) { pipe_name = $"log_{Process.GetCurrentProcess().Id}"; } PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); NamedPipeServerStream pipeServer = new NamedPipeServerStream(pipe_name, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, // default in buffer size 0, // default out buffer size pipeSa); return(pipeServer); }
/// <summary> /// Open a pipe to the remote process /// </summary> public ProcessManager(string pipeName, bool server) { try { mPipeName = pipeName; if (server) { var pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); mServerPipe = new NamedPipeServerStream(mPipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 8192, 8192, pipeSecurity); mPipe = mServerPipe; } else { var clientPipe = new NamedPipeClientStream(".", mPipeName, PipeDirection.InOut, PipeOptions.Asynchronous); clientPipe.Connect(); mPipe = clientPipe; } mPipeWriter = new StreamWriter(mPipe); mPipeReader = new StreamReader(mPipe); } catch (Exception ex) { Log.Write("Error initializing pipe: ", ex); } }
private void ReceiveDataFromClient() { while (true) { try { PipeSecurity pse = new PipeSecurity(); pse.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow));//设置访问规则 NamedPipeServerStream _pipeServer = new NamedPipeServerStream("StartupAddPipe", PipeDirection.InOut, 10, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 1024, 1024, pse, HandleInheritability.None); _pipeServer.WaitForConnection(); //Waiting using (StreamReader sr = new StreamReader(_pipeServer)) { string path = sr.ReadLine().Trim(); string defaultName = System.IO.Path.GetFileNameWithoutExtension(path).ToLower(); // InstructionTextBox 被主线程占用,利用 Dispatcher 进行操作 InstructionTextBox.Dispatcher.BeginInvoke((Action)(() => { InstructionTextBox.Text = "@add" + " " + defaultName + " " + path; InstructionTextBox.SelectionStart = ("@add" + " ").Length; InstructionTextBox.SelectionLength = defaultName.Length; Visibility = Visibility.Visible; InstructionTextBox.Focus(); })); } Thread.Sleep(1000); } catch (Exception) { /* I don't care */ } } }
public virtual async Task StartListeningAsync(Endpoint Endpoint, CancellationToken Token, Func <Object> GetHandler) { var EP = StreamName(Endpoint); while (true) { if (!Token.IsCancellationRequested) { try { var Security = new PipeSecurity(); { var Everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); var AllowEveryone = new PipeAccessRule(Everyone, PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow); Security.SetAccessRule(AllowEveryone); } var C = new NamedPipeServerStream(EP, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 0, Security); await C.WaitForConnectionAsync(Token) .DefaultAwait() ; _ = Task.Run(() => ProcessConnectionAsync(C, GetHandler)); } catch (TaskCanceledException) { } } else { break; } } }
private static bool ServerLoop() { var ps = new PipeSecurity(); var authorizedUser = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); ps.SetAccessRule(new PipeAccessRule(authorizedUser, PipeAccessRights.ReadWrite, AccessControlType.Allow)); using (var pipe = new NamedPipeServerStream(GetPipeName(), PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.WriteThrough, 1024 * 100, 1024 * 100, ps)) { pipe.WaitForConnection(); string cmd; using (var reader = new StreamReader(pipe, Encoding.UTF8, false, 1024, true)) { cmd = reader.ReadLine(); } if (cmd == ShutdownCommandName) { return(false); } if (!Commands.ContainsKey(cmd)) { return(true); } var result = Commands[cmd](); using (var writer = new StreamWriter(pipe, Encoding.UTF8, 1024, true)) { writer.WriteLine(result == null ? null : result.ToJsonString()); } pipe.WaitForPipeDrain(); } return(true); }
private void IPCServerThread() { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); while (true) { try { using (NamedPipeServerStream pipeStream = new NamedPipeServerStream( "Aurora\\server", PipeDirection.In, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.None, 5 * 1024, 5 * 1024, pipeSa, HandleInheritability.None )) { wrapper_connected = false; wrapped_process = ""; Global.logger.LogLine(String.Format("[IPCServer] Pipe created {0}", pipeStream.GetHashCode())); pipeStream.WaitForConnection(); Global.logger.LogLine("[IPCServer] Pipe connection established"); using (StreamReader sr = new StreamReader(pipeStream)) { string temp; while ((temp = sr.ReadLine()) != null) { //Global.logger.LogLine(String.Format("{0}: {1}", DateTime.Now, temp)); //Begin handling the game state outside this loop var task = new System.Threading.Tasks.Task(() => HandleNewIPCGameState(temp)); task.Start(); } } } WrapperConnectionClosed?.Invoke(wrapped_process); wrapper_connected = false; wrapped_process = ""; Global.logger.LogLine("[IPCServer] Pipe connection lost"); } catch (Exception exc) { WrapperConnectionClosed?.Invoke(wrapped_process); wrapper_connected = false; wrapped_process = ""; Global.logger.LogLine("[IPCServer] Named Pipe Exception, " + exc, Logging_Level.Error); } } }
public ElevatorServer() { // Need to specifically set the security to allow "Everyone" since this app runs as an admin // while the client runs as the default user PipeSecurity pSecure = new PipeSecurity(); try { pSecure.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); } catch (Exception e) when(e is SystemException || e is System.Security.Principal.IdentityNotMappedException) { pSecure.SetAccessRule(new PipeAccessRule("Все", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); } _pipeServer = new NamedPipeServerStream("TracingControllerPipe", PipeDirection.InOut, 10, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 255, 255, pSecure); _inputPipeStream = new StreamReader(_pipeServer); _outputPipeStream = new StreamWriter(_pipeServer); }
/// <summary> /// CreatePipeServerSecurity method implementation /// </summary> private PipeSecurity CreatePipeServerSecurity() { SecurityIdentifier dom = GetDomainSid(); PipeSecurity pipeSecurity = new PipeSecurity(); SecurityIdentifier id1 = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null); SecurityIdentifier id2 = new SecurityIdentifier(WellKnownSidType.LocalServiceSid, null); SecurityIdentifier id3 = new SecurityIdentifier(WellKnownSidType.AccountDomainAdminsSid, dom); SecurityIdentifier id4 = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null); SecurityIdentifier id5 = new SecurityIdentifier(WellKnownSidType.WorldSid, null); // Allow Everyone read and write access to the pipe. pipeSecurity.SetAccessRule(new PipeAccessRule(id1, PipeAccessRights.ReadWrite, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id2, PipeAccessRights.ReadWrite, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id3, PipeAccessRights.ReadWrite, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id4, PipeAccessRights.ReadWrite, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id5, PipeAccessRights.ReadWrite, AccessControlType.Allow)); return(pipeSecurity); }
public void Start() { _logger.InfoFormat("Pipe server start"); PipeSecurity pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); _pipe = new NamedPipeServerStream("rsl_admin", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 4096, 4096, pipeSecurity); _logger.InfoFormat("Pipe server wait connection"); _pipe.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), _pipe); }
public PipeListener(string pipeName) { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.FullControl, AccessControlType.Allow)); int buffLen = 2 * 1024 * 1024; // 2MB buffer should be plany ;) pipeStream = new NamedPipeServerStream(pipeName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, buffLen, buffLen, pipeSa); pipeStream.BeginWaitForConnection(new AsyncCallback(PipeConnected), null); }
public PipeServer(string pipeName) { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(FileOps.SID_Worls), PipeAccessRights.FullControl, AccessControlType.Allow)); int buffLen = 1029; // 4 + 1024 + 1 pipeStream = new NamedPipeServerStream(pipeName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, buffLen, buffLen, pipeSa); pipeStream.BeginWaitForConnection(new AsyncCallback(PipeConnected), null); }
private PipeSecurity CreatePipeSecurity() { // Allow Authenticated Users to read and write access to the service's pipe var pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); return(pipeSecurity); }
static void Main(string[] args) { //Allow all authenticated users PipeSecurity pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); while (true) { using (NamedPipeServerStream pipeServer = new NamedPipeServerStream("NPAttackPipe", PipeDirection.InOut, 10, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, pipeSecurity)) { Console.WriteLine("NamedPipeServerStream object created."); // Wait for a client to connect Console.Write("Waiting for client connection..."); pipeServer.WaitForConnection(); Console.WriteLine("Client connected."); try { // Read user input and send that to the client process. using (StreamReader sr = new StreamReader(pipeServer)) { string commandLine = sr.ReadLine(); long clientPID = 0; GetNamedPipeClientProcessId(pipeServer.SafePipeHandle.DangerousGetHandle(), out clientPID); if (clientPID == 0) { Console.WriteLine("Failed to get client PID, bailing..."); continue; } Process clientProcess = Process.GetProcessById((int)clientPID); if (clientProcess.ProcessName != "NPClient") { Console.WriteLine("Hax0r detected, execution denied!"); continue; } Process.Start(commandLine); Console.WriteLine($"NPClient validated, lanched process {commandLine}"); } } // Catch the IOException that is raised if the pipe is broken // or disconnected. catch (Exception e) { Console.WriteLine("ERROR: {0}", e.Message); } finally { pipeServer.Close(); } } } }
private static PipeSecurity CreatePipeSecurity() { PipeSecurity pipeSecurity = new PipeSecurity(); var id = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); // Allow Everyone read and write access to the pipe. pipeSecurity.SetAccessRule(new PipeAccessRule(id, PipeAccessRights.ReadWrite, AccessControlType.Allow)); return(pipeSecurity); }
private static void ListenPipe() { var pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule( new PipeAccessRule( new SecurityIdentifier( WellKnownSidType.BuiltinUsersSid , null), PipeAccessRights.ReadWrite , AccessControlType.Allow)); using (var pipe = new NamedPipeServerStream( "\\.\\antiv1", PipeDirection.InOut, 1 , PipeTransmissionMode.Message , PipeOptions.None, 128, 128 , pipeSecurity)) { byte[] buf; while (!closing) { buf = new byte[256]; if (!pipe.IsConnected) { pipe.WaitForConnection(); pipe.Read(buf, 0, buf.Length); } lock (messageOut) { if (messageOut.Count > 0) { buf = Encoding.UTF8.GetBytes(messageOut.Dequeue()); } else { buf = new byte[] { 0, 0 } }; } pipe.Write(buf, 0, buf.Length); buf = new byte[256]; pipe.Read(buf, 0, buf.Length); if (buf[1] != 0) { lock (messageIn) { messageIn.Enqueue( Encoding.UTF8.GetString(buf, 0, buf.Length)); } } } buf = new byte[] { 0, 6 }; pipe.Write(buf, 0, buf.Length); pipe.WaitForPipeDrain(); } }
/* public static string RunSimulationService(string npipe, string log) { string currentPath = AppDomain.CurrentDomain.BaseDirectory; Lib.Logger logger = new Lib.Logger(currentPath + "simagent.txt"); try { logger.TimestampInfo("starting!"); string technique; using (var pipeServer = new NamedPipeServerStream(npipe, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message)) //using (var pipeServer = new NamedPipeServerStream(npipe)) { var reader = new StreamReader(pipeServer); var writer = new StreamWriter(pipeServer); //logger.TimestampInfo("Waiting for client connection..."); pipeServer.WaitForConnection(); logger.TimestampInfo("Client connected!"); var line = reader.ReadLine(); logger.TimestampInfo("received from client: " + line); if (line.ToLower().StartsWith("technique:")) { technique = line.Replace("technique:", ""); writer.WriteLine("ACK"); writer.Flush(); return technique; } pipeServer.Disconnect(); } return ""; } catch (Exception ex) { logger.TimestampInfo(ex.ToString()); logger.TimestampInfo(ex.Message.ToString()); return ""; } } */ public static string[] RunSimulationService(string npipe, string log) { string[] result = new string[2]; try { //https://helperbyte.com/questions/171742/how-to-connect-to-a-named-pipe-without-administrator-rights PipeSecurity ps = new PipeSecurity(); ps.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); //logger.TimestampInfo("starting!"); string technique; string sleep; using (var pipeServer = new NamedPipeServerStream(npipe, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 4028, 4028, ps)) //using (var pipeServer = new NamedPipeServerStream(npipe)) { var reader = new StreamReader(pipeServer); var writer = new StreamWriter(pipeServer); //logger.TimestampInfo("Waiting for client connection..."); pipeServer.WaitForConnection(); //logger.TimestampInfo("Client connected!"); var line = reader.ReadLine(); //logger.TimestampInfo("received from client: " + line); if (line.ToLower().StartsWith("technique:")) { string[] options = line.Split(' '); technique = options[0].Replace("technique:", ""); sleep = options[1].Replace("sleep:", ""); //technique = line.Replace("technique:", ""); writer.WriteLine("ACK"); writer.Flush(); result[0] = technique; result[1] = sleep; return result; //return technique; } pipeServer.Disconnect(); } return result; //return ""; } catch { //logger.TimestampInfo(ex.ToString()); //logger.TimestampInfo(ex.Message.ToString()); //return ""; return result; } }
/// <summary> /// Gets a security descriptor that will permit non-elevated clients to connect to the server. /// </summary> /// <returns> /// A security descriptor that will permit non-elevated clients to connect to the server. /// </returns> private static PipeSecurity GetSecurityForChannel() { PipeSecurity pipeSecurity = new PipeSecurity(); var permissions = PipeAccessRights.CreateNewInstance | PipeAccessRights.Read | PipeAccessRights.Synchronize | PipeAccessRights.Write; var authUsersSid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); var authUsersAcct = authUsersSid.Translate(typeof(NTAccount)); pipeSecurity.SetAccessRule(new PipeAccessRule(authUsersAcct, permissions, AccessControlType.Allow)); return(pipeSecurity); }
public void CreatePipe2() { string ss; if (strPipeName2 == "") { ss = "Cannot create pipe " + strPipeName2; LogMessage(ss);//DataPipeInfoTxt, ss); return; } if (DataSrvHandle != null) { return; } try { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, AccessControlType.Allow)); DataSrvHandle = new NamedPipeServerStream( strPipeName2, // The unique pipe name. PipeDirection.In, // The pipe is read only NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, // Message type pipe PipeOptions.Asynchronous, // No additional parameters MAX_DATA_SIZE, // Input buffer size MAX_DATA_SIZE, // Output buffer size pipeSa, // Pipe security attributes HandleInheritability.None // Not inheritable ); ss = "The server named pipe " + strPipeName2 + " is created"; LogMessage(ss);//DataPipeInfoTxt, ss); if (EmulatorEnabled == false) { DataSrvHandle.WaitForConnection(); } ss = "The named pipe " + strPipeName2 + " is connected"; LogMessage(ss);//DataPipeInfoTxt, ss); DataPipeConnected = true; } catch (Exception ex) { ss = "Cannot create pipe " + strPipeName2; LogMessage(ss); //DataPipeInfoTxt, ss); LogMessage(ex.Message); //DataPipeInfoTxt, ex.Message); DataPipeConnected = false; } }
public static string[] RunSimulationService(string npipe, string log) { string[] result = new string[5]; try { //https://helperbyte.com/questions/171742/how-to-connect-to-a-named-pipe-without-administrator-rights PipeSecurity ps = new PipeSecurity(); ps.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); //logger.TimestampInfo("starting!"); string technique, pbsleep, tsleep, cleanup, variation; using (var pipeServer = new NamedPipeServerStream(npipe, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 4028, 4028, ps)) { var reader = new StreamReader(pipeServer); var writer = new StreamWriter(pipeServer); pipeServer.WaitForConnection(); var line = reader.ReadLine(); if (line.ToLower().StartsWith("technique:")) { string[] options = line.Split(' '); technique = options[0].Replace("technique:", ""); variation = options[1].Replace("variation:", ""); pbsleep = options[2].Replace("pbsleep:", ""); tsleep = options[3].Replace("tsleep:", ""); cleanup = options[4].Replace("cleanup:", ""); writer.WriteLine("ACK"); writer.Flush(); result[0] = technique; result[1] = variation; result[2] = pbsleep; result[3] = tsleep; result[4] = cleanup; return(result); } pipeServer.Disconnect(); } return(result); } catch { return(result); } }
private void AuroraCommandsServerIPC() { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); while (isRunning) { try { using (IPCCommandpipeStream = new NamedPipeServerStream( "Aurora\\interface", PipeDirection.In, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.None, 5 * 1024, 5 * 1024, pipeSa, HandleInheritability.None )) { Global.logger.LogLine(String.Format("[AuroraCommandsServerIPC] Pipe created {0}", IPCCommandpipeStream?.GetHashCode())); IPCCommandpipeStream?.WaitForConnection(); Global.logger.LogLine("[AuroraCommandsServerIPC] Pipe connection established"); using (StreamReader sr = new StreamReader(IPCCommandpipeStream)) { string temp; while ((temp = sr.ReadLine()) != null) { Global.logger.LogLine("[AuroraCommandsServerIPC] Recieved command: " + temp); string[] split = temp.Contains(':') ? temp.Split(':') : new[] { temp }; CommandRecieved.Invoke(split[0], split.Length > 1 ? split[1] : ""); } } } Global.logger.LogLine("[AuroraCommandsServerIPC] Pipe connection lost"); } catch (Exception exc) { Global.logger.LogLine("[AuroraCommandsServerIPC] Named Pipe Exception, " + exc, Logging_Level.Error); } } }
public StudioServer() { try { pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); serverStream = NamedPipeServerStreamConstructors.New($@"\.\DSParamStudio\pipe\CommandQueue", PipeDirection.InOut, System.IO.Pipes.NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 0, 0, pipeSecurity); serverStream.BeginWaitForConnection(handleConnection, serverStream); new Thread(TestThread).Start(); } catch { } }
private void Processing() { while (true) { try { PipeSecurity ps = new PipeSecurity(); var rule = new PipeAccessRule( new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow); ps.SetAccessRule(rule); using (_pipeServer = new NamedPipeServerStream(_address, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0, ps)) { while (true) { _pipeServer.WaitForConnection(); lock (_locker) { if (_isStopped) { return; } } var request = _pipeServer.ReadByte(); if (request == Const.GC_COLLECT_COMMAND) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); _pipeServer.WriteByte(Const.OK_RESPONSE); } _pipeServer.Disconnect(); } } } catch { Thread.Sleep(10); } } }
/// <summary> /// CreatePipeServerSecurity method implementation /// </summary> private PipeSecurity CreatePipeServerSecurity() { SecurityIdentifier dom = GetDomainSid(); if (Config == null) { Certs.InitializeAccountsSID(string.Empty, string.Empty, string.Empty); } else { Certs.InitializeAccountsSID(Config.Hosts.ActiveDirectoryHost.DomainName, Config.Hosts.ActiveDirectoryHost.Account, Config.Hosts.ActiveDirectoryHost.Password); } PipeSecurity pipeSecurity = new PipeSecurity(); SecurityIdentifier id1 = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null); SecurityIdentifier id2 = new SecurityIdentifier(Certs.ADFSServiceSID); SecurityIdentifier id3 = new SecurityIdentifier(WellKnownSidType.AccountDomainAdminsSid, dom); SecurityIdentifier id4 = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null); SecurityIdentifier id5 = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null); SecurityIdentifier id6 = new SecurityIdentifier(WellKnownSidType.WorldSid, null); SecurityIdentifier id7 = new SecurityIdentifier(Certs.ADFSAccountSID); SecurityIdentifier id8 = null; if (!string.IsNullOrEmpty(Certs.ADFSAdminGroupSID)) { id8 = new SecurityIdentifier(Certs.ADFSAdminGroupSID); } // Allow Everyone read and write access to the pipe. pipeSecurity.SetAccessRule(new PipeAccessRule(id1, PipeAccessRights.FullControl, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id2, PipeAccessRights.FullControl, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id3, PipeAccessRights.FullControl, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id4, PipeAccessRights.FullControl, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id5, PipeAccessRights.ReadWrite, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id6, PipeAccessRights.ReadWrite, AccessControlType.Allow)); pipeSecurity.SetAccessRule(new PipeAccessRule(id7, PipeAccessRights.FullControl, AccessControlType.Allow)); if (id8 != null) { pipeSecurity.SetAccessRule(new PipeAccessRule(id8, PipeAccessRights.FullControl, AccessControlType.Allow)); } return(pipeSecurity); }
private void btnServerCreate_Click(object sender, RoutedEventArgs e) { try { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); server = new NamedPipeServerStream(txtServer.Text, PipeDirection.InOut, 10, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024, pipeSa); ServerName = txtServer.Text; Thread TServer = new Thread(StartServer); TServer.Start(); btnServerCreate.IsEnabled = false; } catch (Exception ex) { MessageBox.Show("btnServerCreate_Click : " + ex.Message); } }
public void Start(Boolean isClient) { if (isClient) { NamedPipeClientStream client = new NamedPipeClientStream(".", _pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); client.Connect(10000); // 10 second timeout. pipe = client; isReady = true; } else { // Grant read/write access to everyone, so the pipe can be written to from impersonated processes PipeSecurity pipeSecurity = new PipeSecurity(); pipeSecurity.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); NamedPipeServerStream server = new NamedPipeServerStream(_pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 4096, 4096, pipeSecurity); server.BeginWaitForConnection(new AsyncCallback(WaitForConnection), server); } }
/// <summary> /// Constructor that will spawn a new process using named pipes as its I/O stream. /// If it fails to spawn the designated process, an error will be thrown. /// </summary> /// <param name="lpApplicationName">Application to spawn.</param> /// <param name="lpCommandLine">Any command line arguments to pass to the application.</param> /// <param name="processCreationFlags">Process creation flags to spawn the process with. By default, this is SUSPENDED.</param> /// <param name="useLogon">If true, this will use the current network logon token the agent has.</param> /// <param name="useCredentials">If true, this will first create a new logon session for the current credential set in Token.Cred and use that session to spawn a process.</param> public ProcessWithAnonymousPipeIO(string lpApplicationName, string lpCommandLine = "", Advapi32.ProcessCreationFlags processCreationFlags = Advapi32.ProcessCreationFlags.CREATE_SUSPENDED, bool useLogon = false, bool useCredentials = false, bool useToken = false) { if (useLogon && useCredentials) { throw new Exception("Cannot create a new process using the current logon session and using a set of credentials simultaneously."); } PipeSecurity sec = new PipeSecurity(); sec.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.FullControl, AccessControlType.Allow)); PipeServer = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable, 1024, sec); PipeClient = new AnonymousPipeClientStream(PipeDirection.Out, PipeServer.GetClientHandleAsString()); //PipeServer.ReadTimeout = 10000; if (!CreateProcess(lpApplicationName, lpCommandLine, processCreationFlags, useLogon, useCredentials, useToken)) { CloseHandles(); throw new Exception("Failed to start child process."); } }
public static SimulationPlaybook RunSimulationServiceSerialized(string npipe, string log) { string currentPath = AppDomain.CurrentDomain.BaseDirectory; Logger logger = new Logger(currentPath + log); SimulationPlaybook playbook = new SimulationPlaybook(); try { //https://helperbyte.com/questions/171742/how-to-connect-to-a-named-pipe-without-administrator-rights PipeSecurity ps = new PipeSecurity(); ps.SetAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow)); logger.TimestampInfo("starting Simulator!"); using (var pipeServer = new NamedPipeServerStream(npipe, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 4028, 4028, ps)) { SimulationResponse sim_response; logger.TimestampInfo("Waiting for client connection..."); pipeServer.WaitForConnection(); logger.TimestampInfo("Client connected."); var messageBytes = ReadMessage(pipeServer); var line = Encoding.UTF8.GetString(messageBytes); logger.TimestampInfo("Received from client: " + line); SimulationRequest sim_request = JsonConvert.DeserializeObject <SimulationRequest>(line); playbook = sim_request.playbook; sim_response = new SimulationResponse("ACK"); byte[] bytes_sim_response = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(sim_response)); pipeServer.Write(bytes_sim_response, 0, bytes_sim_response.Length); logger.TimestampInfo("Replied to client: " + Encoding.UTF8.GetString(bytes_sim_response)); pipeServer.Disconnect(); return(playbook); } } catch (Exception ex) { logger.TimestampInfo(ex.Message); return(playbook); } }
public static void CreatePipe() { PipeSecurity pipeSec = new PipeSecurity(); pipeSec.SetAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); server = new NamedPipeServerStream( PipeCs.pipeName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.None, PipeCs.bufSize, PipeCs.bufSize, pipeSec, HandleInheritability.None); reader = new StreamReader(server); writer = new StreamWriter(server); server.WaitForConnection(); Console.WriteLine("connect!"); }