Giter Club home page Giter Club logo

powerwebshot's Introduction

PowerWebShot

A PowerShell tool for taking screenshots of multiple web servers quickly.

Requirements

This tool utilizes Selenium and PhantomJS to screenshot web servers. I've included the phantomjs.exe and Selenium WebDriver.dll in this repository but if you would like to download them directly from their sources they can be found here:

Selenium - http://www.seleniumhq.org/download/

PhantomJS - http://phantomjs.org/

The phantomjs.exe and WebDriver.dll must be in the current working directory of the PowerWebShot.ps1 script.

Usage

PowerWebShot can be used to screenshot a single URL with the -URL option or a list of URL's from a file with the -UrlList option. Each web server will have a thumbnail generated and added to an HTML report at report.html in the output directory.

First, run powershell.exe and import the script with:

C:\PS> Import-Module PowerWebShot.ps1

Screenshot a single URL

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.

C:\PS> Invoke-PowerWebShot -URL http://www.google.com

Screenshot a list of URLs and output to a custom directory

This command will take a screenshot each of the URLs 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".

C:\PS> Invoke-PowerWebShot -UrlList urllist.txt -OutputDir web-server-screenshot-directory

PowerWebShot Options

URL             - A single URL to screenshot.
UrlList         - A list of URL's one per line to screenshot.
OutputDir       - The directory to output the screenshots to. If none is specified one will be created automatically.

Special Thanks

Thanks goes to Chris Truncer for developing EyeWitness (https://github.com/ChrisTruncer/EyeWitness), which this tool was heavily inspired by.

powerwebshot's People

Contributors

dafthack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powerwebshot's Issues

Could not load file or assembly 'file:///D:\Powershell\PowerWebShot-master\WebDriver.dll'

I'm having the error below? Any ideas? Location of the webdriver is correct.

Add-Type : Could not load file or assembly 'file:///D:\Powershell\PowerWebShot-master\WebDriver.dll' or one of its
dependencies. Operation is not supported.
(Exception from HRESULT: 0x80131515)
At D:\Powershell\PowerWebShot-master\PowerWebShot.ps1:81 char:1

  • Add-Type -path $SeleniumDriverPath
  •   + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
      + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
    
    

New-Object : Cannot find type [OpenQA.Selenium.PhantomJS.PhantomJSOptions]: verify that the assembly containing this
type is loaded.
At D:\Powershell\PowerWebShot-master\PowerWebShot.ps1:82 char:56

  • ... ions]$options = New-Object OpenQA.Selenium.PhantomJS.PhantomJSOptions
  •                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    • FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Screenshots failing for me

Downloaded the zip, followed the instructions, and received the following error. The report.html file is generated, but no screenshot. Not sure what I'm missing. Both the exe & dll are in the same directory. End-user error?

PS C:\Users\user\Desktop\PowerWebShot> Invoke-PowerWebShot -URL http://www.google.com
New-Object : Exception calling ".ctor" with "2" argument(s): "The file .\PhantomJS.exe does not exist. The driver can be downloaded at http://phantomjs.org/download.html"
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:93 char:11

  • $driver = New-Object OpenQA.Selenium.PhantomJS.PhantomJSDriver($phant ...
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
    • FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'Url' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:96 char:1

  • $driver.Url = "about:constant"
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound
    
    

[*] The output directory 2017-07-11-125101 does not exist. Creating directory 2017-07-11-125101.

Directory: C:\Users\user\Desktop\PowerWebShot

Mode LastWriteTime Length Name


d----- 7/11/2017 12:51 PM 2017-07-11-125101
The property 'Url' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:169 char:9

  •     $driver.Url = $name
    
  •     ~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:170 char:9

  •     $driver.Manage().Window.Maximize()
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:178 char:9

  •     $driver.GetScreenshot().SaveAsFile(($OutputPath + "\" + $file ...
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:185 char:9

  •     $driver.Navigate().Back()
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Users\user\Desktop\PowerWebShot\PowerWebShot.ps1:273 char:1

  • $driver.Quit()
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
    
    
    

PS C:\Users\user\Desktop\PowerWebShot>

Failure to Screenshot Servers With SSL Certificate Issues

Currently, PowerWebShot fails to screenshot web servers with SSL issues such as self-signed certificates, or invalid certificates. I believe this is due to the "acceptSslCerts" flag being set to 'false' by PhantomJS. I've tried a number of different options for accepting SSL certs but none seem to be working.

I've tried the following:

  • Passing CLI Args to phantomjs.exe including --ignore-ssl-errors=yes
  • Setting DesiredCapabilities prior to creating the PhantomJS object including ('CapabilityType.ACCEPT_SSL_CERTS', $true)
  • Adding additional capabilities after creating the PhantomJS object.

Adding additional capabilities to a PhantomJSOptions object prior to creating the PhantomJS object appears to set some options correctly but not "acceptSslCerts". For example, in the current code setting ("phantomjs.page.settings.webSecurityEnabled", $false) does actually set that option to false. However trying a number of variations on ignore-ssl-errors doesn't seem to work.

Current Relevant Code:

$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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.