Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read password as secure string #8

Open
jdtrojan opened this issue Apr 12, 2018 · 1 comment
Open

Read password as secure string #8

jdtrojan opened this issue Apr 12, 2018 · 1 comment

Comments

@jdtrojan
Copy link

Just modified the script a bit and added the ability to read the password as a secure string so it's not stored in the script in plain-text.

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

Replace with the server, username and password for your Nexpose install

$user = 'user'
$secpass = Read-Host "Enter Password" -AsSecureString
$pwd = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($secpass))
$server = 'localhost'
$port = '3780'
$api_version = '1.1'
$uri = "https://${server}:${port}/api/${api_version}/xml"
$login_request = ""

#[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd))

login and get the session id

$resp = Invoke-WebRequest -URI $uri -Body $login_request -ContentType 'text/xml' -Method post
$session_id = $resp.content | Select-Xml -XPath '//@session-id' | Select-Object -ExpandProperty Node | foreach-object {$_.'#text'}

Get a list of Sites

$sites_request = ""
$resp = Invoke-WebRequest -URI $uri -Body $sites_request -ContentType 'text/xml' -Method post
$sites = $resp.content | Select-XMl -XPath '//@name' | Select-Object -ExpandProperty Node | foreach-object {$_.'#text'}
Write-Output $sites

@patrickave
Copy link

patrickave commented Jan 26, 2019

It doesn't store it in plain text. You first generate a hashed text in a text file that it reads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants