|
<# |
|
.SYNOPSIS |
|
Auto-login to IUST captive portal. |
|
|
|
.DESCRIPTION |
|
Set your credentials below, or leave blank to be prompted. |
|
#> |
|
|
|
# ========== CONFIG ========== |
|
$Username = "" # e.g. "student123" |
|
$Password = "" # e.g. "pa$$w0rd" |
|
# ============================ |
|
|
|
# Prompt for username/password if empty |
|
if ([string]::IsNullOrWhiteSpace($Username)) { |
|
$Username = Read-Host "Enter your username" |
|
} |
|
if ([string]::IsNullOrWhiteSpace($Password)) { |
|
$Secure = Read-Host "Enter your password" -AsSecureString |
|
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto( |
|
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($Secure) |
|
) |
|
} |
|
|
|
# Initialize session |
|
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession |
|
|
|
# STEP 1: Submit login.php to get response |
|
Write-Host "`n[Step 1] Logging in..." -ForegroundColor Cyan |
|
$response = Invoke-WebRequest -UseBasicParsing -Uri "https://login.iust.ac.ir/login.php" ` |
|
-Method "POST" ` |
|
-WebSession $session ` |
|
-ContentType "application/x-www-form-urlencoded" ` |
|
-Body "dst=status.html&popup=false&username=$Username&password=$Password" |
|
|
|
# Extract values using regex |
|
$formAction = "" |
|
$dst = "" |
|
$jsUsername = "" |
|
$jsPassword = "" |
|
|
|
if ($response.RawContent -match '<form[^>]*action="([^"]+)"') { |
|
$formAction = $matches[1] |
|
} |
|
if ($response.Content -match '<input[^>]*name="dst"[^>]*value="([^"]+)"') { |
|
$dst = $matches[1] |
|
} |
|
if ($response.RawContent -match "document\.login\.username\.value\s*=\s*'([^']+)'") { |
|
$jsUsername = $matches[1] |
|
} |
|
if ($response.RawContent -match "document\.login\.password\.value\s*=\s*'([^']+)'") { |
|
$jsPassword = $matches[1] |
|
} |
|
|
|
Write-Host "→ Form action URL: $formAction" |
|
Write-Host "→ Hidden dst value: $dst" |
|
Write-Host "→ JS username: $jsUsername" |
|
Write-Host "→ JS password hash: $jsPassword" |
|
|
|
# STEP 2: Submit actual login form |
|
Write-Host "`n[Step 2] Submitting form..." -ForegroundColor Cyan |
|
|
|
$authResponse = Invoke-WebRequest -UseBasicParsing ` |
|
-Uri $formAction ` |
|
-Method POST ` |
|
-WebSession $session ` |
|
-ContentType "application/x-www-form-urlencoded" ` |
|
-Body @{ |
|
username = $jsUsername |
|
password = $jsPassword |
|
dst = $dst |
|
popup = "true" |
|
} |
|
|
|
# Show results |
|
Write-Host "`n=== Captive Portal Response ===" -ForegroundColor Green |
|
Write-Host "Status Code : $($authResponse.StatusCode)" |
|
Write-Host "Final URL : $($authResponse.BaseResponse.ResponseUri)" |
|
$snippet = $authResponse.RawContent.Substring(0, [Math]::Min(200, $authResponse.RawContent.Length)) |
|
Write-Host "Body Snippet:`n$snippet…" |