-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathPowerWebShot.ps1
executable file
·277 lines (217 loc) · 8.4 KB
/
PowerWebShot.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
function Invoke-PowerWebShot{
<#
.SYNOPSIS
This function uses Selenium and PhantomJS to screenshot web servers and create a report with thumbnails of each one for quick analysis. (Based of of Chris Truncer's Eyewitness)
Invoke-PowerWebShot
Author: Beau Bullock (@dafthack)
License: MIT
Required Dependencies: Phantomjs.exe and the Selenium WebDriver.dll need to be in the current working directory off the script.
Optional Dependencies: None
.DESCRIPTION
This function uses Selenium and PhantomJS to screenshot web servers and create a report with thumbnails of each one for quick analysis. (Based of of Chris Truncer's Eyewitness)
.PARAMETER URL
A single URL to screenshot.
.PARAMETER UrlList
A list of URL's one per line to screenshot.
.PARAMETER Threads
(Placeholder for multi-threading to be added in later)
.PARAMETER OutputDir
The directory to output the screenshots to. If none is specified one will be created automatically.
.EXAMPLE
C:\PS> Invoke-PowerWebShot -URL http://www.google.com
Description
-----------
This command will take a screenshot of http://www.google.com and add it to a file called report.html in an automatically generated directory with the current date/time as the folder title.
.EXAMPLE
C:\PS> Invoke-PowerWebShot -UrlList urllist.txt -OutputDir web-server-screenshot-directory
Description
-----------
This command will take a screenshot each of the URL's in the file "urllist.txt" and add them to a file called report.html. Each screenshot and the report will be located in a directory called "web-server-screenshot-directory".
#>
Param
(
[Parameter(Position = 0, Mandatory = $false)]
[string]
$URL = "",
[Parameter(Position = 1, Mandatory = $false)]
[string]
$UrlList = "",
[Parameter(Position = 2, Mandatory = $false)]
[string]
$Threads = "",
[Parameter(Position = 3, Mandatory = $false)]
[string]
$OutputDir = ""
)
if (($URL -eq "") -and ($UrlList -eq ""))
{
Write-Output "[*] No URL's were specified to be scanned. Please use the -URL option to specify a single URL or -UrlList to specify a list."
break
}
# Load up the Selenium and PhantomJS drivers
$SeleniumDriverPath = ".\WebDriver.dll"
Add-Type -path $SeleniumDriverPath
[OpenQA.Selenium.PhantomJS.PhantomJSOptions]$options = New-Object OpenQA.Selenium.PhantomJS.PhantomJSOptions
#$caps = [OpenQA.Selenium.Remote.DesiredCapabilities]::phantomjs()
#$caps.SetCapability('CapabilityType.ACCEPT_SSL_CERTS', $true)
$cli_args = @()
$cli_args += "--web-security=no"
$cli_args += "--ignore-ssl-errors=yes"
$options.AddAdditionalCapability("phantomjs.cli.args", $cli_args)
$options.AddAdditionalCapability("phantomjs.page.settings.ignore-ssl-errors", $true)
$options.AddAdditionalCapability("phantomjs.page.settings.webSecurityEnabled", $false)
$options.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko")
$phantomjspath = ".\"
$driver = New-Object OpenQA.Selenium.PhantomJS.PhantomJSDriver($phantomjspath, $options)
#$driver = New-Object OpenQA.Selenium.Remote.RemoteWebDriver($uri,$caps)
$driver.Url = "about:constant"
# If no output directory was named we will create one in with the current date/time.
If($OutputDir -eq "")
{
$OutputDir = Get-Date -format yyyy-MM-dd-HHmmss
}
# Testing to see if the output directory exists. If not, we'll create it.
$TestOutputDir = Test-Path $OutputDir
If($TestOutputDir -ne $True)
{
Write-Output "[*] The output directory $OutputDir does not exist. Creating directory $OutputDir."
mkdir $OutputDir
}
# Getting the full path of the output dir.
$OutputPath = Convert-Path $OutputDir
## Choose to ignore any SSL Warning issues caused by Self Signed Certificates
## Code From http://poshcode.org/624
## Create a compilation environment
$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler=$Provider.CreateCompiler()
$Params=New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable=$False
$Params.GenerateInMemory=$True
$Params.IncludeDebugInformation=$False
$Params.ReferencedAssemblies.Add("System.DLL") > $null
$TASource=@'
namespace Local.ToolkitExtensions.Net.CertificatePolicy {
public class TrustAll : System.Net.ICertificatePolicy {
public TrustAll() {
}
public bool CheckValidationResult(System.Net.ServicePoint sp,
System.Security.Cryptography.X509Certificates.X509Certificate cert,
System.Net.WebRequest req, int problem) {
return true;
}
}
}
'@
$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly
## We now create an instance of the TrustAll and attach it to the ServicePointManager
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
## end code from http://poshcode.org/624
# Function to escape filenames of websites. Credit to: https://chrisseroka.wordpress.com/2012/11/27/get-website-screenshots-with-custom-web-crawler/
function EscapeFileName{
param($filename)
$pattern = "[{0}]" -f ([Regex]::Escape([String] [System.IO.Path]::GetInvalidFileNameChars()))
$newfile = [Regex]::Replace($filename, $pattern, '')
$newfile
}
# Function to screenshot the website with Selenium. Credit to: https://chrisseroka.wordpress.com/2012/11/27/get-website-screenshots-with-custom-web-crawler/
$global:images = @()
$global:UrlNames = @()
$global:PrevName = ""
function Take-ScreenShot{
param($driver, $name)
$fileName = ($name + ".png")
$fileName = EscapeFileName -filename $fileName
$driver.Url = $name
$driver.Manage().Window.Maximize()
if (($driver.Url -eq "") -or ($driver.Url -eq "about:blank") -or ($driver.Url -eq "about:constant") -or ($driver.Url -eq $PrevName))
{
Write-Output "[*] Something went wrong for $name"
}
else
{
$driver.GetScreenshot().SaveAsFile(($OutputPath + "\" + $fileName), [System.Drawing.Imaging.ImageFormat]::Png)
$global:images += $filename
$global:UrlNames += $name
}
$global:PrevName = $driver.Url
$driver.Navigate().Back()
}
# If only one URL was specified let's just screenshot that. Else go through the list of URLs.
If($URL -ne "")
{
Take-ScreenShot -driver $driver -name $URL
}
else
{
$URLArray = @()
$URLArray = Get-Content $UrlList
Foreach ($link in $UrlArray)
{
Write-Output "[*] Now analyzing $link"
Take-ScreenShot -driver $driver -name $link
}
}
# Now we generate an HTML page containing the screenshots for rapid analysis.
function GenerateHtml{
param($images, $OutputPath)
$Html = @()
$Html = "<html><body>
<style>
#sample{
width:300px;
height:300px;
overflow:hidden;
position: relative;
border: 1px solid black;
}
#sample img {
position: absolute;
top: 0px;
left: 0px;
}
#wrapper {
margin-left: 500px;
}
#content {
float: right;
width: 100%;
}
#sidebar {
float: left;
width: 200px;
margin-left: -200px;
background-color: #808080;
}
#cleared {
clear: both;
}
</style>"
$counter = 0
foreach($img in $images)
{
$Html += '<div id ="wrapper">
<div id ="sidebar"><p><a href="'
$Html += $global:UrlNames[$counter]
$Html += '">'
$Html += $global:UrlNames[$counter]
$Html += '</a></p></div>'
$Html += '<div id ="content">'
$Html += '<div id="sample"><a href="'
$Html += $img
$Html += '">'
$Html += "<img src='$img' style=`"max-width:300px`"/></a></div></div>"
$Html += '<div id="cleared"></div>
</div>
<br>
<br>
<br>'
$counter++
}
$Html += "</body></html>"
$Html | Out-File -FilePath ($OutputPath + "\" + "report.html")
}
GenerateHtml -images $global:images -OutputPath $OutputPath
$driver.Quit()
}