Detection rules › Sublime MQL

Attachment: Embedded Javascript in SVG file

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

Javascript inside SVG files can be used to smuggle malicious payloads or execute scripts.

Threat classification

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

CategoryValues
Attack typesMalware/Ransomware
Tactics and techniquesScripting

Event coverage

Rule body MQL

type.inbound
and any(attachments,
        (
          (
            .file_extension in~ ("svg", "svgz")
            or .content_type in~ ("image/svg+xml")
            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.

Javascript inside SVG files can be used to smuggle malicious payloads or execute scripts.

  1. inbound message
  2. any of attachments where any holds:
    • all of:
      • any of:
        • .file_extension in ('svg', 'svgz')
        • .content_type in ('image/svg+xml')
        • .file_type is 'svg'
      • 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, attachments[].file_type, type.inbound. Sensors: beta.scan_base64, file.explode, file.parse_text, regex.icontains, strings.ilike. Reference lists: $file_extensions_common_archives.

Indicators matched (19)

FieldMatchValue
attachments[].file_extensionmembersvg
attachments[].file_extensionmembersvgz
attachments[].content_typememberimage/svg+xml
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*
strings.ilikesubstring*location.assign*
7 more
strings.ilikesubstring*decodeURIComponent*
regex.icontainsregex<iframe[^\>]+src\s*=\s*\"data:[^\;]+;base64,
attachments[].file_typeequalsgz
attachments[].content_typeequalsapplication/x-gzip
file.explode(attachments[])[].file_extensionmembersvg
file.explode(attachments[])[].file_extensionmembersvgz
file.explode(attachments[])[].flavors.mimeequalsimage/svg+xml