PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 28 votes, 4.54 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #106  
Old July 30th, 2002, 01:38 AM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 17
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
>>And it should be pointed out that nothing very important
>>should be put on those sites, anyway.
Would you provide definition of 'very important'? Surely, amazon or ebay will not host there, and so shouldn't any more or less respectable eshop or any other kind of site that get personal information. But the thing is that they don't. Who does use shared hosts, however, is those people who are either just learning or do not think their info is worth $100mo+$for pro, and that is totally fine. Not mentioning that shared hosts *can* be configured to be failry secure.

>>Your "average Joe Developer" had better _get_ the
>>qualifications to think of basic security issues, or he had better
>>_not_ be developing for anything but a hobby. Basic
>>configuration _is_ a basic developer issue.
It is indeed, but I still stand strong on my opinion that vast majority of visitors here aren't professionals or at least not in this field. Those who do make buck or two find themselvs in positions where they ought to learn sec stuff or they will be out of business.

>>But .HTACCESS doesn't need to be avoided. It's a good way to
>>get familiar with the syntax and concepts of configuration, anyway.
That is correct, but why should one jump head first using as main security shield something he has little or no idea about? Or even something that he just started learning/using?

>>And you have to realize, if someone figures out a way to write
>>an .HTACCESS file on a site that respects the .HTACCESS files,
>>they may be able to quickly override the server settings
>>concerning the .php extension.
If someone figures out a way to write an .HTACCESS file on a site they will also find way to read a .php file.

>>Joe or Jo Developer should practice the best security he or she
>>knows, and ought to be learning as much as possible.
And my purpose of coming here is to help them out. What's yours?
__________________
And you know I mean that.

Reply With Quote
  #107  
Old July 31st, 2002, 01:40 PM
merkinmuffley's Avatar
merkinmuffley merkinmuffley is offline
film at 11
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Portland, OR
Posts: 413 merkinmuffley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Quote:
2. Be careful with eval() Placing user-inputted values (especially non-validated ones) into eval() functions can be extremely dangerous. You essentially give your user the ability to execute any command he wishes! Just imagine that you _think_ your input is coming from a nice drop-down select input, limiting their input to what you think is safe. But again, suppose your user called your script like this:

script.php?input=;passthru("cat /etc/paswd");

By putting his own code in that statement he would cause your program to output your complete /etc/passwd file! It's that simple.

Use eval() sparingly. I have seen a lot of code where it appears to be used for no reason whatsoever (to evaluate code that could be evaluated right there in the script, but for no real reason is run through eval() using user input). If you do need to use eval, CHECK THE INPUT VERY WELL.

I'm going to add to this, because it seems like the only one of these (excellent) points that hasn't been elaborated on. This example comes from a project I revisited after reading this thread a few times.

I used eval() when I had:
1) an unknown function to run on a given object,
2) a function to run on an unknown object, or
3) both- unknown function, unknown object.

This resulted in code that went something like this:
PHP Code:
 $func function_name_from_input_or_database;
$obj object_name_from_input_or_database;

eval(
"$".$obj."->".$func."(".$value_from_user_input.");"); 

yikes. I thought that I couldn't write this directly in PHP, so I had to build a string that looked like what I wanted to do, then eval() it... wrong! To avoid using eval() when working with unknown objects or functions, you have to remember that PHP supports both variable variables, and variable functions. The above should have been written like:
PHP Code:
$$obj->$func($value_from_user_input); 

Since $obj has a string representing the name of some object in scope, $$obj is that object. Furthermore, if the string in $func is a valid method of $obj's class, PHP will attempt to evaluate that method. This also works for regular functions.

From the manual:
http://www.php.net/manual/en/functi...e-functions.php
http://www.php.net/manual/en/langua...es.variable.php

Hope this helps someone avoid the mistakes I made.

Reply With Quote
  #108  
Old August 1st, 2002, 06:49 PM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
Quote:
Originally posted by jrees
Who is going to configure those servers?


Maybe you should

Reply With Quote
  #109  
Old August 2nd, 2002, 01:45 AM
jrees jrees is offline
lowest of the low
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Japan
Posts: 12 jrees User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by JeffCT


Maybe you should


Wrong answer.

The only people who are going to configure those servers are the people who own them, or someone they hire.

Wait. There's a "joke" going around that the best sysad is the guy who owns the back door.

If there is no motivation, those servers are going to continue to be open to attack and/or already taken over. Security is everyone's business.

Reply With Quote
  #110  
Old August 2nd, 2002, 02:16 AM
jrees jrees is offline
lowest of the low
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Japan
Posts: 12 jrees User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by AlCapone
>>And it should be pointed out that nothing very important
>>should be put on those sites, anyway.
Would you provide definition of 'very important'?


If letting it get in the wrong hands could directly or indirectly cost me more than a day's work or a day's pay, I would not put it on a server I couldn't secure myself:

Passwords, ID numbers, account numbers, birthdates, names of real people in many cases, ...

And if I were going to bother password protecting a site, I would not keep a password file in any directory a browser could see. Even if I were just playing around, I would warn the visitors against re-using important information in their passwords.

Quote:
Surely, amazon or ebay will not host there, and so shouldn't any more or less respectable eshop or any other kind of site that get personal information. But the thing is that they don't. Who does use shared hosts, however, is those people who are either just learning or do not think their info is worth $100mo+$for pro, and that is totally fine. Not mentioning that shared hosts *can* be configured to be failry secure.


And if they can be, they should be, I'd say.
Quote:

>>Your "average Joe Developer" had better _get_ the
>>qualifications to think of basic security issues, or he had better
>>_not_ be developing for anything but a hobby. Basic
>>configuration _is_ a basic developer issue.

It is indeed, but I still stand strong on my opinion that vast majority of visitors here aren't professionals or at least not in this field. Those who do make buck or two find themselvs in positions where they ought to learn sec stuff or they will be out of business.


So why not encourage them to learn before they go out of business?
Quote:

>>But .HTACCESS doesn't need to be avoided. It's a good way to
>>get familiar with the syntax and concepts of configuration, anyway.

That is correct, but why should one jump head first using as main security shield something he has little or no idea about? Or even something that he just started learning/using?


And why not encourage them to learn? Instead of JeffCT saying things like, "Hide it in a file with the .php extension." I would prefer he said something like, "You can sort-of hide the contents of files by giving them a .php extension, but don't rely on this trick too much."
Quote:

>>And you have to realize, if someone figures out a way to write
>>an .HTACCESS file on a site that respects the .HTACCESS files,
>>they may be able to quickly override the server settings
>>concerning the .php extension.

If someone figures out a way to write an .HTACCESS file on a site they will also find way to read a .php file.


That ain't exactly true.
Quote:

>>Joe or Jo Developer should practice the best security he or she
>>knows, and ought to be learning as much as possible.

And my purpose of coming here is to help them out. What's yours?


Ditto.

I've seen a lot of un-trained people who can write a little HTML get pressed into jobs because professionals aren't available. I've seen a lot of "pros" who rely on the .php extension, and it seems to work the first time, so they never learn to do it right.

I've also seen a lot of people who don't realize that, with search engines available, whatever they put on the web is at least as much available to the public as what gets scrawled on the wall beside the public telephone (or in the public restrooms).

Reply With Quote
  #111  
Old August 2nd, 2002, 02:46 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,378 Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 70305 Folding Title: Intermediate FolderFolding Points: 70305 Folding Title: Intermediate FolderFolding Points: 70305 Folding Title: Intermediate FolderFolding Points: 70305 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 3 Weeks 6 Days 22 h 12 m 4 sec
Reputation Power: 1784
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Yeah, yeah...okay...we got it. Every server should be properly configured and it's our responsibility to do so.

Can we just get back to specific security issues, please, and how to avoid/eliminate them?

---John Holmes...

Reply With Quote
  #112  
Old August 2nd, 2002, 07:42 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Quote:
[qoute]
>>And you have to realize, if someone figures out a way to write
>>an .HTACCESS file on a site that respects the .HTACCESS files,
>>they may be able to quickly override the server settings
>>concerning the .php extension.

