Apache Example Servlet leads to \(\)
The default Apache Tomcat examples page was left accessible on a subdomain, and its cookie example reflected cookies from the main site. An attacker could use clickjacking to trick a logged-in user into submitting their cookies to the page, then decode them to steal the session.
Published on medium.com
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Apache Tomcat ships with a set of example web applications that are installed by default. The author describes these as part of the default Tomcat installation page that appears right after the application is first installed, and recommends removing the page as soon as possible. The examples live under a path such as:
site.com/examples
or, when Tomcat is deployed in a subdirectory:
site.com/tomcat-dir/examples

The write-up references a Rapid7 entry, "Apache Tomcat Example Scripts Information Leakage", which lists example scripts that ship with Apache Tomcat and can be used by attackers. That list includes pages potentially vulnerable to XSS issues. In this particular case the author notes he was not so lucky on the XSS front.

On the target there were three servlets available:
- Servlet Examples
- JSP Examples
- Websocket Examples
Setup
The report does not describe any accounts, roles or special tooling. The work was done against a subdomain of the target that hosted the Tomcat examples, and the only external tool named is SecurityHeaders, used to check response headers. The author also mentions a short conversation with hakluke about the impact of one of the findings.
Finding it
The author worked through the three servlets in order.
Websocket Examples
The Websocket examples offered functionality to connect to an external WSS (WebSocket) server and possibly display messages there. Because the examples sat on a secluded subdomain, away from the main application, the author judged that CSWSH (Cross-Site-Websocket-Hijacking) would not be very impactful. He did note that an external connection is initiated here, which is exploitable by connecting to your own WSS server.

After a quick chat with hakluke about the impact, the author's assessment was confirmed.
JSP Examples
Next he looked at the JSP servlet, hoping to find something other than XSS.

He found it interesting but nothing so impactful. There could well be vulnerabilities in the JSP servlet, but he did not find any responsive input fields, so he moved on.

Servlet Examples

He first tried the Byte Counter example because it had an upload functionality, but had no success there.
He then targeted the Session Example and the Cookie Example.

The Session Example was interesting, but because it was on a secluded subdomain it was not that impactful.
Exploitation
Step 1: Notice that main-site cookies are reflected
The Cookie Example turned out to be the interesting one: cookies from the main site were reflecting on this page. That reflection is what made the author think about how the page could be exploited, and clickjacking came to mind.

Step 2: Check the response headers
He went to SecurityHeaders to check the headers served by the page, and as expected the framing protections were missing.

Step 3: Build a framing page
He wrote what he describes as a hasty piece of code, which he says can obviously be improved further.


His note on making the attack more convincing: you can reduce the opacity to minimal and add an overlay element. He did not do that, citing time constraints.
Step 4: Recover the cookie
With the page framed, the url-encoded cookie is simply pasted into a decoder and the value is recovered. As the author puts it: COOKIES == STOLEN.


Root cause
The Cookie Example servlet reflects cookies from the main site, and the page carrying that reflection can be framed by a third-party site because the framing protections are absent. The author used this to build a clickjacking demonstration and recover the cookie value.
Impact
The author is explicit about the limits. The examples sat on a secluded subdomain, away from the main application, and he repeatedly judged findings there as not that impactful for that reason. The clickjacking path was still enough to demonstrate impact and to steal cookies, and the report was rewarded. The write-up does not state which cookies were exposed or what privileges they carried.
Fix
The general recommendation it makes is to remove the default Tomcat examples page as soon as possible after installation, since it is part of the default installation and is not needed in production.
Variants to test
- Look for
/examplesand<tomcat-dir>/exampleson hosts that still serve the default Tomcat installation. A positive result is the example index with the Servlet, JSP and Websocket example sets reachable. - Check the Cookie Example servlet for reflection of cookies belonging to the main site. A positive result is a cookie value from the parent domain appearing in the page content.
- Run the candidate page through a header checker such as SecurityHeaders and look for missing framing protections. A positive result is the absence of the headers that would prevent the page being framed.
- Try the Byte Counter example's upload functionality. The author had no success here, but it is a concrete place to spend time.
- Try the Websocket example's external WSS connection by pointing it at your own server. A positive result is the example initiating a connection to a server you control.
- Keep an eye out for abandoned or rarely used subdomains, especially ones that display a message such as "This Web Application Has Been Disabled".
Timeline
| Event | Date |
|---|---|
| Reported | 29 Jun 2020 |
| Rewarded | 17 Jul 2020 |

