Repository navigation
Expand file tree
/
Copy pathdownload.php
More file actions
113 lines (95 loc) · 4.01 KB
/
Copy pathdownload.php
File metadata and controls
113 lines (95 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
include("./inc/config.php");
/*
Extension to the ZipArchive to allow recursive directory zipping
Define if you want to include base directory in zip or not
You can also select files to ignore
Returns True on success, false otherwise...
Ex:
zipIt('/path/to/folder', '/path/to/compressed.zip', false, array('.DS_Store'));
ref:
http://stackoverflow.com/questions/1334613/how-to-recursively-zip-a-directory-in-php
*/
function zipIt($source, $destination, $include_dir = false, $additionalIgnoreFiles = array()) {
// Ignore "." and ".." folders by default
$defaultIgnoreFiles = array('.', '..');
// include more files to ignore
$ignoreFiles = array_merge($defaultIgnoreFiles, $additionalIgnoreFiles);
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
if (file_exists($destination)) {
unlink ($destination);
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
if ($include_dir) {
$arr = explode("/",$source);
$maindir = $arr[count($arr)- 1];
$source = "";
for ($i=0; $i < count($arr) - 1; $i++) {
$source .= '/' . $arr[$i];
}
$source = substr($source, 1);
$zip->addEmptyDir($maindir);
}
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
// purposely ignore files that are irrelevant
if( in_array(substr($file, strrpos($file, '/')+1), $ignoreFiles) ) {
continue;
}
$file = realpath($file);
if (is_dir($file) === true) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else if (is_file($file) === true) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
} else if (is_file($source) === true) {
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}
if((isset($_GET['target'])) && (!preg_match("#\.\./|\.\.%2f|\.\.%25%5c|\.\.%5c|\.\.%bg%qf|\.\.%u2215|\.\.%c0%9v|\.\.%u2216|%2e%2e/#i", $_GET['target']))) {
// Check SQLMAP output dir for matching directory
// If exists, zip directory contents and everything inside
// Provide zip archive file as download attachment to user
$dir_contents = array_diff(glob(preg_replace("#/$#", "", SQLMAP_OUTPUT_PATH) . "/**"), array('.', '..'));
$hdc = array();
foreach($dir_contents as $dir) {
$dc = explode("/", $dir);
$hdc[] = $dc[sizeof($dc)-1];
}
if(in_array($_GET['target'], $hdc)) {
$dl_file = TMP_PATH . uniqid('sqlmap_') .'_scan_results.zip'; // This doesnt work for unique filenames?, need to find better way (maybe pass in task/scanID)...
if(zipIt(SQLMAP_OUTPUT_PATH . $_GET['target'], $dl_file, true)) {
// Include custom scan log from web panel since API usage wipes the normal log file....
if(file_exists(TMP_PATH . $_GET['target'] . "/api_scan.log")) {
$zip = new ZipArchive;
if ($zip->open($dl_file) === TRUE) {
$zip->addFile(TMP_PATH . $_GET['target'] . "/api_scan.log", $_GET['target'] . '/api_scan.log');
$zip->close();
}
}
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"sqlmap_scan_results.zip\"");
echo readfile($dl_file);
}
@unlink($dl_file);
} else {
echo '<div class="epic_fail" id="epic_fail">';
echo "Problem Downloading Results Directory for Target!<br />";
echo "</div>";
echo "<script>setTimeout('redirectHome()', 5000);</script>";
}
} else {
header("Location: /sqlmap/index.php");
}
?>