当前位置:首页 > CN2资讯 > 正文内容

php 攻击

2天前CN2资讯

 

让PHP程序永远在后台运行

PHP里有个函数很有用。这是在最近的开发中才逐渐用到的。 
int ignore_user_abort ( [bool setting] ) 

这个函数的作用是指示服务器端在远程客户端关闭连接后是否继续执行下面的脚本。

setting 参数是一个可选参数。如设置为True,则表示如果用户停止脚本运行,仍然不影响脚本的运行(即:脚本将持续执行);如果设置为False,则表示当用户停止运行脚本程序时,脚本程序将停止运行。

下面这个例子,在用户关闭浏览器后,该脚本仍然后在服务器上继续执行:

<?php
ignore_user_abort(); // 后台运行
set_time_limit(0); // 取消脚本运行时间的超时上限
do{
sleep(60); // 休眠1分钟
}while(true);
?>
除非在服务器上关闭这个程序,否则这断代码将永远执行下去。

-------------------------------------------------------------------------

<?php
   ignore_user_abort(); // 后台运行
   set_time_limit(0); // 取消脚本运行时间的超时上限
   echo 'start.<br/>';
   while(!file_exists('close.txt')){
    $fp = fopen('test.txt','a+');
    fwrite($fp,date("Y-m-d H:i:s") . " 成功了!\r\n");
    fclose($fp);
    sleep(10);
   }
   echo 'end.<br/>';
?>

所谓的CC攻击就是对方利用程序或一些代理对您的网站进行不间断的访问,造成您的网站处理不了而处于当机状态。这种时候您的统计系统(可能是量子、百度等)当然也是统计不到的。不过我们可以借助于一些防攻击的软件来实现,不过效果有时并不明显。下面我提供一段PHP的代码,可以起到一定的防CC效果。

主要功能:在3秒内连续刷新页面5次以上将指向本机 http://127.0.0.1

$P_S_T  = $t_array[0] + $t_array[1];
$timestamp = time(); 

session_start();
$ll_nowtime = $timestamp;
if (session_is_registered('ll_lasttime')){
$ll_lasttime = $_SESSION['ll_lasttime'];
$ll_times = $_SESSION['ll_times'] + 1;
$_SESSION['ll_times'] = $ll_times;
}else{
$ll_lasttime = $ll_nowtime;
$ll_times = 1;
$_SESSION['ll_times'] = $ll_times;
$_SESSION['ll_lasttime'] = $ll_lasttime;
}
if (($ll_nowtime - $ll_lasttime)<3){
if ($ll_times>=5){
header(sprintf("Location: %s",'http://127.0.0.1'));
exit;
}
}else{
$ll_times = 0;
$_SESSION['ll_lasttime'] = $ll_nowtime;
$_SESSION['ll_times'] = $ll_times;
}

 

<?php /**************PHP Web木马扫描器************************/ /* [+] 作者: alibaba */ /* [+] QQ: 1499281192 */ /* [+] MSN: [email protected] */ /* [+] 首发: t00ls.net , 转载请注明t00ls */ /* [+] 版本: v1.0 */ /* [+] 功能: web版php木马扫描工具 */ /* [+] 注意: 扫描出来的文件并不一定就是后门, */ /* 请自行判断、审核、对比原文件。 */ /* 如果你不确定扫出来的文件是否为后门, */ /* 欢迎你把该文件发给我进行分析。 */ /*******************************************************/ ob_start(); set_time_limit(0); $username = "t00ls"; //设置用户名 $password = "t00ls"; //设置密码 $md5 = md5(md5($username).md5($password)); $version = "PHP Web木马扫描器 v1.0"; $realpath = realpath('./'); $selfpath = $_SERVER['PHP_SELF']; $selfpath = substr($selfpath, 0, strrpos($selfpath,'/')); define('REALPATH', str_replace('//','/',str_replace('\\','/',substr($realpath, 0, strlen($realpath) - strlen($selfpath))))); define('MYFILE', basename(__FILE__)); define('MYPATH', str_replace('\\', '/', dirname(__FILE__)).'/'); define('MYFULLPATH', str_replace('\\', '/', (__FILE__))); define('HOST', "http://".$_SERVER['HTTP_HOST']); ?> <html> <head> <title><?php echo $version?></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style> body{margin:0px;} body,td{font: 12px Arial,Tahoma;line-height: 16px;} a {color: #00f;text-decoration:underline;} a:hover{color: #f00;text-decoration:none;} .alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;} .alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;} .focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;} .head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;} .head td span{font-weight:normal;} </style> </head> <body> <?php if(!(isset($_COOKIE['t00ls']) && $_COOKIE['t00ls'] == $md5) && !(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5))) { echo '<form id="frmlogin" name="frmlogin" method="post" action="">用户名: <input type="text" name="username" id="username" /> 密码: <input type="password" name="password" id="password" /> <input type="submit" name="btnLogin" id="btnLogin" value="登陆" /></form>'; } elseif(isset($_POST['username']) && isset($_POST['password']) && (md5(md5($_POST['username']).md5($_POST['password']))==$md5)) { setcookie("t00ls", $md5, time()+60*60*24*365,"/"); echo "登陆成功!"; header( 'refresh: 1; url='.MYFILE.'?action=scan' ); exit(); } else { setcookie("t00ls", $md5, time()+60*60*24*365,"/"); $setting = getSetting(); $action = isset($_GET['action'])?$_GET['action']:""; if($action=="logout") { setcookie ("t00ls", "", time() - 3600); Header("Location: ".MYFILE); exit(); } if($action=="download" && isset($_GET['file']) && trim($_GET['file'])!="") { $file = $_GET['file']; ob_clean(); if (@file_exists($file)) { header("Content-type: application/octet-stream"); header("Content-Disposition: filename=\"".basename($file)."\""); echo file_get_contents($file); } exit(); } ?> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr class="head"> <td><?php echo $_SERVER['SERVER_ADDR']?><span style="float: right; font-weight:bold;"><?php echo "<a href='http://www.t00ls.net/'>$version</a>"?></span></td> </tr> <tr class="alt1"> <td><span style="float: right;"><?=date("Y-m-d H:i:s",mktime())?></span> <a href="?action=scan">扫描</a> | <a href="?action=setting">设定</a> | <a href="?action=logout">登出</a> </td> </tr> </tbody></table> <br> <?php if($action=="setting") { if(isset($_POST['btnsetting'])) { $Ssetting = array(); $Ssetting['user']=isset($_POST['checkuser'])?$_POST['checkuser']:"php | php? | phtml"; $Ssetting['all']=isset($_POST['checkall'])&&$_POST['checkall']=="on"?1:0; $Ssetting['hta']=isset($_POST['checkhta'])&&$_POST['checkhta']=="on"?1:0; setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); echo "设置完成!"; header( 'refresh: 1; url='.MYFILE.'?action=setting' ); exit(); } ?> <form name="frmSetting" method="post" action="?action=setting"> <FIELDSET style="width:400px"> <LEGEND>扫描设定</LEGEND> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="60">文件后缀:</td> <td width="300"><input type="text" name="checkuser" id="checkuser" style="width:300px;" value="<?php echo $setting['user']?>"></td> </tr> <tr> <td><label for="checkall">所有文件</label></td> <td><input type="checkbox" name="checkall" id="checkall" <?php if($setting['all']==1) echo "checked"?>></td> </tr> <tr> <td><label for="checkhta">设置文件</label></td> <td><input type="checkbox" name="checkhta" id="checkhta" <?php if($setting['hta']==1) echo "checked"?>></td> </tr> <tr> <td> </td> <td> <input type="submit" name="btnsetting" id="btnsetting" value="提交"> </td> </tr> </table> </fieldset> </form> <?php } else { $dir = isset($_POST['path'])?$_POST['path']:MYPATH; $dir = substr($dir,-1)!="/"?$dir."/":$dir; ?> <form name="frmScan" method="post" action=""> <table width="100%%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="35" style="vertical-align:middle; padding-left:5px;">扫描路径:</td> <td width="690"> <input type="text" name="path" id="path" style="width:600px" value="<?php echo $dir?>"> <input type="submit" name="btnScan" id="btnScan" value="开始扫描"></td> </tr> </table> </form> <?php if(isset($_POST['btnScan'])) { $start=mktime(); $is_user = array(); $is_ext = ""; $list = ""; if(trim($setting['user'])!="") { $is_user = explode("|",$setting['user']); if(count($is_user)>0) { foreach($is_user as $key=>$value) $is_user[$key]=trim(str_replace("?","(.)",$value)); $is_ext = "(\.".implode("($|\.))|(\.",$is_user)."($|\.))"; } } if($setting['hta']==1) { $is_hta=1; $is_ext = strlen($is_ext)>0?$is_ext."|":$is_ext; $is_ext.="(^\.htaccess$)"; } if($setting['all']==1 || (strlen($is_ext)==0 && $setting['hta']==0)) { $is_ext="(.+)"; } $php_code = getCode(); if(!is_readable($dir)) $dir = MYPATH; $count=$scanned=0; scan($dir,$is_ext); $end=mktime(); $spent = ($end - $start); ?> <div style="padding:10px; background-color:#ccc">扫描: <?php echo $scanned?> 文件 | 发现: <?php echo $count?> 可疑文件 | 耗时: <?php echo $spent?> 秒</div> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="head"> <td width="15" align="center">No.</td> <td width="48%">文件</td> <td width="12%">更新时间</td> <td width="10%">原因</td> <td width="20%">特征</td> <td>动作</td> </tr> <?php echo $list?> </table> <?php } } } ob_flush(); ?> </body> </html> <?php function scan($path = '.',$is_ext){ global $php_code,$count,$scanned,$list; $ignore = array('.', '..' ); $replace=array(" ","\n","\r","\t"); $dh = @opendir( $path ); while(false!==($file=readdir($dh))){ if( !in_array( $file, $ignore ) ){ if( is_dir( "$path$file" ) ){ scan("$path$file/",$is_ext); } else { $current = $path.$file; if(MYFULLPATH==$current) continue; if(!preg_match("/$is_ext/i",$file)) continue; if(is_readable($current)) { $scanned++; $content=file_get_contents($current); $content= str_replace($replace,"",$content); foreach($php_code as $key => $value) { if(preg_match("/$value/i",$content)) { $count++; $j = $count % 2 + 1; $filetime = date('Y-m-d H:i:s',filemtime($current)); $reason = explode("->",$key); $url = str_replace(REALPATH,HOST,$current); preg_match("/$value/i",$content,$arr); $list.=" <tr class='alt$j' onmouseover='this.className=\"focus\";' onmouseout='this.className=\"alt$j\";'> <td>$count</td> <td><a href='$url' target='_blank'>$current</a></td> <td>$filetime</td> <td><font color=red>$reason[0]</font></td> <td><font color=#090>$reason[1]</font></td> <td><a href='?action=download&file=$current' target='_blank'>下载</a></td> </tr>"; //echo $key . "-" . $path . $file ."(" . $arr[0] . ")" ."<br />"; //echo $path . $file ."<br />"; break; } } } } } } closedir( $dh ); } function getSetting() { $Ssetting = array(); if(isset($_COOKIE['t00ls_s'])) { $Ssetting = unserialize(base64_decode($_COOKIE['t00ls_s'])); $Ssetting['user']=isset($Ssetting['user'])?$Ssetting['user']:"php | php? | phtml | shtml"; $Ssetting['all']=isset($Ssetting['all'])?intval($Ssetting['all']):0; $Ssetting['hta']=isset($Ssetting['hta'])?intval($Ssetting['hta']):1; } else { $Ssetting['user']="php | php? | phtml | shtml"; $Ssetting['all']=0; $Ssetting['hta']=1; setcookie("t00ls_s", base64_encode(serialize($Ssetting)), time()+60*60*24*365,"/"); } return $Ssetting; } function getCode() { return array( '后门特征->cha88.cn'=>'cha88\.cn', '后门特征->c99shell'=>'c99shell', '后门特征->phpspy'=>'phpspy', '后门特征->Scanners'=>'Scanners', '后门特征->cmd.php'=>'cmd\.php', '后门特征->str_rot13'=>'str_rot13', '后门特征->webshell'=>'webshell', '后门特征->EgY_SpIdEr'=>'EgY_SpIdEr', '后门特征->'=>'tools88\.com', '后门特征->SECFORCE'=>'SECFORCE', '后门特征->eval("?>'=>'eval\((\'|")\?>', '可疑代码特征->system('=>'system\(', '可疑代码特征->passthru('=>'passthru\(', '可疑代码特征->shell_exec('=>'shell_exec\(', '可疑代码特征->exec('=>'exec\(', '可疑代码特征->popen('=>'popen\(', '可疑代码特征->proc_open'=>'proc_open', '可疑代码特征->eval($'=>'eval\((\'|"|\s*)\\$', '可疑代码特征->assert($'=>'assert\((\'|"|\s*)\\$', '危险MYSQL代码->returns string soname'=>'returnsstringsoname', '危险MYSQL代码->into outfile'=>'intooutfile', '危险MYSQL代码->load_file'=>'select(\s+)(.*)load_file', '加密后门特征->eval(gzinflate('=>'eval\(gzinflate\(', '加密后门特征->eval(base64_decode('=>'eval\(base64_decode\(', '加密后门特征->eval(gzuncompress('=>'eval\(gzuncompress\(', '加密后门特征->eval(gzdecode('=>'eval\(gzdecode\(', '加密后门特征->eval(str_rot13('=>'eval\(str_rot13\(', '加密后门特征->gzuncompress(base64_decode('=>'gzuncompress\(base64_decode\(', '加密后门特征->base64_decode(gzuncompress('=>'base64_decode\(gzuncompress\(', '一句话后门特征->eval($_'=>'eval\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->assert($_'=>'assert\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->require($_'=>'require\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->require_once($_'=>'require_once\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->include($_'=>'include\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->include_once($_'=>'include_once\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->call_user_func("assert"'=>'call_user_func\(("|\')assert("|\')', '一句话后门特征->call_user_func($_'=>'call_user_func\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '一句话后门特征->$_POST/GET/REQUEST/COOKIE[?]($_POST/GET/REQUEST/COOKIE[?]'=>'\$_(POST|GET|REQUEST|COOKIE)\[([^\]]+)\]\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)\[', '一句话后门特征->echo(file_get_contents($_POST/GET/REQUEST/COOKIE'=>'echo\(file_get_contents\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '上传后门特征->file_put_contents($_POST/GET/REQUEST/COOKIE,$_POST/GET/REQUEST/COOKIE'=>'file_put_contents\((\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)\[([^\]]+)\],(\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)', '上传后门特征->fputs(fopen("?","w"),$_POST/GET/REQUEST/COOKIE['=>'fputs\(fopen\((.+),(\'|")w(\'|")\),(\'|"|\s*)\\$_(POST|GET|REQUEST|COOKIE)\[', '.htaccess插马特征->SetHandler application/x-httpd-php'=>'SetHandlerapplication\/x-httpd-php', '.htaccess插马特征->php_value auto_prepend_file'=>'php_valueauto_prepend_file', '.htaccess插马特征->php_value auto_append_file'=>'php_valueauto_append_file' ); } ?>

 

    你可能想看:

    扫描二维码推送至手机访问。

    版权声明:本文由皇冠云发布,如需转载请注明出处。

    本文链接:https://www.idchg.com/info/26352.html

    标签: php攻击PHP
    分享给朋友:

    “php 攻击” 的相关文章

    香港服务器CN2线路解析:为什么它是全球企业的首选?

    随着全球化进程的加速,越来越多的企业需要在跨境业务中实现高效的数据传输和稳定的网络连接。而作为国际金融中心,香港因其优越的地理位置和成熟的网络基础设施,成为全球企业部署服务器的热门选择。在众多服务器解决方案中,香港服务器CN2线路因其卓越的性能和稳定性,受到了广泛的关注和青睐。香港服务器CN2线路到...

    波测评分析及其在医疗与教育领域的重要性

    波测评的定义与重要性 波测评是一种重要的技术手段,专注于评估波动的特性和行为。我发现,这种测评方法在多个行业中都扮演了至关重要的角色,比如医疗、工业和电力等领域。以脑波测评为例,它不仅可以帮助医生了解病人的大脑状态,还能在教育领域评估学习能力。这些应用展示了波测评技术在科学与技术进步中的不可或缺性。...

    VPS论坛:虚拟主机爱好者的交流与学习平台

    VPS论坛概述 VPS论坛是一个专为VPS主机爱好者提供交流与分享的平台。在这里,像我这样对VPS感兴趣的人们,可以参与关于虚拟专用服务器的各种讨论。VPS实际上属于一个相对小众的领域,因此知名的VPS论坛数量较少,但它们所承载的信息和交流却是丰富多彩的。这些论坛不仅是获取信息的重要来源,更是与其他...

    IPv6 测速方法与工具:提升网络体验的技巧

    IPv6 测速的基本概念 IPv6,作为互联网协议的最新版本,让我们在网络世界中畅游无阻。它的推出旨在解决IPv4所面临的地址枯竭问题,推进更加广泛的设备连接。简单来说,IPv6提供了更大的地址空间,能够支持越来越多的设备上线。因为万物互联的时代已经来临,我们的手机、电脑、家居设备甚至汽车都需要连接...

    如何选择合适的VPS进行购买:关键因素解析

    选择合适的VPS进行购买是一项涉及多个因素的决策。VPS,即虚拟专用服务器,是一种介于共享主机和独立服务器之间的托管解决方案。特别适合需要灵活性和可扩展性的用户,无论是个人开发者、企业还是网站管理员。这种灵活性让VPS成为现代网络环境中一个非常受欢迎的选择。 VPS与传统的共享主机存在显著区别。传统...

    Linode vs Vultr:选择最佳云服务提供商的指南

    Linode与Vultr概述 在这个云计算的时代,Linode和Vultr是两家备受瞩目的云服务提供商。作为一个用户,我常常在这两者之间进行比较,寻找最适合的解决方案。Linode成立于2003年,专注于为开发者提供虚拟私人服务器(VPS)。它的服务以简单和高效著称,非常适合中小型企业和开发者使用。...