search
HomeBackend DevelopmentPHP TutorialPHP injection solution_PHP tutorial
PHP injection solution_PHP tutorialJul 13, 2016 pm 05:09 PM
phpthingforhostWoolen clothyesServeinjectionof

This article is mainly for side dishes. If you are already an old bird, some things may feel boring, but as long as you look carefully, you will find a lot of interesting things.

After reading this article, you only need to understand the following things.

1. Understand how the php+mysql environment is set up.
2. Have a general understanding of the configuration of php and apache, mainly using php.ini and httpd.conf
In this article we mainly use the configuration of php.ini. For safety reasons, we generally turn on the safe mode in php.ini, that is, let safe_mode = On, and the other is display_errors that returns PHP execution errors. This will return a lot of useful information, so we should turn it off,
That is, after setting display_errors=off to turn off the error display, the PHP function execution error information will no longer be displayed to the user.
There is also a very important configuration option magic_quotes_gpc in the PHP configuration file php.ini. The default for higher versions is magic_quotes_gpc=On, which is only available in the original antique PHP
The default configuration is magic_quotes_gpc=Off, but some people also use antique things!
What will happen when magic_quotes_gpc=On in php.ini? Don’t panic, the sky won’t fall! It just converts all ' (single quotes), " (double quotes), (backslashes) and null characters in the submitted variables into escape characters containing backslashes, for example, ' becomes ', Change it to \. This is what makes us very unhappy. Many times we have to say BYEBYE to character types,
But don’t be discouraged, we still have good ways to deal with it, take a look below!
3. Have a certain basic knowledge of PHP language and understand some SQL statements. These are very simple. We use very few things, so it’s still time to recharge!

Let’s first take a look at what we can do when magic_quotes_gpc=Off, and then we’ll figure out how to deal with magic_quotes_gpc=On

1: Injection when magic_quotes_gpc=Off

ref="http://hackbase.com/hacker" target=_blank>attack

Although magic_quotes_gpc=Off is very unsafe, the new version also allows it by default
magic_quotes_gpc=On, but we also found magic_quotes_gpc=Off in many servers, such as www.qichi.*.
There are also some programs like vbb forum. Even if you configure magic_quotes_gpc=On, it will automatically eliminate escape characters and give us an opportunity, so
The injection method of magic_quotes_gpc=Off is still very popular.

Below we will explain mysql+php injection in detail from the aspects of syntax, injection point and injection type

A: Let’s start with MYSQL syntax

1. Let me first talk about some basic syntax of MySQL, which can be regarded as a supplementary lesson for children who have not studied well~_~
1) select
SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT]
Select_expression,...
[INTO {OUTFILE | DUMPFILE} 'file_name' export_options]
[FROM table_references
         [WHERE where_definition]
          [GROUP BY col_name,...]
[ORDER BY {unsigned_integer | col_name | formula} [ASC | DESC] ,...] ; ]
These are the commonly used ones. select_expression refers to the column you want to retrieve. Later we can use where to restrict the conditions. We can also use into outfile to output the select results to a file. Of course we can also use select to directly output
For example

mysql> select 'a';

+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)
For details, please see section 7.12 of the mysql Chinese manual
Here are some uses
Let’s look at the code first
This code is used for searching
.........
SELECT * FROM users WHERE username LIKE ‘%$search%’ ORDER BY username
.......
?>

Here we talk about the wildcards in mysql by the way, '%' is the wildcard character, other wildcard characters include '*' and '_', among which "*" is used to match field names, and "%" is used to match fields Value, please note that % must be applied together with like, and there is also a wildcard character, which is the underscore "_", which has a different meaning from the above and is used to match any single character. In the above code, we use '*' to represent all returned field names, and %$search% represents all content containing the $search character.

How do we inject it?

Haha, very similar to asp
Submit in the form
Aabb%' or 1=1 order by id#
Note: # means a comment in mysql, which means that the following sql statements will not be executed, which will be discussed later.
Some people may ask why or 1=1 is used, see below,

Put the submitted content into the sql statement to become

SELECT * FROM users WHERE username LIKE ‘%aabb%’ or 1=1 order by id# ORDER BY username

If there is no username containing aabb, then or 1=1 makes the return value still true, enabling all values ​​to be returned

We can still do this

Submit in the form
%' order by id#
or
' order by id#
Bring it into the sql statement and become
SELECT * FROM users WHERE username LIKE ‘% %’ order by id# ORDER BY username
and
SELECT * FROM users WHERE username LIKE ‘%%’ order by id# ORDER BY username
Of course, all content is returned.
All users are listed, and maybe even their passwords are listed.
Here is an example first. More subtle select statements will appear below. Select is actually almost everywhere!
2) See the update below
This is explained in the Mysql Chinese manual:
UPDATE [LOW_PRIORITY] tbl_name SET col_name1=expr1,col_name2=expr2,...
         [WHERE where_definition]
UPDATE updates the columns of an existing table row with new values. The SET clause specifies which columns are to be modified and the values ​​they should be given. The WHERE clause, if given, specifies which rows should be updated, otherwise all rows are updated.
For details, please see Section 7.17 of the MySQL Chinese Manual. It would be very wordy to introduce in detail here.
It can be seen from the above that update is mainly used for data updates, such as article modifications and user profile modifications. We seem to be more concerned about the latter because...
Look at the code first
Let’s first give the structure of the table so that everyone can understand it
CREATE TABLE users (
id int(10) NOT NULL auto

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629770.htmlTechArticleThis article is mainly for novices. If you are already an old bird, maybe some things will It feels rather boring, but as long as you look carefully, you will find a lot of interesting things. ...
Statement
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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

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

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

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

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

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

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

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

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

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

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

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

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

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

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

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

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

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),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.