SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Vulnerability In PHP and Safe Coding Practices
By : Sachin Thakuri
Contents
1) About
2) Setup and Configurations
3) Remote File Inclusion
3.0 - Basic example
3.1 - Exploitation
3.2 - How to fix
4) Local File Inclusion
4.0 - Basic example
4.1 - Exploitation
4.2 - How to fix
5) Local File Disclosure/Download
5.0 - Basic example
5.1 - Exploitation
5.2 - How to fix
6) SQL Injection
6.0 - Basic example
6.1 - Exploitation
6.2 - How to fix
Contents
7) Remote Command Execution
7.0 - Basic example
7.1 - Exploitation
7.2 - How to fix
8) Remote Code Execution
8.0 - Basic example
8.1 - Exploitation
8.2 - How to fix
9) Cross-Site Scripting
9.0 - Basic example
9.1 - Exploitation
9.2 - How to fix
10) Authentication Bypass
10.0 - Basic example
10.1 - Via login variable
10.2 - Unprotected Admin CP
10.3 - How to fix
11) Cross Site Request Forgery
11.0 - Basic example
11.1 - Exploitation
11.2 - How to fix
About
This presentation will cover :
• Finding Vulnerabilities in PHP
• Identify Vulnerable Code
• Exploit Vulnerable code and compromise a Web System
• Fixing those Vulnerable Code
Setup and Configurations
• Install Apache, PHP and MySQL (phpmyadmin)
- Can be WAMP server for Windows, MAMP server for Mac OS
and LAMP for Linux.
• PHP configuration file (php.ini)
◦ disabled_functions = N/A
register_globals = on
magic_quotes_gpc = off
short_tag_open = on
file_uploads = on
display_errors = on
safe_mode = off
allow_url_include = on
allow_url_fopen = on
Remote File Inclusion
• Remote File Inclusion allows the attacker to upload a custom coded/malicious file on a
website or server using a script.
• This can lead to
- Code execution on the web server.
- Code execution on the client such as Javscript which can lead to other attacks
such as cross site scripting (XSS).
- Denial Of Service (DoS)
- Data Theft/Manipulation
Basic Example : From rfitest.php
<?php
$page=$_GET['page'];
include $page;
?>
Exploitation : (Demo)
How To Fix :
• Set allow_url_fopen and allow_url_include to "Off" in php.ini
• Don't allow special chars in variables. Filter "http" , "https" , "ftp" and "smb".
Local File Inclusion
• Local File Inclusion (LFI) is similar to a Remote File Inclusion vulnerability except
instead of including remote files, only local files i.e. files on the current server can
be included.
Basic Example : From lfitest.php
<?php
$page=$_GET['page'];
include '/pages/'.$page;
?>
Exploitation : (Demo)
How To Fix :
• Don't allow special chars in variables. Filter the dot "."
• Filter "/" , "" and "." .
Local File Disclosure/Download
• A vulnerability through which you can read the content of files.
• PHP functions that allow reading files.
- file_get_contents() Reads entire file into a string
- readfile() Outputs a file
- file() Reads entire file into an array
- fopen() Opens file or URL
- show_source() Alias of highlight_file()
Basic Example : From disclosetest.php
<?php
$page=$_GET['page'];
readfile($page);
?>
Exploitation : (Demo)
How To Fix :
• Don't allow special chars in variables. Filter the dot "."
• Filter "/" , "" and "." .
SQL Injection
• SQL injection is a code injection technique, used to attack data driven applications,
in which malicious SQL statements are inserted into an entry field for execution
(e.g. to dump the database contents to the attacker).
Basic Example :
<?php
require('config.php');
$safe=$_GET['id'];
$query="SELECT * FROM tbl_status WHERE id=$safe";
$a=mysql_query($query);
while($row=mysql_fetch_array($a))
{
echo $row['status'];
}?>
Exploitation : (Demo)
How To Fix :
• Don't allow special chars in variables.
• For non-numeric variables : filter all special chars used in
SQLI : - , . ( ) ' " _ + / *
Remote Command Execution
• Remote command execution vulnerability allows a remote attacker to execute
arbitrary code in the system with administrator privileges without the attention of
the owner of the targeted site.
Basic Example : (remotetest.php)
<?php
$cmd=$_GET['cmd'];
system($cmd);
?>
Exploitation : (Demo)
How To Fix :
• Don't allow user input .
• Use escapeshellarg() and escapeshellcmd() functions .
Remote Code Execution
• Remote code execution vulnerability allows a remote attacker to execute code in
the system of the targeted site.
Basic Example : (codetest.php)
<?php
$code=$_GET['code'];
eval($code);
?>
Exploitation : (Demo)
How To Fix :
• Don't allow ";" and the PHP code will be invalid.
• Don't allow any special char like "(" or ")" etc.
Cross-site Scripting (XSS)
• Cross-site scripting (XSS) is a vulnerability in which the attacker inserts malicious
coding into a link that appears to be from a trustworthy source.
• There are mostly 2 types of xss
- Non-Persistent :
In case of Non-Persistent attack, it requires a user to visit the specially crafted link by the
attacker. When the user visit the link, the crafted code will get executed by the user’s
browser.
- Persistent :
In case of persistent attack, the code injected by the attacker will be stored in a secondary
storage device (mostly on a database). The damage caused by Persistent attack is more than
the non-persistent attack.
Basic Example : (xsstest.php)
<?php
$name=$_GET['name'];
print $name;
?>
Exploitation : (Demo)
How To Fix :
• Use htmlentities() or htmlspecialchars() functions.
• Filter all special chars used for XSS ( a lot ).
Authentication Bypass
• This vulnerability allows attacker to bypass the authentication system and give
access to admin panel.
Basic Example : (bypasstest.php)
<?php
if ($logged==true) {
echo 'Logged in.'; }
else {
print 'Not logged in.';
}
?>
Exploitation : (Demo)
If we set the value of $logged variable to 1 the if condition will be true and we are
logged in.
Via Login Variable : (logintest.php)
<?php
if ($login_ok)
{
$_SESSION['loggato'] = true;
echo "<p>Welcome Admin</p>";
echo"<div align='center'><a href='index.php'>Admin Panel</a> |
<a href='admin.php'>Delete|Edit</a> | <a href='install.php'>Install
</a></div>";
}
else{
echo "login failed";
}?>
Exploitation : (Demo)
If the "login_ok" variable is TRUE ( 1 ) the script set us a SESSION which tells the
script that we are logged in. So lets set the "login_ok" variable to TRUE.
Unprotected Admin CP :
This is hard to believe but some PHP programmers don't protect the admin
control panel : no login, no .htaccess, no nothing. So we simply go to
the admin panel directory and we take the control of the website.
How To Fix :
• Login variable bypass : Use a REAL authentication system, use SESSION and
verify login using SESSION.
• Unprotected Admin CP : Use an authentication system or use .htaccess to
allow access from specific IP's or .htpasswd to request an username and a
password for admin CP.
◦ Example :
.htaccess :
order deny, allow
deny from all
allow from 127.0.0.1
.htpasswd :
AuthUserFile /the/path/.htpasswd
AuthType Basic
AuthName "Admin CP"
Require valid-user
Cross Site Request Forgery
Basic Example : (csrftest.php)
<?php
if(isset($_GET['news']))
{ unlink($news.'.txt'); }
else {
die('File not deleted'); }
?>
Exploitation : (Demo)
• localhost/phpv/csrftest.php?news=file1
How To Fix :
• Use tokens. At each login,generate a random token and save it
in the session. Request the token in URL to do administrative
actions, if the token missing or is wrong,don't execute the
action.
Example :
<?php
if(isset($_GET['news']) && $token=$_SESSION['token'])
{ unlink('$news.'.txt'); }
else {
die('Error.'); }
?>
End Of Session
Vulnerability In PHP and Safe Coding Practices
By: Sachin Thakuri
Feedbacks and Comment are Welcomed!!

Weitere ähnliche Inhalte

Was ist angesagt?

PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015Colin O'Dell
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkGosuke Miyashita
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
Sql Injections With Real Life Scenarious
Sql Injections With Real Life ScenariousSql Injections With Real Life Scenarious
Sql Injections With Real Life ScenariousFrancis Alexander
 
What should a hacker know about WebDav?
What should a hacker know about WebDav?What should a hacker know about WebDav?
What should a hacker know about WebDav?Mikhail Egorov
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life CycleXinchen Hui
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHPNat Weerawan
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQUA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQMichelangelo van Dam
 
PHP and Databases
PHP and DatabasesPHP and Databases
PHP and DatabasesThings Lab
 
Web App Testing With Selenium
Web App Testing With SeleniumWeb App Testing With Selenium
Web App Testing With Seleniumjoaopmaia
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 

Was ist angesagt? (20)

Flask SQLAlchemy
Flask SQLAlchemy Flask SQLAlchemy
Flask SQLAlchemy
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Hacking Wordpress Plugins
Hacking Wordpress PluginsHacking Wordpress Plugins
Hacking Wordpress Plugins
 
Presentation (PPT)
Presentation (PPT)Presentation (PPT)
Presentation (PPT)
 
Sql Injections With Real Life Scenarious
Sql Injections With Real Life ScenariousSql Injections With Real Life Scenarious
Sql Injections With Real Life Scenarious
 
Secure Your Wordpress
Secure Your WordpressSecure Your Wordpress
Secure Your Wordpress
 
What should a hacker know about WebDav?
What should a hacker know about WebDav?What should a hacker know about WebDav?
What should a hacker know about WebDav?
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQUA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
 
PHP and Databases
PHP and DatabasesPHP and Databases
PHP and Databases
 
Web App Testing With Selenium
Web App Testing With SeleniumWeb App Testing With Selenium
Web App Testing With Selenium
 
Web Security
Web SecurityWeb Security
Web Security
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 

Andere mochten auch

PHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTREPHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTREjatin batra
 
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in PunePHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in PuneCNC WEB WORLD
 
PHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial TrainingPHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial TrainingConjoinix Xscademy
 
PHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTREPHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre groversimrans
 
PHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer CentrePHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer Centrejatin batra
 
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report 6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report c-tac
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training PresentationNitesh Sharma
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorialalexjones89
 

Andere mochten auch (17)

Php live project training
Php live project trainingPhp live project training
Php live project training
 
PHP
PHPPHP
PHP
 
Phpwebdevelping
PhpwebdevelpingPhpwebdevelping
Phpwebdevelping
 
PHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTREPHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTRE
 
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in PunePHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
 
Php training in ahmedabad
Php training in ahmedabadPhp training in ahmedabad
Php training in ahmedabad
 
PHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial TrainingPHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial Training
 
PHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTREPHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTRE
 
PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre
 
PHP
PHPPHP
PHP
 
PHP Training in Hyderabad
PHP Training in Hyderabad PHP Training in Hyderabad
PHP Training in Hyderabad
 
php
phpphp
php
 
PHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer CentrePHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer Centre
 
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report 6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 

Ähnlich wie Php vulnerability presentation

Web-servers & Application Hacking
Web-servers & Application HackingWeb-servers & Application Hacking
Web-servers & Application HackingRaghav Bisht
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
OWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web AttacksOWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web AttacksNarendra Bhati
 
Application and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental EditionApplication and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental EditionDaniel Owens
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: BackendVõ Duy Tuấn
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php confHash Lin
 
Everybody loves html5,h4ck3rs too
Everybody loves html5,h4ck3rs tooEverybody loves html5,h4ck3rs too
Everybody loves html5,h4ck3rs tooNahidul Kibria
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Securityjemond
 
Top 10 Security Vulnerabilities (2006)
Top 10 Security Vulnerabilities (2006)Top 10 Security Vulnerabilities (2006)
Top 10 Security Vulnerabilities (2006)Susam Pal
 
Web application security
Web application securityWeb application security
Web application securityRavi Raj
 
Secure programming with php
Secure programming with phpSecure programming with php
Secure programming with phpMohmad Feroz
 
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...CODE BLUE
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applicationsDevnology
 

Ähnlich wie Php vulnerability presentation (20)

Web-servers & Application Hacking
Web-servers & Application HackingWeb-servers & Application Hacking
Web-servers & Application Hacking
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
PHP Secure Programming
PHP Secure ProgrammingPHP Secure Programming
PHP Secure Programming
 
OWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web AttacksOWASP Pune Chapter : Dive Into The Profound Web Attacks
OWASP Pune Chapter : Dive Into The Profound Web Attacks
 
LFI to RCE Exploit with Perl Script
LFI to RCE Exploit with Perl ScriptLFI to RCE Exploit with Perl Script
LFI to RCE Exploit with Perl Script
 
Application and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental EditionApplication and Website Security -- Fundamental Edition
Application and Website Security -- Fundamental Edition
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Orange@php conf
Orange@php confOrange@php conf
Orange@php conf
 
Rails Security
Rails SecurityRails Security
Rails Security
 
Everybody loves html5,h4ck3rs too
Everybody loves html5,h4ck3rs tooEverybody loves html5,h4ck3rs too
Everybody loves html5,h4ck3rs too
 
General Principles of Web Security
General Principles of Web SecurityGeneral Principles of Web Security
General Principles of Web Security
 
Unusual Web Bugs
Unusual Web BugsUnusual Web Bugs
Unusual Web Bugs
 
Web Bugs
Web BugsWeb Bugs
Web Bugs
 
Top 10 Security Vulnerabilities (2006)
Top 10 Security Vulnerabilities (2006)Top 10 Security Vulnerabilities (2006)
Top 10 Security Vulnerabilities (2006)
 
LFI to RCE
LFI to RCELFI to RCE
LFI to RCE
 
Web application security
Web application securityWeb application security
Web application security
 
Secure programming with php
Secure programming with phpSecure programming with php
Secure programming with php
 
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
[CB20] Operation I am Tom: How APT actors move laterally in corporate network...
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
 

Kürzlich hochgeladen

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Kürzlich hochgeladen (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Php vulnerability presentation

  • 1. Vulnerability In PHP and Safe Coding Practices By : Sachin Thakuri
  • 2. Contents 1) About 2) Setup and Configurations 3) Remote File Inclusion 3.0 - Basic example 3.1 - Exploitation 3.2 - How to fix 4) Local File Inclusion 4.0 - Basic example 4.1 - Exploitation 4.2 - How to fix 5) Local File Disclosure/Download 5.0 - Basic example 5.1 - Exploitation 5.2 - How to fix 6) SQL Injection 6.0 - Basic example 6.1 - Exploitation 6.2 - How to fix
  • 3. Contents 7) Remote Command Execution 7.0 - Basic example 7.1 - Exploitation 7.2 - How to fix 8) Remote Code Execution 8.0 - Basic example 8.1 - Exploitation 8.2 - How to fix 9) Cross-Site Scripting 9.0 - Basic example 9.1 - Exploitation 9.2 - How to fix 10) Authentication Bypass 10.0 - Basic example 10.1 - Via login variable 10.2 - Unprotected Admin CP 10.3 - How to fix 11) Cross Site Request Forgery 11.0 - Basic example 11.1 - Exploitation 11.2 - How to fix
  • 4. About This presentation will cover : • Finding Vulnerabilities in PHP • Identify Vulnerable Code • Exploit Vulnerable code and compromise a Web System • Fixing those Vulnerable Code
  • 5. Setup and Configurations • Install Apache, PHP and MySQL (phpmyadmin) - Can be WAMP server for Windows, MAMP server for Mac OS and LAMP for Linux. • PHP configuration file (php.ini) ◦ disabled_functions = N/A register_globals = on magic_quotes_gpc = off short_tag_open = on file_uploads = on display_errors = on safe_mode = off allow_url_include = on allow_url_fopen = on
  • 6. Remote File Inclusion • Remote File Inclusion allows the attacker to upload a custom coded/malicious file on a website or server using a script. • This can lead to - Code execution on the web server. - Code execution on the client such as Javscript which can lead to other attacks such as cross site scripting (XSS). - Denial Of Service (DoS) - Data Theft/Manipulation Basic Example : From rfitest.php <?php $page=$_GET['page']; include $page; ?> Exploitation : (Demo) How To Fix : • Set allow_url_fopen and allow_url_include to "Off" in php.ini • Don't allow special chars in variables. Filter "http" , "https" , "ftp" and "smb".
  • 7. Local File Inclusion • Local File Inclusion (LFI) is similar to a Remote File Inclusion vulnerability except instead of including remote files, only local files i.e. files on the current server can be included. Basic Example : From lfitest.php <?php $page=$_GET['page']; include '/pages/'.$page; ?> Exploitation : (Demo) How To Fix : • Don't allow special chars in variables. Filter the dot "." • Filter "/" , "" and "." .
  • 8. Local File Disclosure/Download • A vulnerability through which you can read the content of files. • PHP functions that allow reading files. - file_get_contents() Reads entire file into a string - readfile() Outputs a file - file() Reads entire file into an array - fopen() Opens file or URL - show_source() Alias of highlight_file() Basic Example : From disclosetest.php <?php $page=$_GET['page']; readfile($page); ?> Exploitation : (Demo) How To Fix : • Don't allow special chars in variables. Filter the dot "." • Filter "/" , "" and "." .
  • 9. SQL Injection • SQL injection is a code injection technique, used to attack data driven applications, in which malicious SQL statements are inserted into an entry field for execution (e.g. to dump the database contents to the attacker). Basic Example : <?php require('config.php'); $safe=$_GET['id']; $query="SELECT * FROM tbl_status WHERE id=$safe"; $a=mysql_query($query); while($row=mysql_fetch_array($a)) { echo $row['status']; }?> Exploitation : (Demo) How To Fix : • Don't allow special chars in variables. • For non-numeric variables : filter all special chars used in SQLI : - , . ( ) ' " _ + / *
  • 10. Remote Command Execution • Remote command execution vulnerability allows a remote attacker to execute arbitrary code in the system with administrator privileges without the attention of the owner of the targeted site. Basic Example : (remotetest.php) <?php $cmd=$_GET['cmd']; system($cmd); ?> Exploitation : (Demo) How To Fix : • Don't allow user input . • Use escapeshellarg() and escapeshellcmd() functions .
  • 11. Remote Code Execution • Remote code execution vulnerability allows a remote attacker to execute code in the system of the targeted site. Basic Example : (codetest.php) <?php $code=$_GET['code']; eval($code); ?> Exploitation : (Demo) How To Fix : • Don't allow ";" and the PHP code will be invalid. • Don't allow any special char like "(" or ")" etc.
  • 12. Cross-site Scripting (XSS) • Cross-site scripting (XSS) is a vulnerability in which the attacker inserts malicious coding into a link that appears to be from a trustworthy source. • There are mostly 2 types of xss - Non-Persistent : In case of Non-Persistent attack, it requires a user to visit the specially crafted link by the attacker. When the user visit the link, the crafted code will get executed by the user’s browser. - Persistent : In case of persistent attack, the code injected by the attacker will be stored in a secondary storage device (mostly on a database). The damage caused by Persistent attack is more than the non-persistent attack. Basic Example : (xsstest.php) <?php $name=$_GET['name']; print $name; ?> Exploitation : (Demo) How To Fix : • Use htmlentities() or htmlspecialchars() functions. • Filter all special chars used for XSS ( a lot ).
  • 13. Authentication Bypass • This vulnerability allows attacker to bypass the authentication system and give access to admin panel. Basic Example : (bypasstest.php) <?php if ($logged==true) { echo 'Logged in.'; } else { print 'Not logged in.'; } ?> Exploitation : (Demo) If we set the value of $logged variable to 1 the if condition will be true and we are logged in.
  • 14. Via Login Variable : (logintest.php) <?php if ($login_ok) { $_SESSION['loggato'] = true; echo "<p>Welcome Admin</p>"; echo"<div align='center'><a href='index.php'>Admin Panel</a> | <a href='admin.php'>Delete|Edit</a> | <a href='install.php'>Install </a></div>"; } else{ echo "login failed"; }?> Exploitation : (Demo) If the "login_ok" variable is TRUE ( 1 ) the script set us a SESSION which tells the script that we are logged in. So lets set the "login_ok" variable to TRUE. Unprotected Admin CP : This is hard to believe but some PHP programmers don't protect the admin control panel : no login, no .htaccess, no nothing. So we simply go to the admin panel directory and we take the control of the website.
  • 15. How To Fix : • Login variable bypass : Use a REAL authentication system, use SESSION and verify login using SESSION. • Unprotected Admin CP : Use an authentication system or use .htaccess to allow access from specific IP's or .htpasswd to request an username and a password for admin CP. ◦ Example : .htaccess : order deny, allow deny from all allow from 127.0.0.1 .htpasswd : AuthUserFile /the/path/.htpasswd AuthType Basic AuthName "Admin CP" Require valid-user
  • 16. Cross Site Request Forgery Basic Example : (csrftest.php) <?php if(isset($_GET['news'])) { unlink($news.'.txt'); } else { die('File not deleted'); } ?> Exploitation : (Demo) • localhost/phpv/csrftest.php?news=file1 How To Fix : • Use tokens. At each login,generate a random token and save it in the session. Request the token in URL to do administrative actions, if the token missing or is wrong,don't execute the action. Example : <?php if(isset($_GET['news']) && $token=$_SESSION['token']) { unlink('$news.'.txt'); } else { die('Error.'); } ?>
  • 17. End Of Session Vulnerability In PHP and Safe Coding Practices By: Sachin Thakuri Feedbacks and Comment are Welcomed!!