gpt4 book ai didi

c# - 在未能使用网络级身份验证向远程桌面服务器提供正确凭据后防止登录尝试失败窗口

转载 作者:太空狗 更新时间:2023-10-29 21:56:49 34 4
gpt4 key购买 nike

我正在使用“Microsoft 终端服务控件类型库”来建立与远程桌面服务器的连接。我正在寻找一种方法来阻止或抑制在连接到使用网络级身份验证 (NLA) 的远程桌面服务器时未能提供正确的用户名/密码组合时显示的“Windows 安全”提示。窗口看起来像这样:

enter image description here

我已经阅读并尝试了目前可以在网上找到的所有设置组合,但没有一个成功。以下是我在 stackoverlow 上发现的几个问题,它们讨论了这个确切的问题,据说可以解决,但答案对我不起作用:

AxMsRdpClient9 Dismiss login dialog

AxMsRdpClient6NotSafeForScripting AllowPromptingForCredentials

这听起来可能很荒谬,但我的最终目标只是尝试连接到 rdp 服务器并故意输入无效的用户名/密码,然后在失败时断开连接。我不关心实际连接或显示任何东西。如果这很重要,我这样做是为了在远程服务器上的事件日志中触发失败的登录尝试,稍后另一个应用程序将使用该登录尝试。

下面的代码已经在事件日志中触发了一次失败的登录尝试,但我只是找不到阻止这个失败的登录框在客户端计算机上弹出的方法,我宁愿不求助于尝试关闭窗口后的黑客攻击是打开。当远程桌面服务器配置为允许来自运行任何版本的远程桌面的计算机的连接(不太安全的选项)时,我没有同样的问题,因为弹出提示显然是 NLA 提供的额外安全性的一部分。

我已经为此控件尝试了许多不同的设置组合,以至于我的头都在旋转。这是一个示例,它以上述其他 stackoverflow 问题之一为模型:

Public Class Form1
Dim WithEvents oRemote As AxMSTSCLib.AxMsRdpClient6NotSafeForScripting

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
oRemote = New AxMSTSCLib.AxMsRdpClient6NotSafeForScripting
CType(oRemote, System.ComponentModel.ISupportInitialize).BeginInit()
oRemote.Dock = System.Windows.Forms.DockStyle.Fill
oRemote.Enabled = True
oRemote.Name = "OfficeWin7"
Me.Controls.Add(oRemote)
CType(oRemote, System.ComponentModel.ISupportInitialize).EndInit()
oRemote.CreateControl()
oRemote.Size = New System.Drawing.Size(800, 600)

oRemote.Server = "IPADDRESS"
oRemote.UserName = "TestAccount"
oRemote.AdvancedSettings7.ClearTextPassword = "WrongPassword"

Dim ocx As MSTSCLib.IMsRdpClientNonScriptable4 = oRemote.GetOcx()

ocx.EnableCredSspSupport = True
ocx.AllowCredentialSaving = False
ocx.PromptForCredentials = False
ocx.PromptForCredsOnClient = False

oRemote.Connect()
End Sub

Private Sub oRemote_OnAuthenticationWarningDismissed(sender As Object, e As EventArgs) Handles oRemote.OnAuthenticationWarningDismissed
MessageBox.Show("The credentials popup is now closing")
End Sub

Private Sub oRemote_OnAuthenticationWarningDisplayed(sender As Object, e As EventArgs) Handles oRemote.OnAuthenticationWarningDisplayed
MessageBox.Show("The credentials popup is about to be shown")
End Sub
End Class

据说是 ocx.PromptForCredentials = False应该阻止此弹出的行,但如果将该值设置为 True 似乎没有什么区别或 False .我几乎会假设 ocx.PromptForCredsOnClient 的属性名称可能实际上有效,但同样,我设置该值并没有什么不同。我总是得到相同的弹出窗口。

在这一点上,我不知道我做错了什么,但我的直觉告诉我,要让它工作,我需要实例化基础 AxMsRdpClient6NotSafeForScriptingAxMsRdpClient9NotSafeForScripting 这样的其他对象甚至 AxMsTscAxNotSafeForScripting当我将它放到表单上时,这是控件使用的默认类型。但是,我已经尝试了一堆这些设置组合,并希望有人能对这种情况有所了解。

我还应该提到,我愿意接受使用 .Net 连接到远程桌面服务器的替代方法,这些方法不涉及使用 Microsoft Terminal Services Control Type Library。如果有的话。如果它们确实存在,我没有太多运气找到它们,但如果我在搜索中遗漏了任何内容,请告诉我。

编辑:为确保您自己的服务器设置与我的相同或相似,只需满足两个要求:
  • 远程桌面必须在 Vista 或更高版本的 Windows 上运行
  • 远程桌面必须设置为使用 NLA。在 Win7 中,确切的选项文本是:“仅允许来自运行具有网络级别身份验证的远程桌面的计算机的连接(更安全)”

  • 那时我不在乎您在代码中更改了哪些选项,只要服务器在您尝试连接时记录失败的登录并且凭据框(或任何其他弹出窗口)永远不会出现在客户端。

    似乎添加此代码所需的正确引用的最简单方法是将 COM 选项卡中的“Microsoft 终端服务控件”添加到您的工具箱,然后将“Microsoft RDP 客户端控件”拖放到表单上。更多信息在这里: http://s.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET

    以下是 C# 中的相同代码,以防使这个问题更受欢迎:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    private AxMSTSCLib.AxMsRdpClient6NotSafeForScripting withEventsField_oRemote;
    public AxMSTSCLib.AxMsRdpClient6NotSafeForScripting oRemote {
    get { return withEventsField_oRemote; }
    set {
    if (withEventsField_oRemote != null) {
    withEventsField_oRemote.OnAuthenticationWarningDismissed -= oRemote_OnAuthenticationWarningDismissed;
    withEventsField_oRemote.OnAuthenticationWarningDisplayed -= oRemote_OnAuthenticationWarningDisplayed;
    }
    withEventsField_oRemote = value;
    if (withEventsField_oRemote != null) {
    withEventsField_oRemote.OnAuthenticationWarningDismissed += oRemote_OnAuthenticationWarningDismissed;
    withEventsField_oRemote.OnAuthenticationWarningDisplayed += oRemote_OnAuthenticationWarningDisplayed;
    }
    }
    }
    private void Form1_Load(object sender, EventArgs e)
    {
    oRemote = new AxMSTSCLib.AxMsRdpClient6NotSafeForScripting();
    ((System.ComponentModel.ISupportInitialize)oRemote).BeginInit();
    oRemote.Dock = System.Windows.Forms.DockStyle.Fill;
    oRemote.Enabled = true;
    oRemote.Name = "OfficeWin7";
    this.Controls.Add(oRemote);
    ((System.ComponentModel.ISupportInitialize)oRemote).EndInit();
    oRemote.CreateControl();
    oRemote.Size = new System.Drawing.Size(800, 600);

    oRemote.Server = "IPADDRESS";
    oRemote.UserName = "TestAccount";
    oRemote.AdvancedSettings7.ClearTextPassword = "WrongPassword";

    MSTSCLib.IMsRdpClientNonScriptable4 ocx = (MSTSCLib.IMsRdpClientNonScriptable4)oRemote.GetOcx();

    ocx.EnableCredSspSupport = true;
    ocx.AllowCredentialSaving = false;
    ocx.PromptForCredentials = false;
    ocx.PromptForCredsOnClient = false;

    oRemote.Connect();
    }

    private void oRemote_OnAuthenticationWarningDismissed(object sender, EventArgs e)
    {
    MessageBox.Show("The credentials popup is now closing");
    }

    private void oRemote_OnAuthenticationWarningDisplayed(object sender, EventArgs e)
    {
    MessageBox.Show("The credentials popup is about to be shown");
    }
    public Form1()
    {
    Load += Form1_Load;
    }
    }
    }

    最佳答案

    首先,您确实需要确保您的测试环境使用 RDP 的最新更新,特别是如果它是 Windows 7 - 只需运行 Windows Update。

    接下来,关注这一行:

        ocx.EnableCredSspSupport = True

    它正在启用安全支持提供程序。我不是这方面的专家,但可能有一个内部惯例说:
    Load locally stored credentials; if there aren't such - ask the user then crypt, hash, bla-bla, and store them locally, in order to use them next time
    此时会弹出对话框,要求提供凭据。我不认为你可以影响这种行为,但幸运的是,你可以影响提供者是否出现在图片中。所以设置为 False看看会发生什么。

    关于c# - 在未能使用网络级身份验证向远程桌面服务器提供正确凭据后防止登录尝试失败窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37669589/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com