-
Notifications
You must be signed in to change notification settings - Fork 6
/
upload.php
96 lines (86 loc) · 2.81 KB
/
upload.php
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
<?php
/** Lysis Web Decompiler Wrapper
*
* Copyright (C) 2017 Michael Flaherty // michaelwflaherty.com // [email protected]
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/.
*
**/
$target_dir = "/home/admin/public_html/lysis/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$type = pathinfo($target_file, PATHINFO_EXTENSION);
if(isset($_POST["submit"])) // submit pressed
{
if (is_valid_file($_FILES["fileToUpload"], $type)) // file is valid
{
$output = shell_exec('timeout 30s java -jar lysis-java.jar '.$_FILES["fileToUpload"]["tmp_name"]); // get lysis output
if ($output == NULL) {
include('error.html');
die();
}
if (isset($_POST["fileOutput"])) // download to file
{
download_output($output, basename($_FILES["fileToUpload"]["name"]));
}
else // print to browser
{
$cleanoutput = htmlentities($output);
echo "<pre> $cleanoutput </pre>";
}
$file = basename($_FILES["fileToUpload"]["name"]).'.txt';
if (file_exists($file))
unlink($file); // we're not nsa
}
else // ya fucked up
{
include('error.html');
}
}
function download_output($output, $filename)
{
$file = fopen($filename . ".txt", "w");
fwrite($file, $output);
fclose($file);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($filename . ".txt")).' GMT');
header('Cache-Control: private',false);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="'.basename($filename . ".txt").'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($filename . ".txt"));
header('Connection: close');
readfile($filename . ".txt");
}
function is_valid_file($array, $type)
{
$check = filesize($array["tmp_name"]);
if($check == false)
{
return false;
}
else if ($array["size"] > 500000)
{
return false;
}
else if(!($type == "smx" || $type == "amxx"))
{
return false;
}
else
{
return true;
}
}
?>