cuckoosandbox / cuckoo

Cuckoo Sandbox is an automated dynamic malware analysis system
http://www.cuckoosandbox.org
Other
5.56k stars 1.7k forks source link

No HTTPS decryption on the web interface #2103

Open LetMeR00t opened 6 years ago

LetMeR00t commented 6 years ago

Hello, I'm stuck since few days concerning the decryption of the HTTPS traffic in the web interface. mitmproxy is setup and is working (in transparent mode). What I understand is that the "DumpTLSMasterSecrets" auxiliary is used to get the server_random and master_secret information. According to my analysis.log, it seems to be well started : analysis.log

According to mitmproxy, I'm able to decrypt the traffic on the PCAP using Wireshark and the SSLKEYLOGFILE environment variable : capture du 2018-02-03 20-11-18

However, nothing in my web interface : capture du 2018-02-03 20-14-30 capture du 2018-02-03 20-14-56

I'm not understand what is going wrong ... Can someone help me on this issue ? Thank you !

jbremer commented 6 years ago

Where is the SSLKEYLOGFILE stored? What if you copy it to ~/.cuckoo/storage/analyses/task_id/tlsmaster.txt and reprocess the analysis (cuckoo -d process -r task_id)?

LetMeR00t commented 6 years ago

Thanks for the reply,

As detailed in the PR https://github.com/cuckoosandbox/cuckoo/pull/2102, I created a file named "mitm.sslkeylogfile" for each analysis. It contains all TLS secrets as you can see here : capture du 2018-02-04 10-45-26

Now I copied the file mitm.sslkeylogfile in tlsmaster.txt (I would like to add that the previous tlsmaster.txt file was empty) And I rerun the process using your command "cuckoo -d process -r 1": capture du 2018-02-04 10-47-11 capture du 2018-02-04 10-48-36

Nothing change capture du 2018-02-04 10-48-51 capture du 2018-02-04 10-48-58

But I would like to notice that tlsmaster.txt is now empty ! Probably because of this line : https://github.com/cuckoosandbox/cuckoo/blob/59d32361c1636b2b3802a1746f480a7768f6384f/cuckoo/processing/dumptls.py#L41-L45 where the file is opened using the "w" mode. But well, I suppose that is the network processing that decrypt the traffic.

Moreover, the format of the file is not the same as the SSLKEYLOGFILE file ...

Another proof that the SSLKEYLOGFILE is working : capture du 2018-02-04 10-54-04

Tell me if you need more information on my analysis. PS : I'm using a Windows 7 VM with the last release of mitmproxy (v3-RC2)

jbremer commented 6 years ago

I'm confident you can make it work if you update the regex used to parse the tlsmaster.txt file. Feel free to make the file opening "a+b" instead, although in that case should make sure that TLS Master Secret entries aren't inserted twice (e.g., when reprocessing an analysis).

LetMeR00t commented 6 years ago

Which regexp are you talking about ?.. I don't find where the tlsmaster.txt is parsed using a regexp sorry

jbremer commented 6 years ago

Oh, sorry, it's elsewhere: https://github.com/jbremer/httpreplay/blob/master/httpreplay/misc.py

LetMeR00t commented 6 years ago

Thanks,

I tried to modify your code : capture du 2018-02-04 11-13-16

and compile with "python setup.py sdist develop" (only the httpreplay)

But same result, no decryption and I check the tlsmaster contains the expected format with no duplicate.

Is what you were thinking ?

jbremer commented 6 years ago

Just to be sure, can you check that the ret variable is filled with values?

LetMeR00t commented 6 years ago

Right, it seems that the code is never used ... capture du 2018-02-04 11-19-57 I say that because none of the both print in the function appears...

jbremer commented 6 years ago

Well, I can assure you that code is used. Perhaps pip uninstall httpreplay & pip install -e . once more.

LetMeR00t commented 6 years ago

Even with these commands, the both print aren't used ... I assumed that we should at list see the "print filepath" no ? (even both ...)

LetMeR00t commented 6 years ago

Even if I put a log.debug and a print on these portions of code : capture du 2018-02-04 11-39-41 capture du 2018-02-04 11-39-47 Nothing appears in the "cuckoo -d process -r 1" results

LetMeR00t commented 6 years ago

Wait, I find the code where httpreplay is set to log everything only critical. If I set it to DEBUG, I have some errors : capture du 2018-02-04 11-44-21 But nothing appears for the "read_tlsmaster" function anyway

LetMeR00t commented 6 years ago

If I understand, the code is using the "https_handler" function that already have the tlsmaster information from cuckoo. capture du 2018-02-04 11-52-24

And it has it from this line I think : https://github.com/cuckoosandbox/cuckoo/blob/59d32361c1636b2b3802a1746f480a7768f6384f/cuckoo/processing/network.py#L897-L908 And well, it doesn't care about the tlsmaster.txt file :)

What do you think ?

If you agree with me, I can propose a patch to use the mitmproxy SSLKEYLOGFILE with the new regexp (and keep the first in case when it's concerning Windows because I'm assuming that this format is coming from the lsass.exe process right ?)

jbremer commented 6 years ago

Oh, right, sorry for that - can't always be correct, hehe. How about just parsing the SSLKEYLOGFILE somewhere in network.py and making sure the get_tlsmaster() method returns it?

LetMeR00t commented 6 years ago

Don't worry :) I tried to understand all the code hehe Well, I would like to say that there are two things here :

There is a dumptls processing that happened after the network processing. The dumptls processing is just recovering all TLS master from lsass.exe program and store them in a tlsmaster.txt file (If I'm understanding what is doing). https://github.com/cuckoosandbox/cuckoo/blob/59d32361c1636b2b3802a1746f480a7768f6384f/cuckoo/processing/dumptls.py#L11-L45

I think we should use the dumptls processing BEFORE the network one and read the result stored in the tlsmaster.txt on the get_tlsmaster function based in network.py (and not recover it from results). Moreover, during the dumptls process, we could recover the TLS Master key from the mitm.sslkeylogfile generated thanks to one of my PR if the file exists. https://github.com/cuckoosandbox/cuckoo/blob/59d32361c1636b2b3802a1746f480a7768f6384f/cuckoo/processing/network.py#L897-L908

So, the solution would be :

What do you think about this ?

jbremer commented 6 years ago

All sounds good to me! Just one thing; rename the file to something like tlsmaster.mitm, would make more sense I think :-)

saxenakanishk commented 6 years ago

@LetMeR00t Hi, sorry for commenting randomly, but I wanted to ask you whether mitmproxy is same as wireshark? I am having trouble in dealing with mitm root certificate, so I was curious to know whether I can somehow get my network analysis results (pcap file) with Wireshark only.

LetMeR00t commented 6 years ago

Hi, No, mitmproxy is a proxy that can intercept and modify traffic between a client and a server. Wireshark is a tool for analyzing the traffic on the network, it can't modify anything. But of course, if you configure well the interaction between the host machine and the VM (on vboxnet0 for example), you can easily listen the traffic on this interface and see what is going on :)