gpt4 book ai didi

powershell - 如何检测 Powershell 中的 Powershell 嵌套?

转载 作者:行者123 更新时间:2023-12-04 18:15:26 38 4
gpt4 key购买 nike

是否可以从 Powershell 中检测它是否是嵌套 shell?

如果我打开 Powershell 或 cmd.exe 窗口,然后输入 powershell 在那里,是否有一个神奇的 $host.somevariable 我可以查询它是否是一个“内部”shell?

最佳答案

没有这样一个神奇的变量,更有可能。但是有可能得到这个信息:

$me = Get-WmiObject -Query "select * from Win32_Process where Handle=$pid"
$parent = Get-Process -Id $me.ParentProcessId
if ($parent.ProcessName -eq 'powershell') {
'nested, called from powershell'
}
elseif ($parent.ProcessName -eq 'cmd') {
'nested, called from cmd'
}
else {
'not nested'
}

关于powershell - 如何检测 Powershell 中的 Powershell 嵌套?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380531/

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