Repository navigation
Expand file tree
/
Copy pathlelcrypt.php
More file actions
124 lines (102 loc) · 4.18 KB
/
Copy pathlelcrypt.php
File metadata and controls
124 lines (102 loc) · 4.18 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
114
115
116
117
118
119
120
121
122
123
124
<?php
require_once 'aes/AESCryptFileLib.php';
require_once 'aes/aes256/MCryptAES256Implementation.php';
include 'config.php';
include 'backend.php';
$backend = new Backend();
$pass = $_POST["pass"];
$upload = $_POST["upload"];
$decrypt = $_POST["decrypt"];
if(isset($decrypt)) {
try {
$sql = "SELECT * FROM `crypt` WHERE `id` = :id";
$query = $backend->dbh->prepare($sql);
$identifier = (int) $_POST["file"];
$query->bindParam(":id", $identifier);
$query->execute();
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$original = $row['originalfile'];
$encrypted = $row['encryptedfile'];
}
$cryptpass = md5($pass);
$crypt = new MCryptAES256Implementation();
$lib = new AESCryptFileLib($crypt);
$lib->decryptFile($encrypted,$cryptpass,$original);
if (file_exists($original)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($original));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($original));
readfile($original);
exit;
}
}
catch (Exception $e) {
header('Location: https://wesh.gift/crypt/?error');
}
}
if(isset($upload)) {
$dir = "uploads/";
/*** cycle through all files in the directory ***/
foreach (glob($dir."*") as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
/*** if file is 5 minutes old then delete it ***/
if ($ext != "aes") {
if (filemtime($file) < time() - 300) {
unlink($file);
}
}
}
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk = 1;
if(isset($_POST["submit"])) {
$uploadOk = 1;
}
// Check file size
if ($_FILES["file"]["size"] > 500000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
}
else {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
$filename = $target_dir . $_FILES["file"]["name"];
$rootfile = $filename;
$cryptloc = $filename . ".aes";
//MCrypt Initialization
$crypt = new MCryptAES256Implementation();
$lib = new AESCryptFileLib($crypt);
$cryptpass = md5($pass);
if(!isset($cryptpass)) {
die("No password specified.");
}
echo ('<br/>root: ' . $rootfile . " - cryptloc: " . $cryptloc . " - pass: " . $cryptpass);
$lib->encryptFile($rootfile, $cryptpass, $cryptloc);
$id = rand(0,2147483647);
try {
$sql = "INSERT INTO `" . DB_NAME . "`.`crypt` (`id` ,`originalfile` ,`encryptedfile`) VALUES (:id, :file, :crypt);";
$query = $backend->dbh->prepare($sql);
$query->bindParam(":id", $id);
$query->bindParam(":file", $rootfile);
$query->bindParam(":crypt", $cryptloc);
$query->execute();
echo $count;
echo "your id is " . $id;
unlink($rootfile);
header('Location: https://wesh.gift/crypt/?id=' . $id);
$backend->dbh = null;
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
}
}