Last active
November 13, 2017 11:27
-
-
Save d-oderbolz/0dd0f92818827e8ab62a5550d94fcb27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This scipt does a check of all the email adresses given in a CSV File | |
# See also http://www.govcert.admin.ch/blog/20/leaked-mail-accounts | |
# Written by Daniel C. Oderbolz, 2016 using code by Jon Gurgul | |
# Blessing from https://github.com/endlesssoftware/sqlite3/blob/master/btree.c | |
# May you do good and not evil. | |
# May you find forgiveness for yourself and forgive others. | |
# May you share freely, never taking more than you give | |
# When resulting page contains | |
# <center><h1>Email Address <b>NOT</b> in Database</h1><br /></center> | |
# the adress is not in the DB | |
# The File has a simple Header: "Email" | |
$filepath = "users.csv" | |
$baseurl = "https://checktool.ch/index.php?hash=" | |
#http://jongurgul.com/blog/get-stringhash-get-filehash/ | |
Function Get-StringHash([String] $String,$HashName = "SHA256") | |
{ | |
$StringBuilder = New-Object System.Text.StringBuilder | |
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{ | |
[Void]$StringBuilder.Append($_.ToString("x2")) | |
} | |
$StringBuilder.ToString() | |
} | |
# Main Loop | |
Import-CSV $filepath -Header Email | Foreach-Object{ | |
# Progress | |
Write-Host -NoNewline "." | |
# Get SHA256 Hash | |
$hash = Get-StringHash($_.Email.toLower().trim()) | |
$url = $baseurl + $hash | |
# https://teusje.wordpress.com/2012/12/29/web-scraping-with-powershell/ | |
$site = Invoke-WebRequest -UseBasicParsing -Uri $url | |
# Check if text is there (which is good) | |
$ok = $site.Content -match "Email Address <b>NOT</b> in Database" | |
if ( -not $ok) | |
{ | |
$message = "WARNING: Address " + $_.Email + " Found in Database!" | |
Write-Host | |
Write-Host $message | |
} | |
# Trottle requests | |
Start-Sleep -milliseconds 500 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment