SlideShare a Scribd company logo
1 of 33
Сигурност при разработката на
        разширения

         Веселин Николов
             @dzver
          WordCamp Sofia 2012
За мен
За мен


●   Работя с компютри
За мен


●   Работя с компютри
●   В Automattic – WordPress.com
За мен


●   Работя с компютри
●   В Automattic – WordPress.com
●   http://automattic.com/jobs
Сигурност...
Сигурност и плъгини
1. Пароли и хешове
2. XSS
3. XSRF
4. SQL Injection (да, в 2012.)
Пароли и хешове




    ~30%
От сайтовете ползват пароли в
          явен вид.
... и някой знае паролата ви.
Пароли и хешове
1. Пароли
wp_hash_password( 'test' );
-> $P$BGMjSkfCR8K6WlxaIYZvFii89aZ
Пароли и хешове
2. Salts
wp_generate_password( 30 );
-> P*DtBn)1WIGi)ekrSrxwDMXq1*N&Wm
(не пестете байтове)
Пароли и хешове
3. Опасности
error_log( print_r( $_POST ) )
wp_mail( ..., ..., print_r( $_POST ) )
md5( 'нещо предвидимо' )
XSS
XSS
  <?php echo $_GET['name']; ?>


http://myproject.com/index.php?name=<script...
XSS
<?php echo $name; ?>


vs


<?php echo esc_html( $name ); ?>
XSS
●   esc_html
●   esc_url
●   esc_attr
●   esc_js
●   esc_textarea
XSS
Често срещани проблеми:
1. Липса на esc_*
2. Погрешна употреба на esc_* функция
3. Липса или неправилна валидация
4. Typos
XSS
Погрешна употреба на esc_*

<script>
var a = '<?php echo esc_html( $a ) ?>'
var b = <?php echo json_encode( $b ) ?>
XSS
Употреба на esc_* без валидация:

<script src=”<?php echo esc_url( $js ) ?>”>


където
$js = 'http://evil-project.com/js';
XSS
Неправилна валидация на ID-та
1. Проверка вместо cast

if ( intval( $myfield ) )
   echo $myfield;


   // $myfield = '1 <script...';
XSS
Неправилна валидация на ID-та
2. Липса на ^ и $ в regexp

if ( ! preg_match( '/[a-z0-9_-]/i', $myfield ) )
   return 'You are trying to hack me!';


   // $myfield = '<script ...'
XSS
Неправилна валидация на URL


1. . е wildcard.

