SlideShare a Scribd company logo
1 of 31
Download to read offline
© 2019 Rogue Wave Software, Inc. All rights reserved
Webinar series: PHP security best practices
Part 1: Web security best practices for PHP
© 2019 Rogue Wave Software, Inc. All rights reserved
PHPsecuritybestpracticesPHPsecuritybestpractices
by Daryl Wood
Senior Technical Trainer
Webinar, March 25, 2019
Rogue Wave Software, Inc.
© 2019 Rogue Wave Software, Inc. All rights reserved
PHPapplicationsecurityPHPapplicationsecurity
BestpracticefundamentalsBestpracticefundamentals
Security attack types
Log monitoring
Attack injection
Attack severities and impacts
PHP version end of life
© 2019 Rogue Wave Software, Inc. All rights reserved
AttackseveritiesandimpactsAttackseveritiesandimpacts
© 2019 Rogue Wave Software, Inc. All rights reserved
AttackseveritiesAttackseverities
© 2019 Rogue Wave Software, Inc. All rights reserved
AttackimpactsAttackimpacts
Impacts of injection success include:
Data loss, corruption, access denial, or complete host takeover
Lack of accountability
Bad public relations
Litigation expense
Web site front-facing impacts
Account(s) compromise
© 2019 Rogue Wave Software, Inc. All rights reserved
Injectionandattacktypes(limited)Injectionandattacktypes(limited)
Some of the most common attacks or vulnerabilities include:
Cross-site scripting (XSS)
SQL injection
Broken session management
Brute force
© 2019 Rogue Wave Software, Inc. All rights reserved
InjectionInjection
Injection is an attempt to insert something nefarious into an
application. It can:
Allow malicious code pass through
Include system calls
Include whole scripts
Cause an interpreter to execute unauthorized code
© 2019 Rogue Wave Software, Inc. All rights reserved
Cross-sitescripting(XSS)Cross-sitescripting(XSS)
An injection of script code, typically JavaScript, into an application from
an outside client.
This vulnerability occurs when input data is used without proper
ltering, validation, and escaping.
Two types of XSS (can occur on a server or client):
Stored
Re ected
© 2019 Rogue Wave Software, Inc. All rights reserved
Cross-sitescripting(XSS)Cross-sitescripting(XSS)
AstoredvulnerableexampleAstoredvulnerableexample
$_POST['username'] = 'pablo';
$_POST['comment'] = '<script>alert("document.cookie")</script>';
if($_POST) {
$result = null;
try {
$pdo = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=blog',
'vagrant', 'vagrant');
$stmt = $pdo->query("INSERT INTO blog (username, comment) VALUES ({$_POST['username']},
{$_POST['comment']})");
if($stmt) $stmt->execute();
// Then subsequently
$result = $pdo->exec("SELECT * FROM blog WHERE username='{$_POST['username']}'");
} catch (Throwable $e){
// Handle ...
}
if($result){
echo $result['comment'];
}
}
© 2019 Rogue Wave Software, Inc. All rights reserved
SQLinjectionSQLinjection
SQL injection de nes an attempt to inject some amount of SQL, or any
database interface language, in input data from a client.
It attempts to execute unauthorized database actions on a database
server.
© 2019 Rogue Wave Software, Inc. All rights reserved
SQLinjectionSQLinjection
AvulnerabledodeexampleAvulnerabledodeexample
But, what if the Id parameter looks like this:
if ($_GET && isset($_GET['Submit'])) {
1.
//Employ ACL to determine access
try {
$pdo = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=blog',
'vagrant', 'vagrant');
$stmt = $pdo->query("SELECT first_name, last_name FROM blog
WHERE user_id = '{$_GET['id']}'");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// Handle ...
}
}
;update blog set username = attacker where user_id = 1;
© 2019 Rogue Wave Software, Inc. All rights reserved
BrokensessionmanagementBrokensessionmanagement
Broken session management can allow unauthorized attackers access
to privileged account data. When this happens:
Account(s) are compromised
Can allow further exploitation
© 2019 Rogue Wave Software, Inc. All rights reserved
BrokensessionmanagementBrokensessionmanagement
AvulnerablecodeexampleAvulnerablecodeexample
class LoginController {
// ...
public function logoutAction() {
$this->view->setTemplate('login');
$this->view->render();
}
// ...
}
© 2019 Rogue Wave Software, Inc. All rights reserved
BruteforceBruteforce
A brute force attack is an attempt to break authentication.
The brute force attacker tries every character/special
character/symbol/number mutation possible until successful.
Robotic
Attempts to identify authentication mechanism
Good at covering tracks
Success is a not a matter of if, but when?
Extremely dangerous on success
© 2019 Rogue Wave Software, Inc. All rights reserved
BruteforceBruteforce
AvulnerablecodeexampleAvulnerablecodeexample
if($_POST && isset( $_POST['Login'] ) ) {
$username = $_POST['username'];
$password = md5($_POST['password']);
try{
$stmt = $this->getPdo()->query("SELECT * FROM users
WHERE username='$username' AND password='$password'");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}catch(PDOException $e){
// Handle ...
}
if( $result && count($result) ) {
// Login Successful
echo "<p>Welcome to the password protected area " . $user . "</p>";
} else {
//Login failed
echo "<pre><br>Username and/or password incorrect.</pre>";
}
}
© 2019 Rogue Wave Software, Inc. All rights reserved
LogmonitoringLogmonitoring
© 2019 Rogue Wave Software, Inc. All rights reserved
LogmonitoringLogmonitoring
Log monitoring is all about keeping an eye on what's being attacked,
from where, and sometimes by whom.
This section includes:
Log location
Enabling
Monitoring tools
© 2019 Rogue Wave Software, Inc. All rights reserved
LoglocationLoglocation
Where are the logs? This is dependant on your server's OS. Here are
locations for a Debian-based Linux server using the Apache web server:
Syslog: /var/log/syslog
Apache access: /var/log/apache2/access.log
Apache error: /var/log/apache2/error.log
PHP error When enabled, and by default, is the syslog.
© 2019 Rogue Wave Software, Inc. All rights reserved
LogmonitoringLogmonitoring
LogEntryExamplesLogEntryExamples
A cut from a Debian-based Linux syslog:
A cut from an Apache access log:
A cut from an Apache error log:
Mar 15 09:58:40 linux systemd[1]: Timed out waiting for device
dev-disk-byx2did-usbx2dWDC_WD10_02FAEXx2d00Z3A0_152D00539000x2d0:0x2dpart1.device.
127.0.0.1 - - [14/Mar/2019:08:10:14 -0700] "GET / HTTP/1.1" 200 1330 "-"
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0"
[Fri Mar 15 08:11:41.867281 2019] [mpm_prefork:notice] [pid 1473]
AH00169: caught SIGTERM, shutting down
© 2019 Rogue Wave Software, Inc. All rights reserved
EnablingPHPerrorloggingEnablingPHPerrorlogging
PHP application error logging is not enabled by default. Enabeling in a
Debian-based Linux PHP installation for apache looks like this:
The le location: /etc/php/<version>/<parser type>/php.ini.
...
; Besides displaying errors, PHP can also log errors to locations such as a
; server-specific log, STDERR, or a location specified by the error_log
; directive found below. While errors should not be displayed on productions
; servers they should still be monitored and logging is a great way to do that.
; Default Value: Off
; Development Value: On
; Production Value: On
; http://php.net/log-errors
log_errors = On
...
© 2019 Rogue Wave Software, Inc. All rights reserved
MonitoringtoolsMonitoringtools
Include:
Framework tools
Third party library (https://packagist.org)
Third party service
© 2019 Rogue Wave Software, Inc. All rights reserved
PHPversionend-of-lifePHPversionend-of-life
© 2019 Rogue Wave Software, Inc. All rights reserved
PHPversionend-of-lifePHPversionend-of-life
PHP servers must be kept up to date, and a formal process established
to a ect that update.
Version end of life means that support for:
Bug xes will cease
Security xes will cease
System optimizations will cease
System monitoring might be impacted and fail to function correctly, if
at all.
Being proactive with version updates will help prevent problems!
© 2019 Rogue Wave Software, Inc. All rights reserved
RecapRecap
© 2019 Rogue Wave Software, Inc. All rights reserved
RecapRecap
Let's recap:
Attack severities and their technical and business impacts.
A limited set of injection and attack types.
Logging importance and some monitoring information.
The risks of PHP version end of life.
© 2019 Rogue Wave Software, Inc. All rights reserved
Whatelse?Whatelse?
Oh, and, we never mentioned:
Cross site request forgery
Remote code injection
Command injection
Man-in-the-middle attacks
How to target log for severities
And more...
© 2019 Rogue Wave Software, Inc. All rights reserved
What'snext?What'snext?
© 2019 Rogue Wave Software, Inc. All rights reserved
StaytunedStaytuned
Additional resources:
PHP Security, support and migration: zend.com/phpsecurity
Training, PHP security and more: zend.com/en/services/training
Don't forget to join this webinar where we’ll dive a little deeper into the
PHP security best practices with code xes!
April25th:PHPsecuritybestpracticescontinuesApril25th:PHPsecuritybestpracticescontinues
© 2019 Rogue Wave Software, Inc. All rights reserved
Q&AQ&A
© 2019 Rogue Wave Software, Inc. All rights reserved
Thankyou!Thankyou!
Contact Ryan: ryan.krszjzaniek@roguewave.com
Contact Daryl: daryl.wood@roguewave.com
Follow me on Twitter: @datashuttle

More Related Content

More from Zend by Rogue Wave Software

Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i Zend by Rogue Wave Software
 
Standard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerStandard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerZend by Rogue Wave Software
 

More from Zend by Rogue Wave Software (20)

Middleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.xMiddleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.x
 
Ongoing management of your PHP 7 application
Ongoing management of your PHP 7 applicationOngoing management of your PHP 7 application
Ongoing management of your PHP 7 application
 
Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7
 
The Docker development template for PHP
The Docker development template for PHPThe Docker development template for PHP
The Docker development template for PHP
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Deploying PHP apps on the cloud
Deploying PHP apps on the cloudDeploying PHP apps on the cloud
Deploying PHP apps on the cloud
 
Data is dead. Long live data!
Data is dead. Long live data! Data is dead. Long live data!
Data is dead. Long live data!
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Resolving problems & high availability
Resolving problems & high availabilityResolving problems & high availability
Resolving problems & high availability
 
Developing apps faster
Developing apps fasterDeveloping apps faster
Developing apps faster
 
Keeping up with PHP
Keeping up with PHPKeeping up with PHP
Keeping up with PHP
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM i
 
Continuous Delivery e-book
Continuous Delivery e-bookContinuous Delivery e-book
Continuous Delivery e-book
 
Standard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerStandard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend Server
 
Dev & Prod - PHP Applications in the Cloud
Dev & Prod - PHP Applications in the CloudDev & Prod - PHP Applications in the Cloud
Dev & Prod - PHP Applications in the Cloud
 
The Truth about Lambdas and Closures in PHP
The Truth about Lambdas and Closures in PHPThe Truth about Lambdas and Closures in PHP
The Truth about Lambdas and Closures in PHP
 
Application Deployment on IBM i
Application Deployment on IBM iApplication Deployment on IBM i
Application Deployment on IBM i
 

Recently uploaded

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Web security best practices for PHP

  • 1. © 2019 Rogue Wave Software, Inc. All rights reserved Webinar series: PHP security best practices Part 1: Web security best practices for PHP
  • 2. © 2019 Rogue Wave Software, Inc. All rights reserved PHPsecuritybestpracticesPHPsecuritybestpractices by Daryl Wood Senior Technical Trainer Webinar, March 25, 2019 Rogue Wave Software, Inc.
  • 3. © 2019 Rogue Wave Software, Inc. All rights reserved PHPapplicationsecurityPHPapplicationsecurity BestpracticefundamentalsBestpracticefundamentals Security attack types Log monitoring Attack injection Attack severities and impacts PHP version end of life
  • 4. © 2019 Rogue Wave Software, Inc. All rights reserved AttackseveritiesandimpactsAttackseveritiesandimpacts
  • 5. © 2019 Rogue Wave Software, Inc. All rights reserved AttackseveritiesAttackseverities
  • 6. © 2019 Rogue Wave Software, Inc. All rights reserved AttackimpactsAttackimpacts Impacts of injection success include: Data loss, corruption, access denial, or complete host takeover Lack of accountability Bad public relations Litigation expense Web site front-facing impacts Account(s) compromise
  • 7. © 2019 Rogue Wave Software, Inc. All rights reserved Injectionandattacktypes(limited)Injectionandattacktypes(limited) Some of the most common attacks or vulnerabilities include: Cross-site scripting (XSS) SQL injection Broken session management Brute force
  • 8. © 2019 Rogue Wave Software, Inc. All rights reserved InjectionInjection Injection is an attempt to insert something nefarious into an application. It can: Allow malicious code pass through Include system calls Include whole scripts Cause an interpreter to execute unauthorized code
  • 9. © 2019 Rogue Wave Software, Inc. All rights reserved Cross-sitescripting(XSS)Cross-sitescripting(XSS) An injection of script code, typically JavaScript, into an application from an outside client. This vulnerability occurs when input data is used without proper ltering, validation, and escaping. Two types of XSS (can occur on a server or client): Stored Re ected
  • 10. © 2019 Rogue Wave Software, Inc. All rights reserved Cross-sitescripting(XSS)Cross-sitescripting(XSS) AstoredvulnerableexampleAstoredvulnerableexample $_POST['username'] = 'pablo'; $_POST['comment'] = '<script>alert("document.cookie")</script>'; if($_POST) { $result = null; try { $pdo = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=blog', 'vagrant', 'vagrant'); $stmt = $pdo->query("INSERT INTO blog (username, comment) VALUES ({$_POST['username']}, {$_POST['comment']})"); if($stmt) $stmt->execute(); // Then subsequently $result = $pdo->exec("SELECT * FROM blog WHERE username='{$_POST['username']}'"); } catch (Throwable $e){ // Handle ... } if($result){ echo $result['comment']; } }
  • 11. © 2019 Rogue Wave Software, Inc. All rights reserved SQLinjectionSQLinjection SQL injection de nes an attempt to inject some amount of SQL, or any database interface language, in input data from a client. It attempts to execute unauthorized database actions on a database server.
  • 12. © 2019 Rogue Wave Software, Inc. All rights reserved SQLinjectionSQLinjection AvulnerabledodeexampleAvulnerabledodeexample But, what if the Id parameter looks like this: if ($_GET && isset($_GET['Submit'])) { 1. //Employ ACL to determine access try { $pdo = new PDO('mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=blog', 'vagrant', 'vagrant'); $stmt = $pdo->query("SELECT first_name, last_name FROM blog WHERE user_id = '{$_GET['id']}'"); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); } catch (PDOException $e) { // Handle ... } } ;update blog set username = attacker where user_id = 1;
  • 13. © 2019 Rogue Wave Software, Inc. All rights reserved BrokensessionmanagementBrokensessionmanagement Broken session management can allow unauthorized attackers access to privileged account data. When this happens: Account(s) are compromised Can allow further exploitation
  • 14. © 2019 Rogue Wave Software, Inc. All rights reserved BrokensessionmanagementBrokensessionmanagement AvulnerablecodeexampleAvulnerablecodeexample class LoginController { // ... public function logoutAction() { $this->view->setTemplate('login'); $this->view->render(); } // ... }
  • 15. © 2019 Rogue Wave Software, Inc. All rights reserved BruteforceBruteforce A brute force attack is an attempt to break authentication. The brute force attacker tries every character/special character/symbol/number mutation possible until successful. Robotic Attempts to identify authentication mechanism Good at covering tracks Success is a not a matter of if, but when? Extremely dangerous on success
  • 16. © 2019 Rogue Wave Software, Inc. All rights reserved BruteforceBruteforce AvulnerablecodeexampleAvulnerablecodeexample if($_POST && isset( $_POST['Login'] ) ) { $username = $_POST['username']; $password = md5($_POST['password']); try{ $stmt = $this->getPdo()->query("SELECT * FROM users WHERE username='$username' AND password='$password'"); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); }catch(PDOException $e){ // Handle ... } if( $result && count($result) ) { // Login Successful echo "<p>Welcome to the password protected area " . $user . "</p>"; } else { //Login failed echo "<pre><br>Username and/or password incorrect.</pre>"; } }
  • 17. © 2019 Rogue Wave Software, Inc. All rights reserved LogmonitoringLogmonitoring
  • 18. © 2019 Rogue Wave Software, Inc. All rights reserved LogmonitoringLogmonitoring Log monitoring is all about keeping an eye on what's being attacked, from where, and sometimes by whom. This section includes: Log location Enabling Monitoring tools
  • 19. © 2019 Rogue Wave Software, Inc. All rights reserved LoglocationLoglocation Where are the logs? This is dependant on your server's OS. Here are locations for a Debian-based Linux server using the Apache web server: Syslog: /var/log/syslog Apache access: /var/log/apache2/access.log Apache error: /var/log/apache2/error.log PHP error When enabled, and by default, is the syslog.
  • 20. © 2019 Rogue Wave Software, Inc. All rights reserved LogmonitoringLogmonitoring LogEntryExamplesLogEntryExamples A cut from a Debian-based Linux syslog: A cut from an Apache access log: A cut from an Apache error log: Mar 15 09:58:40 linux systemd[1]: Timed out waiting for device dev-disk-byx2did-usbx2dWDC_WD10_02FAEXx2d00Z3A0_152D00539000x2d0:0x2dpart1.device. 127.0.0.1 - - [14/Mar/2019:08:10:14 -0700] "GET / HTTP/1.1" 200 1330 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0" [Fri Mar 15 08:11:41.867281 2019] [mpm_prefork:notice] [pid 1473] AH00169: caught SIGTERM, shutting down
  • 21. © 2019 Rogue Wave Software, Inc. All rights reserved EnablingPHPerrorloggingEnablingPHPerrorlogging PHP application error logging is not enabled by default. Enabeling in a Debian-based Linux PHP installation for apache looks like this: The le location: /etc/php/<version>/<parser type>/php.ini. ... ; Besides displaying errors, PHP can also log errors to locations such as a ; server-specific log, STDERR, or a location specified by the error_log ; directive found below. While errors should not be displayed on productions ; servers they should still be monitored and logging is a great way to do that. ; Default Value: Off ; Development Value: On ; Production Value: On ; http://php.net/log-errors log_errors = On ...
  • 22. © 2019 Rogue Wave Software, Inc. All rights reserved MonitoringtoolsMonitoringtools Include: Framework tools Third party library (https://packagist.org) Third party service
  • 23. © 2019 Rogue Wave Software, Inc. All rights reserved PHPversionend-of-lifePHPversionend-of-life
  • 24. © 2019 Rogue Wave Software, Inc. All rights reserved PHPversionend-of-lifePHPversionend-of-life PHP servers must be kept up to date, and a formal process established to a ect that update. Version end of life means that support for: Bug xes will cease Security xes will cease System optimizations will cease System monitoring might be impacted and fail to function correctly, if at all. Being proactive with version updates will help prevent problems!
  • 25. © 2019 Rogue Wave Software, Inc. All rights reserved RecapRecap
  • 26. © 2019 Rogue Wave Software, Inc. All rights reserved RecapRecap Let's recap: Attack severities and their technical and business impacts. A limited set of injection and attack types. Logging importance and some monitoring information. The risks of PHP version end of life.
  • 27. © 2019 Rogue Wave Software, Inc. All rights reserved Whatelse?Whatelse? Oh, and, we never mentioned: Cross site request forgery Remote code injection Command injection Man-in-the-middle attacks How to target log for severities And more...
  • 28. © 2019 Rogue Wave Software, Inc. All rights reserved What'snext?What'snext?
  • 29. © 2019 Rogue Wave Software, Inc. All rights reserved StaytunedStaytuned Additional resources: PHP Security, support and migration: zend.com/phpsecurity Training, PHP security and more: zend.com/en/services/training Don't forget to join this webinar where we’ll dive a little deeper into the PHP security best practices with code xes! April25th:PHPsecuritybestpracticescontinuesApril25th:PHPsecuritybestpracticescontinues
  • 30. © 2019 Rogue Wave Software, Inc. All rights reserved Q&AQ&A
  • 31. © 2019 Rogue Wave Software, Inc. All rights reserved Thankyou!Thankyou! Contact Ryan: ryan.krszjzaniek@roguewave.com Contact Daryl: daryl.wood@roguewave.com Follow me on Twitter: @datashuttle