473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

security question(s)

I am new to PHP but have done other programming
can someone please hold my hand and slowly talk me through some simple
security issues?

I have seen in PHP documents that there are 'strip slashes' commands and
so on but I dont understand where the security issues actually are.

i am writing some scripts that will shell out and call different linux
shell programs such as 'ls' or 'grep' or 'sed' and so on and possibly
update a 'mysql' database.

can you tell me at what point in this procedure security is needed and
what exactly as ideally I would like to not hamper anything I send to
grep and so on? In other words I would like any security modification of
my parameters to happen as late in the process as possible.

I am obviously interested in how to stop someone using pipes '||' or
redirecting the output '>' or entering anything that might trigger the
database to think i was getting code or a varialble of some sort - I
think that may just be '$' but dont really know. Are there any actual
strings rather than characters that must be watched for?

can someone explain what point the issues take effect - is it php, or
when php passes the parameters or is it the (eg) 'grep' program itself
that is written to do things that must be prevented or is it linux
itself when it passes the parameters?

and is there anything else I need to watch out for?

can anyone explain in simple terms please (perhaps a security table ?)

nancy
Nov 27 '06 #1
1 1457
>I am new to PHP but have done other programming
>can someone please hold my hand and slowly talk me through some simple
security issues?
"simple" and "security issues" don't go together.
>I have seen in PHP documents that there are 'strip slashes' commands and
so on but I dont understand where the security issues actually are.
If you allow user-supplied input on a shell command-line unaltered, you are
asking for trouble. Consider, for example, the search pattern:

`rm -rf /`

and if you stick it into a shell command:

grep "`rm -rf /`" INDEX.txt | pretty_up_index_entries

it's likely to do a lot of damage to your system. One approach to
dealing with this is to quote the string appropriately for the shell
being invoked.

>i am writing some scripts that will shell out and call different linux
shell programs such as 'ls' or 'grep' or 'sed' and so on and possibly
update a 'mysql' database.
Also beware of wierdly-formatted stuff that becomes dangerous SQL,
such as entering a user name such as:
george' OR '' LIKE '
substitued into sql that says:
DELETE FROM users where user = '$user'

DELETE FROM users where user = 'george' OR '' LIKE ''
which deletes all the records in users.
>can you tell me at what point in this procedure security is needed and
what exactly as ideally I would like to not hamper anything I send to
grep and so on? In other words I would like any security modification of
my parameters to happen as late in the process as possible.
Security should be designed in as EARLY as possible. Bolting a
very secure vault door onto a building originally intended as a
greenhouse (including its glass walls and rickety screen back door with
no lock) doesn't make a very good bank vault.
>I am obviously interested in how to stop someone using pipes '||' or
redirecting the output '>' or entering anything that might trigger the
database to think i was getting code or a varialble of some sort - I
think that may just be '$' but dont really know. Are there any actual
strings rather than characters that must be watched for?
What USER-SUPPLIED input is going to be used (especially on the command
line, but worry about the data passed to the command also)? Where?

If you are putting stuff in as a command-line argument, you probably
have to worry about:

- quotes
- shell variable substitutions
- backquote substitutions
- any way to get command terminators (like semicolon, |, ||,
&, &&, etc.) followed by a new command outside quotes

If you pass the input through the PHP function escapeshellarg()
before putting it on the command line, it should be safe (at least
for reasonably normal UNIX shells).

If you are substituting stuff for use within a quoted string in a
SQL query, you need to make sure it can't get outside the quotes
(mysql_escape_string() is one possibility).
>can someone explain what point the issues take effect - is it php, or
when php passes the parameters or is it the (eg) 'grep' program itself
that is written to do things that must be prevented or is it linux
itself when it passes the parameters?
Unchecked user-supplied strings in shell commands are very touchy.
Unchecked user-supplied strings in file names (e.g. passed to PHP
fopen()) are touchy. For example, "../../../../../../../etc/passwd"
is likely to refer to the password file, which someone might download
for cracking or spamming purposes. Unchecked user-supplied strings
in any mail headers you send are very touchy (they can be abused
to spam large numbers of people). Unchecked user-supplied parameters
passed to the PHP eval function are very touchy. Unchecked
user-supplied parameters passed to include() are very touchy,
especially if remote URLs are allowed, and this is used by a number
of viruses. Allowing the user to post articles containing raw
Javascript (or for that matter, even certain HTML) allows that user
to hijack other user's browsers when they view the post.

This list is nowhere near complete.
>and is there anything else I need to watch out for?
TRUST NO ONE.
>can anyone explain in simple terms please (perhaps a security table ?)
Exercise: list all the ways of stealing money out of a state-of-the-art ATM
that requires a smart card with RSA certificates to open the money-loading
compartment.



Think of your answer, then scroll down.





















If even half of your answers are ways to make a fake smart card,
you aren't thinking far enough outside the box.

If you didn't include anything about wrapping a chain around the
ATM, pulling it out of the ground, driving off with it, and then
blowing it open with explosives, you're not thinking far enough
outside the box.

If you didn't include anything about bribing the guy who loads the
machine, you're not thinking far enough outside the box.

If you didn't at least think about whether it is possible to teleport
the ATM away leaving the cash, you're not thinking far enough outside
the box.

If you didn't include anything about stealing what the cash is
backed with, thereby making the cash worthless, you're not thinking
far enough outside the box.

Nov 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
32
by: Mike MacSween | last post by:
Further to 'Security - more complex than I thought' Has anybody ever seen any studies? Or anecdotal evidence? Done any studies themselves? Done any lab testing - you know - 10 users asked to get...
5
by: Greg Strong | last post by:
Hello All, What are the best ways to implement security for Access databases (i.e. ..MDB files)? I ask the question from a general perspective. Why? Well I had written a prototype database...
1
by: Jeremy S. | last post by:
..NET's code Access Security enables administrators to restrict the types of things that a .NET application can do on a local computer. For example, a ..NET Windows Forms application can be...
15
by: himilecyclist | last post by:
My State government organization has written a PHP/MySQL application which has been in production for about 6 months and has been highly successful. We are now embarking on a similar database...
0
by: jobs | last post by:
Using the delivered login controls, I see there is something for passwordrecovery. But I can't seem to find how to set properties so it does not ask me for my security question. Is there any way...
18
by: Earl Anderson | last post by:
First, I feel somewhat embarrassed and apologetic that this post is lengthy, but in an effort to furnish sufficient information (as opposed to too little information) to you, I wanted to supply all...
4
by: vincent90152900 | last post by:
How to remove Security Question and Security Answer from membership provider? Following is my codes. Please tell me how to remove Question and Answer from membership provider. Thank you for...
1
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
Question 1: How do I turn off WCF security to get my apps out the door quickly? Question 2: Where can I find a step by step article/flowchart how to configure WCF security (the WCF books miss this...
2
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.