Skip to content

Commit 8580727

Browse files
Merge commit from fork
Patch Zip Slip leading to RCE in Backup
2 parents 32d6192 + 8bc77b6 commit 8580727

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

modules/Backup/Controllers/Backup.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,35 @@ public function restore()
9696
$file->move($uploadPath, $newName);
9797
$filePath = WRITEPATH . 'uploads/' . $newName;
9898
$sqlPath = $filePath;
99-
if ($ext === 'zip') {
99+
if ($ext === 'zip') {
100100
$zip = new \ZipArchive();
101101
if ($zip->open($filePath) === true) {
102-
$zip->extractTo($uploadPath);
103-
$sqlPath = $uploadPath . $zip->getNameIndex(0);
102+
$extractedSql = '';
103+
for ($i = 0; $i < $zip->numFiles; $i++) {
104+
$entryName = $zip->getNameIndex($i);
105+
$safeEntryName = basename($entryName);
106+
107+
if (preg_match('/\.sql$/i', $safeEntryName)) {
108+
$fileContent = $zip->getFromIndex($i);
109+
$extractedSql = $uploadPath . $safeEntryName;
110+
file_put_contents($extractedSql, $fileContent);
111+
break;
112+
}
113+
}
104114
$zip->close();
105115
@unlink($filePath);
116+
117+
if (empty($extractedSql)) {
118+
return redirect()->route('backup')->with('error', lang('Backup.dbNotRestore'));
119+
}
120+
$sqlPath = $extractedSql;
121+
} else {
122+
@unlink($filePath);
123+
return redirect()->route('backup')->with('error', lang('Backup.dbNotRestore'));
106124
}
107125
}
126+
}
127+
}
108128

109129
$dbBackup = new \Modules\Backup\Libraries\DbBackup();
110130
if ($dbBackup->restore($sqlPath)) {

0 commit comments

Comments
 (0)