11
Secure Coding Tran Anh Tuan

Grokking TechTalk 9 - Secure Coding

Embed Size (px)

Citation preview

Page 1: Grokking TechTalk 9 - Secure Coding

Secure Coding

Tran Anh Tuan

Page 2: Grokking TechTalk 9 - Secure Coding

whoami• Tran Anh Tuan• Security Engineer (old)• [email protected]• xtuanta on irc.freenode.net

Page 3: Grokking TechTalk 9 - Secure Coding

Content

• Security with PHP• Secure Web Coding - OWASP

•Input Validation•Output Encoding•Authentication•Data Protection

Page 4: Grokking TechTalk 9 - Secure Coding

Security with PHP - CTF Boston Key Party 2015

if (isset($_GET['password'])) { if (is_numeric($_GET['password'])){ if (strlen($_GET['password']) < 4){ if ($_GET['password'] > 999) die('Flag: '.$flag); else print '<p class="alert">Too little</p>'; } else print '<p class="alert">Too long</p>'; } else print '<p class="alert">Password is not numeric</p>';}

Page 5: Grokking TechTalk 9 - Secure Coding

Security with PHP - hint

• Descriptionbool is_numeric ( mixed $var )

Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal (e.g. 0xf4c3b00c), Binary (e.g. 0b10100111001), Octal (e.g. 0777) notation is not allowed.

Page 6: Grokking TechTalk 9 - Secure Coding

Secure Web Coding - OWASP

• OWASP - The Open Web Application Security Project•free and open community focused on improving the security of application•A free resource for any development team

• OWASP Projects•OWASP Top 10•OWASP WebGoat•OWASP ZAP•...

Page 7: Grokking TechTalk 9 - Secure Coding

1. Input Validation

• Conduct all data validation on a trusted system (e.g. The server)• Validate all data from untrusted sources (e.g, other servers)• Data from the client should never be trusted• Where to include validation?

•there should be a centralized input validation?•must be performed on every tier?•but at least, should be checked before use

Page 8: Grokking TechTalk 9 - Secure Coding

2. Output Encoding

• Contextually output encode all data returned to the client• Encode all characters unless they are known to be safe• Eg:

Search results for aaaaaaaaaaaaaaaaa'"<>

Page 9: Grokking TechTalk 9 - Secure Coding

3. Authentication

• Require authentication for all pages and resources• Password hashing must be implemented• Use only HTTP POST requests to transmit authentication credentials• Please use "Invalid username and/or password", in all function

Page 10: Grokking TechTalk 9 - Secure Coding

4. Data Protection

• Remove comments, unnecessary information, documentation,...• and yes, obfuscate, please

Page 11: Grokking TechTalk 9 - Secure Coding

Thanks youMore questions, contact me at [email protected]