Scanning /16 subnets - PowerShell 7 Cheats

The following is for those needing to scan /16 subnets on the community edition. Requires Powershell7

Long story short, Used Development Tools to scrape the GET/PUT’s from the network traffic so I can make life a little easier. I could have used a similar method in creating the scanning targets as well but I failed to do that initially.

GSM doesn’t allow the scanning of /16 subnets unless you cover every single /24 within the /16 as a target and task. And there is now way to really schedule tasks either. This allows you to kick off the tasks (possibly automatically if you craftily generate the session keys by other means).

#To automate tasks/scans:

$myGSADID=“”
$mytoken=“”
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.Cookies.Add((New-Object System.Net.Cookie(“GSAD_SID”, $myGSADID, “/”, “”)))

#Get all task IDS in XML format from
https:///gmp?token=&cmd=get_tasks&usage_type=scan&filter=sort%3Dname%20first%3D1%20rows%3D100000
You can use a similar method to grab any information you need in XML format. It just needs to be XML parsed into powershell using the $var=[XML](gc .\your stuff.txt)

$taskid=“sample task id but you can enumerate through all of them, no idea what effect that would have.”
Invoke-WebRequest -SkipCertificateCheck -Uri “https:///gmp” -Method “POST” -WebSession $session -Form @{token=$mytoken;cmd=“start_task”;task_id=$($taskid)}

The following is a similar method in PowerShell 7 to create the “tasks” themselves from an existing list of targets.

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$session.Cookies.Add((New-Object System.Net.Cookie(“GSAD_SID”, $myGSADID, “/”, “”)))
Invoke-WebRequest -SkipCertificateCheck -UseBasicParsing -Uri “https:///gmp” -Method "POST"
-WebSession $session `
-Form @{token=$mytoken;cmd=“create_task”;add_tag:0;apply_overrides:1;auto_delete=“no”;auto_delete_data=5;comment=$($target.name);config_id=$config_id;host_ordering=“sequential”;in_assets=1;max_checks=4;max_hosts=20;min_qod=70;name=$($target.name);scanner_id=$scanner_id;scanner_type=2;schedule_id=0;schedule_periods=0;source_iface=“”;target_id=$($target.id);usage_type=“scan”}

–Logging into GreenBone from Powershell (community Edition)

#credentials for webfront end
$username=“yourusername”
$password=“yourpassword”

#new websession
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession

#grab results of login
$results=Invoke-WebRequest -SkipCertificateCheck -Uri “https:///gmp” -Method “POST” -WebSession $session -Form @{cmd=“login”;login=$username;password=$password}

#parse session info
$myGSADID=$results.headers.“Set-Cookie”.Split(“;”)[0].Trim().Replace(“GSAD_SID=”,“”)
$mytoken=$([XML]$results).envelope.token

#add session id
$session.Cookies.Add((New-Object System.Net.Cookie(“GSAD_SID”, $myGSADID, “/”, “”)))

glhf!

V/R
Nick