简体   繁体   English

从传递参数的外部程序调用 Powershell 脚本

[英]Calling Powershell script from external program passing an argument

I have an external program which calls a powershell script with a random secret identifier as a single argument.我有一个外部程序,它调用 powershell 脚本,其中随机秘密标识符作为单个参数。 The powershell script needs to return the same random secret id when it calls the REST client on the external program. powershell 脚本在外部程序上调用 REST 客户端时需要返回相同的随机密钥 id。

Even though the powershell scripts are in secured location on the server, can anyone open the powershell and debug to get $args[0] value.即使 powershell 脚本位于服务器上的安全位置,任何人都可以打开 powershell 并调试以获得$args[0]值。 The powershell script cannot run on its own as it needs get a secret id from external program. powershell 脚本无法自行运行,因为它需要从外部程序获取秘密 ID。

I tried on as script as below我尝试如下脚本

$gg = [Security.Principal.WindowsIdentity]::GetCurrent().Name 

$args[0]
$gg

The external program was calls the powershell script every 2 seconds and passed the secret identifier.外部程序每 2 秒调用一次 powershell 脚本并传递秘密标识符。 During debugging - I could not value $args[0] .在调试期间 - 我无法评估$args[0]

Any feedback.任何反馈。 Am I correct that no one can debug and get the value of the argument even in the de-bug?我是否正确,即使在调试中也没有人可以调试并获得参数的值?

As with security, it really depends on who you do trust, what kind of attacks you are preparing against and who is attacking you.与安全性一样,这实际上取决于您信任的人、您准备应对的攻击类型以及攻击您的 Consider asking people at Security.SE for more details, but here are my two cents.考虑向Security.SE的人员询问更多详细信息,但这是我的两分钱。 The following list is by no means complete.以下列表绝不是完整的。

If the attacker has permissions to edit the script, it is trivial to add statements logging the secret key.如果攻击者有权编辑脚本,那么添加记录密钥的语句就很简单了。 If script editing is not possible, editing all users' profile $PSHOME\Microsoft.PowerShell_profile.ps1 could be leveraged to add snooping.如果无法进行脚本编辑,则可以利用编辑所有用户的配置文件$PSHOME\Microsoft.PowerShell_profile.ps1来添加监听。

Even if the attacker doesn't have read or write permissions to the script location, they might have permissions to get process listing.即使攻击者没有对脚本位置的读取或写入权限,他们也可能拥有获取进程列表的权限。 Tools such as Sysinterals' Process Explorer can display each process' startup command - including any command line arguments. Sysinterals 的Process Explorer等工具可以显示每个进程的启动命令——包括任何命令行 arguments。

Is the REST endpoint secured with HTTPS? REST 端点是否由 HTTPS 保护? If not, a network sniffer can pick up the secret key.如果没有,网络嗅探器可以获取密钥。 Can the attacker inject a trusted certificate into the client?攻击者能否将可信证书注入客户端? That's a fast way to MITM attacks, and key can be picked up via eavesdropping.这是 MITM 攻击的快速方法,并且可以通过窃听获取密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM