Please consider donating:


Exchange 2007 Administration : Antispam and Content Filtering

Enable content filtering on a HUB Transport server

If you want to enable the content filter on a HUB transport server, run the "./install-AntispamAgents.ps1" script from the %Program Files%\Exchange Server\Scripts folder. Next, restart the Microsoft Exchange Transport Service by running Restart-Service MSExchangeTransport. (

Enabling IPBlockListProvider on a HUB that does not directly accept incoming internet emails

If the Hub transport is responsible for performing content filtering, and the HUB does not receive incoming internet emails itself (but receives the messages from a relay server), then all incoming connections will appear to be coming from that relay server (and not from the "real" IP address of the sender’s mailserver). This means that options such as Real Time block lists (IP Block List Provider in 2007) won’t work properly. You can solve this by telling the transport engine on the HUB to treat certain IP addresses as internal and skip those IP addresses in the email header.
Suppose you want to define and the entire IP range as internal, run this script on the HUB transport : set-transportconfig -InternalSMTPServers "","" You can read more info about IP Block List providers at and . Depending on your setup, you may need to add to the list of InternalSMTPServers. Use a sniffer such as wireshark to ensure that everything is set up correctly.
Example : I have installed a POP3 collector on one of my servers. This connector connects to the POP3 mailserver of my ISP and downloads my emails. Next, it uses SMTP to connect to my own internal Exchange server to deliver the messages to my local user. The connection to my Exchange server always originates from a local IP address in my network. And if I skip those local IP addresses, I even have to skip the IP address of my ISP’s SMTP servers. So I created a transportconfig that looks like this :
[PS] C:\>set-transportconfig -InternalSMTPServers "","","","",""
[PS] C:\>Get-TransportConfig
ClearCategories : True
GenerateCopyOfDSNFor : {5.4.8, 5.4.6, 5.4.4, 5.2.4, 5.2.0, 5.1.4}
InternalSMTPServers : {,,,,}
JournalingReportNdrTo : <>
MaxDumpsterSizePerStorageGroup : 18MB
MaxDumpsterTime : 7.00:00:00
MaxReceiveSize : unlimited
MaxRecipientEnvelopeLimit : unlimited
MaxSendSize : unlimited
TLSReceiveDomainSecureList : {}
TLSSendDomainSecureList : {}
VerifySecureSubmitEnabled : False
VoicemailJournalingEnabled : True
Xexch50Enabled : True

As you can see, I’m ignoring my local IP addresses and the ISP IP addresses, and localhost. The "IP block List provider" filter will now ignore those IP addresses and (hopefully) only look for the IP address of the server that delivered the email to my ISP’s mail server (which is exactly what I want my server to look for). I’ve sent a test email from my mailserver at work ( and the wireshark sniffer shows this :


Conclusion : it works fine ! Instead of performing a DNS lookup to my internal IP, or the IP of my ISP, the filter skips those IP addresses and performs the lookup for the real IP address of the mailserver that delivered the message to my ISP.
When I look in the header of the email, this is what I can see :

Received: from socrates ( by ( with
Microsoft SMTP Server id 8.0.744.0; Sat, 6 Oct 2007 13:28:36 +0200
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="=_alternative 003EFF6DC125736C_="
Subject: test
Date: Sat, 6 Oct 2007 13:28:09 +0200
Received: (qmail 14237 invoked from network); 6 Oct 2007 11:28:17 -0000
Received: from ([]) (envelope-sender
) by
(qmail-ldap-1.03) with SMTP for ; 6 Oct 2007 11:28:17
Received: from (
[])    by (8.13.1/8.13.1) with ESMTP id
l96BSD2o008260    for ; Sat, 6 Oct 2007 13:28:14 +0200
Received: from localhost (localhost.localdomain [])    by (Postfix) with SMTP id E820B158018    for
; Sat, 6 Oct 2007 13:28:13 +0200 (CEST)
Received: from ( [])    by (Postfix) with ESMTP id DF4B7158005    for
; Sat, 6 Oct 2007 13:28:13 +0200 (CEST)
Received: from
( [])   
(Postfix) with ESMTP id D6BB333E613    for ; Sat, 6 Oct

Text in red = contains the IP addresses that I want to ignore. Text in blue = IP address of mailserver that delivered the email to my ISP. Text in green = internal IP addresses (need to be ignored as well).

You can test IP Block List provider settings using Get-IpBlockListProvider | Test-IpBlockListProvider -IpAddress

[PS] C:\>Get-IPBlockListProvider | Test-IPBlockListProvider -IPAddress




Additionally, you can send an email to ‘’ and wait for a reply , or use the "Get-AgentLog" query below to see if the returning message was stopped.
If you want to know if the filter works in real life, you can use the following command to read the logs :

[PS] C:\>Get-AgentLog | where {$_.Reason -eq "BlockListProvider"}

Timestamp : 6/10/2007 14:08:01
SessionId : 08C9D621EC2F88DC
IPAddress :
MessageId :
P1FromAddress :
P2FromAddresses : {}
Recipients : {}
Agent : Connection Filtering Agent
Event : OnEndOfHeaders
Action : RejectMessage
SmtpResponse : 550 5.7.1 Your server is listed as an open relay at
Reason : BlockListProvider
ReasonData :

Timestamp : 6/10/2007 22:28:02
SessionId : 08C9D621EC2F8BB2
IPAddress :
MessageId :
P1FromAddress :
P2FromAddresses : {}
Recipients : {}
Agent : Connection Filtering Agent
Event : OnEndOfHeaders
Action : RejectMessage
SmtpResponse : 550 5.7.1 Your server is listed as an open relay at
Reason : BlockListProvider
ReasonData :

The IP block list providers that I’m using are :,, and
Note : You can watch IPBlockListProvider statistics through performance monitor, or view the top RBL block list providers by running get-AntispamTopRBLProviders.ps1. You can dig up other anti-spam statistics by using the scripts that can be found in the Exchange Server installation folder, under "scripts" :
get-AntispamTopBlockedSenders.ps1 "P1"
or get-AntispamTopBlockedSenders.ps1 "P2"
with one of the following parameters : messagesrejected / messagesquarantined / connections / commands / messagesdeleted

Using quarantine mailbox

In case you want to quarantine spam emails (as opposed to blocking/rejecting spam emails), this document will provide more info on Spam Quarantine : and . If you have set up your quarantine mailbox and you want to be able to properly recover messages from the quarantine, have a look at

See SCL rating in Outlook 2007

You can use the procedure that was written by Microsoft to expose the SCL rating field in Outlook 2003 and apply it to Outlook 2007. You may need to click "OK" at the warning to overwrite a similar form in the library, but if definitely works. The procedure can be found at or Additionally, you can expose original senders and recipients using a procedure explained in

How to set up scheduled safe-list aggregation
First, set up initial safe-list aggregation by running the Update-SafeList command for each mailbox on the server. If you want to run this on a scheduled basis, create a batch file with the following contents :
"C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe" -psconsolefile "d:\Exchange Server\bin\exshell.psc1" -command "& {get-mailbox | where {$_.RecipientType -eq [Microsoft.Exchange.Data.Directory.Recipient.RecipientType]::UserMailbox } | update-safelist -verbose}"
(Make sure to verify the paths in the script – both the path to powershell.exe and the path to the console file). Next, use the scheduled tasks panel to schedule the script.
Warning : Pay attention to selecting the correct time for running this script. Since the command updates 2 attributes in AD, you may generate a lot of replication data after running this command.

Note : Since outlook users have the option to add users to the safe senders/safe recipients, the safe-list aggregation technique may result in unwanted behavior. If users add their own email address to the safe recipients, then all policies will be bypassed, leaving
Also, make sure to disable "Automatically add people I e-mail to the Safe Senders List", because it will create a huge list of email addresses without really verifying that they are using a trusted mailserver… In fact, you disable all policies, including policies that look at the IP address of the sender’s server, simply by trusting a user… and that does not make any sense at all to me. So if you start seeing a lot of messages in the Get-AgentLog output that should have been blocked,then you know that you have to look at the Junk E-Mail options from that specific user… Odds are that the user has added himself as a safe recipient….

If you are seeing a lot of allowed messages in the agent log that state "not available: policy is disabled", then emails for that users are not being checked. One of the reasons for this behavior could be the fact that you’re using a POP3 collector, and set up the collector to use an authenticated smtp connection to your Exchange server (port 587). In general, if you use partner permissions (authenticated client connections) on the receive connector on your Exchange Server, then anti-spam will be bypassed for those connections. Also, make sure you have only one connector that accepts incoming mails for certain IP addresses, or anti-spam will be confused. See for more info. You can pull up the list of messages that have bypassed the filters by running Get-AgentLog -start "27/10/2007 00:00:00" | where {$_.ReasonData -eq "not available: policy is disabled."} | FT Timestamp,IPAddress,P1FromAddress,Recipients

Logging & Troubleshooting

Show anti-spamcontent filter log : get-AgentLog. If you want to see which messages were blocked, use Get-AgentLog | where {$_.Action -ne "AcceptMessage"}. The logs are saved for 30days or until they’ve become 250Mb in size (whichever comes first). If you have copied log files to another location (to prevent them from being deleted) and you want to read those log files, use get-AgentLog drive:\path\to\file More commands can be found at

Tracking messages : get-messagetrackinglog -Start "start date and time" -End "end date and time". Example : get-messagetrackinglog -Start "5/10/2007 23:58:00" -End "6/10/2007 0:08:00"

If you have enabled Sender Reputation filtering (which uses IP Block Lists to stop spammers) or if you are using IP Block Lists, you can get the list of blocked IP addresses using Get-IPBlockListEntry

Make sure to enable Antispam updates on your Exchange server. You can use the Enable-AntispamUpdates cmdlet to activate automatic updates. (See for more info) :
Enable-AntispamUpdates -IPReputationUpdatesEnabled $true -MicrosoftUpdate RequestScheduled –SpamSignatureUpdatesEnabled $true -UpdateMode Automatic

You can find more information about Anti-Spam and Anti-Virus filtering in Exchange on

© 2007 – 2021, Peter Van Eeckhoutte (corelanc0d3r). All rights reserved.

Comments are closed.

Corelan Training

We have been teaching our win32 exploit dev classes at various security cons and private companies & organizations since 2011

Check out our schedules page here and sign up for one of our classes now!


Want to support the Corelan Team community ? Click here to go to our donations page.

Want to donate BTC to Corelan Team?

Your donation will help funding server hosting.

Corelan Team Merchandise

You can support Corelan Team by donating or purchasing items from the official Corelan Team merchandising store.

Protected by Copyscape Web Plagiarism Tool

Corelan on Slack

You can chat with us and our friends on our Slack workspace:

  • Go to our facebook page
  • Browse through the posts and find the invite to Slack
  • Use the invite to access our Slack workspace
  • Categories