Security Flashcards

1
Q

When invoked as a CGI binary, PHP refuses to…

A

…interpret the command line arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the following runtime configuration directives: cgi.force_redirect, doc_root, user_dir?

A

cgi.force_redirect – provides security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default.

doc_root – PHP’s root directory on the server. Only used if non-empty. If PHP is configured with safe mode, no files outside this directory are served.

user_dir – the base name of a directory used on a user’s home directory for PHP files, for example public_html.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is –enable-force-cgi-redirect for?

A

It enables the security check for internal server redirects. You should use this if you are running the CGI version of Apache. As of PHP 5.3, this argument is enabled by default and no longer exists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does cgi.force_redirect do?

A

It’s a configuration directive that prevents anyone from calling PHP directly. Instead, PHP will only parse in this mode if it has gone through a web server redirect rule.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are three ways to set the PHP script document root?

A
  1. The configuration directive doc_root in the config file
  2. Set the environment variable PHP_DOCUMENT_ROOT.
  3. Set user_dir.

user_dir expansion happens regardless of the doc_root setting, so you can control the document root and user directory access separately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is open_basedir for?

A

It’s a configuration directive used for limiting the files that can be accessed by PHP to the specified directory-tree, including the file itself. This directive is unaffected by safe mode.

When a script tries to access the filesystem, for example, using include or fopen, the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it. All symbolic links are resolved, so it’s not possible to avoid this restriction with a symlink.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are 6 things you can do to prevent SQL injection?

A
  1. Never connect to the database as superuser. Use a limited privileges user.
  2. Use prepared statements with bound variables, such as those provided by PDO, MySQLi, and by other libraries.
  3. Check if the given input has the expected data type
  4. If the application takes numerical input, verify it with ctype_digit(), change its type with settype(), or use its numeric representation with sprintf().
  5. If the database layer doesn’t support binding variables, then quote values with the database-specific string escape function.
  6. Do not print out any database-specific information.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What would you set error reporting to to test your code?

A

E_ALL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you turn off error displays completely?

A

Either set error_reporting() to 0, or use display_errors in php.ini. You can also then define the path to your log file using the error_log ini directive, and turn log_errors on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is $_REQUEST a mix of?

A

$_GET, $_POST, and $_COOKIE.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Are magic quotes available in PHP?

A

Deprecated in 5.3 and removed in 5.4.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some ways to hide PHP?

A
  1. Set expose_php to ‘off’ in php.ini.
  2. Use apache directives to parse non-php extension files with php (either as other suffixes, like .asp, as unknown suffixes, like .foo, or as .html).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly