Defensive Programming To Reduce PHP Vulnerabilities
Defensive Programming To Reduce PHP Vulnerabilities
Volume 4: Issue 2
[ISSN: 2250-3757]
Publication Date : 25 June 2014
I.
II.
Introduction
PHP Vulnerabilities
A.
<?php
$headers = 'From: ' . $_GET['from'] . "\r\n" .
'Reply-To: ' . $_GET['replyto'] . "\r\n";
71
C.
D.
Information Disclosure
<?php
.
ob_start();
system('ping ' . $_GET['user']);
$contents = ob_get_contents();
ob_clean();
.
?>
<?php
.
$incfile = $_REQUEST["file"];
include($incfile.".php");
.
?>
72
{WhereRoot
IIV
IGET
ICMD
MWD
TINC
ERG
IR
UV
=
=
=
=
=
=
=
=
=
IV.
Defensive Programming
Techniques
Two leaf nodes from the left side of the attack tree
represented in Fig. 5 are improper input validation and input
pass through GET. Path from these nodes to root node
represents attacker can compromised the Web Application if
Web Application does not sanitize the input fields properly
and input values goes send through GET method.
Configuration
File Modification
Application
Penetration
Script
Execution
Improper
Input
Validation
Command
Execution
Input Pass
through GET
Modules in
Web
Directory
Modification in
Internal Variables
.inc file in
Text Form
Register
_Global
Enabled
Input Pass to
Command line
73
Input Strings
pass through
$_Request
Uninitialized
Variable in
code
D.
E.
Restrict Access
?>
Figure 6. Script prevents direct input passing to include statement
if (!ctype_alnum($_GET['login'])) {
echo "Only A-Za-z0-9 are allowed.";
}
if (!ctype_alpha($_GET['captcha'])) {
echo "Only A-Za-z are allowed.";
}
if (!ctype_xdigit($_GET['color'])) {
echo "Only hexadecimal values are allowed";
}
74
V.
References
[1]
[2]
ini_set(display_errors, FALSE);
ini_set(log_errors, TRUE);
[3]
[4]
[5]
[6]
Disable
Apache
ServerSignature=off
identification
Conclusion
[7]
[8]
About Authors:
header
<?php
$clean = array();
if ($_POST['num'] ==strval(intval($_POST['num'])))
{
$clean['num'] = $_POST['num'];
}
?>
75