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

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Recently uploaded (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

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