cvs: presentations / nyphp-security.xml /slides/nyphp-security command-injection.xml db-cmd-injection-stop.xml db-cmd-injection.xml db-esc-chars.xml
defeating-xss.xml esc-shell-args.xml esc-shell-cmds.xml hash-receive.xml hash-send.xml more-info.xml shell-cmd-injection.xml titlepage.xml toc.xml
validate-syntax.xml validate-value.xml xss.xml
| From: | David Sklar | Date: | Thu, 06 Mar 2003 16:45:25 +0000 |
| Subject: | cvs: presentations / nyphp-security.xml /slides/nyphp-security command-injection.xml db-cmd-injection-stop.xml db-cmd-injection.xml db-esc-chars.xml defeating-xss.xml esc-shell-args.xml esc-shell-cmds.xml hash-receive.xml hash-send.xml more-info.xml shell-cmd-injection.xml titlepage.xml toc.xml validate-syntax.xml validate-value.xml xss.xml |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-595@lists.php.net to get a copy of this message | ||
sklar Thu Mar 6 11:45:25 2003 EDT
Added files:
/presentations nyphp-security.xml
/presentations/slides/nyphp-security command-injection.xml
db-cmd-injection-stop.xml
db-cmd-injection.xml
db-esc-chars.xml
defeating-xss.xml
esc-shell-args.xml
esc-shell-cmds.xml
hash-receive.xml hash-send.xml
more-info.xml
shell-cmd-injection.xml
titlepage.xml toc.xml
validate-syntax.xml
validate-value.xml xss.xml
Log:
NYPHP security presentation
Index: presentations/nyphp-security.xml +++ presentations/nyphp-security.xml <presentation> <topic>PHP</topic> <title>PHP Web Application Security Vulnerabilities</title> <event>NYPHP</event> <location>New York, NY</location> <date>February 25, 2003</date> <speaker>David Sklar</speaker> <email>sklar@sklar.com</email> <url>http://www.sklar.com/</url> <slide>slides/nyphp-security/titlepage.xml</slide> <slide>slides/nyphp-security/toc.xml</slide> <slide>slides/nyphp-security/validate-syntax.xml</slide> <slide>slides/nyphp-security/validate-value.xml</slide> <slide>slides/nyphp-security/hash-send.xml</slide> <slide>slides/nyphp-security/hash-receive.xml</slide> <slide>slides/nyphp-security/xss.xml</slide> <slide>slides/nyphp-security/defeating-xss.xml</slide> <slide>slides/nyphp-security/command-injection.xml</slide> <slide>slides/nyphp-security/db-esc-chars.xml</slide> <slide>slides/nyphp-security/db-cmd-injection.xml</slide> <slide>slides/nyphp-security/db-cmd-injection-stop.xml</slide> <slide>slides/nyphp-security/shell-cmd-injection.xml</slide> <slide>slides/nyphp-security/esc-shell-args.xml</slide> <slide>slides/nyphp-security/esc-shell-cmds.xml</slide> <slide>slides/nyphp-security/more-info.xml</slide> </presentation> Index: presentations/slides/nyphp-security/command-injection.xml +++ presentations/slides/nyphp-security/command-injection.xml <slide title="Command Injection"> <list><li>Like XSS, but nasty stuff is intended for your server or database</li></list> <list><li>Different set of code/data delimiters:</li></list> <list marginleft="2em"> <li>Database escapes and wildcard characters</li> <li>Shell escapes, wildcards, and metacharacters</li> </list> </slide> Index: presentations/slides/nyphp-security/db-cmd-injection-stop.xml +++ presentations/slides/nyphp-security/db-cmd-injection-stop.xml <slide title="Stopping Database Command Injection"> <example title="Use the %?% placeholder with PEAR DB"><![CDATA[$sth = $dbh->query('INSERT INTO songs (title,artist) VALUES (?,?)', array($title, $artist));]]></example> <example title="Use %strtr()% to escape %%% and %_% before escaping %'%"><![CDATA[$title = $dbh->quote($title); $title = strtr($title, array('_' => '\_', '%' => '\%')); $sth = $dbh->query("DELETE FROM songs WHERE title LIKE $title");]]></example> <blurb title="You can also use %mysql_real_escape_string()% or %addslashes()%"/> </slide> Index: presentations/slides/nyphp-security/db-cmd-injection.xml +++ presentations/slides/nyphp-security/db-cmd-injection.xml <slide title="Database Command Injection"> <example title="Escape %'% %%% and %_% or users can write their own queries">DELETE FROM songs WHERE title LIKE '$title' // What if $title = "%' OR 'a' = 'a"? DELETE FROM songs WHERE title LIKE '%' OR 'a' = 'a' // All rows are deleted! </example> <example>INSERT INTO songs (title, artist) VALUES ('$title','$artist') // What if $title = "a','b'),('c" and $artist = "d" INSERT INTO songs (title, artist) VALUES ('a','b'),('c','d') // Multiple records inserted! </example> </slide> Index: presentations/slides/nyphp-security/db-esc-chars.xml +++ presentations/slides/nyphp-security/db-esc-chars.xml <slide title="Database Escape Characters"> <example title="Escape %'% to prevent errors">SELECT * FROM songs WHERE title LIKE 'Don't Be Cruel'</example> <example title="Escape %%% and %_% to prevent unexpected wildcarding">SELECT * FROM solutions WHERE concentration LIKE '10%'</example> </slide> Index: presentations/slides/nyphp-security/defeating-xss.xml +++ presentations/slides/nyphp-security/defeating-xss.xml <slide title="Defeating XSS"> <blurb>Before displaying, modify user input to defang scripts:</blurb> <example title="HTML Entities"><![CDATA[$ok = htmlspecialchars($bad,ENT_QUOTES); // < > & " ']]></example> <example title="Parentheses"><![CDATA[$ok = strtr($bad, array('(' => '&040;', ')' => '&041;'));]]></example> <example title="HTML and PHP tags">$ok = strip_tags($bad);</example> <example title="UTF-8 Encodiing">$iso_8859_1 = utf8_decode($bad);</example> </slide> Index: presentations/slides/nyphp-security/esc-shell-args.xml +++ presentations/slides/nyphp-security/esc-shell-args.xml <slide title="Escaping Shell Arguments"> <list> <li>%escapeshellarg()% puts single quotes around an argument and escapes single quotes inside the argument</li> </list> <example>$bad_arg = '-al; rm -rf /'; $ok_arg = escapeshellarg($bad_arg); // list all files, then delete everything! system("ls $bad_arg"); // is there a file called "-al; rm -rf /"? system("ls $ok_arg");</example> </slide> Index: presentations/slides/nyphp-security/esc-shell-cmds.xml +++ presentations/slides/nyphp-security/esc-shell-cmds.xml <slide title="Escaping Shell Commands"> <list> <li>%escapeshellcmd()% escapes more characters, but doesn't quote: %<![CDATA[# & ; ` ' " | * ? ~ < > ^ ( ) [ ] { } $ \ 0x0A 0xFF]]>% </li> </list> <example><![CDATA[$bad_format = 'html <a>'; $also_bad_format = escapeshellarg($bad_format); $ok_format = escapeshellcmd($bad_format); // redirection error system("/usr/local/bin/formatter-$bad_format"); // no such program system("/usr/local/bin/formatter-$also_bad_format"); // runs program with correct argument system("/usr/local/bin/formatter-$ok_format"); ]]></example> </slide> Index: presentations/slides/nyphp-security/hash-receive.xml +++ presentations/slides/nyphp-security/hash-receive.xml <slide title="Detect Data Tampering with Hashes"> <list title="Checking the hash"> <li>When you get the data back, re-hash</li> <li>Compare received and calculated hashes</li> </list> <example title="Receiving and verifying the cookie"> list($cookie_id,$cookie_hash) = explode('-',$_COOKIE['id']); if (md5($secret_word.$cookie_id) == $cookie_hash) { $id = $cookie_id; } else { die('Invalid cookie.'); } </example> </slide> Index: presentations/slides/nyphp-security/hash-send.xml +++ presentations/slides/nyphp-security/hash-send.xml <slide title="Detect Data Tampering with Hashes"> <list title="Sending the hash"> <li>For cookies or hidden form fields</li> <li>Hash the data with a secret word</li> <li>Include the hash in the cookie or form</li> </list> <example title="Sending the cookie">$secret_word = 'salt-baked squid'; $id = 31415926; $hash = md5($secret_word.$id); setcookie('id',$id.'-'.$hash);</example> </slide> Index: presentations/slides/nyphp-security/more-info.xml +++ presentations/slides/nyphp-security/more-info.xml <slide title="More Information"> <list marginbottom="0em" title="PHP Security Resources"> <li>This presentation: <![CDATA[<a href="http://www.sklar.com/talks/nyphp-security">http://www.sklar.com/talks/nyphp-security</a>]]></li> <li>PHP Manual - Chapter 5 ("Security"): <![CDATA[<a href="http://www.php.net/security">http://www.php.net/security</a>]]></li> <li><![CDATA[<a href="http://www.oreilly.com/catalog/progphp">Programming PHP</a>]]> - Chapter 8 ("Security")</li> <li>Open Web Application Security Project: <![CDATA[<a href="http://www.owasp.org">http://www.owasp.org</a>]]></li> <li>PHP and the OWASP Top Ten: <![CDATA[<a href="http://www.sklar.com/page/article/owasp-top-ten">http://www.sklar.com/page/article/owasp-top-ten</a>]]></li> <li><![CDATA[<a href="http://www.oreilly.com/catalog/phpckbk">PHP Cookbook</a>]]> Recipes:</li> </list> <list margintop="0em" marginleft="2em"> <li>Validating Data: 9.7, 14.3</li> <li> XSS: 8.8, 9.8</li> <li>Command Injection: 10.9, 18.20 </li> </list> </slide> Index: presentations/slides/nyphp-security/shell-cmd-injection.xml +++ presentations/slides/nyphp-security/shell-cmd-injection.xml <slide title="Shell Command Injection"> <list> <li>There can't be command injection if there's no command -- do you really need to run an external program?</li> <li>Plenty of PHP built-ins for file operations:</li> </list> <list marginleft="2em"> <li>%mkdir()%</li><li>%rmdir()%</li><li>%copy()%</li> <li>%move()%</li><li>%unlink()%</li><li>%chmod()%</li> <li>%chown()%</li><li>%chgrp()%</li><li>%...%</li> </list> </slide> Index: presentations/slides/nyphp-security/titlepage.xml +++ presentations/slides/nyphp-security/titlepage.xml <slide template="titlepage" fontsize="6em"> <title>Welcome!</title> </slide> Index: presentations/slides/nyphp-security/toc.xml +++ presentations/slides/nyphp-security/toc.xml <slide title="Topics"> <blurb talign="center" fontsize="4em" title="Vulnerabilities"> <blurb></blurb> <blurb title="Validating Data"> Making sure you're getting what you think you're getting </blurb> <blurb title="Preventing Cross-Site Scripting"> Don't let one user run client-side code on another user's browser </blurb> <blurb title="Preventing Command Injection"> Don't let a malicious user monkey around with your database or filesystem. </blurb> </blurb> </slide> Index: presentations/slides/nyphp-security/validate-syntax.xml +++ presentations/slides/nyphp-security/validate-syntax.xml <slide title="Validating Data"> <list> <li> Turn off %register_globals% and rely on %$_GET%, %$_POST%, %$_COOKIE%, and %$_REQUEST%</li> <li> Test submitted data for expected syntax:</li> </list> <example><![CDATA[if (is_numeric($_POST['age'])) { ... }]]></example> <example><![CDATA[if (strlen(trim($_GET['address']))) { ... }]]></example> </slide> Index: presentations/slides/nyphp-security/validate-value.xml +++ presentations/slides/nyphp-security/validate-value.xml <slide title="Testing Values"> <example title="Check allowable range of numeric values"><![CDATA[if (($_GET['age'] < 13) || ($_GET['age'] > 65)) {...}]]></example> <example title="Restrict %&lt;select>% choices to a preset array"><![CDATA[$choices = array(1 => 'Trout', 'Halibut', 'Tilapia'); if (! $choices[$_POST['fish']]) { ... }]]></example> <example title="Use Regular Expressions"><![CDATA[if (! preg_match('/^\d{5}(-\d{4})?$/', $_POST['zipcode'])) { ... } if (! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $_POST['email'])) { ... }]]></example> </slide> Index: presentations/slides/nyphp-security/xss.xml +++ presentations/slides/nyphp-security/xss.xml <slide title="Cross-Site Scripting"> <list> <li>Interactive features of your site are used as unwitting carriers of client-side attacks</li> </list> <list> <li> Anywhere you display external input:</li> </list> <list marginleft="2em"> <li> User profile </li> <li> Forums</li> <li> Error pages (the URL is external input)</li> </list> </slide>
Index: presentations/nyphp-security.xml +++ presentations/nyphp-security.xml <presentation> <topic>PHP</topic> <title>PHP Web Application Security Vulnerabilities</title> <event>NYPHP</event> <location>New York, NY</location> <date>February 25, 2003</date> <speaker>David Sklar</speaker> <email>sklar@sklar.com</email> <url>http://www.sklar.com/</url> <slide>slides/nyphp-security/titlepage.xml</slide> <slide>slides/nyphp-security/toc.xml</slide> <slide>slides/nyphp-security/validate-syntax.xml</slide> <slide>slides/nyphp-security/validate-value.xml</slide> <slide>slides/nyphp-security/hash-send.xml</slide> <slide>slides/nyphp-security/hash-receive.xml</slide> <slide>slides/nyphp-security/xss.xml</slide> <slide>slides/nyphp-security/defeating-xss.xml</slide> <slide>slides/nyphp-security/command-injection.xml</slide> <slide>slides/nyphp-security/db-esc-chars.xml</slide> <slide>slides/nyphp-security/db-cmd-injection.xml</slide> <slide>slides/nyphp-security/db-cmd-injection-stop.xml</slide> <slide>slides/nyphp-security/shell-cmd-injection.xml</slide> <slide>slides/nyphp-security/esc-shell-args.xml</slide> <slide>slides/nyphp-security/esc-shell-cmds.xml</slide> <slide>slides/nyphp-security/more-info.xml</slide> </presentation> Index: presentations/slides/nyphp-security/command-injection.xml +++ presentations/slides/nyphp-security/command-injection.xml <slide title="Command Injection"> <list><li>Like XSS, but nasty stuff is intended for your server or database</li></list> <list><li>Different set of code/data delimiters:</li></list> <list marginleft="2em"> <li>Database escapes and wildcard characters</li> <li>Shell escapes, wildcards, and metacharacters</li> </list> </slide> Index: presentations/slides/nyphp-security/db-cmd-injection-stop.xml +++ presentations/slides/nyphp-security/db-cmd-injection-stop.xml <slide title="Stopping Database Command Injection"> <example title="Use the %?% placeholder with PEAR DB"><![CDATA[$sth = $dbh->query('INSERT INTO songs (title,artist) VALUES (?,?)', array($title, $artist));]]></example> <example title="Use %strtr()% to escape %%% and %_% before escaping %'%"><![CDATA[$title = $dbh->quote($title); $title = strtr($title, array('_' => '\_', '%' => '\%')); $sth = $dbh->query("DELETE FROM songs WHERE title LIKE $title");]]></example> <blurb title="You can also use %mysql_real_escape_string()% or %addslashes()%"/> </slide> Index: presentations/slides/nyphp-security/db-cmd-injection.xml +++ presentations/slides/nyphp-security/db-cmd-injection.xml <slide title="Database Command Injection"> <example title="Escape %'% %%% and %_% or users can write their own queries">DELETE FROM songs WHERE title LIKE '$title' // What if $title = "%' OR 'a' = 'a"? DELETE FROM songs WHERE title LIKE '%' OR 'a' = 'a' // All rows are deleted! </example> <example>INSERT INTO songs (title, artist) VALUES ('$title','$artist') // What if $title = "a','b'),('c" and $artist = "d" INSERT INTO songs (title, artist) VALUES ('a','b'),('c','d') // Multiple records inserted! </example> </slide> Index: presentations/slides/nyphp-security/db-esc-chars.xml +++ presentations/slides/nyphp-security/db-esc-chars.xml <slide title="Database Escape Characters"> <example title="Escape %'% to prevent errors">SELECT * FROM songs WHERE title LIKE 'Don't Be Cruel'</example> <example title="Escape %%% and %_% to prevent unexpected wildcarding">SELECT * FROM solutions WHERE concentration LIKE '10%'</example> </slide> Index: presentations/slides/nyphp-security/defeating-xss.xml +++ presentations/slides/nyphp-security/defeating-xss.xml <slide title="Defeating XSS"> <blurb>Before displaying, modify user input to defang scripts:</blurb> <example title="HTML Entities"><![CDATA[$ok = htmlspecialchars($bad,ENT_QUOTES); // < > & " ']]></example> <example title="Parentheses"><![CDATA[$ok = strtr($bad, array('(' => '&040;', ')' => '&041;'));]]></example> <example title="HTML and PHP tags">$ok = strip_tags($bad);</example> <example title="UTF-8 Encodiing">$iso_8859_1 = utf8_decode($bad);</example> </slide> Index: presentations/slides/nyphp-security/esc-shell-args.xml +++ presentations/slides/nyphp-security/esc-shell-args.xml <slide title="Escaping Shell Arguments"> <list> <li>%escapeshellarg()% puts single quotes around an argument and escapes single quotes inside the argument</li> </list> <example>$bad_arg = '-al; rm -rf /'; $ok_arg = escapeshellarg($bad_arg); // list all files, then delete everything! system("ls $bad_arg"); // is there a file called "-al; rm -rf /"? system("ls $ok_arg");</example> </slide> Index: presentations/slides/nyphp-security/esc-shell-cmds.xml +++ presentations/slides/nyphp-security/esc-shell-cmds.xml <slide title="Escaping Shell Commands"> <list> <li>%escapeshellcmd()% escapes more characters, but doesn't quote: %<![CDATA[# & ; ` ' " | * ? ~ < > ^ ( ) [ ] { } $ \ 0x0A 0xFF]]>% </li> </list> <example><![CDATA[$bad_format = 'html <a>'; $also_bad_format = escapeshellarg($bad_format); $ok_format = escapeshellcmd($bad_format); // redirection error system("/usr/local/bin/formatter-$bad_format"); // no such program system("/usr/local/bin/formatter-$also_bad_format"); // runs program with correct argument system("/usr/local/bin/formatter-$ok_format"); ]]></example> </slide> Index: presentations/slides/nyphp-security/hash-receive.xml +++ presentations/slides/nyphp-security/hash-receive.xml <slide title="Detect Data Tampering with Hashes"> <list title="Checking the hash"> <li>When you get the data back, re-hash</li> <li>Compare received and calculated hashes</li> </list> <example title="Receiving and verifying the cookie"> list($cookie_id,$cookie_hash) = explode('-',$_COOKIE['id']); if (md5($secret_word.$cookie_id) == $cookie_hash) { $id = $cookie_id; } else { die('Invalid cookie.'); } </example> </slide> Index: presentations/slides/nyphp-security/hash-send.xml +++ presentations/slides/nyphp-security/hash-send.xml <slide title="Detect Data Tampering with Hashes"> <list title="Sending the hash"> <li>For cookies or hidden form fields</li> <li>Hash the data with a secret word</li> <li>Include the hash in the cookie or form</li> </list> <example title="Sending the cookie">$secret_word = 'salt-baked squid'; $id = 31415926; $hash = md5($secret_word.$id); setcookie('id',$id.'-'.$hash);</example> </slide> Index: presentations/slides/nyphp-security/more-info.xml +++ presentations/slides/nyphp-security/more-info.xml <slide title="More Information"> <list marginbottom="0em" title="PHP Security Resources"> <li>This presentation: <![CDATA[<a href="http://www.sklar.com/talks/nyphp-security">http://www.sklar.com/talks/nyphp-security</a>]]></li> <li>PHP Manual - Chapter 5 ("Security"): <![CDATA[<a href="http://www.php.net/security">http://www.php.net/security</a>]]></li> <li><![CDATA[<a href="http://www.oreilly.com/catalog/progphp">Programming PHP</a>]]> - Chapter 8 ("Security")</li> <li>Open Web Application Security Project: <![CDATA[<a href="http://www.owasp.org">http://www.owasp.org</a>]]></li> <li>PHP and the OWASP Top Ten: <![CDATA[<a href="http://www.sklar.com/page/article/owasp-top-ten">http://www.sklar.com/page/article/owasp-top-ten</a>]]></li> <li><![CDATA[<a href="http://www.oreilly.com/catalog/phpckbk">PHP Cookbook</a>]]> Recipes:</li> </list> <list margintop="0em" marginleft="2em"> <li>Validating Data: 9.7, 14.3</li> <li> XSS: 8.8, 9.8</li> <li>Command Injection: 10.9, 18.20 </li> </list> </slide> Index: presentations/slides/nyphp-security/shell-cmd-injection.xml +++ presentations/slides/nyphp-security/shell-cmd-injection.xml <slide title="Shell Command Injection"> <list> <li>There can't be command injection if there's no command -- do you really need to run an external program?</li> <li>Plenty of PHP built-ins for file operations:</li> </list> <list marginleft="2em"> <li>%mkdir()%</li><li>%rmdir()%</li><li>%copy()%</li> <li>%move()%</li><li>%unlink()%</li><li>%chmod()%</li> <li>%chown()%</li><li>%chgrp()%</li><li>%...%</li> </list> </slide> Index: presentations/slides/nyphp-security/titlepage.xml +++ presentations/slides/nyphp-security/titlepage.xml <slide template="titlepage" fontsize="6em"> <title>Welcome!</title> </slide> Index: presentations/slides/nyphp-security/toc.xml +++ presentations/slides/nyphp-security/toc.xml <slide title="Topics"> <blurb talign="center" fontsize="4em" title="Vulnerabilities"> <blurb></blurb> <blurb title="Validating Data"> Making sure you're getting what you think you're getting </blurb> <blurb title="Preventing Cross-Site Scripting"> Don't let one user run client-side code on another user's browser </blurb> <blurb title="Preventing Command Injection"> Don't let a malicious user monkey around with your database or filesystem. </blurb> </blurb> </slide> Index: presentations/slides/nyphp-security/validate-syntax.xml +++ presentations/slides/nyphp-security/validate-syntax.xml <slide title="Validating Data"> <list> <li> Turn off %register_globals% and rely on %$_GET%, %$_POST%, %$_COOKIE%, and %$_REQUEST%</li> <li> Test submitted data for expected syntax:</li> </list> <example><![CDATA[if (is_numeric($_POST['age'])) { ... }]]></example> <example><![CDATA[if (strlen(trim($_GET['address']))) { ... }]]></example> </slide> Index: presentations/slides/nyphp-security/validate-value.xml +++ presentations/slides/nyphp-security/validate-value.xml <slide title="Testing Values"> <example title="Check allowable range of numeric values"><![CDATA[if (($_GET['age'] < 13) || ($_GET['age'] > 65)) {...}]]></example> <example title="Restrict %&lt;select>% choices to a preset array"><![CDATA[$choices = array(1 => 'Trout', 'Halibut', 'Tilapia'); if (! $choices[$_POST['fish']]) { ... }]]></example> <example title="Use Regular Expressions"><![CDATA[if (! preg_match('/^\d{5}(-\d{4})?$/', $_POST['zipcode'])) { ... } if (! preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $_POST['email'])) { ... }]]></example> </slide> Index: presentations/slides/nyphp-security/xss.xml +++ presentations/slides/nyphp-security/xss.xml <slide title="Cross-Site Scripting"> <list> <li>Interactive features of your site are used as unwitting carriers of client-side attacks</li> </list> <list> <li> Anywhere you display external input:</li> </list> <list marginleft="2em"> <li> User profile </li> <li> Forums</li> <li> Error pages (the URL is external input)</li> </list> </slide>