-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaaa.php
More file actions
69 lines (58 loc) · 1.71 KB
/
Copy pathaaa.php
File metadata and controls
69 lines (58 loc) · 1.71 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
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$a=false;
$tmp = $_FILES["up"]["tmp_name"];
$name = $_FILES["up"]["name"];
$ext = strtolower(pathinfo($name,PATHINFO_EXTENSION));
//mime类型
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo,$tmp);
$allowed2 = ['image/jpg', 'image/png', 'image/gif', 'image/jpeg'];
if(!in_array($type,$allowed2)){
$a=true;
}
//允许的文件尾
$allowed3 = ['jpg', 'png', 'gif', 'jpeg'];
if(!in_array($ext,$allowed3)){
$a=true;
}
//头部检测
$f=fopen($tmp,"rb");
$head=bin2hex(fread($f,2));
$allowed = ["ffd8","8950","4749"];
if(!in_array($head,$allowed)){
$a=true;
}
$dangerous = ["<?php", "<?= ", "<?=", "eval(", "system(", "shell_exec", "base64_decode("];
$content = strtolower(file_get_contents($tmp));
foreach($dangerous as $bad){
if(strpos($content,$bad)){
$a =true;
break;
}}
if($a==true){
$uploadMessages='sb';
}else{
$newname = bin2hex(random_bytes(12)) . "." .$ext;
$save = 'img/'.$newname;
if($tmp == ""){
}
if(move_uploaded_file($tmp,$save)){
$uploadMessages= "文件 '" . $save. "' 上传成功。";
}}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post" enctype="multipart/form-data">
<input type="file" id="up" name="up" >
<input type="submit" value="上传">
<?php print_r ($uploadMessages) ?>
</form>
</body>
</html>