./logout.sh
What happened, in plain words
A security researcher found a forgotten corner of a company's website: a set of demonstration pages that come bundled with a piece of server software called Apache Tomcat. These pages are meant to show developers what the software can do, and they are installed automatically. Nobody needs them once a site is live, but they are easy to leave behind.
On one of these demo pages, the researcher noticed that the page was showing back the cookies that belong to the company's main website. A cookie is a small piece of data that a website asks your browser to store and send back on every visit, and it is often used to keep you logged in. If another website can read or capture that cookie, it may be able to use it.
The researcher then found that the demo page could be loaded inside another website's page, a technique called framing. That opened the door to clickjacking: tricking a visitor into clicking something on the hidden demo page while thinking they are clicking something harmless. The researcher built a small page to demonstrate the framing, and separately showed that the url-encoded cookie could be decoded and read. The report was rewarded.
Background: what Apache Tomcat and its examples are
Apache Tomcat is a web server program. A web server is the software that sits on a computer somewhere and answers the requests your browser makes when you type in an address. Tomcat is written for Java applications, but you do not need to know Java to follow this.
When you install Tomcat for the first time, it comes with a set of example web applications already in place. The author describes these as part of the default Tomcat installation page that appears right after the application is first installed, and recommends removing the page as soon as possible. Think of it like a new phone that arrives with a set of demo apps preinstalled: useful to see what the phone can do, but you would not leave them on a phone you use every day.
The examples live under a path such as:
site.com/examples
or, when Tomcat is deployed in a subdirectory:
site.com/tomcat-dir/examples

A path is the part of a web address after the domain name. site.com is the domain, and /examples is the path. The first form is what you see when the examples sit at the top level of the site. The second form is what you see when the whole Tomcat installation lives inside a folder called tomcat-dir on the server, so the examples are one level deeper.
The write-up references a Rapid7 entry, "Apache Tomcat Example Scripts Information Leakage", which lists example scripts that ship with Apache Tomcat and can be used by attackers. Rapid7 is a security company that publishes a database of known vulnerabilities, which are weaknesses in software that an attacker could abuse. That list includes pages potentially vulnerable to XSS issues. XSS, or cross-site scripting, is a weakness where a website displays text that an attacker supplied in a way that makes the browser treat it as code. In this particular case the author notes he was not so lucky on the XSS front, meaning he did not find one of those.

On the target there were three servlets available:
- Servlet Examples
- JSP Examples
- Websocket Examples
A servlet is a small program that runs on the server and produces a web page when your browser asks for it. JSP is a way of writing those programs that mixes HTML with Java code. A WebSocket is a connection that stays open in both directions, so the server can push messages to the browser without the browser asking each time. The three example sets are simply three groups of demo pages, one for each of these technologies.
Setup
The report does not describe any accounts, roles or special tooling. The work was done against a subdomain of the target that hosted the Tomcat examples. A subdomain is a prefix on a domain name, like shop.example.com versus www.example.com; it is a separate address that can host a separate application. The only external tool named is SecurityHeaders, used to check response headers. Response headers are small pieces of information the server sends alongside the page, telling the browser things like what type of content it is and what it is allowed to do. The author also mentions a short conversation with hakluke about the impact of one of the findings.
Finding it
The author worked through the three servlets in order.
Websocket Examples
The Websocket examples offered functionality to connect to an external WSS (WebSocket) server and possibly display messages there. WSS is simply the secure, encrypted version of a WebSocket connection, the same way HTTPS is the secure version of HTTP. Because the examples sat on a secluded subdomain, away from the main application, the author judged that CSWSH (Cross-Site-Websocket-Hijacking) would not be very impactful. CSWSH is a weakness where another website can open a WebSocket connection to a server on your behalf, using your existing session, and read what comes back. He did note that an external connection is initiated here, which is exploitable by connecting to your own WSS server: if the demo page will connect to any server you name, you can point it at a server you control and watch what it sends.

After a quick chat with hakluke about the impact, the author's assessment was confirmed.
JSP Examples
Next he looked at the JSP servlet, hoping to find something other than XSS.

He found it interesting but nothing so impactful. There could well be vulnerabilities in the JSP servlet, but he did not find any responsive input fields, so he moved on. An input field is a box on a page where you can type something, like a search box or a login form. If a page has no input fields, there is nothing for you to type into, so many kinds of attack that rely on feeding the page your own text have nowhere to go.

Servlet Examples

He first tried the Byte Counter example because it had an upload functionality, but had no success there. Upload functionality means the page lets you send a file from your computer to the server. That is interesting to a researcher because files that get stored and later served back are a common place for weaknesses.
He then targeted the Session Example and the Cookie Example. A session is the server's memory of who you are across several page loads; the Session Example demonstrates how that works. The Cookie Example demonstrates how cookies are set and read.

