14

In Windows Store application development for Windows 8, there is a class called remoteSettings that lets a developer store batches of data so that the user will have access to it across several machines, as long as they are logged in with the same account.

I hooked up WireShark and discovered that the packet is stored in Azure, and is secured with TLS. I would like to MITM myself so that I can decrypt the packet and see if the data in encrypted on Azure.

I obviously don't have the private key for Azure, so I'd like to know if anyone has an idea on how to accomplish that MITM analysis.

5 Answers 5

10

If the data is being passed as HTTPS you could try the classic Fiddler man-in-the-middle approach. I'm not sure whether the Windows store respects the proxy settings or whether it has a pinned certificate. If it does respect the proxy settings, which it should, and it doesn't have a pinned certificate you should be able to trivially man-in-the-middle it with Fiddler.

If the data isn't HTTPS and the cerificate isn't pinned, one option is to proxy the secure connection using SSLNetcat. What you do is that you change your hosts file so that the Store executable connects to SSLNetcat running locally, then you set up SSLNetcat such that it uses a cerificate for which you have the private key. Then you either just have SSLNetcat forward the data directly to a program of your choice or enter the private keys into Wireshark and use it to sniff the traffic.

If the data isn't HTTPS, if the cerificate in the binary is pinned and not stored in a file, you can either patch the Windows Store executable and replace the certificate with your own for which you have the private key. OpenSSL should be able to generate a replacement certificate for you easily. This private key can then be entered into Wireshark which will then decrypt the traffic.

You're fairly close to copy protection territory so you might run into a number of complications.

3
  • Let me be clear - I am doing this to my own app, to see if the data in Azure is stored encrypted or not. Not breaking someone else's app. I tried Fiddler, but I may have done it wrong, so I'll research that. I wasn't familiar with SSLNetcat, so thank for that too. Awesome answer.
    – Bill Sempf
    Mar 24, 2013 at 14:51
  • Oh, I assumed as much. I just meant that you could run into issues where the communication is heavily protected due to copy protection. It complicates matters a bit since you're more likely to run into pinned certificates, self verifying executables and even kernel level integrity checks. I'm unfamiliar with the Microsoft Store so I can't advice further than generalizations. Mar 24, 2013 at 15:15
  • Your advice is pretty awesome though. I'll get to work once I am done watching basketball here ...
    – Bill Sempf
    Mar 24, 2013 at 19:06
12

One other thing that you could do, which is perhaps overkill but is useful in other scenarios, is to intercept the creation of the 48-byte TLS master secret. For many Windows applications (including IE), this happens in lsass.exe in the following function (taken from Win7 SP1 32-bit):

Caller:  ncrypt!_Tls1ComputeMasterKey@32+0x57 
EIP:     ncrypt!_PRF@40+0x11a

You can then decrypt the captured packets after the fact in Wireshark by setting (Pre)-Master-Secret log filename in the SSL preferences to a file file that looks like:

RSA Session-ID:87492B3586DE289FAE1598B0A19CC7BCCB69371993F2C0DF32438034E06FE3FB
Master-Key:F58C0EFA2BF87602646B318400DFEB0C8CCDE59408C9F13C6D923F6208743BD34EA8BA17BCE02B9BD8DFED5A58036068

The session ID here can be found in the TLS headers (unencrypted) for the stream you're interested in. (Don't be fooled by the RSA -- this works for all TLS connections regardless of the ciphersuite in use.)

The advantage of this method is that, since you're not doing a man in the middle, the client application doesn't have to trust your CA, which is especially handy if you're trying to reverse some malware that actually does crypto right.

The downside is that you need to be able to debug lsass.exe, which can be tricky; there's some information on how to do that here.

1
  • Couldn't I just use Frida to intercept and hppl the call to ncrypt!_Tls1ComputeMasterKey in lsass.exe and get the TLS secret? Mar 17, 2021 at 6:36
5

There are a number of approaches you could take with extracting the local key being used by Windows Store and feeding that into Wireshark, however, I think your best bet is to inject a DLL that hooks the Network IO functions send() and recv() out of your process.

You could try to do this on a "low level" yourself, but in the interest of pragmatism you'd be wise to examine Microsoft Detours for hooking, there are so many examples that utilize it - it's easy enough now that knowing your function prototype is the only essential requirement.

2
  • Not sure I can get to the Network IO functions in WinRT - maybe with some C++ hacking since this isn't exactly going through certification. Hadn't heard about Detours yet - thanks for that.
    – Bill Sempf
    Mar 24, 2013 at 14:46
  • Wouldn't hooking send() and recv() also end up logging encrypted traffic? Most probably the encryption happens then sent/received through the socket API, right? Mar 17, 2021 at 6:38
4

You could also try oSpy which basically hooks the appropriate API calls and lets you see the data before and after it has been encrypted/decrypted.

oSpy is a tool which aids in reverse-engineering software running on the Windows platform. [...] when the sniffing is done on the API level it allows a much more fine-grained view of what's going on. [...] if an application uses encrypted communication it's easy to intercept these calls as well. oSpy already intercepts one such API, and is the API used by MSN Messenger, Google Talk, etc. for encrypting/decrypting HTTPS data.

2

Most probably Windows 8 is using WinINet to connect with the App Store. If this is the case, you can see the unencrypted streams hooking into the wininet.dll instead of using a proxy. HookME does this and it was presented last year in BlackHat.

Probably you need to make some minor changes to compile and use it under Windows 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.