T09 · Insecure Skill Coding Practices
- Location
SKILL.md:35- Finding
Unsafe Cross-Domain IP Selection and Privileged Hosts-File Modification
- Content
View full analysis
$null $ips[$domain] = ($result | Select-String -Pattern "Addresses:" -Context 0,10 | ForEach-Object { $_.Context.PostContext }) -replace '\s+', '' | Where-Object { $_ -match '^\d+\.\d+\.\d+\.\d+$' } } # Ping each IP and find fastest $results = @() foreach ($ip in ($ips.Values | Select-Object -Unique)) { $avg = (ping -n 3 $ip | Select-String -Pattern "平均").ToString() -replace '.*= (\d+)ms.*', '$1' if ($avg) { $results += [PSCustomObject]@{ IP = $ip; Avg = [int]$avg } } } $fastest = ($results | Sort-Object Avg | Select-Object -First 1).IP # Update hosts $entry = "$fastest github.com`n$fastest api.github.com" $current = Get-Content $hostsPath -Raw -ErrorAction SilentlyContinue if ($current -notmatch "github\.com") { Add-Content -Path $hostsPath -Value $entry } else { $updated = $current -replace "[\d\.]+\s+github\.com`n?[\d\.]+\s+api\.github\.com", $entry Set-Content -Path $hostsPath -Value $updated } # Flush DNS ipconfig /flushdns | Out-Null Write-Host "Done! Fastest IP: $fastest" ``` ### Technical Analysis The script combines all IPv4 addresses resolved for `github.com`, `api.github.com`, and `objects.githubusercontent.com` into one candidate pool. It then selects a single address based only on ping latency and assigns that address to both `github.com` and `api.github.com`. This process does not verify that the selected address is valid for each hostname being mapped. An address returned for `objects.githubusercontent.com`, for example, can be selected and assigned to the two unrelated hostnames. Latency alon ...[truncated 2893 chars]- Remediation
View remediation
