Hello everyone, today I will talk about how to tag desktop, desktop applications use web security skills. Uh this may sound weird but after this talk you can see how we can pop up a calculator without reversing our binary exploring team's knowledge. Uh I'm Sot, I'm from Tencent Security Show Lab and I'm member of whoops the CDF team and I have spoken at zero nine and hit B. And my friend Herman, he also from Show Lab and he's a speaker of Asia Sec West. And another friend uh he's from Tencent Show Lab too, he's a member of C Clover security team and uh he's spoken at zero nine and hit B too. Uh unfortunately these two, these two guys doesn't come here. Okay. Uh I'm Sot, I'm from Tencent Security Show Lab and I have spoken at zero nine and hit B. Uh when people are talking about tagging desktop applications you may think about point go on. Yeah. Hackers at point go on may uh may use memory corruption bugs to get a calculator. I dream of that one day I can pop up calculators just like them. But there's some difference between me and them. I know, just know something about web security. And I know I can do little reversing. I know nothing about punning. Can I pop up a calculator like uh people in the point go on? Hmm. That sounds a good question. Yeah. And we notice more and more applications use hybrid technologies. Uh uh people write applications use their, use frameworks like electron or nw dot gs. So their applications can run at all the platforms. And web techniques are used in these frameworks and they may use web techniques to develop their applications. So that's a good news for our web secur- web security researchers. Yeah. We can use web security tricks to pun them reliably. Oh let's see how to pop up a calculator. Use web security knowledge. Let's keep web security great. So let's see how to use web security let's start off from the attack surfaces. So today in this talk we will talk about three sections. Uh one is open ports. The second one is UR schemes. And the third one is some features of the applications. Yeah. So we start from uh when uh application opens up port. So why do they open up port? Maybe they open up port for the web server because they want to expose some API calls. And maybe they use the port for debugging and not many other purposes. And the application may bind the port on all the interfaces or on the local host. Yeah. On all the interfaces you can access them really remotely but how to how do we access the ports on local host? And the browser is our good friend. If the, if the browser is our good friend. The service running on the port accepts HTTP protocol or it has a tolerance of illegal commands. And then we can use browser to attack these local host ports. And before we come to the exploiting uh let's see some basics. The same origin policy. Yeah. We see that two pages have the same protocol host and port. And these two pages are in the same origin. So for pages in the same origin they can send simple HTTP requests or send requests with custom headers and get the response. If they are not in the same origin they can only send the HTTP requests and cannot get the response. So how this uh, how this uh, how this uh, how this uh, how this uh, how this uh, how the uh, this uh, basic restriction in the browsers, is there a way to bypass this? There comes DKф debinding. The process is or follows uh we first access the rebinder dot com. It will resolve to an uh attacker's IP, and pull all the pylons from the attack server. And uh you see the browser just you just wait with a few uh with a uh with a few minutes and you request rebind.com again and then this domain will resolve to the target IP uh such as localhost. And in the uh and uh the port the protocol and the host are not changed in this process. So the browser believes that in the same origin. So we can attack it just uh bypass the FTP. Yeah. So we need the uh there are some prerequisites. This web service should not check the host name because we need the we need a domain name that we control. And the weak team should wait until the dnf has changed because there is a cache in the browser. And there is uh uh another attack method called cfrf and there is some difference about uh cfrf and dnf rebinding. We can use dnf rebinding to bypass bypass FTP but if there is a hostname check it will field. And if uh the client cannot wait uh with a few seconds and this may be not work. But for cfrf uh it is restricted by FTP. But uh it doesn't uh the host check doesn't matter and it will uh be effective immediately. Yeah. So let's just go to a keys. And the uh the uh the uh the uh the uh key is uh wechat. And it is a popular third party plugin for wechat. Uh it is uh popular chat software in China. Yeah. And it is called this wechat plugin. Uh macOS. Uh using this third party plugin we can keep the record message. We can auto reply a message. And it has many users. You see the many stars and many folks. But it just stop maintained maintained. But it um it was all filmed in libguide a month ago. And it has it binds a port a fixed port on local host. And it exposed some API's. From these API's you can get all the all the users friends or the chat logs and you can send any message to any user. And we can use dnf rebinding to attack this plugin. The uh the um wechat plugin is also a real challenge. Uh uh we wechat So, we reported this issue to the author and the author fixed with checking the host. Yeah, the host cannot be a local host. Because of this host check we cannot use DNS rebinding to attack them but it is still affected by a CRF attack. If, if we know a username we can then use CRF to send a message to that user. Yeah. So, it is not enough to just check the host. Because check the host it just can just uh keep DNS rebinding away. You should also use some unpredictable data or path to prevent CRF attack. Also, most importantly, you should avoid using third party plugins. And there is another case called XDEBUG. XDEBUG is for PHP debugging. It's a PHP extension. So, how does it works? Uh, uh first you should send a request with uh this um in parameters XDEBUG session start just like that URL in the bot, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh. Next you can just use the URL below and then the XDEBUG will connect to a server and the server can the X with the XDEBUG. So, which server to connect? XDEBUG will check the following things in a fallback order. The first one in the, in the XDEBUG's configuration file, the XDEBUG remote host. If not set then it will check x4d4 header. Uh, you can also use a in the HTTP request. And if not, uh, Xdebug will use remote address. So, if we have these three configurations in the Xdebug, Xdebug remote connect back set to true, uh, Xdebug remote enable set to true, and the remote host is not set. And this is always met for most of the PHP developers. Then, we can attack it using dithrebind. We can set up a UBL server, waiting for Xdebug to connect, and then use dithrebinding to send a custom X4D4 header, and points to the UBL server. So, the UBL server will connects, uh, will, uh, interacts with the Xdebug, and finally we can get a real, real shell. And I have reported this to the PHP. So, if you are a PHP developer, if you use Xdebug, and you use this on the, on a URL page for 40 or fi- or 50 seconds, and then you may be hacked. So, how do the Xdebug officially think about this attack? Well, the Xdebug is by default, by default back on你要 after an attack. And the ys response, with hey, it thinks this is a just a rumor. And uh, for developers, uh, himself should take care of this. Yeah, so, anyway. And the for NodeJS debugging port, or Java debugging port. Or Java, uh, RMI port, they may also be affected by that rebinding attack or setup attack. So, inа So, if you find a port opened by an application, you can check it, binds on all interfaces or binds on localhost. So, you can choose to attack that remotely or using rebu- data rebinding or set an effort to attack them. And next part, UISchemes. This is a short part, yeah. Uh, people use UISchemes to launch applications or send some messages inside an application. Uh, we can see the following picture. We can use React code UISchemes to launch React code. Yes. And on Windows, in Windows, uh, it is registered in the registry and has an item for the, uh, UI, URI protocol name and the command it will exude. Windows will use shell exude w, this API, to call that command, to call the React code command and launch it. But there is a well known bug in this API. We can use a code to close the former code and we can inject other parameters. So, uh, we can use the code to close the former code and we can inject other parameters. There comes the- famous exploit last year for Electron. We can use a Chrome Ul permanent, permanent injection and to exude any command. Just like that. And we found all frameworks based on ChromeUl may have the same issue. So, the nw.js framework. We found a famous application for notetaking a, uh, target data within a user, uh, on the Network. Uh, we uh use nw.gf and it has 200 millions of users. So we can just in- inject chromium parameters to exude uh any command. Just like the electron bug. So here comes the demo. Uh oh. Yeah. Uh we- we set our web server local on the local host and this is explore page. Yeah. If we clicked that we will get a calculator. Okay. This is the first calculator and this bug is fixed. Uh already fixed. Yeah. And uh in this years, in this May, uh Microsoft released a patch called KB4497935. If you applied this patch you will find the UI scheme is now UIO encoded. So this is the first patch. So this is the first patch. This is the second patch. So in this case we cannot inject parameters because the code are UIO encoded. We cannot close the formal code. Maybe UI scheme is that? Or there is some bypass? Who knows? Yeah. So if you found- if you want to find the UI scheme bugs you should check the UI schemes that the application has. Also the free-for-all, the free-for-all, the free-for-all, the free-for-all, the free-for-all framework has. Don't forget the framework. Yes. And the main part we attack the features of the application. On this section we have three parts. First one is cross-site scripting in the desktop applications. Uh the second part section is for pre-privileged API's. And the last one is for imp- improper protocol handling. Now, this is for- this is also for UK And this cross-site scripting story begins from MacDone editors. And in the year 2016 we found many MacDone editors just renders the Javascript in the preview window. Such as MOU, MacDone or or even with code. So um many MacDone editors are using this and many of the MacDone editors just uh previews the page in the file domain. So we can use the Javascript excuse on the file domain to steal files on the local disk. And we can steal some credentials from the local code and we may clone his account and lock it in another machine. And also if it's used uh it has some problems. So we can use the Javascript to preview the APIs or it has a, it uses a outdated browsers. We can, we maybe get remote code in execution. Yeah let's see a case for MacDone. It has thousands of stars and manifolds. And this is also uh uh this this exploit can also be used in the latest version. So we can see the location is uh in the file domain. And if we can actually uh execute this uh and we can use XML HTTP request to get the ETC password. And we can also send that uh the response uh that the container of the ETC password to the remote server. So we can steal local files. Yeah. I reported this in the year 2016 and it is still not fixed. Um, I think it's still not fixed. But things are always getting harder. There's little cross-site scripting in Markdown editors nowadays. And some editors use content site, content security policy to limit Javascript execution. And some editors use Sandbox to run the Javascript in the in a uh isolated context and they're without node modules. So, um, I don't know if you can see this. The pro- uh the issues are harder to find and harder to exploit. But we should think uh about the libraries that used by Markdown editors. Um, the first one, Mermaid, uh it is used for charts or diagrams. It has it on the on the GitHub it has thousands of used products. And many stars and many folks. Uh, we have found three cross-site scriptings. In the latest version when I uh make this slides. But now in the latest, latest version it has fixed. Okay. Uh, latest version here is when I make this slides. It is fixed days ago. Just days ago. Yeah. Uh, we can see, uh, we can see, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, uh, the the tipper, uh, the HEKMD, the Evernote and gitlab me, uh, uh use Mermaid. And there is the cross-site scripting. And the first two just renders the HTML. Uh, the last one need a click. It is, yeah it has click cross-site scripting. And here is demo page. The off-official demo page we can alert. And next to Catax and Magix. Uh these two libraries for MathType setting. And uh in their old version it has a Qlik, Qlik cross-site scripting tool. And this tool is reported by other guys. Okay. And the last library flowchess.js it has a Qlik cross-site scripting tool. In the latest version this has not fixed yet. So, if you use Mamed, please upgrade it to the latest version. Yeah. And the older version of MathJax and Catax has cross-site scripting issues. And the latest version of Flowchart has a Qlik cross-site scripting. So this is useful. As this issues lies in the libraries. So, this issues may affects more applications than we can find. So, here comes a keys for HackMD. Uh it uses Mamed. It is an online Markdown editor. And it has many many users. Uh we just used the payload before for Mamed. But the payload is blocked by CSP. Yeah we cannot see the alert box here. Because the CSP just blocks it. And then we checked the CSP. We found a an interesting site. There. The Google Analytics. There is no way for using Google Analytics to bypass CSP by Kitten. Yeah. So we can use Google Tag Manager. And set a set a variable there. And set a malicious function. We can define our malicious code there. And the code will be shown in the Google Analytics. And we you can check the details in the following link. So then we can get a large box. Yeah. And we found there is also a desktop application for HackMD. It use uh there are two uh two elements. One is uh script element for renderer.js in uh uh excuse in uh privilege context. And uh WebView tag renders the user page. There is no node integration. So we can use the script element. So how to turn our cross-site scripting in the WebView tag to RCE in the desktop application. So let's check the renderer.js first. We can see from the code. It adds uh event listener for DOM ready. And when DOM ready it will get the title from the WebView. And set it to the inner HTML. Okay. So now we can see that the web view is not to the uh privileged context. So if we can control the title we can execute any JavaScript code in a privileged context. So we can use our cross-site scripting to redirect the page to our EWIO page. Which can trigger the DOM ready event. And then our page have uh a special header a special title. And we can use this to uh to call the node modules uh process uh uh the chat process and execute any command. And then we can see the calculator. Just click the malicious markdown and pops up the calculator. Okay. I have reported this to the handy and it has already fixed. So um there's uh some in some cases we may not execute JavaScript. We can only inject some HTML code. So we can also use this uh use HTML code for phishing or just add advertising. Yeah. Uh s- s- s- s- s- s- s- s- s- s- s- s- s- um- anyway. So the next sections the next part of uh privilege- privileged APIs. Uh privileged APIs comes from uh about two ways. One is the node modules. Another is maybe some uh from the custom APIs. The program just adds care these APIs. Uh program uh usually use uh JI aisle breach with some wrapper to provide custom APIs and these usually has a public documentations. So, let's see a case. It is a case for a popular chat application. It has billions of users. In this application it has a has a embedded browser with some custom APIs. So if you render a, when render your page on the embedded browser you can call the custom APIs because there is no domain restriction. And these APIs are well documented for developers. And how to open UIs in the embedded browsers? There are two ways. One is in the Sparrow type message which is called feed card message. Just like, feed card message. So, you can send a message to the data. And also we can use a inner app application UIL scheme. We can use a Sparrow scheme to open a, open the embedded browser. And in the custom APIs there is two interesting APIs. One is download a file. If you call this API, you can, you can pass a UIL to it and we will download a file from that URL. But uh it will pop up a box for the user to choose a location to save that file. Yeah they this needs some user interactions. And another API called open local file. It just opens the file you just downloaded without confirmation. Yeah this API is without user interaction. But only works on macOS. Uh so we can uh we can use this to think we can make it download uh ELF to execute but failed because he's it has no x mode after downloaded. Yeah we can we may we think we can use a bash or python script but it is usually open opened by a text editor. Hmm. So how to exploit this? Java is a good friend. Yeah. We can just make it download a jar file and use that API just open the jar. It will execute our Java code. So if you have Java and you click a feed card message from a hacker and uh a dialog will ask you to save a file. Uh save a file usually harmless so you click save and then you are hacked. So let's see the demo. Yeah maybe some conversations for social engineering. And come the feed card message just click it in the embedded uh yeah you should click save and then the calculator. Yeah. So now you can see that the file is already there. And this is already fixed in the latest version. Yeah. And it is fixed by oh just open the folder instead of the file. Yeah. And the last part. Uh uh let's go to the part for protocol handler. Uh when developing desktop allocations you should pay attention to these three protocols. HTTP, Javascript, or file protocol. For HTTP protocol protocol you should avoid you render pages in a in an untrusted context. Because uh if you have uh outdated uh browser code you may be affected by the browser one day. Or if you use Javascript uh you the Javascript makes using a file domain you can steal files. And for the file protocol you can use it to launch programs in uh in your in your computer. Or the file protocol may leak NTM credentials. So just be care uh be careful of a tag. So uh we find a library. And it is used in Chinese applications. And it is widely used. It has uh many stars and many folks. And uh it supports HTML like tags. If you set show HTML to true. And there are some tags for such as a tag for hyperlink. An i tag for image. And a tag for a C tag for a text color. Change the text color. And in a chat application it show it it says show HTML to true. And it readers the tags in the chat group name or your personal status. We can use C tag here to change the text uh colors. Yeah we change it to the red. We change the text color. And change the color may be harmful. We can use i tag to do some NTM relay attacks. So we can use i tag to insert a file protocol uh uh a FNB protocol. And it will uh uh in Windows it will send the Windows credentials automatically. Once the tag are rendered. And you are at the and these tags are in the status and the status of the tag. And we can also use it. So you can see that it at this point the user can see this one. This is a tag that the user can see. And uh I mentioned that you can see this one. And when the user sees the tag right. The user sees the tag. So that means as if uh it is uh uh a feature of the browser. Also by the user see the tag when the user has an image which is a picture of the tag. team and get all the emails. Or if the weak team have another machine have the same, share the same password, we can relate to that machine and get remote code execution. And there is another case for Ghira. And Ghira is developed based on Java and it use HTML to describe a project. So, there is a XFCE in the Ghira project description file. It is found by this guy. Yeah we can use XFCE to steal files or use XFCE to send HTTP request but can we turn the XFCE to RCE? Uh based on our previous research, we can use XFCE to steal files. Uh based on our previous research, this can be done. Uh we found that Java will send credentials when it encounters uh NTL- NTLM based 401HTTP response. Not the basic authentication. It is uh it is uh NTLM based 401HTTP response. Yeah. The attacker can set up a malicious HTTP server to response uh the that. And the Java will send the credentials to the attacker and the attacker can just reflect the credentials to the C machine. Just the C machine. So, if you just opens a malicious project and you have opened your FNBA service and then you may be hacked. So, here's demo. We set up a malicious server. And here is our Ghira. And we, and it will opens a malicious project. And then the after the triggers, we can dump the hashis. Just get the hashis of that machine. And then we can use the pass and then we can run the password. We can pass the hash to execute any commands on the victim. We just use that hash. And there is a mystic. Uh they are mystic. And we fix the command. And then we pass the hash to the user. Yeah. We can see the calculator. So there's many features in desktop applications. So we can find cross art scripting. And we can find if there are some privileged APIs. We can find how it handles the protocol. We can find how it handles the code. We can find how it handles the code. We can find that and check how how we can attack these application. So here's come to the end. If you are a developer just be careful while debugging PHP, NodeJS or some other version of Java. You maybe you maybe be pop up a calculator on your desktop. And also you are a developer you should be careful while using these libraries. Uh some other version of Mermaid. And other version of MathJax, Kitex. And the latest version of Flowcharts. And if you use DLIP you should not set the show HTML to true. And if you are if you use NW NW dot JS. You be careful while re-registering of the code. And if you use the uh URL scheme. And thanks for this guys. And thank you all. So maybe any questions? Oh yeah. Okay. Thank you guys. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you.