Suppose we wanted to detect Vienna in execs.
What is best to look for in an exectuable…
in terms of performance? false positives? true positives?
|
|
|
/* C */ = constant changes when Vienna relocated
/* A */ = application code
mov to %si
0x1000x100 was DOS program entry code
foo:
foo onlyFoofoo␣foobarC\+\+ — matches exactly C++ only\n, \t, \x3C, … — work like in C[b-fi] — b or c or d or e or f or i[^b-fi] — any character but b or c or …. — any character except newline(.|\n) — any charactera* — zero or more as:
a, aa, aaa, …a{3,5} — three to five as:
aaa, aaaa, aaaaa(abc){3,5} — three to five abcs: (‘‘grouping’’)
abcabcabc, abcabcabcabc, abcabcabcabcabcab|cd
ab, cd(ab|cd){2} — two ab-or-cds:
abab, abcd, cdab, cdcd\xAB — the byte 0xAB\x00 — the byte 0x00
\n — newline (and other C string escapes)ing: [a-zA-Z]*ing/* … */ comments: /\*([^*]|\*[^/])*\*/yylexthree sections separated by %%
first — declarations for later C code in output file
patterns, code to run on match
(when flex is used as parser would return “token” here)
extra C code to include
yytext contains contents of currently matched thing
definitions of common patterns included later
/* bytes of fixed part of Vienna sample */
\xFC\x89\xD6\x83\xC6\x81\xc7\x00\x01\x83(etc.) {
printf("found Vienna code\n");
}
/* Vienna sample with wildcards for
changing bytes: */
/* push %CX; mov ???, %dx; cld; ... */
\x51\xBA(.|\n)(.|\n)\xFC\x89(etc.) {
printf("found Vienna code w/placeholder\n");
}
/* mov $0x100, %di; push %di; xor %di, %di; ret */
\xBF\x00\x01\x57\x31\xFF\xC3 {
printf("found Vienna return code\\n");
}
for Vienna: lots of flex features we didn’t need
malware makes modificates to evade pattern matching
exercise: suppose we have a pattern for a Vienna-like virus, and a new version makes the following change. Which of the following is going to be easiest/hardest to change the pattern for?
check entry point and end only
check known offsets from entry point
heuristic: is entry point close to end of file?
ClamAV: open source (mostly email) scanning software
signature types:
hash of file
hash of contents of segment of executable
fixed string
basic regular expressions
more complete regular expressions
meta-signatures: match if other signatures match
icon image fuzzy-matching
4b3858c8b35e964a5eb0e291ff69ced6:78454:Xls.Exploit.Agent-4323916-1:73
7873be8fc5e052caa70fdb8f76205892:293376:Win.Trojan.Sality-93158:73
f358d77926045cba19131717a7b15dec:293376:Win.Trojan.Sality-93159:73
48d4c5294357e664bac1a07fce82ea22:450024:Win.Trojan.Sality-93160:73
e4b8442638b3948ab0291447affa6790:293376:Win.Trojan.Sality-93161:73
df36dc207b689a73ab9cf45a06fb71b0:232448:Win.Trojan.Sality-93162:73
baaeeabc7f4be3199af3d82d10c6b39f:293376:Win.Trojan.Sality-93163:73
...
Win.Trojan.Vienna-1:0:*:5051e8??00{1-255}5b83eb??fc8d37bf0001b90300f3a48bf3558bec83ec7cb430cd21
Win.Trojan.Vienna-2:0:*:be000356c3*50be????8bd6fcb90500bf0001f3a48bfab430cd21
Win.Trojan.Vienna-3:0:*:50ba????8bf283c60090bf0001b90300fcf3a48bfab430cd213c02
Win.Trojan.Vienna-4:0:*:b440b900048bd681eac102cd21721f3d
Win.Trojan.Vienna-5:0:*:b904048bd681ea130352515350b4
...
Win.Trojan.Vienna-129:0:*:51b89b03cd213d01017503e9????ba6d03fc8bf283c60a90b90300bf0001f3a4
Andr.Trojan.Pjapps-58;Engine:51-255,
Container:CL_TYPE_ZIP,Target:0;
(6&0&1&(2|3)&(4|5)); // expected patterns of below
3a39303333; // pattern 0
696d6569; // pattern 1
616e64726f69642e6c6f67; // pattern 2
77696e646f772e6c6f67; // pattern 3
4e6f6b69614e373631302d31; // pattern 4
336c676f6167646d66656a656b67666f733974313563686f6a6d; // pattern 5
0:646578 // pattern 6: "0:" means must be found at beginning of file
heuristic 1: is entry in last segment?
heuristic 1: is entry in last segment?
heuristic 2: did virus mess up header?