if ( preg_match ( '!^https?://(www.)*good-host.com/js/!i',
$myjs) ...
// $myjs = http://wwwwgoodhost.com/js
XSS
Неправилна валидация на URL


2. Липсващ /

if ( preg_match ( '!^https?://(www.)?good-host.com!i',
$myjs)
// $myjs = 'http://www.good-host.com.dzver.com/'
XSS
Неправилна валидация на URL


3. Липсващ ^

if ( preg_match ( '!https?://(www.)*good-host.com/js/!i',
$myjs)
// $myjs = 'http://dzver.com/bad.js?http://good-host.com/js/'
XSS
Неправилна валидация на URL


4. Позволен / в хост-а

if ( ! preg_match( '!^https?://[^.]+.whatever.com/.+$!i',
$url ) )
// $myjs = 'http://3254656436/or.whatever.com/evil.js'
// $myjs = '<script.../.whatever.com/'
XSS
Бонус - printf вместо sprintf

esc_html( printf( $name ) )
XSRF
<script>
jQuery.get( '
http://mysite.com/index.php?action=delete_user&user_id=5' );
</script>




<img src=
http://mysite.com/index.php?action=delete_user&user_id=5>
XSRF
Nonces

$nonce= wp_create_nonce( 'my-nonce' );
$url = “...&nonce=$nonce”


if ( ! wp_verify_nonce( $nonce, 'my-nonce' ) )
   wp_redirect()
XSRF
Nonces

wp_nonce_url
wp_nonce_field
check_admin_referer


http://codex.wordpress.org/Wordpress_Nonce_Implementation
http://codex.wordpress.org/Function_Reference/wp_verify_nonce
SQL Injection




$wpdb->prepare()
Защита
●   VaultPress
●   Exploit Scanner

    http://wordpress.org/extend/plugins/exploit-scanner/
Защита
●   Не вярвайте на юзърски инпут
●   Man-in-the-middle HTTPS
●   Внимавайте с редиректите. wp_safe_redirect.
●   Extract може да препокрива променливи
●   Внимавайте с call_user_func, $obj->$var, eval
●   `` винаги с escape_shell_args
?

More Related Content

Viewers also liked

Amazing number3
Amazing number3Amazing number3
Amazing number3
ShdwClaw
 
Shn, permaculture pilot, 2008 april, 21 30
Shn, permaculture pilot, 2008 april, 21 30Shn, permaculture pilot, 2008 april, 21 30
Shn, permaculture pilot, 2008 april, 21 30
joaovox
 
Marketing research of the future
Marketing research of the futureMarketing research of the future
Marketing research of the future
Kristof De Wulf
 
Amazing number3
Amazing number3Amazing number3
Amazing number3
ShdwClaw
 
Power point training the power of visuals
Power point training the power of visualsPower point training the power of visuals
Power point training the power of visuals
Linda Mkhize-Manashe
 
Saint valentine’s story
Saint valentine’s storySaint valentine’s story
Saint valentine’s story
anacarietta
 

Viewers also liked (18)

Culture, Economy, Community: A Cultural Plan for Chatham-Kent
Culture, Economy, Community: A Cultural Plan for Chatham-KentCulture, Economy, Community: A Cultural Plan for Chatham-Kent
Culture, Economy, Community: A Cultural Plan for Chatham-Kent
 
Go &amp; microservices
Go &amp; microservicesGo &amp; microservices
Go &amp; microservices
 
Shn Overview Updated 2009 06 P11 20
Shn Overview   Updated 2009 06 P11 20Shn Overview   Updated 2009 06 P11 20
Shn Overview Updated 2009 06 P11 20
 
Integration
IntegrationIntegration
Integration
 
Bloom Filter Based Routing for Content-Based Publish/Subscribe
Bloom Filter Based Routing for Content-Based Publish/SubscribeBloom Filter Based Routing for Content-Based Publish/Subscribe
Bloom Filter Based Routing for Content-Based Publish/Subscribe
 
Wellness on the Internet
Wellness on the InternetWellness on the Internet
Wellness on the Internet
 
Amazing number3
Amazing number3Amazing number3
Amazing number3
 
Shn, permaculture pilot, 2008 april, 21 30
Shn, permaculture pilot, 2008 april, 21 30Shn, permaculture pilot, 2008 april, 21 30
Shn, permaculture pilot, 2008 april, 21 30
 
HRPS DC Deck
HRPS DC DeckHRPS DC Deck
HRPS DC Deck
 
Marketing research of the future
Marketing research of the futureMarketing research of the future
Marketing research of the future
 
Amazing number3
Amazing number3Amazing number3
Amazing number3
 
Imp Act Presentation
Imp Act PresentationImp Act Presentation
Imp Act Presentation
 
Pertemuan Struktural Desember 2008 Baru
Pertemuan Struktural Desember 2008 BaruPertemuan Struktural Desember 2008 Baru
Pertemuan Struktural Desember 2008 Baru
 
Niagaras Journey Towards A Culture Plan Nov 17
Niagaras Journey Towards A Culture Plan   Nov 17Niagaras Journey Towards A Culture Plan   Nov 17
Niagaras Journey Towards A Culture Plan Nov 17
 
Milieu
MilieuMilieu
Milieu
 
Power point training the power of visuals
Power point training the power of visualsPower point training the power of visuals
Power point training the power of visuals
 
Saint valentine’s story
Saint valentine’s storySaint valentine’s story
Saint valentine’s story
 
Economies in Transition: Leveraing Cultural Assets for Prosperityes In Transi...
Economies in Transition: Leveraing Cultural Assets for Prosperityes In Transi...Economies in Transition: Leveraing Cultural Assets for Prosperityes In Transi...
Economies in Transition: Leveraing Cultural Assets for Prosperityes In Transi...
 

Similar to Сигурност при разработката на WordPress разширения

Similar to Сигурност при разработката на WordPress разширения (9)

5494 n nikolov_zashtita
5494 n nikolov_zashtita5494 n nikolov_zashtita
5494 n nikolov_zashtita
 
5494 n nikolov_zashtita_ppt
5494 n nikolov_zashtita_ppt5494 n nikolov_zashtita_ppt
5494 n nikolov_zashtita_ppt
 
Anti SQLi
Anti SQLiAnti SQLi
Anti SQLi
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
JavaScipt and AJAX Programming
JavaScipt and AJAX ProgrammingJavaScipt and AJAX Programming
JavaScipt and AJAX Programming
 
Web Programming with JavaScript and Ajax
Web Programming with JavaScript and AjaxWeb Programming with JavaScript and Ajax
Web Programming with JavaScript and Ajax
 
B7 t7 arrays
B7 t7 arraysB7 t7 arrays
B7 t7 arrays
 
B7 t7 arrays
B7 t7 arraysB7 t7 arrays
B7 t7 arrays
 
Web applications with Catalyst BG
Web applications with Catalyst BGWeb applications with Catalyst BG
Web applications with Catalyst BG
 

More from Veselin Nikolov (7)

Leadership for Developers, WordCamp Norway
Leadership for Developers, WordCamp NorwayLeadership for Developers, WordCamp Norway
Leadership for Developers, WordCamp Norway
 
WordPress Security @ Vienna WordPress + Drupal Meetup
WordPress Security @ Vienna WordPress + Drupal MeetupWordPress Security @ Vienna WordPress + Drupal Meetup
WordPress Security @ Vienna WordPress + Drupal Meetup
 
Lessons from my work on WordPress.com
Lessons from my work on WordPress.comLessons from my work on WordPress.com
Lessons from my work on WordPress.com
 
Veselin word camp-romania-2014
Veselin word camp-romania-2014Veselin word camp-romania-2014
Veselin word camp-romania-2014
 
Разширения
РазширенияРазширения
Разширения
 
20 начина да си убиеш блога, без да се усетиш
20 начина да си убиеш блога, без да се усетиш20 начина да си убиеш блога, без да се усетиш
20 начина да си убиеш блога, без да се усетиш
 
Блоговете между двата блогкемпа във Велико Търново
Блоговете между двата блогкемпа във Велико ТърновоБлоговете между двата блогкемпа във Велико Търново
Блоговете между двата блогкемпа във Велико Търново
 

Сигурност при разработката на WordPress разширения