SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
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!!

Contenu connexe

Tendances

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
 

Tendances (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)
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 

Dernier (20)

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 

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!!