Guest User

Untitled

a guest
Jul 23rd, 2016
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Configurable options:
  2.  
  3. #Make sure the path exists or you will spam your list every time the script runs:
  4. $path_to_notified_file = ".\db\pwnd_list.csv"
  5.  
  6. #users to check for breach
  7. $user_list = ("[email protected]")
  8.  
  9. #SMTP settings:
  10. $email_notify = $true
  11. $subject = "ATTN: Account was included in a data breach"
  12. $body_html = "Hello,<br>It has been noticed by an automated system that your email address was included in the following data breaches:"
  13. $body_signature = "<br>It is recomended you change your passwords on those systems<br><br>Thank you<br>I_script_stuff Notifier Bot<br>"
  14.  
  15. #email credentials enable tested on gmail. If you don't need credentials set $needs_email_creds to false.
  16. $needs_email_creds = $false
  17. #configure credential file for email password if needed:
  18. $creds_path = ".\cred.txt"
  19. #read-host -assecurestring | convertfrom-securestring | out-file $creds_path
  20.  
  21.  
  22.  
  23.  
  24. #SMTP server to use
  25. $smtp = "smtp.gmail.com"
  26. $smtp_port = "587"
  27.  
  28. #process smtp credentials
  29. $pass = get-content $creds_path | convertto-securestring
  30. $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "$from", $pass
  31.  
  32. #
  33. #Functions that power the script
  34. #
  35. function get-breachedstatus() {
  36.     Param(
  37.         [Parameter(Mandatory = $true)][string]$email,
  38.         [AllowEmptyString()]$brief_report="$true"
  39.     )
  40.    
  41.     try{
  42.         if($brief_report) {
  43.         $url = "https://haveibeenpwned.com/api/v2/breachedaccount/" + $email + "?truncateresponse=true"
  44.         } else {
  45.         $url = "https://haveibeenpwned.com/api/v2/breachedaccount/" + $email
  46.         }
  47.     $result = invoke-restmethod "$url" -UserAgent "I_script_stuff checker 0.01"
  48.     return $result
  49.     } catch {
  50.     return $false
  51.     }
  52. }
  53.  
  54. #
  55. # Search and notify
  56. #
  57. if(test-path $path_to_notified_file ) {
  58. $already_found = get-content $path_to_notified_file
  59. } else {
  60. $already_found = ""
  61. echo "Warning: No file loaded for $path_to_notified_file If this is the first time running the script a file will be created."
  62. sleep 1
  63. }
  64.  
  65. foreach($email in $user_list) {
  66.     if($result = get-breachedstatus $email $false) {
  67.         $working_email_body = $body_html
  68.         $act_on_notify = $false
  69.         foreach($line in $result) {
  70.         $service = $line.Name
  71.         $breachdate = $line.breachdate
  72.         $breach_record = "$email,$service,$breachdate"
  73.             if($already_found -notcontains $breach_record) {
  74.             echo "$breach_record"
  75.             echo "$breach_record" >> $path_to_notified_file
  76.                 if($email_notify) {
  77.                 $act_on_notify = $true
  78.                 $working_email_body += "<br>" + $breach_record
  79.                 }
  80.             }
  81.         }
  82.         $working_email_body += $body_signature
  83.         if(($email_notify) -and ($act_on_notify)) {
  84.             if($needs_email_creds) {
  85.             Send-MailMessage -from $from -To "$email" -Subject $subject -bodyashtml($working_email_body) -smtpServer "$smtp" -port "$smtp_port" -credential $credentials -UseSsl
  86.             $working_email_body
  87.             } else {
  88.             #Send-MailMessage -from $from -To "$email" -Subject $subject -bodyashtml($working_email_body) -smtpServer "$smtp" -port "$smtp_port"
  89.             $working_email_body
  90.             }
  91.         }
  92.     }
  93. #lets not over spam
  94. sleep 5
  95. }
Advertisement
Add Comment
Please, Sign In to add comment