Beispiel #1
0
        protected void OnLogOnButtonClick(object sender, EventArgs e)
        {
            string       str         = null;
            string       str1        = null;
            IEtwActivity etwActivity = PowwaEvents.EventCorrelator.StartActivity();

            using (etwActivity)
            {
                try
                {
                    LogOn.FormInfo formInfo = this.ValidateForm();
                    using (formInfo)
                    {
                        this.CreateSession(formInfo);
                    }
                }
                catch (PowwaValidationException powwaValidationException1)
                {
                    PowwaValidationException powwaValidationException = powwaValidationException1;
                    this.ShowError(powwaValidationException.Message);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    LogOn.GetLogonErrorMessage(exception, out str, out str1);
                    this.ShowError(str);
                    object[] objArray = new object[1];
                    objArray[0] = str1;
                    PowwaEvents.PowwaEVENT_LOGON_FAILURE(this.userNameTextBox.Value, SessionHelper.GetSourceIPAddressRemoteAddr(), SessionHelper.GetSourceIPAddressHttpXForwardedFor(), string.Format(CultureInfo.CurrentCulture, Resources.LogonError_LogMessage, objArray));
                    Thread.Sleep(0x3e8);
                }
            }
        }
Beispiel #2
0
        private void ShowError(string message)
        {
            bool flag;

            this.messageLabel.Text = HttpUtility.HtmlEncode(message);
            LogOn.SetErrorState(this.userNameTextBox, true);
            LogOn.SetErrorState(this.passwordTextBox, true);
            LogOn.SetErrorState(this.altUserNameTextBox, this.altUserNameTextBox.Value.Length > 0);
            LogOn.SetErrorState(this.altPasswordTextBox, this.altPasswordTextBox.Value.Length > 0);
            LogOn.SetErrorState(this.targetNodeTextBox, this.targetNodeTextBox.Value.Length > 0);
            LogOn.SetErrorState(this.connectionUriTextBox, this.connectionUriTextBox.Value.Length > 0);
            HtmlInputText htmlInputText = this.portTextBox;

            if (string.Compare(this.portTextBox.Value.Trim(), "5985", StringComparison.OrdinalIgnoreCase) == 0)
            {
                flag = false;
            }
            else
            {
                flag = string.Compare(this.portTextBox.Value.Trim(), "5986", StringComparison.OrdinalIgnoreCase) != 0;
            }
            LogOn.SetErrorState(htmlInputText, flag);
            LogOn.SetErrorState(this.configurationNameTextBox, this.configurationNameTextBox.Value.Length > 0);
            LogOn.SetErrorState(this.applicationNameTextBox, string.Compare(this.applicationNameTextBox.Value.Trim(), "WSMAN", StringComparison.OrdinalIgnoreCase) != 0);
        }
Beispiel #3
0
        private LogOn.FormInfo ValidateForm()
        {
            string           value;
            HtmlInputControl htmlInputControl;

            LogOn.FormInfo formInfo = new LogOn.FormInfo();
            LogOn.ValidateCharactersInString(this.userNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.passwordTextBox.Value);
            LogOn.ValidateCharactersInString(this.altUserNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.passwordTextBox.Value);
            LogOn.ValidateCharactersInString(this.connectionUriTextBox.Value);
            LogOn.ValidateCharactersInString(this.targetNodeTextBox.Value);
            LogOn.ValidateCharactersInString(this.configurationNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.applicationNameTextBox.Value);
            formInfo.UserName = PswaHelper.TranslateLocalAccountName(this.userNameTextBox.Value);
            formInfo.Password = this.passwordTextBox.Value;
            LogOn.FormInfo formInfo1 = formInfo;
            if (this.altUserNameTextBox.Value.Length > 0)
            {
                value = this.altUserNameTextBox.Value;
            }
            else
            {
                value = formInfo.UserName;
            }
            formInfo1.DestinationUserName = value;
            if (this.altPasswordTextBox.Value.Length > 0)
            {
                htmlInputControl = this.altPasswordTextBox;
            }
            else
            {
                htmlInputControl = this.passwordTextBox;
            }
            char[] charArray = htmlInputControl.Value.ToCharArray();
            formInfo.DestinationPassword = new SecureString();
            for (int i = 0; i < (int)charArray.Length; i++)
            {
                formInfo.DestinationPassword.AppendChar(charArray[i]);
                charArray[i] = '*';
            }
            formInfo.IsUriConnection = string.Compare(this.connectionTypeSelection.Value, "connection-uri", StringComparison.OrdinalIgnoreCase) == 0;
            if (!formInfo.IsUriConnection)
            {
                formInfo.ComputerName = this.targetNodeTextBox.Value;
                formInfo.UseSsl       = this.useSslSelection.Value == "1";
                if (this.portTextBox.Value.Length != 0)
                {
                    if (!int.TryParse(this.portTextBox.Value, out formInfo.Port))
                    {
                        throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidPort);
                    }
                }
                else
                {
                    formInfo.Port = 0x1761;
                }
                formInfo.ApplicationName = this.applicationNameTextBox.Value;
            }
            else
            {
                try
                {
                    formInfo.ConnectionUri = new Uri(this.connectionUriTextBox.Value);
                }
                catch (UriFormatException uriFormatException1)
                {
                    UriFormatException uriFormatException = uriFormatException1;
                    object[]           message            = new object[1];
                    message[0] = uriFormatException.Message;
                    throw PowwaException.CreateValidationErrorException(string.Format(CultureInfo.CurrentUICulture, Resources.LogonError_InvalidUri, message));
                }
                formInfo.AllowRedirection = this.allowRedirectionSelection.Value == "1";
            }
            formInfo.ConfigurationName = this.configurationNameTextBox.Value;
            string str  = this.authenticationTypeSelection.Value;
            string str1 = str;

            if (str != null)
            {
                if (str1 == "0")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Default;
                }
                else if (str1 == "1")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Basic;
                }
                else if (str1 == "2")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Negotiate;
                }
                else if (str1 == "4")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Credssp;
                }
                else if (str1 == "5")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Digest;
                }
                else if (str1 == "6")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Kerberos;
                }
                else
                {
                    throw PowwaException.CreateValidationErrorException(Resources.InternalError_InvalidAuthenticationMechanism);
                }
                return(formInfo);
            }
            throw PowwaException.CreateValidationErrorException(Resources.InternalError_InvalidAuthenticationMechanism);
        }
Beispiel #4
0
		private void CreateSession(LogOn.FormInfo formInfo)
		{
			string str;
			string applicationName;
			string str1;
			string originalString;
			WSManConnectionInfo wSManConnectionInfo = null;
			if (formInfo.ConfigurationName.Length == 0)
			{
				str = null;
			}
			else
			{
				str = string.Concat("http://schemas.microsoft.com/powershell/", formInfo.ConfigurationName);
			}
			string str2 = str;
			PSCredential pSCredential = new PSCredential(formInfo.DestinationUserName, formInfo.DestinationPassword);
			if (!formInfo.IsUriConnection)
			{
				if (string.Compare(formInfo.ApplicationName, "WSMAN", StringComparison.OrdinalIgnoreCase) == 0)
				{
					applicationName = null;
				}
				else
				{
					applicationName = formInfo.ApplicationName;
				}
				string str3 = applicationName;
				try
				{
					wSManConnectionInfo = new WSManConnectionInfo(formInfo.UseSsl, formInfo.ComputerName, formInfo.Port, str3, str2, pSCredential);
				}
				catch (UriFormatException uriFormatException)
				{
					throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidComputerNameUriFormat);
				}
				wSManConnectionInfo.AuthenticationMechanism = formInfo.AuthenticationType;
				PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_COMPUTERNAME(formInfo.DestinationUserName, wSManConnectionInfo.ComputerName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri, wSManConnectionInfo.AuthenticationMechanism.ToString());
			}
			else
			{
				wSManConnectionInfo = new WSManConnectionInfo(formInfo.ConnectionUri, str2, pSCredential);
				if (!formInfo.AllowRedirection)
				{
					wSManConnectionInfo.MaximumConnectionRedirectionCount = 0;
				}
				PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_URI(formInfo.DestinationUserName, wSManConnectionInfo.ConnectionUri.AbsoluteUri, wSManConnectionInfo.ShellUri);
			}
			string sourceIPAddressRemoteAddr = SessionHelper.GetSourceIPAddressRemoteAddr();
			string sourceIPAddressHttpXForwardedFor = SessionHelper.GetSourceIPAddressHttpXForwardedFor();
			if (formInfo.IsUriConnection)
			{
				str1 = null;
			}
			else
			{
				str1 = PswaHelper.TranslateLocalComputerName(formInfo.ComputerName);
			}
			string str4 = str1;
			PowwaAuthorizationManager.Instance.CheckLogOnCredential(formInfo.UserName, formInfo.Password, str4, formInfo.ConnectionUri, formInfo.ConfigurationName, sourceIPAddressRemoteAddr, sourceIPAddressHttpXForwardedFor);
			ClientInfo clientInfo = new ClientInfo(HttpContext.Current.Request.UserAgent, CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);
			PowwaSession powwaSession = PowwaSessionManager.Instance.CreateSession(this.Session.SessionID, wSManConnectionInfo, clientInfo, formInfo.UserName);
			string name = powwaSession.Name;
			string userName = formInfo.UserName;
			string str5 = sourceIPAddressRemoteAddr;
			string str6 = sourceIPAddressHttpXForwardedFor;
			if (formInfo.IsUriConnection)
			{
				originalString = wSManConnectionInfo.ConnectionUri.OriginalString;
			}
			else
			{
				originalString = wSManConnectionInfo.ComputerName;
			}
			PowwaEvents.PowwaEVENT_SESSION_START(name, userName, str5, str6, originalString, formInfo.DestinationUserName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri);
			HttpCookie item = base.Request.Cookies["ASP.NET_SessionId"];
			if (FormsAuthentication.RequireSSL && item != null)
			{
				item.Secure = true;
			}
			FormsAuthentication.SetAuthCookie(formInfo.UserName, false, "/");
			base.Response.Redirect ("~/default.aspx");
			//FormsAuthentication.RedirectFromLoginPage(formInfo.UserName, false);
		}