Background
WeChat (if you havenβt heard of it) is a super popular chat app similar to the likes of WhatsApp, and runs on iOS, Android, Windows and MacOS.
Being a chat app, it handles various file formats like images and videos, and also propriety formats like βWxamβ (which honestly I havenβt researched before so youβll see how I approached that).
Youβll also see below some of the challenges I had in my harnessing of the target and how my initial fuzzer framework I chose had to be replaced due to lack of support for certain functionality that WeChat used (and how I debugged this).
Researching the Target
Now that we know what WeChat is we can look at how I decided to write a fuzzer (in 1 day!) for this target!
It started by deciding I wanted to blog about fuzzing something, previously Iβve had blogs on Logic bugs and I wanted to balance that with some cool fuzzing target I havenβt looked at before, so I started by browsing ZDI to see if any displayed targets were interesting.
I noticed a few entries for WeChat like the below:

ZDI WeChat bug disclosures
Now at this point I know what WeChat is, but I have no idea what WXAM is (but its safe to guess its some format that gets parsed).
So my next step was to simply install WeChat in a VM! Note that here Iβm targeting the Windows build of WeChat, for the following reasons:
I want this to be quick, its primarily for this blog post and I know I can fuzz Windows targets faster than iOS/Android
If this parser also exists on other platforms, it probably isnβt much different (potentially if I find the bug on Windows, itβll exist on the other platforms)
Now its installed and I have a bunch of executables and DLL files in C:\Program Files (x86)\Tencent\WeChat, so how do I find the WXAM parsing functionality?
Finding the Target
A good starting point may be to dump all the imported & exported functions from all the executables and DLLs and search for anything with the name βwxamβ in it, but I went a different route β I simply guessed and opened the DLL that sounded interesting in IDA!
For me, looking at the list of DLLs I spotted βWeChatWin.dllβ, this sounds like a main DLL for WeChat that handles certain Windows specific APIs or something? Who knows, but it stood out more than some of the other DLLs, so I opened this in IDA.
This DLL took a while to load, its pretty large (~40mb), once done the first thing I did was search in functions, imports & exports for the name βwxamβ, there I found:

wxam2pic imported function shown in WeChatWin.dll
We spot an imported function named βwxam2picβ that lives in βVoipEngine.dllβ β nice! This is a great starting point, it even sounds like a parser.
Before I look at wxam2pic in VoipEngine, I first examine cross-references to this import within WeChatWin.dll and see how WeChatWin uses this, I spot two functions that call this, including this one:

Usage of wxam2pic in WeChatWin.dll
Scrolling to the top of this function we spot:

Donβt you love debug prints?
This string alone implies the function weβre looking at is a βWxAMDecoderHelperβ, specifically this function handles the βDecodeWxamβ functionality β Awesome! This is exactly the type of function that corresponds with the ZDI entries we saw.
Thereβs something else notable about this function, look at how IDA shows the prototype:

Its a custom calling convention!
This means if we were to target this function for fuzzing directly, weβd have to match this custom parameter passing convention instead of Visual Studioβs provided options (fastcall, cdecl, etc).
Instead, I took a look at the function that calls this function, and I got:

(Note: ignore the function name itself, I named it this from what I saw!)
Nice, this function uses a standard calling convention (fastcall), takes only two arguments and calls the DecodeWxam function (handling the custom calling convention for us!)
We also see from the debug print that this function appears to decode the Wxam and then re-encode it as a jpeg, this would be a great function to fuzz!
(Note: Thereβs another decoder that transforms the Wxam to a GIF! Weβre not going to look at that one in this blog, but its essentially the same).
Reversing the Target Function
Alright so I want to fuzz this function as it appears to take a Wxam file and parse it, lets analyze the parameters.
Lets view cross-references to this function to see how its called:

(Note: I named the read_file function myself, if you open this function you see a simple CreateFile + ReadFile operation on the provided fName variable!)
From this, I see the following:
A filename is provided to the function I myself named βread_fileβ and a buffer is returned in v11
The buffer and a flag is passed to βisWxGFβ, this function reads a header and the flag to determine if we should parse it further or not
-
If we pass the βisWxGFβ check, we call the decoder function passing through:
The file buffer containing the bytes of our input
-
A pointer to a int containing the value 0
This pointer seems to be some output from the decoder, if its non-zero its assumed to be another valid pointer
This seems super easy to fuzz:
We can fuzz using shared-memory mode in a fuzzer like WinAFL
-
Our fuzz function will:
Call isWxGF; and if successful:
Calls the decoder
So I wrote a harness to do this in WinAFL, however:

This usually means our program is crashing before reaching the our fuzz function.
So I run WinAFL under WinDBG and see an invalid address dereference when trying to load the βWeChatWin.dllβ file!
I analyze the DLL entry point and spot:

I see, this DLL uses CRT (also thread-local storage) β this causes issues with DynamoRIO (which I was using with WinAFL).
This can be confirmed by compiling my executable with CRT support and noting that WinAFL crashes before our process main executes at all!
So this means we canβt use DynamoRIO, our options include:
Using WinAFL in IntelPT mode (Iβm using an AMD CPU, so no go here)
Use a different fuzzer
Well I chose a different fuzzer.
I could have gone the snapshot route with Nyx or what-the-fuzz, instead I decided to try Jackalope
This has a very similar command line to WinAFL, and uses TinyInst for instrumentation (no DynamoRIO!)
Upon trying this, it worked:

Its fuzzing, and we are getting new coverage!
At this point I stopped, I got the fuzzer working well enough I was happy for the day, next steps would include:
Analyzing coverage, ensuring weβre not hitting any roadblocks
Understand what all the flag values mean, and how we can leverage them in our fuzzing
Reverse the WXAM format and create better corpus, and a format-aware mutator
Also note that in the isWxGF function, I noted the header bytes it checks for and ensured my initial corpus had that header (so we start with an input that successfully passes that check).
There are other things I did in the harness, which are general fuzzing things like obtaining the non-exported function pointers to our target functions we wanted to fuzz.
Iβve included the harness I used below, along with the Jackalope command line I used to kick off fuzzing, feel free to take this and expand on it or view coverage to see how far it gets!
Overall this was a fun half a day exercise at quickly writing a basic fuzzing harness based on some ZDI entry.
Files
I put all the files on my Github: https://github.com/Kharos102/BasicWXAMFuzzer
Want to Learn Fuzzing?
We offer Vulnerability Research & Fuzzing trainings live or self-paced (For our self-paced trainings, see: https://signal-labs.thinkific.com/collections)
For any questions, feel free to contact us!