-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_sha512.php
112 lines (100 loc) · 3.38 KB
/
check_sha512.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
include('./config.php');
$row_count=1;
$problem_array=[[]];
$problem_counter=0;
$problem_flag=false; //by default is false if there is no problem and will be true if can find problem
$nf=0; //nt means not found
$nm=0; //nm means not match
$np=0; //no problem(OK)
function send_email($from,$to,$getSubject,$getmessage)
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .="From:$from\r\n";
$headers .="Return-Path:$to\r\n";
$headers .= "X-Mailer: Simply Mailer\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
$message="
<html>
<body>
$getmessage
</body>
</html>
";
mail($to, $getSubject, $getmessage,$headers);
if(mail)
{
echo "Mail has been sent to $to<br>";
}
else {
echo 'Please try again';
}
}
function getDirContents($dir, $filter = '', &$results = array()) {
$files = scandir($dir);
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
if(empty($filter) || preg_match($filter, $path)) $results[] = $path;
} elseif($value != "." && $value != "..") {
getDirContents($path, $filter, $results);
}
}
return $results;
}
$result_array=getDirContents($web_path, '/\.php$/');
echo "<table border='1'><tr><td>Row</td><td>File Name</td><td>Path</td><td>sha512 Hash</td><td>Status</td></tr>";
foreach ($result_array as $path)
{
$filename=basename($path);
$sha512_hash=hash_file($hash_function, $path,false);
$sql = "SELECT * FROM file_sha512 WHERE Source_File_Path='$path'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
if($row['sha512']==$sha512_hash)
{
//echo "<td><div style='color: #00cc66'>OK</div></td>";
$np++;
}
else
{
echo "<tr><td>" . $row_count . "</td><td>" . $filename . "</td><td>".$path ."</td><td>" . $sha512_hash . "</td>";
echo "<td><div style='color: red'>Not Matched</div></td>";
echo "<td>" . $row['Date_Time'] . "</td>";
$nm++;
$problem_array[$problem_counter][0]=$path;
$problem_array[$problem_counter][1]="Not Mached";
$problem_counter++;$flag=true;}
}
}
else
{
echo "<tr><td>" . $row_count . "</td><td>" . $filename . "</td><td>".$path ."</td><td>" . $sha512_hash . "</td>";
echo "<td><div style='color: #ff9900'>Not Found</div></td></tr>";
echo "<td>" . "Null" . "</td>";
$nf++;
$problem_array[$problem_counter][0]=$path;
$problem_array[$problem_counter][1]="Not Found";
$problem_counter++;
$flag=true;
}
$row_count++;
}
echo "</table>";
//Sum Result
echo "<center><table style='width:50%'><tr><td>OK</td><td>Not Matched</td><td>Not Found</td><tr>";
echo "<tr><td>".$np."</td><td>".$nm."</td><td>".$nf."</td></tr>";
echo "</table></center>";
for($i=0;$i<$problem_counter;$i++)
{
$message=$message . "File Path: " . $problem_array[$i][0] . " Status: " . $problem_array[$i][1] ."<br>";
}
if($flag==true) {send_email($from,$to,$subject,$message);}
$conn->close();
?>