JSP·ÀSQL×¢Èë¹¥»÷
µÚÒ»ÖÖ²ÉÓÃÔ¤±àÒëÓï¾ä¼¯£¬ËüÄÚÖÃÁË´¦ÀíSQL×¢ÈëµÄÄÜÁ¦£¬Ö»ÒªÊ¹ÓÃËüµÄsetString·½·¨´«Öµ¼´¿É£º
String sql= "select * from users where username=? and password=?;
PreparedStatement preState = conn.prepareStatement(sql);
preState.setString(1, userName);
preState.setString(2, password);
ResultSet rs = preState.executeQuery();
...
µÚ¶þÖÖÊDzÉÓÃÕýÔò±í´ïʽ½«°üº¬ÓÐ µ¥ÒýºÅ(')£¬·ÖºÅ(;) ºÍ ×¢ÊÍ·ûºÅ(--)µÄÓï¾ä¸øÌæ»»µôÀ´·ÀÖ¹SQL×¢Èë
Àý1
public static String TransactSQLInjection(String str)
{
return str.replaceAll(".*([';]+|(--)+).*", " ");
}
userName=TransactSQLInjection(userName);
password=TransactSQLInjection(password);
String sql="select * from users where username='"+userName+"' and password='"+password+"' "
Statement sta = conn.createStatement();
ResultSet rs = sta.executeQuery(sql);
...
»òÕßÀý2
ÒªÒýÈëµÄ°ü£º
import java.util.regex.*;
ÕýÔò±í´ïʽ£º
private String CHECKSQL = “^(.+)\\sand\\s(.+)|(.+)\\sor(.+)\\s$”;
ÅжÏÊÇ·ñÆ¥Å䣺
Pattern.matches(CHECKSQL,targerStr);
ÏÂÃæÊǾßÌåµÄÕýÔò±í´ïʽ£º
¼ì²âSQL meta-charactersµÄÕýÔò±í´ïʽ £º
/(\%27)|(\’)|(\-\-)|(\%23)|(#)/ix
ÐÞÕý¼ì²âSQL meta-charactersµÄÕýÔò±í´ïʽ£º/((\%3D)|(=))[^\n]*((\%27)|(\’)|(\-\-)|(\%3B)|(:))/i
µäÐ굀 SQL ×¢Èë¹¥»÷µÄÕýÔò±í´ïʽ£º/\w*((\%27)|(\’))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/ix
¼ì²âSQL×¢È룬UNION²éѯ¹Ø¼ü×ÖµÄÕýÔò±í´ïʽ £º/((\%27)|(\’))union/ix(\%27)|(\’)
¼ì²âMS SQL Server SQL×¢Èë¹¥»÷µÄÕýÔò±í´ïʽ£º
/exec(\s|\+)+(s|x)p\w+/ix
µÈµÈ…..
µÚÈýÖÖÊÇ×Ö·û´®¹ýÂË
Àý1
sql_inj.javaΪһ¸ö¸Ä½øµÄ·À×¢Èëbean£¬±àÒëºó½«classÎļþ·ÅÔÚtomcatµÄclassesϵÄsql_injĿ¼ÖС£
sql_inj.java´úÂ룺
====================================================================
package sql_inj;
import java.net.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import java.lang.String;
public class sql_inj{
public static boolean sql_inj(String str)
{
String inj_str = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|t
Ïà¹ØÎĵµ£º
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. Ö´ÐÐsqlÓï¾ä
int sqlite3_exec(sqlite3*£¬ const char *sql£¬ sqlite3_callbacksql Óï·¨
£¬ void *£¬ char **errmsg );
Õâ¾ÍÊÇÖ´ÐÐÒ»Ìõ sql Óï¾äµÄº¯Êý¡£
µÚ1¸ö²ÎÊý²»ÔÙ˵ÁË£¬ÊÇÇ°Ãæopenº¯ÊýµÃµ½µÄÖ¸Õ롣˵ÁËÊǹؼüÊý¾Ý½á¹¹¡£
µÚ2¸ö²ÎÊýconst char ......
¸ßЧµÄSQLÓï¾äÖ®·ÖÎöº¯Êý--row_number() /rank()/dense_rank
Oracle·ÖÎöº¯ÊýRANK(),ROW_NUMBER(),LAG()µÈµÄʹÓ÷½·¨
ROW_NUMBER() OVER (PARTITION BY COL1 ORDER BY COL2)
±íʾ¸ù¾ÝCOL1·Ö×飬ÔÚ·Ö×éÄÚ²¿¸ù¾Ý COL2ÅÅÐò
¶øÕâ¸öÖµ¾Í±íʾÿ×éÄÚ²¿ÅÅÐòºóµÄ˳Ðò±àºÅ£¨×éÄÚÁ¬ÐøµÄΨһµÄ£©
RANK() ÀàËÆ£¬²»¹ýRANK ÅÅÐòµÄÊ ......
²é¿´»ØÊÕÕ¾Öбí
select object_name,original_name,partition_name,type,ts_name,createtime,droptime from recyclebin;
»Ö¸´±í
SQL>flashback table test_drop to before drop;»ò
SQL>flashback table "BIN$b+XkkO1RS5K10uKo9BfmuA==$0" to before drop;
......
±ístuinfo£¬ÓÐÈý¸ö×Ö¶Îrecno(×ÔÔö),stuid,stuname
½¨¸Ã±íµÄSqlÓï¾äÈçÏ£º
CREATE TABLE [StuInfo] (
[recno] [int] IDENTITY (1, 1) NOT NULL ,
[stuid] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[stuname] [varchar] (10) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
1.--²éijһÁ ......
´íÎó£º
String realPath = " http:// " + request.getServerName() + " : " + request.getServerPort() + request.getContextPath();
String realPath = " http:// " + request.getSer ......