The Session Example was interesting, but because it was on a secluded subdomain it was not that impactful.
Exploitation
Step 1: Notice that main-site cookies are reflected
The Cookie Example turned out to be the interesting one: cookies from the main site were reflecting on this page. Reflection means the page takes a value you gave it and prints it back into the page it returns. That reflection is what made the author think about how the page could be exploited, and clickjacking came to mind. Clickjacking is a trick where an attacker loads a real page inside an invisible frame on their own page, and places their own buttons on top. When you think you are clicking the attacker's button, you are really clicking the hidden page underneath.

Step 2: Check the response headers
He went to SecurityHeaders to check the headers served by the page, and as expected the framing protections were missing. Framing protections are response headers that tell the browser whether a page is allowed to be loaded inside a frame on another site. When they are absent, any site can frame the page.

Step 3: Build a framing page
He wrote what he describes as a hasty piece of code, which he says can obviously be improved further.


His note on making the attack more convincing: you can reduce the opacity to minimal and add an overlay element. Opacity is how see-through something is; setting it very low makes the framed page almost invisible. An overlay element is something drawn on top, such as a fake button, so the visitor sees only that. He did not do that, citing time constraints.
Step 4: Recover the cookie
With the page framed, the url-encoded cookie is simply pasted into a decoder and the value is recovered. URL encoding is a way of writing characters that are not allowed in a web address, by replacing them with a percent sign and a code, so a space might become %20. A decoder turns that back into readable text. As the author puts it: COOKIES == STOLEN.


Root cause
The Cookie Example servlet reflects cookies from the main site, and the page carrying that reflection can be framed by a third-party site because the framing protections are absent. The author used this to build a clickjacking demonstration and recover the cookie value.
Impact
The author is explicit about the limits. The examples sat on a secluded subdomain, away from the main application, and he repeatedly judged findings there as not that impactful for that reason. The clickjacking path was still enough to demonstrate impact and to steal cookies, and the report was rewarded. The write-up does not state which cookies were exposed or what privileges they carried.
Fix
The general recommendation it makes is to remove the default Tomcat examples page as soon as possible after installation, since it is part of the default installation and is not needed in production. Production means the live site that real users visit, as opposed to a test setup.
Variants to test
- Look for
/examplesand<tomcat-dir>/exampleson hosts that still serve the default Tomcat installation. A positive result is the example index with the Servlet, JSP and Websocket example sets reachable. - Check the Cookie Example servlet for reflection of cookies belonging to the main site. A positive result is a cookie value from the parent domain appearing in the page content.
- Run the candidate page through a header checker such as SecurityHeaders and look for missing framing protections. A positive result is the absence of the headers that would prevent the page being framed.
- Try the Byte Counter example's upload functionality. The author had no success here, but it is a concrete place to spend time.
- Try the Websocket example's external WSS connection by pointing it at your own server. A positive result is the example initiating a connection to a server you control.
- Keep an eye out for abandoned or rarely used subdomains, especially ones that display a message such as "This Web Application Has Been Disabled".
Timeline
| Event | Date |
|---|---|
| Reported | 29 Jun 2020 |
| Rewarded | 17 Jul 2020 |

./logout.sh
Glossary
- Apache Tomcat: a web server program, written for Java applications, that answers browser requests.
- Web server: software that stores and serves web pages to browsers.
- Servlet: a small program on the server that produces a web page when asked.
- JSP: a way of writing server programs that mixes HTML with Java code.
- WebSocket: a connection that stays open in both directions so the server can push messages to the browser.
- WSS: the encrypted version of a WebSocket connection.
- Path: the part of a web address after the domain name, such as
/examples. - Subdomain: a prefix on a domain name, like
shop.example.com, that can host a separate application. - Response header: a small piece of information the server sends with a page, telling the browser how to treat it.
- Cookie: a small piece of data a website asks your browser to store and send back on later visits, often used to keep you logged in.
- Session: the server's memory of who you are across several page loads.
- CSWSH (Cross-Site-Websocket-Hijacking): a weakness where another site opens a WebSocket connection on your behalf and reads the replies.
- Clickjacking: tricking a visitor into clicking a hidden page inside a frame while thinking they are clicking something harmless.
- Framing: loading one web page inside another page.
- Framing protections: response headers that tell the browser whether a page may be loaded inside a frame on another site.
- Reflection: a page printing back a value that was supplied to it.
- Input field: a box on a page where you can type something.
- Upload functionality: a page feature that lets you send a file from your computer to the server.
- URL encoding: writing characters that are not allowed in a web address using a percent sign and a code.
- Decoder: a tool that turns URL-encoded text back into readable text.
- Opacity: how see-through something is.
- Overlay element: something drawn on top of a page, such as a fake button.
- Production: the live site that real users visit, as opposed to a test setup.
- Rapid7: a security company that publishes a database of known vulnerabilities.
- SecurityHeaders: a website that checks the response headers a site sends.