-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-web-request.ps1
289 lines (231 loc) · 9.78 KB
/
get-web-request.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)][string]$list,
[Parameter(Mandatory=$false)][bool]$local_proxy=$false
)
$OutputEncoding = [ System.Text.Encoding]::UTF8
$regex_IP="\b(\d{1,3}\.){3}\d{1,3}\b"
$dns_host=0;
$domain_dict=@{}
$sorted_valid_dom=@()
$sorted_nx_dom=@()
$proxy_burp="http://127.0.0.1:8080"
# API token for ipinfo.io
$token='here goes your token'
# AbuseIP API address and key
$abuseIPurl = 'https://api.abuseipdb.com/api/v2/check'
$headers = @{
Accept= "application/json"
Key= "here goes the key"
}
$path=Test-Path $list;
if($list -eq ''-or $list -eq $null)
{
Write-Host '@
To send GET request via local burp proxy
Usage: ./get-web-request.ps1 -list your_file_list.txt -local_proxy $true
example: /get-web-request.ps1 -list ./test.txt -local_proxy $true
To send GET request directly
Usage: ./get-web-request.ps1 -list your_file_list.txt -local_proxy $false
Example: /get-web-request.ps1 -list ./test.txt -local_proxy $false
You can change your burp port in the this file. variable name is: proxy_burp
By default proxy listens on port 8080
@'
break
}
if(!$path -or $path -eq $null)
{
Write-Output "[*] Unable to locate the spcified input file";
break;
}
# importing domain list froma a file/variable and asigning to the domain_list variable
$domain_list=get-Content $list
$ie=([Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer)
$opera=([Microsoft.PowerShell.Commands.PSUserAgent]::Opera)
$chrome=([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome)
$safari=([Microsoft.PowerShell.Commands.PSUserAgent]::Safari)
$firefox=([Microsoft.PowerShell.Commands.PSUserAgent]::FireFox)
$agents=@($ie,$opera,$chrome,$safari,$firefox)
# 1xx informational response – the request was received, continuing process
# 2xx successful – the request was successfully received, understood and accepted
# 3xx redirection – further action needs to be taken in order to complete the request
# 4xx client error – the request contains bad syntax or cannot be fulfilled
# 5xx server error – the server failed to fulfill an apparently valid request
# creating an array containing both HTTP and HTTPS addresses
#creating an array inside hashtable {domain_name:(http_address,https_address)}
foreach ($a in $domain_list)
{
$trim_a=$a.trim("")
$domain_dict.Add($trim_a,@("http://$trim_a","https://$trim_a"))
}
function get-abuse {
param (
[Parameter(Mandatory=$true)][string]$IP
)
$body = @{
ipAddress= $IP
maxAgeInDays= "365"
verbose=""
}
$abuse=Invoke-RestMethod -uri $abuseIPurl -Headers $headers -Body $body -Method get
if($abuse.data.totalReports -le 0){
return $null
} else {
return $abuse
}
}
function loging {
param (
[Parameter(Mandatory=$true)][string]$key
)
}
foreach($key in $domain_dict.Keys)
{
$abuse=$null
$no_dns=$false
$errorrequest="N/A"
$errorstatus="N/A"
$resp=$null
$city="N/A"
$country="N/A"
$region="N/A"
$hostingname="N/A"
$hostingcompany="N/A"
$IP=$null
for($x=0;$x -lt 2;$x++)
{
$errorrequest=$null
$errorstatus=$null
$resp=try
{
if($local_proxy -eq $true)
{
$agent=$agents | Get-Random
Invoke-WebRequest -uri $domain_dict[$key][$x] -UserAgent $agent -Proxy $proxy_burp -TimeoutSec 3 -SkipCertificateCheck
}
else
{
$agent=$agents | Get-Random
Invoke-WebRequest -uri $domain_dict[$key][$x] -UserAgent $agent -TimeoutSec 3 -SkipCertificateCheck
}
}
catch
{
$errorrequest=$_.exception.response.Headers.Location.AbsoluteUri
$errorstatus=$_.exception.response.statuscode
}
$dns_host=host $key
if ( ($dns_host -match "NXDOMAIN") -or ($dns_host -match "SERVFAIL") -or ($dns_host -eq $null))
{
$no_dns=$true
$sorted_nx_dom+=$key
Write-host "[-] Non existent domain" -BackgroundColor Red -ForegroundColor Black
}
else
{
if($IP -ne $null){
$IP=([system.net.dns]::GetHostByName($key)).AddressList | Select-Object -ExpandProperty ipaddresstostring -First 1
}
else
{
$IP=([system.net.dns]::GetHostByName($key)).AddressList | Select-Object -ExpandProperty ipaddresstostring -First 1
$geo="ipinfo.io/$IP/geo?token=$token"
$hosting="ipinfo.io/$IP/json?org?token=$token"
$geoinfo=Invoke-RestMethod -uri $geo
$hostingInfo=Invoke-RestMethod -uri $hosting
$abuse=get-abuse($IP)
}
$sorted_valid_dom+=$key
$city=$geoinfo.City
$country=$geoinfo.Country
$region=$geoinfo.Region
$hostingname=$hostingInfo.hostname
$hostingcompany=$hostingInfo.org
#$var | select-string "NXDOMAIN" | Out-File -FilePath NXDOMAIN.txt -Append
$r=$resp | Select-Object -ExpandProperty statuscode
if (($r -match '^(1|2|3|4|5)\d\d$' -or $r -eq "Unauthorized" -or $r -eq "Forbidden" -or $r -eq "MethodNotAllowed") -and $resp -notmatch "burp")
{
$domain_dict[$key][$x] | Out-File -FilePath valid_address.txt -Append
Write-Output "■ Response = $r [+] Web Server is reachable" | Tee-Object -FilePath ./SCAN.LOG -Append
}
else
{
$domain_dict[$key][$x] | Out-File -FilePath invalid_address.txt -Append
Write-Output "■ Response = $r [$errorstatus] Web Address cannot be reached " | Tee-Object -FilePath ./SCAN.LOG -Append
}
}
Write-Output "■ Web Server = $($domain_dict[$key][$x])" | Tee-Object -FilePath ./SCAN.LOG -Append
if($no_dns)
{
Write-Output "■ $dns_host" | Tee-Object -FilePath ./SCAN.LOG -Append
}
else
{
Write-Output "■ $dns_host" | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "■ Location -> Country: $country, Region: $region, City: $city" | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "■ Hosting Server = $hostingname, Hosting Company = $hostingcompany" | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "■ Original domain = $($resp.BaseResponse.RequestMessage.RequestUri.Host)" | Tee-Object -FilePath ./SCAN.LOG -Append
if($resp.BaseResponse.RequestMessage.RequestUri.Originalstring -match "http://")
{
Write-Output "■ Destination page = $($resp.BaseResponse.RequestMessage.RequestUri.Originalstring) ¯\_(ツ)_/¯ no ssl?" | Tee-Object -FilePath ./SCAN.LOG -Append
}
else
{
Write-Output "■ Destination page = $($resp.BaseResponse.RequestMessage.RequestUri.Originalstring) " | Tee-Object -FilePath ./SCAN.LOG -Append
}
Write-Output "■ Error Status code = $errorstatus, Redirected to: $errorrequest " | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "=====================================" | Tee-Object -FilePath ./SCAN.LOG -Append
}
}
Write-Output $(Get-Date) | Out-File -FilePath SCAN.LOG -Append
Write-Output "■ IP reputation summary from AbuseIPdb.com ■" | Tee-Object -FilePath ./SCAN.LOG -Append
if ($abuse -eq $null)
{
Write-Output "■ No data for $key ᕕ( ᐛ )ᕗ" | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "+++++++++++++++++++++++++++++++++++++++++++++" | Tee-Object -FilePath ./SCAN.LOG -Append
}
else
{
write-output $abuse.data | Select-Object totalreports,numDistinctUsers,abuseConfidenceScore,lastReportedAt,ipAddress,Countryname | fl | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "Categories : $($abuse.data.reports |
ForEach-Object{ switch($_.categories)
{
3 {",☢ Fraud Orders "}
4 {",☢ DDos "}
5 {",☢ FTP Brute-Force "}
6 {",☢ Ping of Death"}
7 {",☢ Phishing"}
8 {",☢ Fraud VoIP"}
9 {",☢ Open Proxy"}
10 {",☢ Web Spam"}
11 {",☢ Email Spam"}
12 {",☢ Blog Spam"}
13 {",☢ VPN IP"}
14 {",☢ Port Scan"}
15 {",☢ Hacking"}
16 {",☢ SQL Injection"}
17 {",☢ Spoofing"}
18 {",☢ Brute-Force"}
19 {",☢ Bad Web BOT"}
20 {",☢ Exploited Host"}
21 {",☢ Web App Attack"}
22 {",☢ SSH"}
23 {",☢ IOT Attack"}
}
} | Select-Object -Unique)"| Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "https://www.abuseipdb.com/check/$IP" | Tee-Object -FilePath ./SCAN.LOG -Append
Write-Output "+++++++++++++++++++++++++++++++++++++++++++++" | Tee-Object -FilePath ./SCAN.LOG -Append
}
}
$sorted_valid_dom |Select-Object -Unique | Out-File -FilePath VALID_DOMAINS.txt -Append
$sorted_nx_dom | Select-Object -Unique | Out-File -FilePath NXDOMAIN.txt -Append
# $duplicat=Get-Content ./valid_address.txt
# $unikat=@()
# foreach($d in $duplicat){
# if($d -match "https"){
# $unikat+=$d.substring(8,$d.length-8)
# } else {
# $unikat+=$d
# }
# }
# $unikat | select -Unique | Out-File -FilePath VALID_DOMAINS_LIST.txt -Append