Skip to content

Commit

Permalink
Merge pull request #334 from tstromberg/fpr-nov2
Browse files Browse the repository at this point in the history
Optimize YARA process queries by deduping paths
  • Loading branch information
tstromberg authored Nov 2, 2023
2 parents 6a343d0 + 5802021 commit 9e9da12
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 21 deletions.
14 changes: 12 additions & 2 deletions detection/execution/yara-unexpected-miner-process.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 7200)
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 7200)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule miner {
strings:
Expand All @@ -54,4 +64,4 @@ WHERE
condition:
filesize < 10MB and 1 of them
}'
AND yara.count > 0
AND yara.count > 0
14 changes: 12 additions & 2 deletions detection/execution/yara-unexpected-upx-process.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 7200)
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 7200)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule upx {
strings:
Expand All @@ -48,4 +58,4 @@ WHERE
condition:
$upx_sig in (0..1024)
}'
AND yara.count > 0
AND yara.count > 0
15 changes: 12 additions & 3 deletions detection/exfil/yara-exec-connect-process-linux.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 7200)
AND
yara.sigrule = '
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 7200)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule syscalls {
strings:
$inet_ntoa = "inet_ntoa"
Expand Down
12 changes: 11 additions & 1 deletion detection/exfil/yara-unexpected-go-crypt-exec-process.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 3600)
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 3600)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule cryptexec {
strings:
Expand Down
12 changes: 11 additions & 1 deletion detection/exfil/yara-unexpected-rust-http-exec-process.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 7200)
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 7200)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule http_exec {
strings:
Expand Down
31 changes: 20 additions & 11 deletions detection/persistence/yara-libtomcrypt-process.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,23 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 3600)
AND
yara.sigrule = '
rule redflags {
strings:
$libtomcrypt = "LibTomCrypt"
$email = "tomstdenis@gmail.com"
condition:
filesize < 10MB and 1 of them
}'
AND yara.count > 0
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 3600)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule redflags {
strings:
$libtomcrypt = "LibTomCrypt"
$email = "tomstdenis@gmail.com"
condition:
filesize < 10MB and 1 of them
}'
AND yara.count > 0
12 changes: 11 additions & 1 deletion detection/persistence/yara-suspicious-strings-process-linux.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ FROM
LEFT JOIN processes p2 ON p1.parent = p2.pid
LEFT JOIN hash p2_hash ON p2.path = p2_hash.path
WHERE
p0.start_time > (strftime('%s', 'now') - 7200)
p0.pid IN (
SELECT
pid
FROM
processes
WHERE
start_time > (strftime('%s', 'now') - 7200)
AND path != ""
GROUP BY
path
)
AND yara.sigrule = '
rule redflags {
strings:
Expand Down

0 comments on commit 9e9da12

Please sign in to comment.