OWASP安全编码
OWASP
OWASP
Open:开放的、多人维护的
Web
Application
Security
Project : Top 10/Webgoat/Webscarab etc.
https:///
OWASP-Top10
OWASP Top10 风险等级计算方法
A1-Injection
原理:数据被当作代码执行
方式:SQL注入、命令注入等
示例:
/app/accountView?id=1' or '1'='1
代码:String query = "SELECT * FROM accounts WHERE custID='" + ("id") + "'";
http://sensitive/cgi-bin/?doc=%3B/bin/ls
代码:(“cat ;/bin/ls”);
危害:窃取数据、控制服务器
安全编码
安全API
禁止动态拼接、禁止使用系统shell
ESAPI: :OWASP_Enterprise_Security_API
参数化查询:
Java - Standard
String custname = ("customerName");
String query = "SELECT account_balance FROM user_data WHERE user_name = ? ";
PreparedStatement pstmt = ( query );
( 1, custname);
ResultSet results = ( );
PHP - PDO
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);
.NET/C#
String query = "SELECT account_balance FROM user_data WHERE user_name = ?";
try {
mand = new mand(query, connection); (new OleDbParameter("customerName", CustomerName ));
OleDbDataReader reader = (); // …
} catch (OleDbException se) {
// error handling
}
安全过滤/编码
白名单过滤
...0./owasp/esapi/
getValidCreditCard()
getValidDirectoryPath ()
黑名单过滤
元字符
Windows:( ) < > & * ‘| = ? ; [ ] ^ ~ ! . ”% @ / \ : + , `
Linux:{ } ( ) < > & * ‘| = ? ; [ ] $ –# ~ ! . ”% / \ : + , `
https:///php/phpsrc/blob/PHP-
A2-Broken Authentication and Session Management
原理:与身份认证和会话管理相关的应用程序功能没考虑安全性,导致攻击者破坏密码、密钥等去冒充其他用户的身份
方式:
密码没有加密或弱加密(存储/传输)
ID可猜测
ID没有超时限制
示例:
/sale/saleitems?jsessionid=2P0OC2JDPXM0OQSNDLPSKHCJUN2JV&dest=Hawaii
危害:资源窃取,信息泄漏
安全编码
一套单一的强大的认证和会话管理控制系统
ASVS标准:https://ges/3/33/OWASP_Application_
OWASP安全编码建议 来自淘豆网m.daumloan.com转载请标明出处.