如何通过 Powershell / Selenium-Chrome 驱动程序验证防火墙网页?
How to authenticate a Firewall web page via Powershell / Selenium-Chrome Driver?
我在 Powershell 中开发了几个脚本来自动配置我工作的机器,简化并避免了手动配置大量站点的繁重工作。基本上他们使用禁用 UAC、自动登录和任务计划程序。
图片:https://i.stack.imgur.com/pkuDl.png
最大的问题是使用要求通过浏览器进行身份验证的 Fortinet 防火墙,由于许多应用程序使用通过 SMB 在服务器上安装的文件,因此有必要进行此身份验证,因为没有它算法无法向服务器进行身份验证,导致它在课程中失败。
图片:https://i.stack.imgur.com/bqZAR.png
但是,通过 Selenium 测试它甚至可以进行身份验证,但是在计算机重新启动并且 运行 执行下一个脚本后,它会再次要求进行身份验证。
按照我在 Fortnet 中验证的代码,登录后,在 globo.com 网站
中提出请求
############################################
######## Enable Fortinet Firewall ##########
############################################
$YourURL = "https://authenticator.mpms.mp.br/"
# Adds the path for ChromeDriver.exe to the environmental variable
$env:PATH += ";C:\Util\PSL\"
# Adding Selenium's .NET assembly (dll) to access it's classes in this PowerShell session
Add-Type -Path "C:\Util\PSL\WebDriver.dll"
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
$ChromeDriver.Capabilities.BrowserName
# Browse to the specified website
$ChromeDriver.Navigate().GoToURL($YourURL)
# Methods to find the input textbox for google search and then to type something in it
$ChromeDriver.FindElementByName("username").SendKeys("username")
$ChromeDriver.FindElementByName("password").SendKeys("password")
$ChromeDriver.FindElementsByClassName("submit").Submit()
#### New page #####
$YourURL = "https://www.globo.com/"
$ChromeDriver.Navigate().GoToURL($YourURL)
Function Stop-ChromeDriver {Get-Process -Name chromedriver -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue}
# Close selenium browser session method
$ChromeDriver.Close()
# End ChromeDriver process method
$ChromeDriver.Quit()
# Function to make double sure the Chromedriver process is finito (double-tap!)
Stop-ChromeDriver
当我们手动执行此操作时,接下来的步骤将正常 运行,根据我的结论,这使得 Selenium 驱动程序并不是真正的 Google Chrome 浏览器,而是它自己的浏览器,这意味着它不识别身份验证。 .
剩下的问题是:是否可以在脚本中添加此选项,以便我们可以对 Fortinet Web 进行身份验证,从而避免手动步骤并自动化我们的工作?我希望我可以为 Powershell 执行此任务,但我有另一种选择。
谢谢!
为什么不在 PowerShell` 中使用 vbs 来发送 所需的授权?
$wshell = New-Object -ComObject wscript.shell; $obj = New-Object -com Wscript.Shell;
$wshell.AppActivate('Chrome');
pathping 127.0.0.1 -n -q 1 -p 300 >$null
$obj.SendKeys('paulogoncalves');
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys("{TAB}")
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys('senhasecreta')
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys('{ENTER}');```
我在 Powershell 中开发了几个脚本来自动配置我工作的机器,简化并避免了手动配置大量站点的繁重工作。基本上他们使用禁用 UAC、自动登录和任务计划程序。
图片:https://i.stack.imgur.com/pkuDl.png
最大的问题是使用要求通过浏览器进行身份验证的 Fortinet 防火墙,由于许多应用程序使用通过 SMB 在服务器上安装的文件,因此有必要进行此身份验证,因为没有它算法无法向服务器进行身份验证,导致它在课程中失败。
图片:https://i.stack.imgur.com/bqZAR.png
但是,通过 Selenium 测试它甚至可以进行身份验证,但是在计算机重新启动并且 运行 执行下一个脚本后,它会再次要求进行身份验证。
按照我在 Fortnet 中验证的代码,登录后,在 globo.com 网站
中提出请求############################################
######## Enable Fortinet Firewall ##########
############################################
$YourURL = "https://authenticator.mpms.mp.br/"
# Adds the path for ChromeDriver.exe to the environmental variable
$env:PATH += ";C:\Util\PSL\"
# Adding Selenium's .NET assembly (dll) to access it's classes in this PowerShell session
Add-Type -Path "C:\Util\PSL\WebDriver.dll"
$ChromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
$ChromeDriver.Capabilities.BrowserName
# Browse to the specified website
$ChromeDriver.Navigate().GoToURL($YourURL)
# Methods to find the input textbox for google search and then to type something in it
$ChromeDriver.FindElementByName("username").SendKeys("username")
$ChromeDriver.FindElementByName("password").SendKeys("password")
$ChromeDriver.FindElementsByClassName("submit").Submit()
#### New page #####
$YourURL = "https://www.globo.com/"
$ChromeDriver.Navigate().GoToURL($YourURL)
Function Stop-ChromeDriver {Get-Process -Name chromedriver -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue}
# Close selenium browser session method
$ChromeDriver.Close()
# End ChromeDriver process method
$ChromeDriver.Quit()
# Function to make double sure the Chromedriver process is finito (double-tap!)
Stop-ChromeDriver
当我们手动执行此操作时,接下来的步骤将正常 运行,根据我的结论,这使得 Selenium 驱动程序并不是真正的 Google Chrome 浏览器,而是它自己的浏览器,这意味着它不识别身份验证。 .
剩下的问题是:是否可以在脚本中添加此选项,以便我们可以对 Fortinet Web 进行身份验证,从而避免手动步骤并自动化我们的工作?我希望我可以为 Powershell 执行此任务,但我有另一种选择。
谢谢!
为什么不在 PowerShell` 中使用 vbs 来发送 所需的授权?
$wshell = New-Object -ComObject wscript.shell; $obj = New-Object -com Wscript.Shell;
$wshell.AppActivate('Chrome');
pathping 127.0.0.1 -n -q 1 -p 300 >$null
$obj.SendKeys('paulogoncalves');
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys("{TAB}")
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys('senhasecreta')
pathping 127.0.0.1 -n -q 1 -p 150 >$null
$obj.SendKeys('{ENTER}');```