Advertisement
krunk_fu

Check Email Blacklist

Aug 12th, 2014
2,576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3. CheckRLB.ps1 - Checks a list servers against a list of RBL and reports any occurrences.
  4.  
  5. .DESCRIPTION
  6. Checks a list servers or IP against a list of RBL and reports any occurrences.
  7.  
  8. .INPUTS
  9.  
  10. .OUTPUTS
  11. Results are emailed
  12.  
  13. .PARAMETER MXRecord
  14. One or more servers or IP, separated by commas, to be checked against the RLB list.
  15.  
  16. .PARAMETER Verbose
  17. Detailed output from the script.
  18.  
  19. .EXAMPLE
  20. To check the host mx1.hotmail.com and aspmx.l.google.com against the blacklist:
  21. CheckRLB.ps1 -MXRecord mx1.hotmail.com, aspmx.l.google.com
  22.  
  23. .NOTES
  24.  
  25. Make sure to change the MX records and SMTP settings to fit your needs.
  26. #>
  27.  
  28.  
  29. [CmdletBinding()]
  30. Param(
  31.     [Parameter( Mandatory=$false)]
  32.     #List of MX records to monitor if the parameter is not changed
  33.     [string[]]$MXRecord = @(
  34.         'mx1.hotmail.com'
  35.         'mx2.hotmail.com'
  36.         'mx3.hotmail.com'
  37.         'mx4.hotmail.com'
  38.     )
  39. )
  40.  
  41. #List of RLB's to check against
  42. $blacklistServers = @(
  43.     'b.barracudacentral.org'
  44.     'spam.rbl.msrbl.net'
  45.     'zen.spamhaus.org'
  46.     'bl.deadbeef.com'
  47.     'bl.emailbasura.org'
  48.     'bl.spamcannibal.org'
  49.     'bl.spamcop.net'
  50.     'blackholes.five-ten-sg.com'
  51.     'blacklist.woody.ch'
  52.     'bogons.cymru.com'
  53.     'cbl.abuseat.org'
  54.     'cdl.anti-spam.org.cn'
  55.     'combined.abuse.ch'
  56.     'combined.rbl.msrbl.net'
  57.     'db.wpbl.info'
  58.     'dnsbl-1.uceprotect.net'
  59.     'dnsbl-2.uceprotect.net'
  60.     'dnsbl-3.uceprotect.net'
  61.     'dnsbl.ahbl.org'
  62.     'dnsbl.cyberlogic.net'
  63.     'dnsbl.inps.de'
  64.     'dnsbl.njabl.org'
  65.     'dnsbl.sorbs.net'
  66.     'drone.abuse.ch'
  67.     'drone.abuse.ch'
  68.     'duinv.aupads.org'
  69.     'dul.dnsbl.sorbs.net'
  70.     'dul.ru'
  71.     'dyna.spamrats.com'
  72.     'dynip.rothen.com'
  73.     'http.dnsbl.sorbs.net'
  74.     'images.rbl.msrbl.net'
  75.     'ips.backscatterer.org'
  76.     'ix.dnsbl.manitu.net'
  77.     'korea.services.net'
  78.     'misc.dnsbl.sorbs.net'
  79.     'noptr.spamrats.com'
  80.     'ohps.dnsbl.net.au'
  81.     'omrs.dnsbl.net.au'
  82.     'orvedb.aupads.org'
  83.     'osps.dnsbl.net.au'
  84.     'osrs.dnsbl.net.au'
  85.     'owfs.dnsbl.net.au'
  86.     'owps.dnsbl.net.au'
  87.     'pbl.spamhaus.org'
  88.     'phishing.rbl.msrbl.net'
  89.     'probes.dnsbl.net.au'
  90.     'proxy.bl.gweep.ca'
  91.     'proxy.block.transip.nl'
  92.     'psbl.surriel.com'
  93.     'rbl.interserver.net'
  94.     'rdts.dnsbl.net.au'
  95.     'relays.bl.gweep.ca'
  96.     'relays.bl.kundenserver.de'
  97.     'relays.nether.net'
  98.     'residential.block.transip.nl'
  99.     'ricn.dnsbl.net.au'
  100.     'rmst.dnsbl.net.au'
  101.     'sbl.spamhaus.org'
  102.     'short.rbl.jp'
  103.     'smtp.dnsbl.sorbs.net'
  104.     'socks.dnsbl.sorbs.net'
  105.     'spam.abuse.ch'
  106.     'spam.dnsbl.sorbs.net'
  107.     'spam.spamrats.com'
  108.     'spamlist.or.kr'
  109.     'spamrbl.imp.ch'
  110.     't3direct.dnsbl.net.au'
  111.     'tor.ahbl.org'
  112.     'tor.dnsbl.sectoor.de'
  113.     'torserver.tor.dnsbl.sectoor.de'
  114.     'ubl.lashback.com'
  115.     'ubl.unsubscore.com'
  116.     'virbl.bit.nl'
  117.     'virus.rbl.jp'
  118.     'virus.rbl.msrbl.net'
  119.     'web.dnsbl.sorbs.net'
  120.     'wormrbl.imp.ch'
  121.     'xbl.spamhaus.org'
  122.     'zombie.dnsbl.sorbs.net'
  123. )
  124.  
  125.  
  126. $arrAttributes = @()        #Array to store failed checks on
  127. $IPs = @()                  #Array to store IP addresses
  128. $count1 = 1                 #Counter for the first progress bar
  129.  
  130. foreach ($mx in $mxrecord){
  131.     #Main progress bar
  132.     $ActivityMessage = "Gathering the IP's for all of the MX records. Please wait..."
  133.     $StatusMessage = ("Processing {0} of {1}: {2}" -f $count1, @($mxrecord).count, $mx)
  134.     $PercentComplete = ($count1 / @($mxrecord).count * 100)
  135.     Write-Progress -ID 1 -Activity $ActivityMessage -Status $StatusMessage -PercentComplete $PercentComplete
  136.  
  137.     Write-Verbose "Getting IP addresses for the $mx"
  138.     $mxips = [System.Net.Dns]::GetHostAddresses("$mx")
  139.     $IPs += $mxips.IPAddressToString
  140.     $count1++
  141. }
  142.  
  143. #Filter the list of IPs down to only unigue entries
  144. if ($IPs.count -gt 1){
  145.     $IPs += $IPs | select -Unique
  146. }
  147.  
  148. $count2 = 1                 #Counter for the second progress bar
  149. foreach ($IP in $ips){
  150.     #Secondary progress bar
  151.     $ActivityMessage = "Processing IP's. Please wait..."
  152.     $StatusMessage = ("Processing {0} of {1}: {2}" -f $count2, @($ips).count, $ip)
  153.     $PercentComplete = ($count2 / @($ips).count * 100)
  154.     Write-Progress -ID 2 -Activity $ActivityMessage -Status $StatusMessage -PercentComplete $PercentComplete
  155.  
  156.     Write-Verbose "Forming reverse IP for $IP"
  157.     $reversedIP = ($IP -split '\.')[3..0] -join '.'
  158.     Write-Verbose "Reverse IP is $reversedIP"
  159.    
  160.     $count3 = 1             #Counter for the third progress bar
  161.     foreach ($server in $blacklistServers){
  162.         #Third progress bar
  163.         $ActivityMessage = "Checking RLB. Please wait..."
  164.         $StatusMessage = ("Processing {0} of {1}: {2}" -f $count3, @($blacklistServers).count, $server)
  165.         $PercentComplete = ($count3 / @($blacklistServers).count * 100)
  166.         Write-Progress -ID 3 -ParentId 2 -Activity $ActivityMessage -Status $StatusMessage -PercentComplete $PercentComplete
  167.  
  168.         $objAttributes = New-Object PSObject
  169.        
  170.         #Combine the reverse IP with the server checking
  171.         $fqdn = "$reversedIP.$server"
  172.  
  173.         try {
  174.             Write-Verbose "Checking $IP against $server"
  175.             $null = [System.Net.Dns]::GetHostEntry($fqdn)
  176.             $helplink = "http://mxtoolbox.com/SuperTool.aspx?action=blacklist%3a" + $IP
  177.             Add-Member -InputObject $objAttributes -MemberType NoteProperty -Name IP -Value $IP
  178.             Add-Member -InputObject $objAttributes -MemberType NoteProperty -Name "Blacklisted On" -Value $server
  179.             Add-Member -InputObject $objAttributes -MemberType NoteProperty -Name "MX Record" -Value $MX
  180.             Add-Member -InputObject $objAttributes -MemberType NoteProperty -Name "MXToolbox Link" -Value $helplink
  181.             $arrAttributes += $objAttributes
  182.         }
  183.         catch { }
  184.         $count3++
  185.     }  
  186.     $count2++
  187. }
  188.  
  189.  
  190. #Email Settings
  191.  
  192. $date = Get-Date -Format g
  193. $smtpServer = "smtp.domain.com"
  194. $smtpTo = "[email protected]"
  195. $smtpFrom = "[email protected]"
  196. $messageSubject = "An IP Has Been Listed On An Email Blacklist - $date"
  197.  
  198. #CSS style for the HTML message
  199. $emailhead="<html>
  200.            <style>
  201.            BODY{font-family: Calibri; font-size: 11pt;}
  202.            H1{font-size: 18px;}
  203.            H2{font-size: 16px;}
  204.            H3{font-size: 14px;}
  205.            TABLE{border: 1px solid black; border-collapse: collapse; font-size: 11pt;}
  206.            TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;}
  207.            TD{border: 1px solid black; padding: 5px; }
  208.            </style>"
  209.  
  210. #Main body of the email, tailor to fit needs
  211. $emailbody = "<body>
  212.               <h3 align=""center"">An IP Has Been Listed On An Email Blacklist</h3>
  213.               <p>The IP's below have been blacklisted please check the MXToolbox link for more information.</p>"
  214.  
  215. #Convert the array to HTML
  216. $emailtable = $arrAttributes | ConvertTo-Html
  217.  
  218. #Closing tags and when/where the report was generated
  219. $emailbottom = "<p>Generated at $date on $(Get-Content env:computername)</p>
  220.                 </body>
  221.                 </html>"
  222.  
  223. #Combine all the parts together to make one pretty email
  224. $htmlmessage = $emailhead + $emailbody + $emailtable + $emailbottom
  225.  
  226. #Check if there was a hit create an email
  227. if ($arrAttributes -ne $null){
  228.     Write-Verbose "An IP was BlackListed, sending an email to $smtpTo"
  229.     Send-MailMessage -To $smtpTo -From $smtpFrom -SmtpServer $smtpServer -Priority High -Subject $messageSubject -BodyAsHtml -Body $htmlMessage
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement