gpt4 book ai didi

Powershell:从 runas/netonly 启动时发现默认网络凭据

转载 作者:行者123 更新时间:2023-12-03 01:20:34 47 4
gpt4 key购买 nike

我正在寻找一种方法来将当前 session 的网络凭据捕获到一个我可以稍后传递的变量中......

关键是在我有帐户访问/特权的外部域上执行命令,但源域和目标域之间没有信任。

首先,我们在使用 runas 命令(runas/netonly/user:domian\account powershell)生成的 powershell 中运行

从这里我可以做几乎所有我想做的事情,除了在任务调度程序中创建一个事件而不将用户名/密码硬编码到命令行中

调用命令 -computer $destination -scriptblock {schtasks -ru domain\account -rp 密码}

我想做的是像

$username = 获取当前 session 网络用户名($(whoami) 显示实际的本地 longon 帐户,而不是产生 powershell 窗口的 runas 帐户)

$password = 获取执行 RunAs 命令时输入的密码

最佳答案

根据输入的凭据创建安全 token 并针对 Active Directory 进行验证后,密码将不再保留。它不能在其他地方检索和重用。只剩下 token 。这是设计使然。

更新 :

我进一步挖掘以支持我的案例,它与上面的不太一样,但最终结果是一样的。与 runas.exe 一起使用的密码似乎不可用。网络凭据为 不是 针对 AD 进行了验证,回想起来这很有意义,因为您经常使用 /netonly使用远程、不受信任的域:根据定义,您无法验证来自本地系统的远程凭据。来自 MSDN:

这是标志 LOGON_NETCREDENTIALS_ONLY 的信息, 与 CreateProcessWithLogonW 一起使用.

Log on, but use the specified credentials on the network only. The new process uses the same token as the caller, but the system creates a new logon session within LSA, and the process uses the specified credentials as the default credentials.

This value can be used to create a process that uses a different set of credentials locally than it does remotely. This is useful in inter-domain scenarios where there is no trust relationship.

The system does not validate the specified credentials. Therefore, the process can start, but it may not have access to network resources.



好的,所以由于它无法验证凭据并获取 token ,因此它必须将密码存储在内存中的某个位置,因为它必须稍后通过线路将它们传递给 SSPI 等。所以,我们可以从启动的进程中获取它们吗? runas.exe ?让我们来看看:
PS> runas /netonly /user:foo\bar powershell.exe
Enter the password for foo\bar: ******

我确实使用了 foo\bar对于上面的域和用户。如前所述,它未经验证。我输入了 12345密码。上面的行将启动一个新的 powershell 实例。所以,从那个新实例中,让我们看看默认的网络凭据:
PS> [System.Net.CredentialCache]::DefaultNetworkCredentials

UserName Domain
-------- ------

哦,好吧,不走运:那里什么都没有。我的猜测是,凭证被保护在内核内存的某个加密部分中,可能是 LSA(本地安全机构)无法被窥探进程所触及。

关于Powershell:从 runas/netonly 启动时发现默认网络凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15689070/

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