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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #16  
Old August 18th, 2001, 05:13 AM
saintaw's Avatar
saintaw saintaw is offline
Lurker - in your bushes
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Location: .be
Posts: 470 saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level)saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level)saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level)saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level)saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level)saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level)saintaw User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 6 h 33 m 10 sec
Reputation Power: 66
Thumbs up

I'd just like to say that I found this a usefull reminder, and I'd like to thank you for taking your time posting it. (I wouldn't know 50% of what I know today if it wasn't for this board)

Am still totaly clueless when it comes to apache security though, but any info is always welcome
__________________
Saintaw

pending.

Reply With Quote
  #17  
Old August 18th, 2001, 11:06 AM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,298 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 1 h 54 m 21 sec
Reputation Power: 41
__________________
The real n-tier system:

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

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #18  
Old August 18th, 2001, 11:12 AM
Messner's Avatar
Messner Messner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Slovenia
Posts: 29 Messner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 10 sec
Reputation Power: 0
Send a message via ICQ to Messner
Question authentification

Why can't I use $HTTP_SESSION_VARS with my authentification ?
PHP Code:
 session_start();
if(
$HTTP_SESSION_VARS['admin'] == "true")
{
   
// let them in
}
else
{
   
// kick them out


If someone comes from another server (with admin variable set in his session), then his session variable isn't valid anymore on my server (I tought so, till now ). A new session is generated on my page (with new vars) and he cann't break in.

I am new in this stuff, plizz explain this to me

Reply With Quote
  #19  
Old August 19th, 2001, 04:14 AM
jdk's Avatar
jdk jdk is offline
phpkid ~~~~~~ :o)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Nov 2000
Location: NJ, USA
Posts: 2,535 jdk User rank is Lance Corporal (50 - 100 Reputation Level)jdk User rank is Lance Corporal (50 - 100 Reputation Level)jdk User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 11 m 11 sec
Reputation Power: 10
Send a message via Yahoo to jdk
hi,

check this.
Quote:
On sites using user login, we have to be very careful with our SQL. Lets say we have a login page like this:



<form action="login.php" method="post">
User name:
<input type="text" name="Username"/>
Password:
<input type="password" name="Password"/>
<input type="submit" value="OK" />
</form>




We can assume that $Username and $Password are used in an SQL command like this: "SELECT * FROM UserTable WHERE Username='$Username' AND Password='$Password'". The application will then check if the SQL command returned one record and then log in.

Many of these sites have thousands of users, and we can guess that there is a user called "john", "smith", "boss" or even "admin". If we type "admin';--" in the Username field and just some rubbish in the Password field this SQL command would be executed: "SELECT * FROM UserTable WHERE Username='admin'; --' AND Password='fdgd'". As many of you know -- is the SQL syntax for a comment, causing the database to ignore everything behind --. In this example the database will not check the password and return one record of we have a valid user name. In other words: We're in.

There are several ways to avoid this. We could check for -- and ' in Username and ignore there requests. But the best way is probably to escape the string causing ' and -- to be treated like every other character.




i found it here.
pretty interesting !!!
jd
__________________
_____________________________
d.k.jariwala (JD)
~ simple thought, simple act ~
I blog @ http://jdk.phpkid.org

Reply With Quote
  #20  
Old August 19th, 2001, 05:40 AM
Robert_J_Sherman Robert_J_Sherman is offline
Code Junky
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 358 Robert_J_Sherman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 57 m 12 sec
Reputation Power: 0
Re: Security Notes (Everyone should read)

Quote:
Originally posted by JeffCT
6. IF YOU DON'T WANT PEOPLE TO SEE IT, GIVE IT A .PHP EXNTESION.

yoursite.com/lib.inc


Actually, this "can" be changed (on Apache) at least..

here's a "simple" yet effective solution, that makes sure "any" file
you are using on the Apache server (that is PHP) is sent to the
PHP interpreter..

such as ".inc" files..

basically, I simply added an AddType line to my .htaccess file, which tells Apache to pass .inc files through PHP.

AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .inc