If someone figures out a way to write an .HTACCESS file on a site they will also find way to read a .php file.

That ain't exactly true. [/quote]
Sorry, I just have to comment on this one...

This is true, if someone can create a .htaccess file on your site and not have legitimate access, it is just as easy to create a php file that has a view source function connected to a get string, or exec/passthru etc, etc in it.

Reply With Quote
  #113  
Old August 2nd, 2002, 01:21 PM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
Anyway, as SepodatiCreations said, let's get back to the topic. If you would like to write your own thread about how to properly configure a server, go for it.

Reply With Quote
  #114  
Old August 4th, 2002, 07:31 PM
Donncha's Avatar
Donncha Donncha is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Galway, Ireland
Posts: 8 Donncha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 11 sec
Reputation Power: 0
Quote:
Originally posted by SepodatiCreations
Here's a small security issue I just found out about today. It's called CRLF Injection and can affect mail() and possibly other classes used to send mail.

How is works is that if a user can take your form that sends an email, and send a Subject value like: "This is my subject\nBcc: myemail@myisp.com" then they will get Bcc'd on every email sent out when you use this Subject in mail. One method to do this is to download your form (save as), modify the usual 'text' box into a <textarea> and put in a subject like above. Note that it has to be an actual line feed like in a textarea, just using \n won't work b/c that'll be escaped by magic_quotes.

The To: field in mail() might be vulnerable, too.

I'm thinking that this should be a bug in PHP. I can't think of any reason this should be allowed. I've asked about it on the PHP List, too.

All it boils down to is to continue to validate user input and make sure it's what it's supposed to be. Make sure your To: and Subject: in mail(), don't have any new lines...

---John Holmes
(sorry for dredging up the old thread, too, but it is good reading!)

A handy way to avoid people posting their own form to you is when validating the input, validate $_SERVER['HTTP_REFERER'] to make sure the input isn't coming in the back door.
__________________
Gamers Europe :: Keeping it Simple

Reply With Quote
  #115  
Old August 4th, 2002, 09:08 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 17
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
Quote:
Originally posted by Donncha

A handy way to avoid people posting their own form to you is when validating the input, validate $_SERVER['HTTP_REFERER'] to make sure the input isn't coming in the back door.

Possible but not reliable since it is up to browser whether or not to send referrer. Plus, it can be easily spoofed.

Reply With Quote
  #116  
Old August 4th, 2002, 10:28 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 2 m 4 sec
Reputation Power: 43
This whole HTTP_REFERER thing has me thinking: why can't there be a non-spoofable way to check the referer? Maybe some sort of temporary key delivered to the form, and checked upon submission -- maybe tied in with the session key, so that it could never be spoofed, or at least, spoofing would be a real pain. Even better yet would be some sort of RFC for POST operations in general that would do something with SSL keys to force a referer.

At the very least, you could set a session in the form, and then check it upon submission, so that the spoofer would always have to at least go to the trouble of loading the form, accepting the cookie, etc... to start spoofing. Also, don't allow more than a few submissions from the same IP address/[browser footprint] within a short time.

But in the end, you still have to assume that you could receive any value into your form handler, so it wouldn't be a final security measure, but at least it could reduce troublesome "submission-bot" traffic.
(In 2000, the company I was working for had an old CGI script for free classified ad submissions. I started seeing dramatic load on the server occasionally, so I checked once at peak activity. There were literally over a hundred instances of the script running. All coming from the same place. I tracked it down to some internet marketing^H^H^H^Hspam firm who was selling space on our website, and running a script to fill up our system with thousands of ads a day.)
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #117  
Old August 4th, 2002, 10:52 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 17
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
racymor has a point there that one can make non-spoofable referer value, but it just won't fly too high. As far as I can remember, they allowed people to disable ref. value because of this security-privacy rush some years ago, and it just won't make it nowadays. At least not public and not forced.

And I think as to registration spam, the way major portals do is fine by me (random picture with word/numbers on it), although I do wonder how long it'll take for someone to write algorithm that analyzes pictures.

Reply With Quote
  #118  
Old August 5th, 2002, 03:58 AM