Post

XXE and CSV Injection Difference

XXE and CSV Injection Difference

🧨 1. XXE (XML External Entity) Injection

Target: Applications that parse XML input
Cause: Improper XML parser configuration that allows external entity declarations
Exploitation: Attackers inject malicious XML with external entities that can:

  • Read local files (file://)

  • Perform SSRF (Server-Side Request Forgery)

  • Potentially execute remote code (in edge cases)

Example Payload:

1
2
3
4
5
6
7
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
  <data>&xxe;</data>
</root>

Impact:

  • Data exfiltration (e.g., /etc/passwd)

  • Internal network scans (via SSRF)

  • Denial of Service


πŸ“Š 2. CSV Injection (Formula Injection)

Target: Applications that export data to spreadsheets (like Excel)
Cause: Unescaped user input exported into CSV files
Exploitation: Attackers inject spreadsheet formulas like =cmd|' /C calc'!A0 that execute when the file is opened in Excel or similar

Example Payload:

1
=HYPERLINK("http://attacker.com","Click me")

or

1
=cmd|' /C calc'!A0

Impact:

  • Code execution (on the client machine)

  • Phishing via links

  • Exfiltration of data (e.g., using WEBSERVICE() or HYPERLINK())


🧾 Summary Table

FeatureXXE InjectionCSV Injection
AffectsXML parsersSpreadsheet software (Excel, etc.)
Input typeXMLCSV / spreadsheet rows
GoalServer-side file access, SSRF, etc.Client-side code execution or phishing
Risk LevelServer compromiseClient compromise
MitigationDisable external entities in XML parsersSanitize values starting with =, +, -, @

Now you may ask - are excel sheets are combination of/written in xml language?

Nice catch β€” yes, modern Excel files (.xlsx) are actually ZIP archives that contain XML files inside. 😲

Let me break that down:


πŸ“ Modern Excel File Format (.xlsx)

  • Introduced with Office 2007, the .xlsx format is based on Open XML, a Microsoft-developed standard.

  • If you rename an .xlsx file to .zip and unzip it, you’ll see a structure like:

1
2
3
4
5
6
7
8
9
[Content_Types].xml
_rels/
xl/
  workbook.xml
  worksheets/
    sheet1.xml
  styles.xml
  sharedStrings.xml
docProps/

Each worksheet (like sheet1.xml) is stored as an XML file describing cells, styles, data types, etc.


πŸ” So Does That Mean CSV = XML?

Nope! Even though .xlsx uses XML internally, CSV files are completely different:

File TypeFormatStructure
.xlsxXML in ZIPComplex, styled, structured
.csvPlain TextSimple rows and columns separated by commas

CSV files are just text-based and don’t use XML at all. They’re usually generated/exported as raw data, like:

1
2
Name,Email,Comment
John,john@example.com,"=HYPERLINK('http://evil.com')"

So, CSV Injection β‰  XML, but Excel (the app) can process both .csv and .xlsx.


πŸ” Bottom Line

  • CSV injection abuses Excel formulas in .csv files.

  • XXE abuses vulnerabilities in XML parsers.

  • .xlsx files are XML-based, but CSVs are not.

CSV File upload Scenarios:

| Scenario | Vulnerability? | Payload Example | | β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” | β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€” | ———————————– | | User uploads .csv resume file | βœ… Yes, if viewed in Excel | =WEBSERVICE("http://yourserver") | | You input a comment, and the site exports comments to .csv | βœ… Yes | =HYPERLINK("http://attacker.com") | | CSV file gets parsed server-side | ❌ Usually safe (if no Excel viewing involved) | N/A |

XXE File upload Scenarios:

|Scenario|Vulnerability?|Notes / Payload Example| |β€”|β€”|β€”| |Site accepts .xml file upload|βœ… Yes|Try basic XXE to read file:///etc/passwd| |Site accepts .docx or .xlsx uploads|βœ… Sometimes|These are ZIP files with embedded XML (inject in word/document.xml, etc.)| |Site imports user config via XML|βœ… Yes|Classic XXE opportunity| |Site parses SVG files (they’re XML too)|βœ… Yes|Inject <!ENTITY> inside SVG β€” many parsers are vulnerable| |Site parses XML but uses secure parser|❌ No|If external entities are disabled (good config), XXE won’t work| |Site uses JSON only|❌ No|XXE only works in XML-based data| |Site returns an error after XML upload|🟑 Maybe|Could be trying to parse it β€” test further with blind XXE or SSRF payloads| |File upload leads to internal API processing XML|βœ… Yes|Upload XML file β†’ backend service parses it (even if you don’t see output)|

This post is licensed under CC BY 4.0 by the author.

Trending Tags