1
- function Check-CSRFToken {
1
+ function Check-CSRFToken {
2
2
param ($file )
3
3
4
4
$content = Get-Content - Path $file
@@ -91,13 +91,18 @@ if (-not (Test-Path $path -PathType Container)) {
91
91
exit
92
92
}
93
93
94
- # Get all .aspx files in the given path recursively
94
+
95
+ # Get all .aspx, .aspx.cs, and .cs files in the given path recursively
95
96
$aspxFiles = Get-ChildItem - Path $path - Filter " *.aspx" - Recurse
97
+ $aspxCSFiles = Get-ChildItem - Path $path - Filter " *.aspx.cs" - Recurse
98
+ $csFiles = Get-ChildItem - Path $path - Filter " *.cs" - Recurse
99
+
100
+ $allFiles = $aspxFiles + $aspxCSFiles + $csFiles # Combine all the file arrays
96
101
97
- # Perform checks on each .aspx file
98
102
$matchesFound = $false
99
103
$matchCounter = 0 # Initialize total match counter
100
- foreach ($file in $aspxFiles ) {
104
+
105
+ foreach ($file in $allFiles ) {
101
106
$matches , $count = Check- CSRFToken $file.FullName
102
107
if ($matches ) {
103
108
$matchesFound = $true
@@ -106,9 +111,9 @@ foreach ($file in $aspxFiles) {
106
111
}
107
112
108
113
if ($matchesFound ) {
109
- Write-Host " Failing to implement CSRF protection in your web application can expose users to Cross-Site Request Forgery attacks.
114
+ Write-Host " `n`n Failing to implement CSRF protection in your web application can expose users to Cross-Site Request Forgery attacks.
110
115
`n By ensuring the presence of secure, hidden CSRF tokens within forms and associating them with session variables,
111
- `n you can prevent attackers from forging malicious requests and protect user data and actions." - ForegroundColor DarkYellow
116
+ `n you can prevent attackers from forging malicious requests and protect user data and actions."
112
117
113
118
# Calculate the score based on the total match count
114
119
$Severity = " LOW"
@@ -125,10 +130,10 @@ if ($matchesFound) {
125
130
}
126
131
127
132
Write-Host " `n Total Vulnerability Matches Found: $matchCounter " - ForegroundColor Green
128
- Write-Host " `n Severity: $Severity " - ForegroundColor DarkYellow
133
+ Write-Host " `n Severity: $Severity " - ForegroundColor Red
129
134
Write-Host " `n Total Vulnerabilities Score: $score " - ForegroundColor DarkYellow
130
135
}
131
136
else {
132
137
Write-Host " `n No Matches Found For Scanned Vulnerabilities."
133
138
134
- }
139
+ }
0 commit comments