How to authenticate to a Firewall web page via Powershell/Selenium?

Asked

Viewed 220 times

2

I developed several Powershell scripts to automate the configuration of machines I work on, speeding up and avoiding the heavy work of manually setting up a giant number of stations. Basically they use UAC disable, autologon and Task Scheduler.

Scripts em powershell

The biggest problem is the use of the Fortinet Firewall that asks for authentication via browser, as most of the application uses files to install the server via SMB, it is necessary to do this authentication. However, when testing this by Selenium it even performs authentication, but after the computer restarts and runs the next script, it asks again for authentication.

login no chrome manualmente

URL of the page: https://authenticator.mpms.mp.br/caplogin/? login&post=http://10.111.147. 1:1000/fgtauth&magic=0202e294cb1c7073&usermac=10:e7:c6:c5:c3:61&apmac=00:00:00:00:00:00&apip=10.111.147.1&userip=10.111.147.22&ssid=PGJ-BANCADA&apname=FGT2KE3917900027&bssid=00:00:00:00:00:00&device_type=windows-pc

It follows the code I made to authenticate in Fortnet, which after login, makes a request on the website globe.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

When we do it manually, the next steps run normally, which by my conclusion makes the Selenium driver not actually Google Chrome, but one of its own, which makes it not recognize the authentication...

The question that remains is: It is possible to add this option in the script so that we can authenticate in Fortinet Web and thus avoid manual steps and run our work even more automated?

Thank you!

  • Bye, good night, if you do not answer, is not in the desired scope, comment, I see no problem in deleting the answer.

  • Opa my friend. Actually meets yes, but at the moment I am traveling within my state and can not test. When back I can implement. I didn’t think about using vbs, because I didn’t know. You can let me use.

  • 1

    Thank you so much for the comment/reply, I thought you were looking for a solution within the cited "platforms", which I do not.

1 answer

2


Why not use the vbs in the Powershell to send the necessary authentications?

$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}');

Obs.: The first two lines are to bring your browser for foreground!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.