--- layout: post title: "XSS in Kayako helpdesk software" thumbnail: broken-phone-box-240.jpg date: 2016-08-29 --- In the Kayako helpdesk software, customers can submit tickets which staff can then view and answer. In this feature there is a XSS vulnerability in the ticket title. This post describes how I found that vulnerability. ## Checking escape functionality First, I created a new ticket with some HTML tags in each field: ![

foobar

in all the fields](/images/kayako-xss-foobar-ticket.png) I use a easily recognizable word in each field ("foobar") so that I can later on search in the page source and easily find how strings are escaped. I use `

` instead of `` in the title. However, when we try that the whole tag gets removed. ## Looking at the code Time to look at the code to see what escaping is exactly performed: $_documentTitle = addslashes(StripScriptTags($this->_documentTitle)); echo 'SetHeaderTitle("' . $_documentTitle . '");'; The call to [`addslashes`](https://www.php.net/manual/en/function.addslashes.php) is the reason why our quotes are escaped, and the function `StripScriptTags` removes our `` tag: function StripScriptTags($_htmlCode) { // Strips "empty" script tags (e.g. ) $_htmlCode = preg_replace('@.*?@si', '', $_htmlCode); // Strips just closing tags $_htmlCode = preg_replace('@@si', '', $_htmlCode); return $_htmlCode; } The last `preg_replace` call removes our script tag. Let's look at what this regex means exactly: * The `@` is a delimeter. The real regex is in between the two `@`. * The literal ``. So `` is removed. ## Performing the attack As we have seen `` tags are removed, as long as they contain nothing else but whitespace. This means that we can bypass this sanitization code by putting something that is not whitespace in the tag: