<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    如何消除VeraCode檢測(cè)中的SQL Injection Issue(CWE ID 89)

    Veracode是一個(gè)檢測(cè)應(yīng)用程序是否存在安全漏洞的工具,更多細(xì)節(jié)請(qǐng)?jiān)L問(wèn)http://www.veracode.com

    這里主要總結(jié)一下如何消除Veracode檢測(cè)結(jié)果中的SQL Injection issue(CWE ID 89)

    首先,先看看VeraCode對(duì)SQL Injection Issue的定義:
    SQL Injection Description
    SQL injection vulnerabilities occur when data enters an application from an untrusted source and is used to dynamically
    construct a SQL query.  This allows an attacker to manipulate database queries in order to access, modify, or delete arbitrary data.  Depending on the platform, database type, and configuration, it may also be possible to execute administrative operations on the database, access the filesystem, or execute arbitrary system commands.  SQL injection attacks can also be used to subvert authentication and authorization schemes, which would enable an attacker to gain privileged access to restricted portions of the application.

    再瀏覽一下VeraCode對(duì)如何解決這個(gè)問(wèn)題的建議:
    Recommendations
    Several techniques can be used to prevent SQL injection attacks. These techniques complement each other and address
    security at different points in the application. Using multiple techniques provides defense-in-depth and minimizes the likelihood
    of a SQL injection vulnerability.
    Use parameterized prepared statements rather than dynamically constructing SQL queries.  This will prevent the
    database from interpreting the contents of bind variables as part of the query and is the most effective defense against
    SQL injection.
    *
    Validate user-supplied input using positive filters (white lists) to ensure that it conforms to the expected format, using
    centralized data validation routines when possible.
    *
    Normalize all user-supplied data before applying filters or regular expressions, or submitting the data to a database. This
    means that all URL-encoded (%xx), HTML-encoded (&#xx;), or other encoding schemes should be reduced to the
    internal character representation expected by the application. This prevents attackers from using alternate encoding
    schemes to bypass filters.
    *
    When using database abstraction libraries such as Hibernate, do not assume that all methods exposed by the API will
    automatically prevent SQL injection attacks.  Most libraries contain methods that pass arbitrary queries to the database in an unsafe manner.


    通過(guò)對(duì)現(xiàn)有系統(tǒng)的實(shí)踐證明,對(duì)于這類(lèi)SQL Injection Issue,消除時(shí)主要遵循以下幾個(gè)原則:

    1)優(yōu)先使用PreparedSQLStatement,使用它提供的占位符來(lái)填充SQL中的參數(shù)。

    2)因?yàn)镻repareSQLStatement只支持標(biāo)準(zhǔn)的SQL,對(duì)于某些數(shù)據(jù)庫(kù)廠商中中特殊的SQL語(yǔ)句,比如"init device xxxx"等就無(wú)能為力了。
    這是我們可以使用java.text.MessageFormat.format(query, params)來(lái)填充SQL的參數(shù)。
     1      public static String parseQuery( String query, Object[] params)
     2      {
     3          try
     4          {
     5              return MessageFormat.format(query, params);
     6          }
     7          catch( Exception e)
     8          {
     9              System.out.println(e);
    10              return null;
    11          }
    12      }


       3)Veracode會(huì)檢測(cè)傳入SQL的變量是否存在安全隱患(比如是否從文件中讀取的,或者是否從注冊(cè)表里讀取的),這種情況需要重新定義1個(gè)變量,然后將其傳入SQL語(yǔ)句中,看如下例子
          String sql = "create {0} for instance {1} on {2}  = ''{3}''";
           String executedSql 
    = parseQuery(sql,
                     
    new String[]{instance.getDbName(),
                                  instance.getName(),
                                  instance.getDeviceName(),                           
                                  instance.getDeviceSize(),
    });

        這里,instance是一個(gè)已經(jīng)存在的對(duì)象,如果它的變量是從文件中讀取的或者是依賴于程序外部的值,Veracode就認(rèn)為存在安全隱患,因此我們需要做如下的調(diào)整:
     String dbName = FileUtil.removeControlCharacter(instance.getTempdbDbName());
           String instanceName 
    = FileUtil.removeControlCharacter(instance.getName());
           String devName 
    = FileUtil.removeControlCharacter(instance.getTempdbDeviceName());
           String executedSql 
    = parseSQLQuery(IConstants.CREATE_INSTANCE_SYS_TEMP_DB,
                     
    new String[]{dbName,instanceName,devName,deviceSize});
                    
        其中,F(xiàn)ileUtil.removeControlCharacter()的作用是刪除String變量中的控制符,目的就是對(duì)原有的String變量進(jìn)行一次過(guò)濾后,賦值給新的變量,然后再傳給SQL語(yǔ)句。
    public static final String removeControlCharacter(String input)
        {
            
    if (input == null)
            {
                
    return "";
            }
            StringBuilder sb 
    = new StringBuilder();
            
    for (int i=0; i<input.codePointCount(0, input.length()); i++)
            {
                
    int codePoint = input.codePointAt(i);
                
    if(!Character.isISOControl(codePoint))
                {
                    sb.appendCodePoint(codePoint);
                }
            }
            
    return sb.toString();
        }   

    posted on 2011-09-05 14:09 想飛就飛 閱讀(2375) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): J2EE

    評(píng)論

    # re: 如何消除VeraCode檢測(cè)中的SQL Injection Issue(CWE ID 89) 2011-11-24 19:27 liangO

    天,什么東西要求這么嚴(yán)格啊  回復(fù)  更多評(píng)論   

    公告


    導(dǎo)航

    <2011年9月>
    28293031123
    45678910
    11121314151617
    18192021222324
    2526272829301
    2345678

    統(tǒng)計(jì)

    常用鏈接

    留言簿(13)

    我參與的團(tuán)隊(duì)

    隨筆分類(lèi)(69)

    隨筆檔案(68)

    最新隨筆

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲色大成网站www永久男同| 牛牛在线精品观看免费正| 青青草免费在线视频| 亚洲第一成年网站视频| 亚洲自偷自偷在线制服 | 国产亚洲福利一区二区免费看| 中文字幕精品无码亚洲字 | 亚洲国产精品无码久久一区二区| 在线观看免费视频资源| 美美女高清毛片视频黄的一免费 | 亚洲狠狠婷婷综合久久久久| 性做久久久久久免费观看| 久久成人永久免费播放| 亚洲AV无码成人专区| 亚洲人JIZZ日本人| 精品国产免费一区二区| 欧洲精品99毛片免费高清观看 | 曰批全过程免费视频网址| 一级做a免费视频观看网站| 亚洲免费在线视频播放| 国产精品亚洲αv天堂无码| 最新仑乱免费视频| 88xx成人永久免费观看| 国产精品福利片免费看| 亚洲成a人无码亚洲成www牛牛| 精品无码一区二区三区亚洲桃色| 又粗又硬又大又爽免费视频播放| 18pao国产成视频永久免费| eeuss影院ss奇兵免费com| 亚洲一区二区三区高清在线观看 | 亚洲中字慕日产2020| 亚洲精品白浆高清久久久久久| 国产无遮挡吃胸膜奶免费看| 国内精自视频品线六区免费| a级毛片100部免费观看| 一级毛片高清免费播放| 在线视频亚洲一区| 亚洲欧美aⅴ在线资源| 亚洲午夜电影在线观看高清| 久久精品九九亚洲精品| 亚洲AV日韩精品久久久久久久|