-------------------------------------------------------------------------------
So, in my case, if you call one of my .inc files... you will most likely get "nothing" but a blank a browser window.. (this depends on the include file, of course.. if the includes does some type of "execution" - then whatever output is delivered.. )
-------------------------------------------------------------------------------

In short, "if your on Apache, and your host allows "overrides".. then you can set up an htaccess file and establish this type of thing.

Call it a security feature if you wish, to me "it" just makes sense.

I think it's actually a bennie of Apache.. allows you to pretty much use an file extension as a PHP document.. This "isn't recommened!".. i.e. you don't want to set up .htm or .html as an PHP file extension.. you "could" be wasting server processes.

I do recommend checking with your provider before implementing, 1 - they may have some restrictions.
2 - they may "already" have this set.
3 - they may not have Allow Override enabled.

I must admit.. after reading this post, I just "smiled".. going he he.. I know that.. I know that.. I know that .. "cool" more security minded than I thought

Maybe this comes from authoring Perl scripts for so long.. Frankly, I've seen "too" many Perl scripts have "major" wholes in them.. probably the most infamous one (as of late) has been thrid parties exploiting a hole in the "famous" formmail.pl script.. which, did not prevent third parties from using it to send email remotely...

i.e. with FormMail.pl you could pass a query string to it, and it would send email.. so unscroupulous spammers can use your formmail script to send spam...

Reply With Quote
  #21  
Old August 19th, 2001, 07:59 AM
pezzer pezzer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 35 pezzer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to pezzer
internal security vs external security

I've also worked most of this out before, both in my code, and others, and this seems a fairly good guide.

I think JeffCT makes a very good point about the script security being a bigger risk that the webserver's security bugs. I think this has been proven to be the case in the last couple of years, with the biggest security botch ups shown in the media, haveing been discovered by people with very little knoledge of hacking, and mostly by changing things in the url query string.

One of the biggest problems i have come accross is where sites check usernames and passwords, and then give a list of orders etc, and these can be viewed/edited by clicking on them. Although these often check that you are a valid user of the system, they quite often neglect to check if the order you are trying to view is yours! eg you get links to:
www.test.com/order.php?id=1234
www.test.com/order.php?id=5678
and you type:
www.test.com/order.php?id=4321
(which isnt your's)and it works!

Also, another method i have used for including files, is to only take the filename, and not the extension, so:
PHP Code:
include $filename ".jpg"


this is fine, unless you are including files with .php,asp,etc extensions!

Reply With Quote
  #22  
Old August 19th, 2001, 03:28 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
Re: Re: Security Notes (Everyone should read)

Quote:
Originally posted by Robert_J_Sherman


Actually, this "can" be changed (on Apache) at least..

here's a "simple" yet effective solution, that makes sure "any" file
you are using on the Apache server (that is PHP) is sent to the
PHP interpreter..

such as ".inc" files..

basically, I simply added an AddType line to my .htaccess file, which tells Apache to pass .inc files through PHP.

AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .inc




Yeah I know. But that's not practical and I don't recommend anyone does that. Why? If you plan on running it on any servers other than your own, you should assume people aren't going to edit their .htaccess or httpd.conf just for your program when all you need to do is rename it to .php or .php3. I can't honestly see any reason why you would have to name it .inc, you don't get any benefit from doing that as opposed to .php or .php3.

There's a workaround for one of my other points, the global variables one. You can turn those off in PHP. But *always* assume your users are going to have the default configuration. Don't setup your own special workarounds in your PHP configuration or web server configuration - not everyone will hae those. Just write careful PHP code to being with.

Reply With Quote
  #23  
Old August 19th, 2001, 05:20 PM
blu blu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Posts: 1 blu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Important note to users of Dreamweaver

a security issue related to your topic #6--

IF someone directly codes a database connection in a Dreamweaver Template file or Library Item, AND uploads the template or library item files to the server, the php will be readable as plain text in the source, because the files have a .dwt or .lbi file extension and aren't parsed.

So, if you use dreamweaver and php, check your site for uploaded Template files. Any thing in them you don't want seen? then remove them from the server.

Dreamweaver will upload the Templates folder if you choose "upload dependant files" or syncronize the entire site.

macromedia has been made aware of this, and the behavior of Dreamweaver 5 will be changed somehow when it comes to uploading templates and library items.

Reply With Quote
  #24  
Old August 20th, 2001, 06:21 AM
Messner's Avatar
Messner Messner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Slovenia
Posts: 29 Messner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 10 sec
Reputation Power: 0
Send a message via ICQ to Messner
Exclamation why not use sessions

Quote:
5. For protected areas, VALIDATE THE LOGIN EVERY TIME!What am I talking about here? Well, there are some cases where programmers will only use some sort of login.php script to first validate their username and password (entered through a form), test if they're an admin, and actually set an admin variable through a cookie!
I don't get it

It still think that the right way to do it, is to use session variables :
PHP Code:
<?php

session_start
();

// Is the session variable set ?

     
if (!isset($HTTP_SESSION_VARS['UserStatus'])) {
             
header ("Location: LoginU.php"); 
          exit;       

  }

// Am I authorizzed ?
// ------------------------------

      
if ($HTTP_SESSION_VARS['UserStatus'] != "true")

         {
           
header ("Location: LoginU.php"); 
          exit;
         }
Your solution whit checking pass and username everytime is time and server consuming. I will agree to check it every time, if you convince me that there is a posibility to break in my script

I know that session work with cookies, but aren't sessions made for such problems ? How can this be overriden ? Answer plizzz .... I need to know if my scripts using sessions are secure (I can't sleep at nights because of that discussion )

