CVE-2023–38831WinRAR Mantık Hatası Zafiyeti
WinRAR versions before 6.23 mishandled archives that contain a file and a folder whose names differ only by a trailing space, so opening the harmless-looking file also extracted and ran a script hidden in the folder. An attacker could therefore get code to run on a victim's Windows machine while a decoy document was displayed.
medium.com
Published on medium.com
Cybersecurity
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
WinRAR is an archiver for Windows that opens ZIP and RAR archives. When a user double-clicks an archive, WinRAR reads it through its interface, extracts it to the system temporary directory (Temp), and then triggers the Windows Shell API so that the extracted file is opened with the application associated with its extension. For a PDF, that is a preconfigured or any available PDF viewer.
The vulnerability described here, CVE-2023-38831, is a logic flaw in that extraction and hand-off sequence. The author defines a logic flaw as a program behaving unexpectedly because of a gap in its algorithm, even though there is no syntax or memory error in the code. The report also frames the bug as spoofing: a script is made to look like a harmless PDF or image. The Windows Shell is the component that, on a double-click, looks at a file extension and launches the right program, and that behaviour is what turns the naming confusion inside the archive into code execution.
Setup
The only preconditions it states are on the victim side: a Windows machine, and a WinRAR version older than 6.23. The affected software is given as all WinRAR versions before 6.23, and the affected systems as all computers running Windows, because the flaw is triggered in combination with the Windows Shell.
Finding it
The researcher focuses on where the matching algorithm in older WinRAR versions goes wrong: when it parses file names and folder names, it mishandles space characters and extensions. The archive can therefore contain a file and a folder whose names differ only by a trailing space, and WinRAR's name-similarity handling causes the folder to be extracted as well.
In the report's notation, _ stands for a space. The attacker places inside the ZIP archive:
- a file named
a.pdf; - a folder with the same name plus a trailing space,
a.pdf _; - inside that folder, the file to be executed,
a.pdf.cmd.
Exploitation
Step 1: Build the archive
The attacker creates a ZIP archive containing the file a.pdf, the folder a.pdf (with a trailing space), and the payload a.pdf.cmd inside that folder. The payload is the program the attacker wants to run; the PDF is the harmless-looking decoy.
Step 2: The victim opens the archive
When the victim double-clicks the archive, WinRAR follows its normal logic:
- It reads the clicked file through the interface.
- It extracts the file to the temporary folder (Temp) on the computer.
- It triggers the Windows Shell API so the file is opened with the appropriate application, for example a preconfigured or any PDF viewer for a PDF.
Step 3: The name collision is extracted
When the victim clicks a.pdf, WinRAR, because of the name-similarity error, also sends the attacker's folder to the temporary location.
Step 4: The Shell prefers the script
Windows Shell gives priority to .bat and .cmd files over the other program sharing the same name. The attacker's program therefore runs in the background without the victim noticing, and the PDF is displayed at the same time, so the user sees the expected document.
Root cause
The mistake is in the matching algorithm of older WinRAR versions: it parses file names and folder names without correctly handling space characters and extensions, so a file and a folder whose names differ only by a trailing space are treated as related, and the folder's contents are extracted alongside the clicked file.
The second half of the chain is Windows Shell behaviour: when several files share a base name, the Shell gives priority to .bat and .cmd.
Impact
An attacker who can deliver a crafted ZIP or RAR archive to a Windows user running WinRAR before 6.23 can get the attacker's program run on that machine when the user opens the archive and clicks the decoy file. The execution happens in the background while the decoy PDF is shown, so the user does not notice it. The impact it states is the attacker's program running on the victim's computer.
Fix
The fix is to upgrade WinRAR to version 6.23 or newer.
Additional measures it recommends:
- Use antivirus software that inspects programs such as
.exefiles started by WinRAR before they run. - Most importantly, do not download or run suspicious files from unknown or foreign sources.
Variants to test
- Other archive tools with the same extract-then-Shell pattern. Try archives containing a file and a folder whose names differ only by a trailing space, and see whether both are extracted. A positive result is the folder's payload appearing in the temporary directory next to the decoy.
- Other trailing or padding characters. Repeat the collision with characters other than a space, such as a trailing dot, and check whether the archiver still treats the two names as related. A positive result is the same extraction of the folder's contents.
- Other extension pairs. Replace
.pdfand.cmdwith other decoy and script pairs, for example an image and.bat, and check whether the Shell still prefers the script. A positive result is the script running while the decoy opens. - Other Shell-resolved formats. Test whether the same name collision works when the decoy is a format opened by a different handler, and observe which program the Shell launches. A positive result is the script executing before or alongside the decoy.
What happened, in plain words
WinRAR is a program for Windows that opens compressed files, called archives. An archive is a single file that holds many files inside it, a bit like a cardboard box packed with smaller items. The two common archive formats are ZIP and RAR. When you double-click an archive, WinRAR unpacks its contents so you can use them.
In older versions of WinRAR, there was a mistake in the way the program decided which files inside the archive belonged together. An attacker could build an archive that contained a harmless-looking document, such as a PDF, and a hidden program inside a folder with a very similar name. When the victim double-clicked the PDF, WinRAR also sent the attacker's folder to the temporary location, and Windows then ran the hidden program in the background while showing the PDF on screen. The victim saw the expected document and did not notice that anything else had happened.
The bug is tracked as CVE-2023-38831. The report calls it a logic flaw: the program does not crash and there is no broken syntax or memory error, but its internal recipe, its algorithm, has a gap, so it behaves in a way nobody intended. The report also frames the bug as spoofing, meaning one file is made to look like something else: here a script is disguised as a harmless PDF or image.
The ideas you need first
The report defines a few terms before it gets to the bug, and they are worth knowing because each one appears later in the chain.
- Logic flaw (mantık hatası): the code has no syntax or memory error, but the program's algorithm is incomplete, so the program behaves unexpectedly. A comparison: a recipe that lists all the ingredients correctly but forgets to say when to take the cake out of the oven. Nothing is misspelled, yet the result is wrong.
- Spoofing (kandırma/maskeleme): showing a file as something different from what it really is. In this vulnerability a script is displayed as a harmless PDF or image. A comparison: a parcel labelled "books" that actually contains something else.
- Temp directory (geçici dizin): the place where applications put files that are not meant to last, and delete them when they are done. A comparison: the tray by the till where a shop assistant puts your items while scanning them, not the shelf where stock lives.
- Windows Shell execution: the part of Windows that, when you double-click a file, looks at the file's extension and launches the right program for it. A comparison: a receptionist who reads the label on a package and sends it to the right department.
- Zero-day (sıfırıncı gün) vulnerability: a weakness inside a piece of software or an operating system that the developers have not noticed yet. The name comes from the idea that the defenders have zero days to prepare a defence.
Technical analysis of the vulnerability
When you double-click a file (ZIP or RAR), WinRAR follows this logic:
- It reads the clicked file through its interface.
- It extracts that file to the temporary folder (Temp) on the computer.
- It triggers the Windows Shell API so the file is opened with the appropriate application. For a PDF, that is a preconfigured PDF viewer or any available PDF viewer.
An API is a defined way for one program to ask another program to do something, without knowing how that other program works inside. A comparison: ordering at a restaurant counter. You say what you want, the kitchen prepares it, and you do not need to know how the kitchen is organised. The Windows Shell API is the counter through which WinRAR asks Windows to open a file.
Where the mistake happens
The matching algorithm in older WinRAR versions makes a logic error when it parses file names and folder names: it mishandles space characters and extensions. In the report's notation, _ stands for a space.
The attacker puts into the ZIP archive a file with the same name, a.pdf, and a folder with the same name plus a trailing space, a.pdf _. Inside the folder the attacker puts the file to be executed, a.pdf.cmd.
So the archive contains three things:
| Item | What it is | Role |
|---|---|---|
a.pdf |
a file | the decoy the victim sees and clicks |
a.pdf (trailing space) |
a folder | the container for the payload |
a.pdf.cmd |
a file inside that folder | the program the attacker wants to run |
When someone clicks the a.pdf file, WinRAR, because of the name-similarity error, also sends the attacker's folder to the temporary location. Then the Windows Shell gives priority, among the two programs sharing the same name (the PDF and the CMD), to the .bat and .cmd ones. The attacker's program runs in the background before you notice, and at the same time the PDF appears in front of you.
Affected products and systems
- Affected software: all WinRAR versions before 6.23.
- Affected operating systems: every computer running Windows, because the vulnerability is triggered when it combines with the Windows Shell.
How to protect yourself
- Update the software: upgrade WinRAR to version 6.23 or newer.
- Use antivirus software: some antivirus products inspect programs such as
.exefiles that WinRAR starts, before they run. Antivirus software of that kind can be used. - Most importantly: do not download or run a suspicious file from someone you do not know or from a foreign source.
Exploitation, step by step
Step 1: Build the archive
The attacker creates a ZIP archive containing the file a.pdf, the folder a.pdf (with a trailing space), and the payload a.pdf.cmd inside that folder. The payload is the program the attacker wants to run; the PDF is the harmless-looking decoy.
Step 2: The victim opens the archive
When the victim double-clicks the archive, WinRAR follows its normal logic:
- It reads the clicked file through the interface.
- It extracts the file to the temporary folder (Temp) on the computer.
- It triggers the Windows Shell API so the file is opened with the appropriate application, for example a preconfigured or any PDF viewer for a PDF.
Step 3: The name collision is extracted
When the victim clicks a.pdf, WinRAR, because of the name-similarity error, also sends the attacker's file to the temporary location.
Step 4: The Shell prefers the script
Windows Shell gives priority to .bat and .cmd files over the other program sharing the same name. The attacker's program therefore runs in the background before the victim notices, and the PDF is displayed at the same time, so the user sees the expected document.
Root cause
The mistake is in the matching algorithm of older WinRAR versions: it parses file names and folder names without correctly handling space characters and extensions, so a file and a folder whose names differ only by a trailing space are treated as related, and the folder's contents are extracted alongside the clicked file.
The second half of the chain is Windows Shell behaviour: when several files share a base name, the Shell gives priority to .bat and .cmd.
Impact
An attacker who can deliver a crafted ZIP or RAR archive to a Windows user running WinRAR before 6.23 can get the attacker's program run on that machine when the user opens the archive and clicks the decoy file. The execution happens in the background while the decoy PDF is shown, so the user does not notice it. The impact it states is the attacker's program running on the victim's computer.
Fix
The fix is to upgrade WinRAR to version 6.23 or newer.
Additional measures it recommends:
- Use antivirus software that inspects programs such as
.exefiles started by WinRAR before they run. - Most importantly, do not download or run suspicious files from unknown or foreign sources.
Variants to test
These are ideas for checking whether the same pattern appears elsewhere. Each one describes what to try and what a positive result would look like.
- Other archive tools with the same extract-then-Shell pattern. Try archives containing a file and a folder whose names differ only by a trailing space, and see whether both are extracted. A positive result is the folder's payload appearing in the temporary directory next to the decoy.
- Other trailing or padding characters. Repeat the collision with characters other than a space, such as a trailing dot, and check whether the archiver still treats the two names as related. A positive result is the same extraction of the folder's contents.
- Other extension pairs. Replace
.pdfand.cmdwith other decoy and script pairs, for example an image and.bat, and check whether the Shell still prefers the script. A positive result is the script running while the decoy opens. - Other Shell-resolved formats. Test whether the same name collision works when the decoy is a format opened by a different handler, and observe which program the Shell launches. A positive result is the script executing before or alongside the decoy.
Glossary
- Archive: a single file that contains other files inside it, such as a ZIP or RAR file.
- WinRAR: a Windows program that opens and creates ZIP and RAR archives.
- ZIP / RAR: two common formats for archives.
- Logic flaw: a program behaving unexpectedly because its algorithm has a gap, even though the code has no syntax or memory error.
- Spoofing: making a file or message look like something it is not.
- Temp directory: the folder where applications keep temporary files and delete them when they are done.
- Windows Shell: the part of Windows that looks at a file's extension on a double-click and launches the matching program.
- API: a defined way for one program to ask another program to perform an action.
- Zero-day: a software weakness the developers have not noticed yet, so defenders have no time to prepare.
- CVE: a public identifier given to a known vulnerability so people can refer to it unambiguously.
- Extension: the part of a file name after the last dot, such as
.pdfor.cmd, which tells Windows which program to use. - Payload: the program or code an attacker wants to run on the victim's machine.
- Decoy: the harmless-looking file shown to the victim to hide what is really happening.
- Parsing: reading text, such as a file name, and breaking it into parts the program can work with.
- Algorithm: the step-by-step recipe a program follows to do a job.
- Antivirus: software that inspects files and programs for malicious behaviour before or while they run.
- Privilege level: the amount of access a program or user has on a system.
- Persistence: a way for an attacker to keep access after a restart or after the original action is over.