Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats
Loading...
Loading...

HOWTO: Rewriting email bodies with External Commands

Expand / Collapse


This article applies to:

  • Trustwave SEG

Question:

  • Can SEG modify the email message body?
  • How can I remove active links or other material from an email message?

Reply:

SEG does not provide a dedicated rule action to edit email message bodies. You can use an External Command to make changes.

Be aware that External Commands run slowly compared to other rule actions, because they require an external program to load for each usage.

  • You can minimize use of the external commands by identifying the bodies that require rewriting using TextCensor scripts or other rule conditions.
  • If you plan to use External Commands for a large number of items, carefully monitor email throughput.

You can use any executable that runs from the command line and accepts an absolute path for the file to be processed. To avoid unnecessary repacking of email messages, the executable should return different numeric exit codes for "change made" or "no change made".

The example in this article uses a simple open source text replacement tool, "Find And Replace Text" (FART). See the Related Links section below for download and documentation.

  • For a Regular Expression option see the Notes at the end of the article.

This article assumes familiarity with the SEG configuration interface.

The ideas and scripts in this article have been reviewed for accuracy. External executables and scripts are not covered by Trustwave support. Customers use these items at their own discretion.

Procedure:

To set up a rule for text replacement:

  1. Create an External Command (Policy Elements > External Commands)
     
    • Command line: Enter the tool location. The tool must exist in this location on all processing servers.
    • Parameters:
      •  -i indicates case insensitive
      • Use "{CmdfileName}" (including quotes) to refer to the file to be processed. SEG will update this variable with the file location.
      • The next two parameters are the string to find and the replacement. In the example, the URL http://microsoft.com is replaced with a space. (If you enter an empty string "" FART will not do any replacement.)
      • When choosing what to find and replace, be aware that the script will apply to HTML and plain text email bodies. HTML tags are part of the text. A Regular Expression search might be useful to ignore tags (see Notes below).
    • Single Thread should be checked
    • Only execute once should NOT be checked. A message can have more than one body part.
    • Set Command is triggered to >0 and Command is not triggered to <1
    • Save the command.
  2. Create a rule to apply the command
     
     
    • Choose Message attachment type Mail Body (MBODY) to apply the command only to message body parts.
    • Choose Run the external command and select the command you created. Be sure that Repack the message is selected.
       

       
  3. Enable and save the rule, and test. The Content Analysis log will be similar to the below:
    04532 13:34:33.083 001 Requesting Action <Content:Policy Management (Inbound):Text Replace:Text Replace,repack> be run
    04532 13:34:33.090 001 TRIGGERED command <"c:\tools\fart.exe" -i "C:\Program Files\Trustwave\Secure Email Gateway\Unpacking\T1\U2\Plain.txt" "http://www.microsoft.com" "">.  
                                Result= 1 after 7 millisecs 04532 13:34:33.090 001 Repacking message after external command succeeded.

Notes:

Trustwave is not currently aware of a simple executable that provides Regular Expression replacement. For advanced users, the attached zip file (replace-regex.zip) contains a sample Visual Basic script that can be used in an external command. Caution: This script executes somewhat more slowly than FART.


 

  • Command line: Refers to CScript (the Windows VBS command line script interpreter).
  • Parameters: enter a string similar to
    c:\tools\replace-simple.vbs "{CmdFileName}" "http.+://.*?\.microsoft\.com" ""
    • Enter the path to the script. The tool must exist in this location on all processing servers.
    • Use "{CmdfileName}" (including quotes) to refer to the file to be processed. SEG will update this variable with the file location.
    • The next two parameters are the Regular Expression string to find and the replacement. For example:
      http.+://.*?\.microsoft\.com matches http or https and any subdomain/server of microsoft.com
    • You can use an empty replacement string to delete the value found.
  • This script as provided is case sensitive. You can edit the script and add the IgnoreCase flag for the VBS RegEx object.
  • Single Thread should be checked
  • Only execute once should NOT be checked. A message can have more than one body part.
  • Set Command is triggered to 0 and Command is not triggered to >0

 


To contact Trustwave about this article or to request support:


Rate this Article:
     

Attachments


replace-regex.zip replace-regex.zip (468 bytes, 594 views)

Related Links



Add Your Comments


Comment submission is disabled for anonymous users.
Please send feedback to Trustwave Technical Support or the Webmaster
.