private void EnsureSessionSecurity(ServerRemoteSession session)
 {
     if (session.Identity.Name != System.Threading.Thread.CurrentPrincipal.Identity.Name)
     {
         throw new PSSecurityException("Access Denied to requested session");
     }
 }
Esempio n. 2
0
        protected OutOfProcessServerSessionTransportManager CreateSessionTransportManager(string configurationName, PSRemotingCryptoHelperServer cryptoHelper, string workingDirectory)
        {
            PSSenderInfo senderInfo;

#if !UNIX
            WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
            PSPrincipal     userPrincipal   = new PSPrincipal(
                new PSIdentity(string.Empty, true, currentIdentity.Name, null),
                currentIdentity);
            senderInfo = new PSSenderInfo(userPrincipal, "http://localhost");
#else
            PSPrincipal userPrincipal = new PSPrincipal(
                new PSIdentity(string.Empty, true, string.Empty, null),
                null);
            senderInfo = new PSSenderInfo(userPrincipal, "http://localhost");
#endif

            OutOfProcessServerSessionTransportManager tm = new OutOfProcessServerSessionTransportManager(originalStdOut, originalStdErr, cryptoHelper);

            ServerRemoteSession.CreateServerRemoteSession(
                senderInfo,
                _initialCommand,
                tm,
                configurationName,
                workingDirectory);

            return(tm);
        }
Esempio n. 3
0
        private OutOfProcessServerSessionTransportManager CreateSessionTransportManager()
        {
            WindowsIdentity current       = WindowsIdentity.GetCurrent();
            PSPrincipal     userPrincipal = new PSPrincipal(new PSIdentity("", true, current.Name, null), current);
            PSSenderInfo    senderInfo    = new PSSenderInfo(userPrincipal, "http://localhost");
            OutOfProcessServerSessionTransportManager transportManager = new OutOfProcessServerSessionTransportManager(this.originalStdOut);

            ServerRemoteSession.CreateServerRemoteSession(senderInfo, this._initialCommand, transportManager);
            return(transportManager);
        }
Esempio n. 4
0
        public Guid CreateSession(string connection, string username, string password, int authMechanism, int protocolVersion)
        {
            Guid sessionId = Guid.NewGuid();
            var  identity  = new PSIdentity("", true, username, null);
            var  principal = new PSPrincipal(identity, WindowsIdentity.GetCurrent());
            var  sender    = new PSSenderInfo(principal, connection);
            var  session   = ServerRemoteSession.CreateServerRemoteSession(sender, null, new WSManServerSessionTransportManager());

            lock (_lock) {
                _sessions.Add(sessionId, session);
            }
            return(sessionId);
        }
        public Guid CreateSession()
        {
            var    username   = System.Threading.Thread.CurrentPrincipal.Identity.Name;
            string connection = OperationContext.Current.Host.Description.Endpoints[0].Address.Uri.ToString();
            var    identity   = new PSIdentity("", true, username, null);
            var    principal  = new PSPrincipal(identity, WindowsIdentity.GetCurrent());
            var    sender     = new PSSenderInfo(principal, connection);
            var    session    = ServerRemoteSession.CreateServerRemoteSession(sender, null, sessionTransportManager);

            lock (_lock) {
                _sessions.Add(session.InstanceId, session);
            }
            return(session.InstanceId);
        }
        internal override string EncryptSecureString(SecureString secureString)
        {
            ServerRemoteSession session = this.Session as ServerRemoteSession;

            if ((session != null) && (session.Context.ClientCapability.ProtocolVersion >= RemotingConstants.ProtocolVersionWin8RTM))
            {
                base._rsaCryptoProvider.GenerateSessionKey();
            }
            else
            {
                base.RunKeyExchangeIfRequired();
            }
            return(base.EncryptSecureStringCore(secureString));
        }
Esempio n. 7
0
        internal override string EncryptSecureString(SecureString secureString)
        {
            ServerRemoteSession session = Session as ServerRemoteSession;

            // session!=null check required for DRTs TestEncryptSecureString* entries in CryptoUtilsTest/UTUtils.dll
            // for newer clients, server will never initiate key exchange.
            // for server, just the session key is required to encrypt/decrypt anything
            if ((session != null) && (session.Context.ClientCapability.ProtocolVersion >= RemotingConstants.ProtocolVersionWin8RTM))
            {
                _rsaCryptoProvider.GenerateSessionKey();
            }
            else // older clients
            {
                RunKeyExchangeIfRequired();
            }

            return(EncryptSecureStringCore(secureString));
        }
Esempio n. 8
0
        protected OutOfProcessServerSessionTransportManager CreateSessionTransportManager(
            string configurationName,
            string configurationFile,
            PSRemotingCryptoHelperServer cryptoHelper,
            string workingDirectory)
        {
            PSSenderInfo senderInfo;

#if !UNIX
            WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
            PSPrincipal     userPrincipal   = new PSPrincipal(
                new PSIdentity(string.Empty, true, currentIdentity.Name, null),
                currentIdentity);
            senderInfo = new PSSenderInfo(userPrincipal, "http://localhost");
#else
            PSPrincipal userPrincipal = new PSPrincipal(
                new PSIdentity(string.Empty, true, string.Empty, null),
                null);
            senderInfo = new PSSenderInfo(userPrincipal, "http://localhost");
#endif

            var tm = new OutOfProcessServerSessionTransportManager(
                originalStdOut,
                originalStdErr,
                cryptoHelper);

            ServerRemoteSession.CreateServerRemoteSession(
                senderInfo: senderInfo,
                configurationProviderId: "Microsoft.PowerShell",
                initializationParameters: string.Empty,
                transportManager: tm,
                initialCommand: _initialCommand,
                configurationName: configurationName,
                configurationFile: configurationFile,
                initialLocation: workingDirectory);

            return(tm);
        }
        private void Start(string initialCommand)
        {
            WindowsIdentity current    = WindowsIdentity.GetCurrent();
            PSSenderInfo    senderInfo = new PSSenderInfo(new PSPrincipal(new PSIdentity("", true, current.Name, (PSCertificateDetails)null), current), "http://localhost");

            this.sessionTM = new OutOfProcessServerSessionTransportManager(this.originalStdOut);
            ServerRemoteSession.CreateServerRemoteSession(senderInfo, initialCommand, (AbstractServerSessionTransportManager)this.sessionTM);
            try
            {
                while (true)
                {
                    string str = this.originalStdIn.ReadLine();
                    if (!string.IsNullOrEmpty(str))
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(this.ProcessingThreadStart), (object)str);
                    }
                    else
                    {
                        break;
                    }
                }
                this.sessionTM.Close((Exception)null);
                throw new PSRemotingTransportException(PSRemotingErrorId.IPCUnknownElementReceived, new object[1]
                {
                    (object)string.Empty
                });
            }
            catch (Exception ex)
            {
                CommandProcessorBase.CheckForSevereException(ex);
                OutOfProcessMediator.ETWTracer.OperationalChannel.WriteError(PSEventId.TransportError, PSOpcode.Open, PSTask.None, (object)Guid.Empty, (object)Guid.Empty, (object)4000, (object)ex.Message, (object)ex.StackTrace);
                OutOfProcessMediator.ETWTracer.AnalyticChannel.WriteError(PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None, (object)Guid.Empty, (object)Guid.Empty, (object)4000, (object)ex.Message, (object)ex.StackTrace);
                this.originalStdErr.WriteLine(ex.Message);
                Environment.Exit(4000);
            }
        }