Skip to content

Instantly share code, notes, and snippets.

@righettod
Last active September 2, 2022 16:48
Show Gist options
  • Save righettod/5cec4775efc2f626f50efd2145731100 to your computer and use it in GitHub Desktop.
Save righettod/5cec4775efc2f626f50efd2145731100 to your computer and use it in GitHub Desktop.
Quick PowerShell functions to identify any courses or labs missed from the Portswigger WebAcademy courses.
function Test-WebAcademy-Labs-Status($sessionCookieValue){
$storageFile="$env:USERPROFILE\.webacademy-labs-status"
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "SessionId"
$cookie.Value = $sessionCookieValue
$cookie.Domain = ".portswigger.net"
$session.Cookies.Add($cookie);
Write-Host "[i] Status storage file: $storageFile" -ForegroundColor Cyan
Write-Host "[+] Retrieving labs status from PortSwigger labs web page..." -ForegroundColor Yellow
$resp = (Invoke-WebRequest -UseBasicParsing -URI https://portswigger.net/web-security/all-labs -WebSession $session).Content
$verifSession=(Select-String "widgetcontainer-lab-link is-solved" -InputObject $resp -AllMatches).Matches.Count
if($verifSession -eq 0){
Write-Host "[X] Session seems invalid because no labs status was retrieved!" -ForegroundColor Red
}else{
$labNotSolved = (Select-String "Not solved" -InputObject $resp -AllMatches).Matches.Count
[int]$labNotSolvedLastValue=Get-Content $storageFile
Write-Host "[i] Lab not solved: $labNotSolved | Lab not solved value from saved status: $labNotSolvedLastValue." -ForegroundColor Cyan
if($labNotSolved -ne $labNotSolvedLastValue){
$newLab = $labNotSolved - $labNotSolvedLastValue
Write-Host "[!] There is new $newLab labs to solve." -ForegroundColor Red
$labNotSolved | Out-File -FilePath $storageFile
}else{
Write-Host "[V] No new lab to solve detected." -ForegroundColor Green
}
}
}
function Test-WebAcademy-Courses-Status($sessionCookieValue){
$paddingLength = 120
$base = "https://portswigger.net/web-security"
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "SessionId"
$cookie.Value = $sessionCookieValue
$cookie.Domain = ".portswigger.net"
$session.Cookies.Add($cookie);
$resp = (Invoke-WebRequest -UseBasicParsing -URI "$base/all-materials/detailed").Content
Select-String '"/web-security/.*"' -input $resp -AllMatches | ForEach-Object {
$alreadyProcessed = [System.Collections.ArrayList]@()
$toSkip = @("$base/all-labs", "$base/all-materials", "$base/learning-path", "$base/getting-started", "$base/cross-site-scripting/cheat-sheet", "$base/dashboard")
$missed = [System.Collections.ArrayList]@()
foreach ($matches in $_.matches) {
$course = $matches.Value.Replace('"', '').split("#")[0].split(">")[0]
$courseUrl = "https://portswigger.net$course"
if ($alreadyProcessed.Contains($courseUrl) -or $toSkip.Contains($courseUrl)) {
continue
}
$msg = "`rChecking: " + $courseUrl.padRight($paddingLength)
Write-Host $msg -NoNewline
$resp = (Invoke-WebRequest -UseBasicParsing -URI $courseUrl -WebSession $session).Content
$verifCompleted = (Select-String '<span id="PageCompletedContent" class="">' -InputObject $resp -AllMatches).Matches.Count
if ($verifCompleted -eq 0) {
$missed.Add($courseUrl) | out-null
}
$alreadyProcessed.Add($courseUrl) | out-null
Start-Sleep -Seconds 0.5
}
if ($missed.Count -eq 0) {
$msg = "`r[V] No missed course found.".padRight($paddingLength)
Write-Host $msg -ForegroundColor Green
}
else {
$msg = "`r[!] Missed courses found:".padRight($paddingLength)
Write-Host $msg -ForegroundColor Red
$missed
}
}
}
@righettod
Copy link
Author

righettod commented Sep 2, 2022

Note: It is a quick and dirty script 😀

📑 Steps:

  1. Login here: https://portswigger.net/users
  2. Get the value of the cookie named SessionId.
  3. Pass the cookie value to the function called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment