Skip to content

Commit c27ec37

Browse files
[PR #3064] changed rule: Attachment: Web files with suspicious comments
1 parent de7f17d commit c27ec37

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "Attachment: Web files with suspicious comments"
2+
description: "Detects HTML or SVG files under 100KB that contain duplicate or padding text in the form of literary quotes or common sayings within code comments."
3+
type: "rule"
4+
severity: "high"
5+
source: |
6+
type.inbound
7+
and any(attachments,
8+
(
9+
(
10+
.file_type in ("html", "svg")
11+
or .file_extension in ("html", "xhtml", "mhtml", "svg")
12+
or .content_type in ("text/html", "text/plain")
13+
)
14+
and .size < 100000
15+
)
16+
and (
17+
(
18+
// targeting comments that pad the file with quotes from literature
19+
// examples: "// Echoes of the past linger in silence.", "// The wind whispered secrets unknown.", "// Shadows tell stories in the dark."
20+
21+
// count all HTML code comments that match our pattern
22+
regex.count(file.parse_text(.).text, '// [A-Z][ a-z ]+\.') /
23+
// divide by the count of all UNIQUE HTML code comments that match our pattern
24+
length(distinct(regex.extract(file.parse_text(.).text,
25+
'// [A-Z][ a-z ]+\.'
26+
),
27+
.full_match
28+
)
29+
)
30+
// at least 50% of the comments are duplicates
31+
>= 2
32+
)
33+
or (
34+
// targeting comments that pad the file with sayings
35+
// examples: "<!-- <span> No gain without pain. </span> -->", "<!-- <p> Beauty is only skin deep. </p> -->", "<!-- <span> Actions speak louder than words. </span> -->"
36+
regex.count(file.parse_text(.).text,
37+
'<!-- +(<[a-z]+>)? [A-Z][ a-z ]+\. (</[a-z]+>)? +-->'
38+
)
39+
) > 2
40+
or (
41+
// targeting comments inside hidden HTML elements
42+
// example: "<h1 style="display:none;"> Self-confidence inspires others to believe in you. </h1>"
43+
regex.count(file.parse_text(.).text,
44+
'<[a-z0-9]+ style="display:none;">(<[a-z]+>)? [A-Z].*\. </[a-z0-9]+>'
45+
)
46+
) > 2
47+
)
48+
)
49+
tags:
50+
- "Attack surface reduction"
51+
attack_types:
52+
- "Credential Phishing"
53+
- "Malware/Ransomware"
54+
tactics_and_techniques:
55+
- "HTML smuggling"
56+
- "Evasion"
57+
detection_methods:
58+
- "File analysis"
59+
- "HTML analysis"
60+
- "Content analysis"
61+
id: "435fab74-e426-5fca-a85c-650d0f33fbd5"
62+
og_id: "93061d17-730a-5b33-955d-8f8f6cc5cca9"
63+
testing_pr: 3064
64+
testing_sha: 9952fc6c61ff4a6fa36c721efdf3a4ae46e6678a

0 commit comments

Comments
 (0)