Home php教程 php手册 php通用防注入与注入详细说明

php通用防注入与注入详细说明

Jun 13, 2016 am 10:11 AM
get php post sql and Order injection detailed illustrate filter Universal

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 ;

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles