Atbash, Norton, and The Metasploit Reverse - Https Handler
Atbash, Norton, and The Metasploit Reverse - Https Handler
The technique we'll be using can apply to any executable which needs to slip past a
signature-based scanner. To make things a smidge more interesting we'll be building our
backdoor with the Metasploit Framework and injecting it with one of the most fun and
easily-recognizable payloads I could think of: windows/meterpreter/reverse_https. The
antivirus vendors are watching MSF like a hawk, of course, and for good reason. Any a/v
that takes itself seriously will have meterpreter stager signatures.
This is a VM named Atbash. It's running Windows 7 and Norton Antivirus, which is
subsequently in charge of Atbash’s antivirusing needs. Why Norton? It's common. Also
because McAfee wouldn't detect the unmodified reverse_https stager payload, let alone our
permutations.
Our backdoor is a copy of uTorrent.exe taken from Atbash and augmented with the stock
https stager. Norton pounces on it at once as a proper antivirus engine should. In fact
Norton makes a rather decent job of it, electing to scrub the executable down and
maintain its usefulness rather than delete it outright.
Foreground: Metasploit’s stock reverse_https handler is injected into uTorrent.exe.
Background: Norton responds decisively and at once.
Thus the stock reverse_https stager is generally doomed to fail. For all its elegance,
it’s ubiquitous, and therefore in many scenarios it’s as subtle as a brick. Our fix is to
ignore the executable and instead adapt the framework directly. The reverse_https stager
payload is x86 assembly wrapped in ruby and plugged into the framework. By rewriting the
assembly and tweaking the ruby to match, we can wreck the antivirus fingerprint and add
signature evasion capabilities to our local copy of the MSF.
Start by extracting the shellcode from msf's stock reverse_https stager. Copy the
original stager as a new file for us to modify, then open them both in your favorite
editor (be sure your editor has write access to the new file).
udis86 is a work of art. It's an x86 and x86_64 dissassembler that we'll be using to
guide us in our adventures. Install it if you haven't already. Next we need a work
directory with two workspaces.
Toss the original binary payload into the workspaces and perform some find-and-replaces
to get rid of everything that isn't hexadecimal. Be sure to replace all the gaps between
bytes with spaces so udis86 will understand. You should end up with a block of 8-bit hex
separated by spaces. This is your control. Disassemble it in a terminal to see what we've
got.
The stager’s a/v signature is likely to be buried somewhere in here. This isn't some
monolith PE we're modifying, it's only about 350 bytes of asm. That means the sig is
probably fragile. Go crazy. Smash stuff. We'll start with something simple:
[rtyler@gallifrey asm]$ udcli -x msf_rhttps
0000000000000000 fc cld
0000000000000001 e889000000 call 0x8f
0000000000000006 60 pushad
0000000000000007 89e5 mov ebp, esp
0000000000000009 31d2 xor edx, edx
000000000000000b 648b5230 mov edx, [fs:edx+0x30]
000000000000000f 8b520c mov edx, [edx+0xc]
0000000000000012 8b5214 mov edx, [edx+0x14]
Let's find out if this is enough to fool Norton. (Golly, I hope not.) If you haven't set
up shares on your VM and mounted them, now's a great time. We'll need a few tweaks to the
StrainA msf module to use it properly in the framework. We also need to increment the
LPORT offset to 193 since we added 3 bytes before that point in the code. Like so:
module Metasploit3
include Msf::Payload::Stager
include Msf::Payload::Windows
def self.handler_type_alias
"reverse_https_strainA"
end
[...]
Plug the revised shellcode into the StrainA module file. Then open up your msfconsole and
check that our new strain has loaded properly. Use it, configure it, and roll it into a
new copy of uTorrent.exe. Be sure to do the same for the stock stager to give us a
control.
msf > search reverse_https
Matching Modules
================
/media/atbash
msf > ls
[*] exec: ls
uTorrent.exe
NAVDownloader.exe
Norton Installation Files.lnk
desktop.ini
Faced with our trivial Strain A modifications, Norton sounds the alarm immediately. We
can confirm that strainA is functioning properly if we disable the on-access scanner.
Our first modest modifications in StrainA aren’t enough for a bypass.
Chances are decent that somewhere within these ~350 bytes of shellcode is the thumbprint
Norton is using for a signature. This can be a long and frustrating stage. Be creative.
Ghostwrite the assembly code by swapping registers, switching sequences, segmenting
operations, or anything else. So long as the code remains functional when the dust
settles, it's a step towards breaking another antivirus vendor's signature set.
It will be necessary to write custom assembly that can be patched into the existing
shellcode. There are resources at the end of this paper for anyone who doesn't do this
sort of thing on a regular basis. udcli is fantastic for this, acting as a translator and
an error-checker. For example, there’s a typo in the fifth byte of this code:
And repaired:
I’ve also found it useful to write a script which traces asm jumps and calls. Unless
modifications to the assembly happen to be the exact same length as the code they’re
replacing, offsets for any number of relative references will need to be adjusted. This
is a similar process to the increments and decrements to this payload’s LPORT offset.
Metasploit’s obfuscators can add a welcome dash of luck to the exercise. On both stock
and modified versions of this particular payload, I’ve used multiple iterations of
shikata_ga_nai. Most of the better-known antivirus engines are undeterred by this. Their
signatures are based on unchanging aspects of the underlying code. However, the right
obfuscation in the right place can augment our efforts to mutate the shellcode manually.
The process can be arduous, but spontaneity and creativity are powerful tools. When the
modified stager finds itself distorted at the engine’s pressure points, there will be no
match against the signature database, and the antivirus engine will allow the malware to
run unmolested.
Worth noting is strainB’s bypass of Norton’s heuristics engine, which came as a nice
surprise. Raw signature-based evasion was my only target for this operation. Norton
allowed unquestioned execution of the modified payload, including meterpreter session
establishment.
Flexing meterpreter’s muscles.
Good hunting.
Resources: