SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
Secure Coding
with WordPress

        Mark Jaquith
       markjaquith.com
   coveredwebservices.com
XSS     privilege




                    shell execution
       escalation


CSRF
SQL injection
Plugin
security is
hit-or-miss
Mostly
 miss
SQL
Injection
<?php
$wpdb->query(
	 quot;UPDATE $wpdb->posts
	 SET post_title = '$newtitle'
	 WHERE ID = $my_idquot;
	 );
?>
<?php
$newtitle =
	 	 	 	 	 $wpdb->escape( $newtitle );
$my_id = absint( $my_id );

$wpdb->query(
	 quot;UPDATE $wpdb->posts
	 SET post_title = '$newtitle'
	 WHERE ID = $my_idquot;
	 );
?>
$wpdb->update()
<?php
$wpdb->update(
	 $wpdb->posts,
	 array( 'post_title' => $newtitle ),
	 array( 'ID' => $my_id )
	 );
?>
$wpdb->insert()
<?php
$wpdb->insert(
	 $wpdb->posts,
	 array( 'post_title' => $newtitle )
	 );
?>
<?php
$wpdb->update(
	 $wpdb->posts,
	 array(
	 	 'post_title' => $newtitle,
	 	 'post_content' => $newcontent ),
	 array(
	 	 'ID' => $my_id,
	 	 'post_title' => $old_title )
	 );
?>
<?php
$post_title = 'New Title';
$wheres['ID'] = 123;
$wheres['post_title'] = 'Old Title';
$wpdb->update(
	 $wpdb->posts,
	 compact( 'post_title' ),
	 $wheres
	 );
?>
$wpdb->prepare()
<?php
$title = 'Post Title';
$ID = 123;
$content = $wpdb->get_var(
	 $wpdb->prepare(
	 quot;SELECT post_content
	    FROM  $wpdb->posts
	    WHERE post_title = %s
	    AND   ID = %dquot;,
	 $title, $ID )
	 );
?>
•Uses sprintf() formatting
•%s for strings
•%d for integers
•You should not quote or
 escape
Escape
 late
XSS
<h1>
<?php
	 echo $title;
?>
</h1>
<?php
	 $title =
	 	 	 	 '<script> pwnage(); </script>'
?>
<h1>
<?php
	 echo $title;
?>
</h1>
Anything that
isn’t hardcoded
   is suspect
Better:
Everything is suspect
wp_specialchars()
<?php
	 $title =
	 	 	 	 '<script> pwnage(); </script>'
?>
<h1>
<?php
	 echo wp_specialchars( $title );
?>
</h1>
<?php
$title = 'quot; onmouseover=quot;pwnd();';
?>
<a href=quot;#wordcampquot; title=quot;
<?php
	 echo wp_specialchars( $title );
?>
quot;>
Link Text
</a>
attribute_escape()
<?php
$title = 'quot; onmouseover=quot;pwnd();';
?>
<a href=quot;#wordcampquot; title=quot;
<?php
	 echo attribute_escape( $title );
?>
quot;>
Link Text
</a>
<?php
 $url = 'javascript:pwnage();';
?>
<a href=quot;
<?php
	 echo attribute_escape( $url );
?>
quot;>
Link Text
</a>
clean_url()
<?php
 $url = 'javascript:pwnage();';
?>
<a href=quot;
<?php
	 echo clean_url( $url );
?>
quot;>
Link Text
</a>
sanitize_url(),
sister of clean_url()
js_escape()
CSRF
Authorization
     vs.

Intention
Nonces
  action-, object-,
 user-specific time
limited secret keys
Specific to
•WordPress user
•Action attempted
•Object of attempted action
•Time window
wp_nonce_field()
<form action=quot;process.phpquot;
method=quot;postquot;>
<?php
	 wp_nonce_field('plugin-action_object');
?>

...
</form>
check_admin_referer( )
<?php
// before output goes to browser
check_admin_referer('plugin-	 	 	 	 	
	 	 	 	 	 	 	 	 	 	 action_object');
?>
Still need to use
current_user_can()
AJAX
CSRF
• wp_create_nonce(   'your_action' );

• &_ajax_nonce=YOUR_NONCE
• check_ajax_referer(   'your_action' );
Privilege
Escalation
current_user_can()
Set your salts!
http://api.wordpress.org/secret-key/1.1/
Stupid shit
 I see all
 the time
exec()
<form action=quot;<?php echo
$_SERVER['REQUEST_URI']; ?>quot;>
Thank you!

Contenu connexe

Tendances

pasangh bendera di blog
pasangh bendera di blogpasangh bendera di blog
pasangh bendera di blog
ellyndra
 
Maritza
MaritzaMaritza
Maritza
ladyva
 
Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本
a5494535
 
Itsecteam shell
Itsecteam shellItsecteam shell
Itsecteam shell
ady36
 
Class 4 handout w css3 using j fiddle
Class 4 handout w css3 using j fiddleClass 4 handout w css3 using j fiddle
Class 4 handout w css3 using j fiddle
Erin M. Kidwell
 

Tendances (20)

2009 Barcamp Nashville Web Security 101
2009 Barcamp Nashville   Web Security 1012009 Barcamp Nashville   Web Security 101
2009 Barcamp Nashville Web Security 101
 
PHPUG Presentation
PHPUG PresentationPHPUG Presentation
PHPUG Presentation
 
Ae internals
Ae internalsAe internals
Ae internals
 
pasangh bendera di blog
pasangh bendera di blogpasangh bendera di blog
pasangh bendera di blog
 
Wiidget
WiidgetWiidget
Wiidget
 
Earn money with banner and text ads for Clickbank
Earn money with banner and text ads for ClickbankEarn money with banner and text ads for Clickbank
Earn money with banner and text ads for Clickbank
 
Front End on Rails
Front End on RailsFront End on Rails
Front End on Rails
 
JQuery 101
JQuery 101JQuery 101
JQuery 101
 
Maritza
MaritzaMaritza
Maritza
 
Symfony 1, mi viejo amigo
Symfony 1, mi viejo amigoSymfony 1, mi viejo amigo
Symfony 1, mi viejo amigo
 
Htm
HtmHtm
Htm
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 
Itsecteam shell
Itsecteam shellItsecteam shell
Itsecteam shell
 
Web Security
Web SecurityWeb Security
Web Security
 
Flickr Open Api Mashup
Flickr Open Api MashupFlickr Open Api Mashup
Flickr Open Api Mashup
 
Routing System In Symfony 1.2
Routing System In Symfony 1.2Routing System In Symfony 1.2
Routing System In Symfony 1.2
 
Class 4 handout w css3 using j fiddle
Class 4 handout w css3 using j fiddleClass 4 handout w css3 using j fiddle
Class 4 handout w css3 using j fiddle
 

Similaire à Secure Coding With Wordpress (BarCamp Orlando 2009)

High-level Web Testing
High-level Web TestingHigh-level Web Testing
High-level Web Testing
petersergeant
 
Optimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile DevicesOptimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile Devices
Sugree Phatanapherom
 
4. Метапрограмиране
4. Метапрограмиране4. Метапрограмиране
4. Метапрограмиране
Stefan Kanev
 

Similaire à Secure Coding With Wordpress (BarCamp Orlando 2009) (20)

Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
Os Nixon
Os NixonOs Nixon
Os Nixon
 
Ubi comp27nov04
Ubi comp27nov04Ubi comp27nov04
Ubi comp27nov04
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
High-level Web Testing
High-level Web TestingHigh-level Web Testing
High-level Web Testing
 
Concern of Web Application Security
Concern of Web Application SecurityConcern of Web Application Security
Concern of Web Application Security
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
Php My Sql
Php My SqlPhp My Sql
Php My Sql
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
 
Daily notes
Daily notesDaily notes
Daily notes
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
Optimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile DevicesOptimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile Devices
 
Back to basics - PHP_Codesniffer
Back to basics - PHP_CodesnifferBack to basics - PHP_Codesniffer
Back to basics - PHP_Codesniffer
 
Php 3 1
Php 3 1Php 3 1
Php 3 1
 
4. Метапрограмиране
4. Метапрограмиране4. Метапрограмиране
4. Метапрограмиране
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
WordPress Plugin & Theme Security - WordCamp Melbourne - February 2011
 
Php security3895
Php security3895Php security3895
Php security3895
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
Seam Glassfish Slidecast
Seam Glassfish SlidecastSeam Glassfish Slidecast
Seam Glassfish Slidecast
 

Plus de Mark Jaquith

Creating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsCreating and Maintaining WordPress Plugins
Creating and Maintaining WordPress Plugins
Mark Jaquith
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
Mark Jaquith
 

Plus de Mark Jaquith (13)

Cache Money Business
Cache Money BusinessCache Money Business
Cache Money Business
 
Scaling WordPress
Scaling WordPressScaling WordPress
Scaling WordPress
 
Creating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsCreating and Maintaining WordPress Plugins
Creating and Maintaining WordPress Plugins
 
Coding, Scaling, and Deploys... Oh My!
Coding, Scaling, and Deploys... Oh My!Coding, Scaling, and Deploys... Oh My!
Coding, Scaling, and Deploys... Oh My!
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
 
Writing Your First WordPress Plugin
Writing Your First WordPress PluginWriting Your First WordPress Plugin
Writing Your First WordPress Plugin
 
What I Hate About Wordpress
What I Hate About WordpressWhat I Hate About Wordpress
What I Hate About Wordpress
 
Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009Writing Secure Plugins — WordCamp New York 2009
Writing Secure Plugins — WordCamp New York 2009
 
BuddyPress and the Future of WordPress Plugins
BuddyPress and the Future of WordPress PluginsBuddyPress and the Future of WordPress Plugins
BuddyPress and the Future of WordPress Plugins
 
"State of the Word" at WordCamp Mid-Atlantic, by Mark Jaquith
"State of the Word" at WordCamp Mid-Atlantic, by Mark Jaquith"State of the Word" at WordCamp Mid-Atlantic, by Mark Jaquith
"State of the Word" at WordCamp Mid-Atlantic, by Mark Jaquith
 
Wordcamp Charlotte: WordPress Today and Tomorrow
Wordcamp Charlotte: WordPress Today and TomorrowWordcamp Charlotte: WordPress Today and Tomorrow
Wordcamp Charlotte: WordPress Today and Tomorrow
 
Amping up your WordPress Blog
Amping up your WordPress BlogAmping up your WordPress Blog
Amping up your WordPress Blog
 
Contributing To WordPress
Contributing To WordPressContributing To WordPress
Contributing To WordPress
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Secure Coding With Wordpress (BarCamp Orlando 2009)