Detection rules › Sublime MQL

Attachment: EML with embedded Javascript in SVG file

Severity
high
Type
rule
Source
github.com/sublime-security/sublime-rules

Detects incoming messages containing EML attachments with embedded SVG files that contain malicious JavaScript code, including base64-encoded content and potentially harmful event handlers. The rule specifically watches for onload events, location redirects, error handlers, and iframe elements with base64 data URIs.

Threat classification

Sublime's own taxonomy (not MITRE ATT&CK).

CategoryValues
Attack typesCredential Phishing, Malware/Ransomware
Tactics and techniquesScripting, Evasion

Event coverage

Rule body MQL

type.inbound
and any(attachments,
        (.content_type == "message/rfc822" or .file_extension =~ "eml")
        and (
          any(file.parse_eml(.).attachments,
              .file_extension in~ ("svg", "svgz")
              or .file_type == "svg"
              and (
                (
                  strings.ilike(file.parse_text(.,
                                                encodings=[
                                                  "ascii",
                                                  "utf8",
                                                  "utf16-le"
                                                ]
                                ).text,
                                "*onload*",
                                "*window.location.href*",
                                "*onerror*",
                                "*CDATA*",
                                "*<script*",
                                "*</script*",
                                "*atob*",
                                '*location.assign*',
                                '*decodeURIComponent*'
                  )
                  or regex.icontains(file.parse_text(.,
                                                     encodings=[
                                                       "ascii",
                                                       "utf8",
                                                       "utf16-le"
                                                     ]
                                     ).text,
                                     '<iframe[^\>]+src\s*=\s*\"data:[^\;]+;base64,'
                  )
                  or any(beta.scan_base64(file.parse_text(.).text,
                                          encodings=[
                                            "ascii",
                                            "utf8",
                                            "utf16-le"
                                          ]
                         ),
                         strings.ilike(.,
                                       "*onload*",
                                       "*window.location.href*",
                                       "*onerror*",
                                       "*CDATA*",
                                       "*<script*",
                                       "*</script*",
                                       "*atob*",
                                       '*location.assign*',
                                       '*decodeURIComponent*'
                         )
                  )
                )
                or (
                  (
                    .file_extension in $file_extensions_common_archives
                    or .file_type == "gz"
                    or .content_type == "application/x-gzip"
                  )
                  and any(file.explode(.),
                          (
                            .file_extension in~ ("svg", "svgz")
                            or .flavors.mime == "image/svg+xml"
                          )
                          and any(.scan.strings.strings,
                                  strings.ilike(.,
                                                "*onload*",
                                                "*window.location.href*",
                                                "*onerror*",
                                                "*CDATA*",
                                                "*<script*",
                                                "*</script*",
                                                "*atob*",
                                                "*location.assign*",
                                                "*decodeURIComponent*"
                                  )
                          )
                  )
                )
              )
          )
        )
)

Detection logic

Scope: inbound message.

Detects incoming messages containing EML attachments with embedded SVG files that contain malicious JavaScript code, including base64-encoded content and potentially harmful event handlers. The rule specifically watches for onload events, location redirects, error handlers, and iframe elements with base64 data URIs.

  1. inbound message
  2. any of attachments where all hold:
    • any of:
      • .content_type is 'message/rfc822'
      • .file_extension is 'eml'
    • any of file.parse_eml(.).attachments where any holds:
      • .file_extension in ('svg', 'svgz')
      • all of:
        • .file_type is 'svg'
        • any of:
          • any of:
            • file.parse_text(., encodings=['ascii', 'utf8', 'utf16-le']).text matches any of 9 patterns
              • *onload*
              • *window.location.href*
              • *onerror*
              • *CDATA*
              • *<script*
              • *</script*
              • *atob*
              • *location.assign*
              • *decodeURIComponent*
            • file.parse_text(., encodings=['ascii', 'utf8', 'utf16-le']).text matches '<iframe[^\\>]+src\\s*=\\s*\\"data:[^\\;]+;base64,'
            • any of beta.scan_base64(...) where:
              • . matches any of 9 patterns
                • *onload*
                • *window.location.href*
                • *onerror*
                • *CDATA*
                • *<script*
                • *</script*
                • *atob*
                • *location.assign*
                • *decodeURIComponent*
          • all of:
            • any of:
              • .file_extension in $file_extensions_common_archives
              • .file_type is 'gz'
              • .content_type is 'application/x-gzip'
            • any of file.explode(.) where all hold:
              • any of:
                • .file_extension in ('svg', 'svgz')
                • .flavors.mime is 'image/svg+xml'
              • any of .scan.strings.strings where:
                • . matches any of 9 patterns
                  • *onload*
                  • *window.location.href*
                  • *onerror*
                  • *CDATA*
                  • *<script*
                  • *</script*
                  • *atob*
                  • *location.assign*
                  • *decodeURIComponent*

Inspects: attachments[].content_type, attachments[].file_extension, type.inbound. Sensors: beta.scan_base64, file.explode, file.parse_eml, file.parse_text, regex.icontains, strings.ilike. Reference lists: $file_extensions_common_archives.

Indicators matched (20)

FieldMatchValue
attachments[].content_typeequalsmessage/rfc822
attachments[].file_extensionequalseml
file.parse_eml(attachments[]).attachments[].file_extensionmembersvg
file.parse_eml(attachments[]).attachments[].file_extensionmembersvgz
file.parse_eml(attachments[]).attachments[].file_typeequalssvg
strings.ilikesubstring*onload*
strings.ilikesubstring*window.location.href*
strings.ilikesubstring*onerror*
strings.ilikesubstring*CDATA*
strings.ilikesubstring*<script*
strings.ilikesubstring*</script*
strings.ilikesubstring*atob*
8 more
strings.ilikesubstring*location.assign*
strings.ilikesubstring*decodeURIComponent*
regex.icontainsregex<iframe[^\>]+src\s*=\s*\"data:[^\;]+;base64,
file.parse_eml(attachments[]).attachments[].file_typeequalsgz
file.parse_eml(attachments[]).attachments[].content_typeequalsapplication/x-gzip
file.explode(file.parse_eml(attachments[]).attachments[])[].file_extensionmembersvg
file.explode(file.parse_eml(attachments[]).attachments[])[].file_extensionmembersvgz
file.explode(file.parse_eml(attachments[]).attachments[])[].flavors.mimeequalsimage/svg+xml