php通用防注入主要是过滤一些sql命令与php post get传过来的参考我们/要过滤一些非法字符,这样可以防止基本的注入了,那关第于apache 服务器安装设置方法也是必须的。管理员用户名和密码都采取md5加密,这样就能有效地防止了php的注入。
php教程通用防注入主要是过滤一些sql命令与php post get传过来的参考我们/要过滤一些非法字符,这样可以防止基本的注入了,那关第于apache 服务器安装设置方法也是必须的。管理员用户名和密码都采取md5加密,这样就能有效地防止了php的注入。
还有服务器和mysql教程也要加强一些安全防范。
对于linux服务器的安全设置:
加密口令,使用“/usr/sbin/authconfig”工具打开密码的shadow功能,对password进行加密。
禁止访问重要文件,进入linux命令界面,在提示符下输入:
#chmod 600 /etc/inetd.conf //改变文件属性为600
#chattr +i /etc/inetd.conf //保证文件属主为root
#chattr –i /etc/inetd.conf // 对该文件的改变做限制
禁止任何用户通过su命令改变为root用户
在su配置文件即/etc/pam.d/目录下的开头添加下面两行:
auth sufficient /lib/security/pam_rootok.so debug
auth required /lib/security/pam_whell.so group=wheel
删除所有的特殊帐户
#userdel lp等等 删除用户
#groupdel lp等等 删除组
禁止不使用的suid/sgid程序
#find / -type f (-perm -04000 - o –perm -02000 ) -execls –lg {} ;
$arrfiltrate=array("'",";","union","select","insert","update","delete","load_file","outfile");
//出错后要跳转的url
$strgourl="";
function funstringexist($strfiltrate,$arrfiltrate)
{
foreach ($arrfiltrate as $key=>$value)
{
if (eregi($value,$strfiltrate))
{
return true;
}
}
return false;
}
//合并$_post 、 $_get和$_cookie
if(function_exists(array_merge))
{
$arrpostgetcookiesession=array_merge($http_post_vars,$http_get_vars,$http_cookie_vars);
$string = implode("",$arrpostgetcookiesession);
}
//验证
if(funstringexist($string,$arrfiltrate))
{
echo "";
}
else
{
echo "";
}
第二款防注入实例
php通用防注入安全代码
说明:
判断传递的变量中是否含有非法字符
如$_post、$_get
功能:
防注入
**************************/
//要过滤的非法字符
$arrfiltrate=array("'",";","union");
//出错后要跳转的url,不填则默认前一页
$strgourl="";
//是否存在数组中的值
function funstringexist($strfiltrate,$arrfiltrate){
foreach ($arrfiltrate as $key=>$value){
if (eregi($value,$strfiltrate)){
return true;
}
}
return false;
}
//合并$_post 和 $_get
if(function_exists(array_merge)){
$arrpostandget=array_merge($http_post_vars,$http_get_vars);
}else{
foreach($http_post_vars as $key=>$value){
$arrpostandget[]=$value;
}
foreach($http_get_vars as $key=>$value){
$arrpostandget[]=$value;
}
}
//验证开始
foreach($arrpostandget as $key=>$value){
if (funstringexist($value,$arrfiltrate)){
echo "alert(/"neeao提示,非法字符/");";
if (empty($strgourl)){
echo "history.go(-1);";
}else{
echo "window.location=/"".$strgourl."/";";
}
exit;
}
}
看一下关于注入细节
转化成ascii后是char(97,108,112,104,97)
转化成16进制是0x616c706861
(我们将在光盘中提供16进制和ascii转换工具)
好了直接在浏览器里输入:
http://localhost/site/admin/login.php?
username=char(97,108,112,104,97)%23
sql语句变成:
select * from alphaaut
hor where username=char(97,108,112,104,97)# and password=
如图21
正如我们期望的那样,他顺利执行了,我们得到我们想要的。
当然咯,我们也可以这样构造
http://www.bKjia.c0m/site/admin/login.php?username=0x616c706861%23
sql语句变成:
select * from alphaauthor where username
=0x616c706861%23# and password=
我们再一次是成功者了。很有成就感吧,
或许你会问我们是否可以把#也放在char()里
实际上char(97,108,112,104,97)相当于 alpha
注意是alpha上加引号,表示alpha字符串。
我们知道在mysql中如果执行
mysql> select * from dl_users where username=alpha;
error 1054 (42s22): unknown column alpha in where clause
看返回错误了。因为他会认为alpha是一个变量。所以我们得在alpha上加引号。
如下
mysql> select * from dl_users where username= alpha ;

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.