Remote code execution though vulnerability in Facebook Messenger for Windows (June 2024)
This short writeup describes vulnerability found in Facebook Messenger for Windows in June 2024. It was reported during Meta BountyCon hacking event and helped me to climb on 1st place of results table.
Messenger bug
Meta introduced encrypted chats between Messenger users. It was possible to select friend and start encrypted chat with him (similar like we can do in Telegram - select user and start encrypted chat). I played with Messenger for Android trying to send attachments to victim on Windows in encrypted chat. Because chat is encrypted everything is verified on recipient side: client app must validate all data received from thirdparties and we can catch something interesting there.
I've sent attachment with `%2e%2e%5c` symbols and Messenger for Windows placed my attachment by next path:
C:\\Users\\vulna\\AppData\\Local\\Messenger\\TamStorage\\media_bank\\AdvancedCrypto\\100027775233281\\persistent\\da7a85eb-aac7-46da-9cba-7a2f38f88e08\\2024\\06\\03\\20240603T091559605.att.04484a15-4cbf-4a1d-9e65-a48c59dcc7a2\\..\\test.bat
Path traversal bug which triggers by sending encrypted chat message to victim. If victim can receive messages from you, you can place file into any location on victim's Windows machine via Messenger. No!
Windows path length limitation
Unfortunately, it was not possible to place file at any location because Windows has path length limit - 256 symbols!
C:\Users\vulna\AppData\Local\Messenger\TamStorage\media_bank\AdvancedCrypto\100027775233281\persistent\da7a85eb-aac7-46da-9cba-7a2f38f88e08\2024\06\03\20240603T091559605.att.04484a15-4cbf-4a1d-9e65-a48c59dcc7a2\
It is 212 symbols. We have 44 available.
C:\Users\vulna\AppData\Local\Messenger\TamStorage\media_bank\AdvancedCrypto\100027775233281\persistent\da7a85eb-aac7-46da-9cba-7a2f38f88e08\2024\06\03\20240603T091559605.att.04484a15-4cbf-4a1d-9e65-a48c59dcc7a2\..\..\..\..\..\..\..\..\..\..\..\
->
C:\Users\vulna\AppData\Local\
244 symbols, only 12 are left.
So, we have only 12 symbols and no file rewrites. What can we do? `C:\Users\vulna\AppData\Local\` folder with a lot of other apps. For example Viber, Slack.
Making code execution
The solution: DLL Hijacking! I've read very interesting article (https://itm4n.github.io/windows-dll-hijacking-clarified/) about DLL Hijacking and found that Viber and Slack apps are vulnerable for such kind of attack.
Viber tried (and may be tries) to load `qwave.dll` file from `C:\Users\vulna\AppData\Local\Viber`. This file did't existed in that folder.
`..\qwave.dll` - 12 symbols!
Attack steps
- Sending file with name: `%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5c%2e%2e%5cViber%5cqwave.dll`
- The file is going into `c:\Users\vulna\AppData\Local\Viber\qwave.dll`
- When Viber is launching it starts executing `c:\Users\vulna\AppData\Local\Viber\qwave.dll`
- Remote code execution without user interaction (if we have ability to send messages to victim)!
Report timeline
Test environment
- Attacker: Pixel Fold, Android 14, security patch level 2024-04-05, fingerprint: google/felix/felix:14/AP1A.240405.002.A1/11583385:user/release-keys, (com.facebook.orca): versionName=459.1.0.57.108.
- Victim: Windows 11 Home 22H, 22621.2861 Messenger for Windows v. 212.1.0.15.233