click the below Link to see the Code.
https://drive.google.com/file/d/0B9cPcFcKq6vnU3dwWDEtYlB5RDg/view?usp=sharing
// GET data is sent through URL: http://example.com/search.php?search=
$search = $_GET['search'] ?? null;
echo 'Search results for '.$search;
// This can be solved with htmlspecialchars
$search = htmlspecialchars($search, ENT_QUOTES, 'UTF-8');
echo 'Search results for '.$search;
ENT_QUOTES
is used to escape single and double quotes beside HTML entitieshtmlspecialchars()
.../
(dot, dot, slash) attack. It happens where user supplies input file names and can traverse to parent directory. Data can be set as index.php?page=../secret
or /var/www/secret
or something more catastrophic:$page = $_GET['page'] ?? 'home';
require $page;
// or something like this
echo file_get_contents('../pages/'.$page.'.php');
// Checking if the string contains parent directory
if (strstr($_GET['page'], '../') !== false) {
throw new \Exception("Directory traversal attempt!");
}
// Checking remote file inclusions
if (strstr($_GET['page'], 'file://') !== false) {
throw new \Exception("Remote file inclusion attempt!");
}
// Using whitelists of pages that are allowed to be included in the first place
$allowed = ['home', 'blog', 'gallery', 'catalog'];
$page = (in_array($page, $allowed)) ? $page : 'home';
echo file_get_contents('../pages/'.$page.'.php');
exec('rm -rf '.$GET['path']);
eval()
function, so sanitize your data when using it:eval('include '.$_GET['path']);
.yml
files) might not be processed by your web server and user can view them online.app/
config/
parameters.yml
src/
public/
index.php
style.css
javascript.js
logo.png
public
folder instead of your application root folder. Public folder contains the front controller (index.php
). In case web server gets misconfigured and fails to serve PHP files properly only source code of index.php
will be visible to public.password_hash()
function.$_SESSION
array gets populated based on it. Session hijacking is possible through an XSS attack or if someone gains access to folder on server where session data is stored.$page = $_GET['page'] ?? 'home'
require $page . '.php';
$_GET
can be set to a remote file http://yourdomain.tld/index.php?page=http://example.com/evilscript
php.ini
unless you know what you’re doing:; Disable including remote files
allow_url_fopen = off
; Disable opening remote files for include(), require() and include_once() functions.
; If above allow_url_fopen is disabled, allow_url_include is also disabled.
allow_url_include = off
php.ini
that you should check out. You can also use iniscan to scan your php.ini
files for best security practices.display_errors
and log_errors
directives inphp.ini
file:; Disable displaying errors to screen
display_errors = off
; Enable writing errors to server logs
log_errors = on
expose_php
directive and prevent web server to send back header X-Powered-By
:expose_php = off
; disabled opening remote files for fopen, fsockopen, file_get_contents and similar functions
allow_url_fopen = 0
; disabled including remote files for require, include ans similar functions
allow_url_include = 0
fopen
, file_get_contents
) and also including files (include
, require
):open_basedir = "/var/www/test/uploads"
PHPSESSID
) with unique ID for the session.; in most cases you'll want to enable cookies for storing session
session.use_cookies = 1
; disabled changing session id through PHPSESSID parameter (e.g foo.php?PHPSESSID=)
session.use_only_cookies = 1
session.use_trans_sid = 0
; rejects any session ID from user that doesn't match current one and creates new one
session.use_strict_mode = 0
HttpOnly
cookie you’ve set won’t show up in the list.session.cookie_httponly = 1
.example.com
or set this to the domain it should be applied. By default it is not enabled, so it is highly recommended for you to enable it:session.cookie_domain = example.com
session.cookie_secure = 1