Advertisement
ATSmanaged

Decode-ForeFront.ps1

Aug 21st, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Decode-ForeFront.ps1
  2. # v0.05
  3. # u/fosf0r
  4. # 2021/08/23
  5. #
  6. # https://www.sparkpost.com/blog/mircosoft-scl-bcl/
  7. # https://docs.microsoft.com/en-us/Exchange/antispam-and-antimalware/antispam-protection/antispam-stamps?view=exchserver-2019
  8.  
  9. param (
  10.     [Parameter(Mandatory = $True)][string]$EMLfile
  11. )
  12.  
  13. # config:
  14. $ForefrontHeaderName = 'X-Forefront-Antispam-Report'
  15.  
  16. # begin
  17. if ($null -ne $EMLfile -and '' -ne $EMLfile) {
  18.     if (Test-Path -Ea SilentlyContinue $EMLfile) {
  19.         $EMLcontents = Get-Content $EMLfile -Raw
  20.     }
  21. }
  22.  
  23. if ($null -ne $EMLcontents -and '' -ne $EMLcontents) {
  24.     # normalize
  25.     $EMLcontents = $EMLcontents.Replace("`n ",' ')
  26.  
  27.     # split
  28.     $forefrontresults = ($EMLcontents | Select-String -Pattern ($ForefrontHeaderName + '.*')).Matches.Value.Split(' ')[1].Split(';')
  29.  
  30.     # tokenize/explode
  31.     $ForefrontExploded = @{}
  32.     foreach ($item in $forefrontresults) {
  33.         $ForefrontExploded += @{ $item.Split(':')[0] = $item.Split(':')[1] }
  34.     }
  35.  
  36.     # SCL spam confidence level
  37.     'SCL: ' + $ForefrontExploded.SCL
  38.  
  39.     # SFV spam filter verbose explanation
  40.     switch ($forefrontexploded.SFV) {
  41.         'NSPM' {
  42.             'SFV:NSPM The message was marked as non-spam by the content filter and was delivered to the intended recipients.'
  43.         }
  44.         'SPM' {
  45.             'SFV:SPM The message was marked as spam by the content filter.'
  46.         }
  47.         'SKS' {
  48.             'SFV:SKS The message was marked as SPAM prior to being processed by the content filter. This includes messages where the message matched a mail flow rule (also known as a transport rule) to automatically mark it as spam and bypass all additional filtering.'
  49.         }
  50.         'SKA' {
  51.             'SFV:SKA The message skipped filtering and was delivered to the inbox because it matched an allow list in the spam filter policy, such as the Sender allow list.'
  52.         }
  53.         'SKB' {
  54.             'SFV:SKB The message was marked as spam because it matched a block list in the spam filter policy, such as the Sender block list.'
  55.         }
  56.         'SKN' {
  57.             'SFV:SKN The message was marked as non-spam prior to being processed by the content filter. This includes messages where the message matched a mail flow rule to automatically mark it as non-spam and bypass all additional filtering.'
  58.         }
  59.         'SKI' {
  60.             'SFV:SKI Similar to SKN, but the message skipped filtering for another reason such as being intra-organizational email within a tenant.'
  61.         }
  62.         'SKQ' {
  63.             'SFV:SKQ The message was released from the quarantine and was sent to the intended recipients.'
  64.         }
  65.         'SFE' {
  66.             'SFV:SFE Filtering was skipped and the message was forced through because it was sent from an address on an individual''s safe sender list.'
  67.         }
  68.         'BLK' {
  69.             'SFV:BLK Filtering was skipped and the message was blocked because it was sent from an address on an individual''s blocked sender list.'
  70.         }
  71.     }
  72.  
  73.     # CAT category explanation
  74.     switch ($forefrontexploded.CAT) {
  75.         'MALW' {
  76.             'CAT:MALW Malware'
  77.         }
  78.         'PHSH' {
  79.             'CAT:PHSH Phishing'
  80.         }
  81.         'HSPM' {
  82.             'CAT:HSPM High confidence spam'
  83.         }
  84.         'SPOOF' {
  85.             'CAT:SPOOF Spoofing'
  86.         }
  87.         'SPM' {
  88.             'CAT:SPM Spam'
  89.         }
  90.         'BULK' {
  91.             'CAT:BULK Bulk'
  92.         }
  93.         'DIMP' {
  94.             'CAT:DIMP Domain Impersonation'
  95.         }
  96.         'UIMP' {
  97.             'CAT:UIMP User Impersonation'
  98.         }
  99.         'NONE' {
  100.             'CAT:NONE No category'
  101.         }
  102.     }
  103.  
  104.     ''
  105.     # HELO: hostname
  106.     'H: ' + $ForefrontExploded.H
  107.  
  108.     # DNS reverse lookup result (hopefully matches HELO hostname)
  109.     'PTR: ' + $ForefrontExploded.PTR
  110.  
  111.     # test match
  112.     if ($forefrontexploded.H -eq $forefrontexploded.PTR) {
  113.         'Good: PTR and H match.'
  114.     } else {
  115.         '! PTR and H DO NOT match !'
  116.     }
  117.  
  118.     # IPV: IP address veracity
  119.     switch ($forefrontexploded.IPV) {
  120.         'CAL' {
  121.             'IPV:CAL The message was allowed through the spam filters because the IP address was specified in an IP Allow list in the connection filter.'
  122.         }
  123.         'NLI' {
  124.             "IPV:NLI The IP address $($forefrontexploded.CIP) was not listed on any IP reputation list."
  125.         }
  126.     }
  127.     ''
  128.  
  129.     # Country
  130.     'CTRY: ' + $ForefrontExploded.CTRY
  131. }
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement