-
Notifications
You must be signed in to change notification settings - Fork 8
/
boyurl.php
286 lines (278 loc) · 8.19 KB
/
boyurl.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
//记录登录的IP,并写入ip.txt
function getIP()
{
static $realip;
if (isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
$realip = $_SERVER["HTTP_CLIENT_IP"];
} else {
$realip = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv("HTTP_X_FORWARDED_FOR")){
$realip = getenv("HTTP_X_FORWARDED_FOR");
} else if (getenv("HTTP_CLIENT_IP")) {
$realip = getenv("HTTP_CLIENT_IP");
} else {
$realip = getenv("REMOTE_ADDR");
}
}
return $realip;
}
$file = "boyurl_ip.txt";
$ip = getIP();
$handle = fopen($file, 'a');
fwrite($handle, "$ip");
fwrite($handle, "\n");
fclose($handle);
//验证码
function randomkeys($length)
{
$pattern='1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
for($i=0;$i<$length;$i++)
{
$key .= $pattern{mt_rand(0,35)};
}
return $key;
}
function Html()
{
global $statusid;
global $statusid1;
global $statusid2;
global $statusid5;
global $statusid6;
global $statusid7;
global $statusid8;
global $Aid;
global $Aid1;
global $Aid2;
global $Aid3;
global $ip;
if($statusid1 == "" and $statusid2 == "" and $statusid5 == "" and $statusid6 == "" and $statusid7 == ""){
$statusid8 = "checked=checked";
}
if($Aid1 == "" and $Aid2 == "" and $Aid3 == ""){
$Aid1 = "checked=checked";
}
echo '<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>';
echo '
<form action="boyurl.php" method="post">
总开关:<br />
<input type="radio" name="Aid" value="12" '.$Aid1.' />单次执行
<input type="radio" name="Aid" value="6" '.$Aid2.' />关闭
<input type="radio" name="Aid" value="30" '.$Aid3.' />重复执行<br />
需iptables设置IP:<br />
<input type="radio" name="status" value="8" '.$statusid8.' />不设置
<input type="radio" name="status" value="7" '.$statusid7.' />初始化
<input type="radio" name="status" value="1" '.$statusid1.' />允许
<input type="radio" name="status" value="5" '.$statusid5.' />删允许
<input type="radio" name="status" value="2" '.$statusid2.' />禁止
<input type="radio" name="status" value="6" '.$statusid6.' />删禁止<br>
<input type="text" name="set_ip" value="'.$ip.'"><br>
需执行的shell脚本:<br />
<textarea name="shell_txt" rows="5" cols="40">echo ok</textarea><br>
<input type="hidden" name="login" value="3">
<input type="submit">
</form>
</body>
</html>';
}
//登录
if($_POST['login'] == ""){
session_start();
$_SESSION['randomkeys'] = randomkeys(6);
$randomkeys = $_SESSION['randomkeys'];
echo '<html>
<head>用户登录</head>
<form name="LoginForm" method="post" action="boyurl.php" onSubmit="return InputCheck(this)">
<p>
<label for="username" class="label">用户名:</label>
<input id="username" name="username" type="text" class="input" />
<p/>
<p>
<label for="password" class="label">密 码:</label>
<input id="password" name="password" type="password" class="input" />
<p/>
<p>
<label for="randomkeys" class="label">验证码:</label>
<input id="randomkeys" name="randomkeys" type="text" class="input" />'.$randomkeys.'
<p/>
<p>
<input type="hidden" name="login" value="1" />
<input type="submit" name="submit" value=" 确 定 " class="left" />
</p>
</form>
</html> ';
}
//登录判断---1
if($_POST['login'] == "1"){
if(!isset($_POST['submit'])){
exit('非法访问!');
}
session_start();
$_SESSION['username'] = $username;
$_SESSION['userid'] = $result['userid'];
$Aid = $_SESSION['Aid'];
$username = htmlspecialchars($_POST['username']);
$password = MD5($_POST['password']);
$keys = $_POST['randomkeys'];
//默认密码boyurl.com,md5加密值cf861e7add70d498d95d6e6763a87258
if($username == "admin" and $password == "cf861e7add70d498d95d6e6763a87258" and $_SESSION['randomkeys'] == $keys){
//登录成功
echo $username,' 欢迎你!点击此处 <a href="boyurl.php?action=logout">注销</a> 登录!<br />';
echo '<br><br>';
Html();
exit;
} else {
exit('登录失败!点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');
}
//注销登录
if($_GET['action'] == "logout"){
unset($_SESSION['userid']);
unset($_SESSION['username']);
echo '注销登录成功!点击此处 <a href="boyurl.php">登录</a>';
exit;
}
//登录判断---1
}
//执行需写入的shell---3
if($_POST['login'] == "3"){
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
$filename="boyurl_cron.txt";
$set_ip = $_POST["set_ip"];
$str_shell = $_POST["shell_txt"];
$statusid = $_POST["status"];
$Aid = $_POST["Aid"];
if($statusid==1) $statusid1 = "checked=checked";
if($statusid==2) $statusid2 = "checked=checked";
if($statusid==5) $statusid5 = "checked=checked";
if($statusid==6) $statusid6 = "checked=checked";
if($statusid==7) $statusid7 = "checked=checked";
if($statusid==8) $statusid8 = "checked=checked";
if($Aid==12) $Aid1 = "checked=checked";
if($Aid==6) $Aid2 = "checked=checked";
if($Aid==30) $Aid3 = "checked=checked";
switch ($statusid)
{
case 1:
$str_ipt = "
/sbin/iptables -D INPUT -j REJECT
/sbin/iptables -A INPUT -s ".$set_ip." -j ACCEPT
/sbin/iptables -A INPUT -j REJECT
";
break;
case 2:
$str_ipt = "
/sbin/iptables -D INPUT -j REJECT
/sbin/iptables -A INPUT -s ".$set_ip." -j DROP
/sbin/iptables -A INPUT -j REJECT
";
break;
case 5:
$str_ipt = "
/sbin/iptables -D INPUT -j REJECT
/sbin/iptables -D INPUT -s ".$set_ip." -j ACCEPT
/sbin/iptables -A INPUT -j REJECT
";
break;
case 6:
$str_ipt = "
/sbin/iptables -D INPUT -j REJECT
/sbin/iptables -D INPUT -s ".$set_ip." -j DROP
/sbin/iptables -A INPUT -j REJECT
";
break;
case 7:
$str_ipt = "
/sbin/iptables -F
/sbin/iptables -t raw -F
/sbin/iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
/sbin/iptables -A INPUT -s 127.0.0.1 -j ACCEPT
/sbin/iptables -A INPUT -s ".$set_ip." -j ACCEPT
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED,UNTRACKED -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT
/sbin/iptables -t raw -A PREROUTING -p tcp --dport 80 -j NOTRACK
/sbin/iptables -t raw -A PREROUTING -p tcp --dport 443 -j NOTRACK
/sbin/iptables -t raw -A OUTPUT -p tcp --sport 80 -j NOTRACK
/sbin/iptables -t raw -A OUTPUT -p tcp --sport 443 -j NOTRACK
/sbin/iptables -A OUTPUT -j ACCEPT
/sbin/iptables -A INPUT -j REJECT
/sbin/iptables -A FORWARD -j REJECT
/sbin/service iptables save
echo ok
";
break;
case 8:
$str_ipt = "echo ok";
break;
default:
$str_ipt = "echo ok";
}
$Time = date('YmdHis');
$str_txt = "
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/usr/sbin
if [ ! -f /tmp/boyurl_pid.txt ];then
echo 'Lujing /tmp' > /tmp/boyurl_pid.txt
echo 'Bid 2 ok' >> /tmp/boyurl_pid.txt
fi
sed -i 's/Clientid/Bid/g' /tmp/boyurl_pid.txt
sed -i 's/clientid/Bid/g' /tmp/boyurl_pid.txt
curl -fsSL http://www.boyurl.com/xnhbsygdxg/boyurl_cron.txt | sed 's/\\r//g' > /tmp/boyurl_cron.txt
Lujing=`cat /tmp/boyurl_pid.txt | grep Lujing | tail -n 1 |awk -F ' ' '{print $2}'`
Bid=`cat /tmp/boyurl_cron.txt | grep 'it is Bid' | tail -n 1 |awk -F ' ' '{print $5}'`
Cid=`cat \$Lujing/boyurl_cron.txt | grep 'it is Aid' | tail -n 1 |awk -F ' ' '{print $5}'`
if [ \$Cid -gt 18 ];then
sed -i '/Bid/d' /tmp/boyurl_pid.txt
echo 'Bid 31 ok' >> /tmp/boyurl_pid.txt
fi
Fid=`cat /tmp/boyurl_pid.txt | grep Bid | tail -n 1 |awk -F ' ' '{print $2}'`
if [ \$Bid -ne \$Fid ] && [ \$Cid -gt 10 ]; then
$str_ipt
$str_shell
echo 'it is Aid $Aid ok'
echo 'it is Bid $Time ok'
sed -i '/Bid/d' /tmp/boyurl_pid.txt
echo 'Bid $Time ok' >> /tmp/boyurl_pid.txt
else
case \$Cid in
1 | 12)
echo 'Linux command has been executed.'
exit 1
;;
2 | 6)
echo 'Close.'
exit 1
;;
3 | 30)
echo 'ok.'
exit 1
;;
*)
echo 'ok'
;;
esac
fi
";
if (!$head=fopen($filename, "w+")) {
die("尝试打开文件[".$filename."]失败!请检查是否拥有足够的权限!创建过程终止!");
}
if (fwrite($head,$str_txt)==false) {
fclose($head);
die("写入内容失败!请检查是否拥有足够的权限!写入过程终止!");
}
echo $username,' 欢迎你!点击此处 <a href="boyurl.php?action=logout">注销</a> 登录!<br />';
echo '写入成功!<br><br>';
Html();
fclose($head);
}
//执行需写入的shell---3
?>