There's been quite a bit of chatter lately with the recent discovery of the latest IE 0-day. While reading through one of the other researchers posts I decided to take a deeper look into some of the files being used in these reported attacks. The issue that some might be experiencing while trying to analyze the related flash files, as did I, is that they're encrypted with doSWF and therefore take a little more effort in order to get down to what we care about. A quick search about how to go about decrypting this particular type of encryption led me two good articles (one | two).
With the addition of another user posting a decompiled version of the ActionScript within the file I was looking at I decided to give a quick look into this referenced script and modify its 'decrypt' function to correspond with the information provided. I thought it would be an easy task but later turned out to result in errors - Java is something I don't care to debug... The thought of having a script to aid in the future automation of decrypting such files would be helpful and might be re-visited but there's also a learning aspect to doing it manually. With that being said I opted to go about it in a different approach (attaching OllyDbg to IE and dumping the SWF from memory) which would be repeatable in future analysis efforts even if the type of encryption used was different - which makes it more reliable/flexible in my eyes. There will be some overlap here to previously linked posts but instead of just saying what was done I feel it's useful for others to see how to do it.
So after wiping off the dust from OllyDbg I was able to get the end results I was seeking from my analysis by performing the steps outlined below. Note that while some of the steps and content below are specific to the file I set out to analyze, other steps can be applied to help analyze other situations you might encounter.
- This initial step can be bypassed depending on what your analyzing and goals are but for this particular situation I started off by commenting out the part of the initial landing page which was responsible for initializing the variables and just left the part in which loaded the SWF file:
- Open up IE (this could be another browser, again depending on what your analyzing)
- Open OllyDbg and attach the IE process (File > Attach). If you have more than one instance of IE open, make sure you are attaching to the right one!
- Open exploit.htm in IE which will load the SWF file
- Locate the SWF loaded within IE's memory. Go back to OllyDbg:
View > Memory Map > right click > Search (Ctrl + B)
The search criteria will be dependent on what you're looking to locate, and be mindful of little endian. In this case I decided to search for "doSWF" which would be displayed here as "64 6F 53 57 46" in HEX.
There may be multiple hits of the text you are searching for - each of which will pop up in its own 'Dump' window. Take a look at the context of where the found text is located and continue (CTRL + L) until you get one that looks like it's right.
- Once you come across what looks to be your decrypted SWF file, within its Dump window; right click > Copy > Select All . Now you might disagree with this approach and say why copy everything out instead of just what you're after but I'd rather copy it all out and worry about carving the exact SWF file later rather than manually calculating the correct SWF length and carving it out from OllyDbg (more on that latter).
Once it's all highlighted; right click > Binary > Binary Copy
Open a hex editor (HxD in this example) and paste the copied information we took from OllyDbg into a new HEX file; Edit > Paste write (CTRL + B )
You can scroll down to see the 'goodies' which also help in showing it's not encrypted anymore since these are strings we were unable to previously see:
- File header (46 57 53 | FWS)
- iFrame reference and 'call' statement to blob
(image was widened to show it all, not all hex columns are shown as a result)
- Since I copied everything over you can obviously see there's other junk there which we don't care about and will prohibit us from solely having the sought after SWF file. As mentioned earlier, this can be solved by either manually carving it out based on Adobe's SWF specifications [PDF]:
- first 3 bytes = header
- next 1 byte = version(8 bit #, not ascii representation)
- next 4 bytes = total length including header (varies if compressed)
- 46 57 53 = FWS
- 09 = version 9
- BD 18 00 00 = 18BD (little endianed HEX or 6333 (decimal)
- Open up the unencrypted SWF with your tool of choice for analysis. If you're using Adobe's SWF Investigator then copy out the disassembled text by; SWF Dissasembler tab > click 'open with text editor'.
Once you have the dissasembled code, scroll down until you see the blob being passed into the ByteArray and copy out what's inbetween the quotes:
- Take that copied out data and paste into a hex editor. Since we see some 'eval' occurring and this blob being a variable in the ByteArray I'm going to say this looks be the shellcode so let's go ahead and pass this extracted code within a shellcode analyzer for ease (scDbg/libemu in this example). When initially analyzed it detects that the data is XOR'ed with the key '0xE2' :
- Well that's helpful - now we don't have to question if it is and/or search for the key since it's already provided to us. This allows us to move on to reversing the XOR with a capable program (xor.exe in this example):
(you can see these corresponding values to the carved SWF in an image below)
...or have a tool help you out. While it's useful to know the specifications of what you're analyzing, having a tool to help you limit the chance of you creating an error is always nice so I opted use Alexs' kick-ass tool xxxswf to do the thinking and lifting for me.
No matter how you go about it, once you've successfully carved it out you should now have just the unencrypted SWF you can continue your analysis:
A quick test of determining what the actual file is (shown in the second command above) after being reversed shows it's just 'data'. Hm, it doesn't appear to be what I'd expect as a result of the shellcode or did something fail when performing the XOR? If we view the strings of this data we see it displays a link to a file which could indicate a 2nd stage download:
You can continue your analysis as needed from here but for the purpose of this post hopefully this showed you a thing or two that you either previously weren't aware of or was causing a road block in your analysis efforts. As always, there are many ways to accomplish the task at hand and if you have a more efficient way to accomplish what I've touched by all means pass it along.