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

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

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

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

    Veracode是一個檢測應用程序是否存在安全漏洞的工具,更多細節請訪問http://www.veracode.com

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

    首先,先看看VeraCode對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對如何解決這個問題的建議:
    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.


    通過對現有系統的實踐證明,對于這類SQL Injection Issue,消除時主要遵循以下幾個原則:

    1)優先使用PreparedSQLStatement,使用它提供的占位符來填充SQL中的參數。

    2)因為PrepareSQLStatement只支持標準的SQL,對于某些數據庫廠商中中特殊的SQL語句,比如"init device xxxx"等就無能為力了。
    這是我們可以使用java.text.MessageFormat.format(query, params)來填充SQL的參數。
     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會檢測傳入SQL的變量是否存在安全隱患(比如是否從文件中讀取的,或者是否從注冊表里讀取的),這種情況需要重新定義1個變量,然后將其傳入SQL語句中,看如下例子
          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是一個已經存在的對象,如果它的變量是從文件中讀取的或者是依賴于程序外部的值,Veracode就認為存在安全隱患,因此我們需要做如下的調整:
     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});
                    
        其中,FileUtil.removeControlCharacter()的作用是刪除String變量中的控制符,目的就是對原有的String變量進行一次過濾后,賦值給新的變量,然后再傳給SQL語句。
    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 想飛就飛 閱讀(2373) 評論(1)  編輯  收藏 所屬分類: J2EE

    評論

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

    天,什么東西要求這么嚴格啊  回復  更多評論   

    公告


    導航

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

    統計

    常用鏈接

    留言簿(13)

    我參與的團隊

    隨筆分類(69)

    隨筆檔案(68)

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲综合激情五月色一区| 曰韩无码AV片免费播放不卡| 女人张腿给男人桶视频免费版| 男男黄GAY片免费网站WWW| 亚洲成av人影院| 思思99re66在线精品免费观看| 青青草国产免费国产是公开| 国产AV无码专区亚洲AVJULIA| 国产va免费精品观看精品| 女人裸身j部免费视频无遮挡| 亚洲成人网在线播放| 亚洲一区无码精品色| 日本三级2019在线观看免费| 色老头综合免费视频| 亚洲av无码不卡久久| 国产成人综合亚洲AV第一页| 两性刺激生活片免费视频| 成在人线av无码免费高潮水| 久久狠狠爱亚洲综合影院| 亚洲精品无码不卡在线播放HE | 国内免费高清在线观看| 久久国产精品免费一区二区三区| 亚洲人成伊人成综合网久久| 亚洲一级片内射网站在线观看| 99视频全部免费精品全部四虎| 亚洲国产免费综合| 亚洲精品理论电影在线观看| 亚洲国产精品一区第二页| 国产免费av片在线播放| 免费观看激色视频网站bd| 两个人www免费高清视频| 亚洲av午夜电影在线观看| 91亚洲精品视频| 国产亚洲精品自在久久| 国产成人免费手机在线观看视频| 免费成人福利视频| 性色午夜视频免费男人的天堂| 一边摸一边爽一边叫床免费视频| 亚洲中文字幕乱码一区| 亚洲激情黄色小说| 亚洲AV日韩AV永久无码免下载 |