Wednesday, 25 May 2016

Qualys API using Powershell

Below is the code which has been written in Powershell utilizing Qualys eu API

More code will be added with the functionality addon.



param(
[Parameter(Mandatory=$true)][String]$username,
#End user must not be able to see the typed password, so protecting it
[Parameter(Mandatory=$true)][SecureString]$SecurePassword,
[Parameter(Mandatory=$false)][int]$ScanProfile=90348959
)
#Now we will convert back the securepassword input to the plain text as Qualys API works in that way
# Create a "password pointer"
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
# Get the plain text version of the password
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
# Free the pointer
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
# Plain text password is in $password


[String]$Cookie1= "$qualys_scan_schedule.cookies"

function login{

#login to qualys and dump the response cookie into Cookie1 which is pointing to .cookies
$Login ='curl -H "X-Requested-With: Curl Sample" --dump-header "$Cookie1" -d "action=login&username=$username&password=$password" "https://qualysapi.qualys.eu/api/2.0/fo/session/"'
Invoke-Expression $Login
}

function list{

$List='curl -H "X-Requested-With: Curl Sample" -d "action=list" -b "$Cookie1" "https://qualysapi.qualys.eu/api/2.0/fo/report/"'
Invoke-Expression $List
}

function logout{
#Logout
curl -H "X-Requested-With: Curl Sample" -d "action=logout" -b "$Cookie1" "https://qualysapi.qualys.eu/api/2.0/fo/session/"
}

function Main{

login
list
logout

}

. Main

No comments:

Post a Comment