Como pegar a senha do Whatsapp de um Android ou Iphone
WhatsApp is a very popular SMS-like messenger for smartphones, but it’s unfortunately only available for smartphones right now. If you want to use other tools or write web applications that send or receive WhatsApp messages (e.g. WhatsAPI), you have to find a way to sniff the WhatsApp password from your smartphone. Until recently, this password was just an MD5 hash of your IMEI (or MAC address), but that has changed when that was uncovered. Since then, the WhatsApp server assigns a password to each device/account when it first registers.
This tutorial demonstrates how to capture the WhatsApp password of your WhatsApp account using the SSL/TLS proxy mitmproxy. Once you have this password, you can use it to communicate with the WhatsApp servers directly or via a framework. This is the first part of a two-part tutorial. The second part demonstrates how to send and receive WhatsApp messages via PHP.
Contents
Updates
August 2013: I just tried to activate another number from a Samsung Galaxy S3 device with Android 4.1.2 installed. For some reason, WhatsApp traffic is not showing up on neither mitmproxy nor SSLsplit. Although I suspected that the new WhatsApp client is checking the certificate fingerprints (thus making forgery impossible, see github conversation), it might also be an Android issue. I’ll keep you posted.1. Introduction
1.1. Please note: Linux only tutorial!
Please note that this is a tutorial for Linux users. It uses the TLS/SSL proxy mitmproxy to capture the secure connection between your phone and the WhatsApp servers. If you are a Windows user, please check out MissVenom, a tool made just to sniff on WhatsApp passwords. All the stuff that’s done with mitmproxy in this tutorial is basically what MissVenom does for Windows users.1.2. How it works
This tutorial uses a man-in-the-middle attack to intercept the communication between your phone and the WhatsApp servers. To do so, you have to redirect all the traffic from your phone to your Linux machine running mitmproxy (by changing your phone’s default gateway). Mitmproxy, a man-in-the-middle proxy application will then display all of your phone’s HTTP(S) request/responses. While mitmproxy is running, you then need to wipe all of your WhatsApp user data from your phone and set it up as if you were a new user, so that you can sniff into the conversation of your phone and the WhatsApp servers while the WhatsApp account password is exchanged.Don’t worry. It sounds more complicated than it is and your WhatsApp will just look the same afterwards. Here’s a step-by-step:
- Set up and run mitmproxy and prep you phone (as described in this tutorial)
- Stop WhatsApp and wipe the WhatsApp user data
- Open WhatsApp and re-setup your account
- Sniff the password by monitoring the HTTP(S) traffic
1.3. More about mitmproxy
The tutorial does not include a lot of information about how to set up mitmproxy and what it actually does. If you want to read more, please check out my previous blog post about how to use mitmproxy in general, or of course go to the mitmproxy website and read the manual.Advertisement
2. Let’s do it!
The following steps correspond to the short step-by-step above. Since I do not have an iPhone, the WhatsApp screens are from the Android version, but it should work equally on an iPhone.2.1. Set up and run mitmproxy and prep your phone
First you need to set up mitmproxy as described in chapter 2 of the mitmproxy howto. In a nutshell, this tutorial shows you how to enable IP forwarding, set up iptables to redirect all traffic from port 80 and 443 to 8080 as well as how to install and run mitmproxy.Please note: Explanations on this step are kept to a minimum. Check out the post about mitmproxy to read more.
1
2
3
4
5
6
|
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080
apt-get install python-pyasn1 python-flask python-urwid
pip install mitmproxy
mitmproxy -T --host
|
And then change your standard gateway:
If you’ve done everything correctly, you should be able to see all the traffic that your phone sends, like this:
2.2. Close WhatsApp and clear user data
WhatsApp only negotiates a new password with the server when it first communicates with it. If you already have WhatsApp up and running on your iPhone or Android device, you need to wipe the user data, so that WhatsApp can negotiate a new password — which you can then sniff using mitmproxy.Clearing the existing user data is really simply. Simply go to Settings, Application manager and scroll down to WhatsApp. In the WhatsApp screen, click “Force stop” and then “Clear data”.
2.3 Sniff WhatsApp password and restore user data
After wiping all your WhatsApp user data, it’s like you just bought a new phone or reset your smartphone’s operating system. The next time you open WhatsApp, it has to reconnect to your WhatsApp account and exchange a new login password. Given that you now have a sniffer in place and can capture all of your phone’s communication, you can simply read the password off the air.Make sure mitmproxy is running. Then simply open up WhatsApp and follow the screens:
2.4. Examine mitmproxy results
If everything went according to plan, you should now see a couple of requests to the domain v.whatsapp.net — particularly something like this:- https://v.whatsapp.net:443/v2/exist?cc=49&in=<<your login>>&…
- https://v.whatsapp.net:443/v2/code?cc=49&in=<<your login>>&…
- https://v.whatsapp.net:443/v2/register?cc=49&in=<<your login>>&…
You can find your WhatsApp account password in the last of those three requests (https://v.whatsapp.net:443/v2/register?…). Use the arrow keys to navigate to this entry and hit the RETURN key. Then hit TAB to switch to the ‘Response’ overview. And there it is — a JSON reply of the WhatsApp server as a response to the register-request. Your WhatsApp username is indicated by the “login” key, your password by the “pw” key.
Copy the password and save the conversation with the WhatsApp server by using mitmproxy’s save function: Go back to the main screen by hitting q, then hit s and enter a file name (e.g. /home/user/WhatsApp-password.mitmproxy). You can later load this conversation with L.
2.5. Use the password in scripts
So what’s the password good for? You can use this password in scripts or web applications to send and receive WhatsApp messages. I use the PHP framework WhatsAPI to receive notifications from my server and HTPC. As of now, I only use it to receive alerts and warnings from my monitoring service (Nagios) and to get notifications from my podcast download scripts.If you’re interested to see how this works, please check out my blog post about how to send and receive WhatsApp messages using PHP.
3. What this cannot do
One additional comment to what this method does not achieve: Unfortunately, the above described method does not allow reading or altering WhatsApp messages sent from your phone or received by your phone. The WhatsApp application only performs administrative tasks over HTTPS (such as status changes or the login). It does not, however, send or receive messages over HTTPS.Instead, WhatsApp uses a derivate of the Jabber/XMPP protocol to communicate. It communicates on port 5222
Update (July 2013): WhatsApp does not use TLS/SSL on port 5222 as I wrongfully stated above. Instead, it uses its own proprietary protocol to exchange and encrypt messages. That makes sniffing into the connection a little more cumbersome, because simply listening to the socket is not enough. While the individual WhatsApp messages (“nodes”) can be extracted using tcpdump (try: tcpdump -X -vv -i eth0 'port 5222'), the results are quite disappointing at first:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
20:03:46.645026 IP (tos 0x0, ttl 50, id 42975, offset 0, flags [DF], proto TCP (6), length 267)
50.22.231.44-static.reverse.softlayer.com.xmpp-client > pbox.fritz.box.38975: Flags [P.], cksum 0xc9a7 (correct), seq 143:358, ack 124, win 514, options [nop,nop,TS val 924424164 ecr 631853177], length 215
0x0000: 4500 010b a7df 4000 3206 1406 3216 e72c E.....@.2...2..,
0x0010: c0a8 b21c 1466 983f ae43 0976 fdc2 b59d .....f.?.C.v....
0x0020: 8018 0202 c9a7 0000 0101 080a 3719 97e4 ............7...
0x0030: 25a9 5079 8000 5e54 18d1 a86c 8e70 cf13 %.Py..^T...l.p..
0x0040: 290f 3a28 6add b8f6 f8e3 10d7 7bc5 f965 ).:(j.......{..e
0x0050: b672 fe25 fdb8 4730 ce3a dcbe b040 0df4 .r.%..G0.:...@..
0x0060: 84c4 581d d8df 996e 50d5 7f12 b6bf 24f7 ..X....nP.....$.
0x0070: 0d72 f46d 704d cb21 7a56 2032 bc1a e15c .r.mpM.!zV.2...
0x0080: 88db d754 e3a3 4aa7 e7dc a2ad d2f4 2841 ...T..J.......(A
0x0090: f3b8 d52c 6180 005e 524b 1573 757d 2095 ...,a..^RK.su}..
0x00a0: 5f64 28da 3518 1e37 1a07 0f41 265a 867c _d(.5..7...A&Z.|
0x00b0: f016 6e0e 114b 73f2 329f d1b2 b17b dc6f ..n..Ks.2....{.o
0x00c0: 1d16 0b62 194e 9d26 b5cd d5d1 321e b033 ...b.N.&....2..3
0x00d0: ce40 8afe e6c6 79bf 4ada 5149 f29a be13 .@....y.J.QI....
0x00e0: 291c 503d 4661 5cb5 047b 2dfe 41f9 5db9 ).P=Fa..{-.A.].
0x00f0: 6442 0eac 0a8d 8000 1222 6248 7dc9 b7a5 dB......."bH}...
0x0100: 563d 4a9a cafe 42f8 011f ee V=J...B....
|
The actual message starts right after the TCP header, so in this example after 52 bytes (8000 5e54 18d1 a86c 8e70 …). Each message can contain multiple nodes, each of which has a tag name, and can have attributes and content (data) — much like in XML. However, because XML is chatty, WhatsApp encodes tag names an attributes with a dictionary, so that certain numbers correspond to certain tags. The snippet above is an encrypted and encoded representation of the following XML-tags:
1
2
3
4
5
6
|
<message from="49xxxxxxxx@s.whatsapp.net" id="1375004720-28" type="chat" t="1375034628">
<notify xmlns="urn:xmpp:whatsapp" name="Philipp Heckel"></notify>
<request xmlns="urn:xmpp:receipts"></request>
<body>Hi there!</body>
<offline></offline>
</message>
|
All of these things make it more complex to sniff messages from the wire. However, the guys of WhatsAPI already successfully implemented this protocol, so that a lot of their code can be reused to read WhatsApp messages off the network interface.
I am currently working on a script to do just that. My current approach is to use tcpdump to listen to eth0 and pipe the output to a PHP script that parses the TCP packets and uses WhatsAPI to decode/decrypt the communication. Not the most elegant solution, but so far it works quite well. I will update this post as soon as I have something worth sharing.
Comentários
Postar um comentário