Messner

Reply With Quote
  #25  
Old August 20th, 2001, 12:15 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
Re: why not use sessions

Quote:
Originally posted by Messner
Your solution whit checking pass and username everytime is time and server consuming.


Good point, I woule recommend sessions instead.
(the original article was updated)

Reply With Quote
  #26  
Old August 20th, 2001, 02:57 PM
Messner's Avatar
Messner Messner is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Slovenia
Posts: 29 Messner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 10 sec
Reputation Power: 0
Send a message via ICQ to Messner
Arrow session's and authenthication

That about server resources wasn't meant in abslolute values.

My point is, if you have two equally secure options and one is faster then the other, then you should go for the faster one .

But my question that still bothers me a lot is:

Is my script using authenthication check as desribed above secure or not ?

Reply With Quote
  #27  
Old August 20th, 2001, 04:01 PM
pezzer pezzer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 35 pezzer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to pezzer
After thinking about it, i cant see any problems (but there may well be) with storing the logged-in variable in a session var.

However:
1. there is the overall problem with sessions, that they are hijackable, by another user using the same session id from the same or another machine. although the effort involved with this would probably be equivilent to that required to snoop the username/password.
2. remember that when using sessions that the session data is stored in a file. On a system with many users, a properly indexed database may even respond quicker than session functions.
3. depending on the isp's setup, a shared server will probably use the same tmp directory to store session files, so anyone with access to the system may be able to view your session data!

Ofcourse security of a site is only as good as it's weakest point. If you are sending the username and password through unencrypted http requests, then they are prone to snooping (and caching - i have used so many sites that think i'm already logged in as someone else, because i access them through a proxy server).

Another point here, is that you cant get round the problem of snooping etc by checking ip addresses. my current internet connection uses dynamic (hidden) proxy servers. And there are more than one, and my requests go through different ones for each request, giving the webserver varying ips for me.

Reply With Quote
  #28  
Old August 20th, 2001, 08:57 PM
Keiichi Keiichi is offline
aHVoPw==
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,058 Keiichi User rank is Lance Corporal (50 - 100 Reputation Level)Keiichi User rank is Lance Corporal (50 - 100 Reputation Level)Keiichi User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 15 h 24 m 31 sec
Reputation Power: 9
for some of my includes that come from the url:
page.php?page=page1

i try to make the actual file name harder to guess or different.

in my directory of include files for example:
blah_page1.php
blah_page2.php

and no one can see the files in this dir (hopefully).

and the code could be like:

PHP Code:
if (file_exists(blah_$page.php)) {
  include(
"$DOCUMENT_ROOT/director/blah_$page.php");
}
else { echo 
"does not exist"; } 


like someone said, the .php does restrict the file somewhat. also having a directory set in the include() can limit the files included, and files before that dir can't be accessed (right?)
__________________
K1

Reply With Quote
  #