how exactly was is compromised? SQL Injection?
You can extract the get variables then escape them all, or at least escape the ones going into a query string
Main Topics
Browse All TopicsHi All
Im after an alternative to PHPs extract() function for GET variables. I recently have had my site compromised, and I think it was due to me using the extract function. I think.
It needs to be 100% secure this time as cannot face the stress of another hack!
Thanks again
Mark
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I just assumed it was using that method that got me in to trouble - so I could be wrong. Waiting for security to nail it down to specific script though.
The problem was I found a new directory within my images directory, that had a ferw hundred html files which essentially linked to a spam website. They had put redirects in .htaccess in the images directory too
Do you know could they have done this by somewhere abusing the GET extract function?
After the extract function is called, I use the variables - if Im using them for mysql I always use mysql_real_escape_string. Is there other ways to protect variables?
Thanks guys
Mark
escape string should be ok for most uses for SQL.
do you generate directories based on the GET variables? and if done correctly .htaccess should be restricted to everyone. Meaning they cannot be accessed through the httpd.. which means people would have to go around to use ssh or something to ssh into the server, and then change the file. If so that is a serious server security flaw.
Other than that I don't see how someone could use GET to exploit your script, unless you are actually using the GET variables to manipulate files.
Also if the images link to a spam site, then it is likely that these files are generated by a robot? if so then it is probably exploiting a known flaw. Make sure your apache and php are patched to the latest
No, I dont generate any directories or files in any of the scripts.
The server is hosted by Host Gator, and I believe they have everything patched up to latest. And if there was a vunerability, Im sure I wouldnt be the only one experiencing this, and Host Gator say this is an isolated incident.
I read this:
http://forums.macrumors.co
Specifically what sonofslim says with potential problem with extract:
"you're going to automatically set all variables that show up in your GET statement. what if someone starts setting additional variables from the URL? see the manual page (above) for an example wherein someone sets the remote address header to 127.0.0.1 and the script thinks the request is coming from the local host -- that's exactly why you turned off register_globals in the first place"
That couldnt produce the effects Im seeing?
sakuya_su - How would I restrict access through the httpd? Its a shared server by the way
Thank you
Mark
http://wsabstract.com/howt
chmod 644 to your .htaccess file
I see that overridding the $_SERVER and $_SESSION variables having real impacts, as they would allow the person to gain access as a registered user (if you used $_SESSION) to store login status, and setting various other parameters would allow remote script execution as well, which basically means anything and everything.
It is best if you do not use extract on user input data, as the php manual for extract() points out you should only use extract on TRUSTED data, ie data source under your control only, where you know what to expect
Warning
Do not use extract() on untrusted data, like user-input ($_GET, ...). If you do, for example, if you want to run old code that relies on register_globals temporarily, make sure you use one of the non-overwriting extract_type values such as EXTR_SKIP and be aware that you should extract in the same order that's defined in variables_order within the php.ini.
http://nz2.php.net/extract
Business Accounts
Answer for Membership
by: mr_egyptianPosted on 2008-07-13 at 15:19:00ID: 21994494
The best alternative is to explicitly retrieve get values, and do checks on any that are potentially dangerous.