What do netcat -SMTP-self XSS have in common
A self-XSS in the client email field could be turned into a stored XSS by sending a crafted email from a non-client address, which caused the application to create a new client record containing the malicious email. An attacker could then wait for an employee to view the client management page and execute script in their browser.
{{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
This is a story about chaining small issues: a self XSS that the program already knew about and had explicitly placed out of scope, combined with an email-to-ticket feature, to reach a fully blown Stored XSS. The work was done on a private program. The application had a CRM and other related parts, and one of those parts was client management, with the usual functions: create, delete and modify clients, and create and attach invoices. The self XSS lived in the information fields of the client's view.

Setup
The researcher worked on a private program, so no target hostname is given. The only tooling described is Netcat, used to speak SMTP by hand to the target's mail server. The mail server hostname used in the final command is mxa.mailgun.org on port 25. The sender domain used throughout is plenumsec.com, and the recipient is a placeholder [redacted]. The date header in the crafted message is Wed, 26 Sep 2018 14:21:26 -0400.
Finding it
While researching the application, the researcher came across a self XSS in the information fields of the client's view. The program was aware of it and it was explicitly out of scope, so the researcher kept digging into how the app worked instead of reporting it.
The self XSS was reachable by adding a single ' to the email field, which broke out of the surrounding HTML and allowed the researcher to add their own attributes. The shape of the injected markup was:
<a tlclick="sendEmail("email_here")">email_here</a>
So the email value is placed inside an attribute of an anchor element, and a quote in the value lets an attacker close that attribute and introduce new ones.
Exploitation
The pivot came from a second feature: if you send an email to the invoice email address, the application checks whether the sender's email address exists in the client database, and if it is found it creates a new ticket for that client. If the sender is not a known client address, a new client is created alongside the new ticket. That means the attacker controls part of the client information, specifically the email address, and that value ends up rendered in the client management view.
Step 1: build a working XSS payload
The first task was to build a payload that works inside the email field. The second was to work out which characters break SMTP syntax and encode them. The result was this address:
'onmouseover='alert(localStorage.oauth)'@plenumsec.com
The leading ' closes the attribute and onmouseover= introduces a new event handler attribute; the characters that break SMTP syntax were encoded as HTML entities. The handler reads localStorage.oauth.
Step 2: deliver it over raw SMTP
Because the payload has to arrive as a malformed email, the researcher opened a terminal, queried for the target's email server and built the exploit with Netcat:
nc -C mxa.mailgun.org 25 >HELO plenumsec.com>MAIL FROM: <'onmouseover='alert(localStorage.oauth)'@plenumsec.com> >RCPT TO: <[redacted]>>DATAFrom: Attacker <'onmouseover='alert(localStorage.oauth)'@plenumsec.com>To: Victim <[redacted]>Subject: UrgentDate: Wed, 26 Sep 2018 14:21:26 -0400Hello,This is a stored xss poc.Goodbye.
The command connects to the mail server on port 25, issues HELO, sets the envelope sender with MAIL FROM to the crafted address, sets the recipient with RCPT TO, and sends the message body after DATA. The From header carries the same crafted address, the To header is the victim, and the subject is Urgent. The body is a short proof of concept: This is a stored xss poc.
Step 3: wait for the render
Once the message is accepted, the attacker waits for an employee to visit the client management page, or to perform any action that includes the attacker's email. When the stored value is rendered in the client view, the injected attribute fires.
The company email address was completely guessable, so the whole process could be targeted by bruteforcing and automated.

Root cause
A single quote in the email value breaks the surrounding HTML and lets an attacker add their own attributes. The self XSS was already known and accepted as out of scope, but the same sink is fed by a second path: the inbound email handler creates a client record from the sender address of any message sent to the invoice address. That turns a value the attacker fully controls into stored data rendered to staff, which is what upgrades the self XSS into a stored one. The report does not describe any server-side validation or output encoding that would have stopped the payload at either point.
Impact
An attacker can store script in the client management view and have it execute in the browser of an employee who views the client or performs an action that includes the attacker's email. The payload shown reads localStorage.oauth, so the demonstrated target is the OAuth value kept in local storage. Because the company email was guessable, delivery could be bruteforced and automated. The report notes that the attack could have been avoided by implementing SPF, but that security is sometimes not convenient for businesses and compromises get made.
Fix
The report does not say what was changed. It notes that the attack could have been avoided by implementing SPF, though security is sometimes not convenient for businesses.
Variants to test
- Send a message from an unknown address to any inbound address that creates records (invoice, support, ticket), then check whether the sender address is rendered in an internal view. A positive result is the address appearing unencoded in an attribute or HTML context.
- Try a single
'in every field that is populated from inbound mail, not just the email address. A positive result is the surrounding markup breaking and new attributes being accepted. - Reuse the entity trick on other SMTP-sensitive characters, such as parentheses, so the payload survives the mail syntax. A positive result is the message being accepted and the decoded payload rendering in the browser.
- Check whether internal staff addresses follow a guessable pattern, since that is what made bruteforcing and automation practical here. A positive result is a predictable address scheme that can be enumerated.
- Look for the same sink behind other self XSS findings that were closed as out of scope. A positive result is a second, attacker-controlled path into the same rendering context.
What happened, in plain words
A security researcher found a small bug in a private bug bounty program: a self XSS. That means a script could be made to run in the researcher's own browser, but only if the researcher typed the malicious input themselves. The program already knew about it and said it was out of scope, so it would not pay a reward for it. Instead of stopping there, the researcher looked for another way to get the same malicious input into the application, one that did not require the victim to type anything. The answer was the application's email-to-ticket feature: when someone sends an email to the invoice address, the application checks if the sender's email address belongs to an existing client. If it does, a new ticket is created for that client. If it does not, a new client is created along with the ticket. That means an attacker can control part of a client's information, specifically the email address, simply by sending an email. The researcher then crafted a malformed email address that contained a script payload, used a tool called Netcat to send it directly to the target's mail server, and waited for an employee to view the client management page. When the employee did, the script ran in the employee's browser. This turned the self XSS into a stored XSS, which is much more serious because it affects other people, not just the attacker.

Background: the application and the features involved
The researcher was working on a private program, so the name of the target is not given. The application had a CRM (customer relationship management) system and other related parts. One part was client management, which let staff create, delete and modify clients, and create and attach invoices. The self XSS was in the information fields of the client's view. That means when staff looked at a client's details, some of the fields were not properly encoded, so if a value contained HTML code, the browser would treat it as part of the page instead of as plain text.
Finding the self XSS
While exploring the application, the researcher noticed that adding a single quote character (') to the email field broke the surrounding HTML. The email value was being placed inside an HTML attribute of a link element. Here is the shape of the injected markup:
<a tlclick="sendEmail("email_here")">email_here</a>
Let's break this down. The <a> tag creates a link. The tlclick attribute holds a call to sendEmail with the email address. The value of that attribute is sendEmail("email_here"). The " is an HTML entity that represents a double quote character. So the actual value is sendEmail("email_here"). The text between the opening and closing <a> tags is also email_here, which is the email address displayed to the user.
When the application puts the email address into this template, it does not escape special characters. So if the email address contains a single quote, that quote will close the attribute value early.
Now the attribute value is sendEmail("foo and then there is a stray '[redacted]")">foo'[redacted]</a>. The browser will try to interpret this, and an attacker can add their own attributes. For instance, they could add an onmouseover handler to run JavaScript when the mouse hovers over the link. This is a self XSS because the attacker has to inject the payload into their own browser, for example by typing it into a form. It does not affect other users unless the malicious input is stored and shown to them.
The program was aware of this issue and had explicitly marked it as out of scope, so the researcher did not report it. Instead, they kept looking for a way to make the XSS stored.
The pivot: email-to-ticket feature
The researcher found another feature: if you send an email to the invoice email address, the application checks whether the sender's email address exists in the client database. If it does not, a new client is created along with the new ticket. This means the attacker can control the email address of a client by simply sending an email from an address that is not yet in the database. That email address is then stored and later displayed in the client management view. So the attacker can inject a payload into the email address, and it will be stored and shown to staff. That is the definition of stored XSS.
Step 1: building the XSS payload
The first task was to build a payload that would work inside the email field. The second was to figure out which characters break SMTP syntax and encode them. SMTP is the protocol used to send email. It has rules about which characters are allowed in email addresses and in commands. Some characters can break the SMTP syntax, so they had to be encoded. The researcher ended up with this email address:
'onmouseover='alert(localStorage.oauth)'@plenumsec.com
Let's analyse this payload. The leading single quote (') is there to close the attribute value in the HTML. Then onmouseover= introduces a new event handler attribute. The value of that attribute is alert(localStorage.oauth). The ( and ) are HTML entities for ( and ), used to encode characters that break the SMTP syntax. The JavaScript code inside the alert is localStorage.oauth. localStorage is a browser feature that lets websites store data on the user's computer. oauth is likely a key where the application stores an OAuth token. An OAuth token is like a temporary password that allows access to a service. So the payload would show an alert with the value of that token. The rest of the email address, @plenumsec.com, is the domain the researcher controls, making it a valid email address format.
Step 2: delivering the payload over raw SMTP
Because the payload has to arrive as a malformed email, the researcher used Netcat to speak SMTP directly to the target's mail server. Netcat is a command-line tool that can open network connections and send data. The researcher first queried for the target's email server and found mxa.mailgun.org. Then they built the exploit:
nc -C mxa.mailgun.org 25 >HELO plenumsec.com>MAIL FROM: <'onmouseover='alert(localStorage.oauth)'@plenumsec.com> >RCPT TO: <[redacted]>>DATAFrom: Attacker <'onmouseover='alert(localStorage.oauth)'@plenumsec.com>To: Victim <[redacted]>Subject: UrgentDate: Wed, 26 Sep 2018 14:21:26 -0400Hello,This is a stored xss poc.Goodbye.
This command is a single line, but it contains multiple SMTP commands separated by >. In a real Netcat session, you would type each command and press Enter. Let's break it down line by line as if each > starts a new line:
nc -C mxa.mailgun.org 25: This starts Netcat, connects to the mail servermxa.mailgun.orgon port 25 (the standard SMTP port).HELO plenumsec.com: This is the SMTP greeting. The client identifies itself with a domain name.plenumsec.comis the researcher's domain.MAIL FROM: <'onmouseover='alert(localStorage.oauth)'@plenumsec.com>: This sets the envelope sender address. It is the crafted email address with the payload. The angle brackets are part of the SMTP syntax.RCPT TO: <[redacted]>: This sets the recipient address.[redacted]is a placeholder for the target's invoice email address.DATA: This tells the server that the client is ready to send the message body.- The message headers and body follow:
From: Attacker <'onmouseover='alert(localStorage.oauth)'@plenumsec.com>: The From header, which is what the recipient sees. It contains the same crafted address.To: Victim <[redacted]>: The To header, with the victim's address.Subject: Urgent: The subject line, designed to make the email look important.Date: Wed, 26 Sep 2018 14:21:26 -0400: The date header.- A blank line separates headers from body.
Hello,This is a stored xss poc.Goodbye.: The body of the email. It is a simple proof of concept.
The researcher used -C to ensure proper line endings, and sent the commands in sequence. The server would respond with status codes, but those are not shown.
Step 3: waiting for the render
Once the email is accepted, the application creates a new client (or uses an existing one) with the crafted email address. The attacker then waits for an employee to visit the client management page or perform any action that includes the attacker's email. When the stored value is rendered in the client view, the injected attribute fires.
The company email address was completely guessable, so the whole process could be targeted by bruteforcing and automating. That means an attacker could write a script to try many possible email addresses until they find the right one, and then send the malicious email automatically.

Root cause
A single quote in the email value breaks the surrounding HTML and lets an attacker add their own attributes. The self XSS was already known and accepted as out of scope, but the same sink is fed by a second path: the inbound email handler creates a client record from the sender address of any message sent to the invoice address. That turns a value the attacker fully controls into stored data rendered to staff, which is what upgrades the self XSS into a stored one. The report does not describe any server-side validation or output encoding that would have stopped the payload at either point.
Impact
An attacker can store script in the client management view and have it execute in the browser of an employee who views the client or performs an action that includes the attacker's email. The payload shown reads localStorage.oauth, so the demonstrated target is the OAuth value kept in local storage. Because the company email was guessable, delivery could be bruteforced and automated. The report notes that the attack could have been avoided by implementing SPF, but that security is sometimes not convenient for businesses and compromises get made. SPF (Sender Policy Framework) is an email authentication method that allows the receiving mail server to check that an email claiming to come from a domain was actually sent from an IP address authorised by that domain. The report notes that the attack could have been avoided by implementing SPF, though security is sometimes not convenient for businesses.
Fix
The report does not say what was changed. It notes that the attack could have been avoided by implementing SPF, though security is sometimes not convenient for businesses.
Variants to test
- Send a message from an unknown address to any inbound address that creates records (invoice, support, ticket), then check whether the sender address is rendered in an internal view. A positive result is the address appearing unencoded in an attribute or HTML context.
- Try a single
'in every field that is populated from inbound mail, not just the email address. A positive result is the surrounding markup breaking and new attributes being accepted. - Reuse the entity trick on other SMTP-sensitive characters, such as parentheses, so the payload survives the mail syntax. A positive result is the message being accepted and the decoded payload rendering in the browser.
- Check whether internal staff addresses follow a guessable pattern, since that is what made bruteforcing and automation practical here. A positive result is a predictable address scheme that can be enumerated.
- Look for the same sink behind other self XSS findings that were closed as out of scope. A positive result is a second, attacker-controlled path into the same rendering context.
Glossary
- Self XSS: A cross-site scripting vulnerability that only affects the person who injects the malicious code, typically by typing it into a form. It does not automatically affect other users.
- Stored XSS: A cross-site scripting vulnerability where the malicious script is stored on the server (for example, in a database) and then served to other users when they view the affected page.
- CRM: Customer Relationship Management. Software used by businesses to manage interactions with clients and customers.
- SMTP: Simple Mail Transfer Protocol. The standard protocol for sending email over the internet.
- Netcat: A command-line tool for reading from and writing to network connections using TCP or UDP. Often used for debugging and testing.
- HTML attribute: A modifier of an HTML element that provides additional information, such as
hreforonclick. - HTML entity: A way to represent special characters in HTML using a code, such as
"for a double quote or(for a left parenthesis. - JavaScript: A programming language that runs in web browsers and allows web pages to be interactive.
- localStorage: A web browser feature that allows websites to store data persistently on the user's computer.
- OAuth token: A credential used to access protected resources, often used for authorisation in web applications.
- SPF: Sender Policy Framework. An email authentication method that helps prevent email spoofing by checking that the sender's IP address is authorised by the domain.
- Bruteforcing: Trying many possible values (like email addresses) systematically until the correct one is found.
- Output encoding: The process of converting special characters in data into a safe format before displaying it in a web page, to prevent them from being interpreted as code.