AUTHOR : KJ0231320

TEAM : I.S.T.O


以下是对ORACLE HINT FUZZ的时候发现的!


select /*+ NO_PUSH_PRED(* dual  --)*/   * from dual



以还有好些HINT都会出现如此语法错误或者会使当前Connection会话中断


研究了好久都没发现什么细节原因,跟踪不下去了。搁着快有半年了扔出来,后来者可以走少些弯路

顺便给出FUZZ的代码


  1. package cn.isto.fuzz.oracle;

  2. import java.sql.*;
  3. import java.util.List;

  4. public class SQLHintFuzzer {
  5.     private Object[] fuzzData=new Object[38];
  6.     private String[] hints = new String[182];

  7.     private Connection conn;
  8.     Statement stmt = null;

  9.     private String url;
  10.     private String user;
  11.     private String pass;
  12.     private String sql1;

  13.     private String loopCreateString(String initStr,int count){
  14.         StringBuilder tempsb = new StringBuilder();
  15.         for(int i=0;i<count;i++){
  16.             tempsb.append(initStr);
  17.         }
  18.         return tempsb.toString();
  19.     }
  20.     public SQLHintFuzzer(){
  21.         fuzzData[0]=-1;
  22.         fuzzData[1]=-2;
  23.         fuzzData[2]=0;
  24.         fuzzData[3]=1;
  25.         fuzzData[4]=2;
  26.         fuzzData[5]=2147483647;
  27.         fuzzData[6]=-2147483647;
  28.         fuzzData[7]=2147483648l;
  29.         fuzzData[8]=-2147483648;
  30.         fuzzData[9]=Long.MAX_VALUE;
  31.         fuzzData[10]=Long.MIN_VALUE;
  32.         fuzzData[11]=loopCreateString("'')",1);
  33.         fuzzData[12]=loopCreateString("/"",1);
  34.         fuzzData[13]=loopCreateString("--",1);
  35.         fuzzData[14]=loopCreateString("/*",1);
  36.         fuzzData[15]=loopCreateString("%s%s%s%s%s%s%s",1);
  37.         fuzzData[16]=loopCreateString("%x%x%x%x%x%x",1);
  38.         fuzzData[17]=loopCreateString("%d%d%d%d%d%d",1);
  39.         fuzzData[18]=loopCreateString("A",30);
  40.         fuzzData[19]=loopCreateString("A",100);
  41.         fuzzData[20]=loopCreateString("A",128);
  42.         fuzzData[21]=loopCreateString("A",256);
  43.         fuzzData[22]=loopCreateString("A",512);
  44.         fuzzData[23]=loopCreateString("A",1024);
  45.         fuzzData[24]=loopCreateString("A",2048);
  46.         fuzzData[25]=loopCreateString("A",3000);
  47.         fuzzData[26]=loopCreateString("A",4000);
  48.         fuzzData[27]=loopCreateString("A",5000);
  49.         fuzzData[28]=loopCreateString("A",6000);
  50.         fuzzData[29]=loopCreateString("A",8000);
  51.         fuzzData[30]=loopCreateString("A",10000);
  52.         fuzzData[31]=loopCreateString("A",15000);
  53.         fuzzData[32]=loopCreateString("A",20000);
  54.         fuzzData[33]=loopCreateString("A",25000);
  55.         fuzzData[34]=loopCreateString("A",30000);
  56.         fuzzData[35]=loopCreateString("A",32767);
  57.         fuzzData[36]=loopCreateString("SYS",1);
  58.         fuzzData[37]=loopCreateString("ROWID",1);

  59.         hints[0]="ALL_ROWS";
  60.         hints[1]="AND_EQUAL";
  61.         hints[2]="ANTIJOIN";
  62.         hints[3]="APPEND";
  63.         hints[4]="BITMAP";
  64.         hints[5]="BUFFER";
  65.         hints[6]="BYPASS_RECURSIVE_CHECK";
  66.         hints[7]="BYPASS_UJVC";
  67.         hints[8]="CACHE";
  68.         hints[9]="CACHE_CB";
  69.         hints[10]="CACHE_TEMP_TABLE";
  70.         hints[11]="CARDINALITY";
  71.         hints[12]="CHOOSE";
  72.         hints[13]="CIV_GB";
  73.         hints[14]="COLLECTIONS_GET_REFS";
  74.         hints[15]="CPU_COSTING";
  75.         hints[16]="CUBE_GB";
  76.         hints[17]="CURSOR_SHARING_EXACT";
  77.         hints[18]="DEREF_NO_REWRITE";
  78.         hints[19]="DML_UPDATE";
  79.         hints[20]="DOMAIN_INDEX_NO_SORT";
  80.         hints[21]="DOMAIN_INDEX_SORT";
  81.         hints[22]="DRIVING_SITE";
  82.         hints[23]="DYNAMIC_SAMPLING";
  83.         hints[24]="DYNAMIC_SAMPLING_EST_CDN";
  84.         hints[25]="EXPAND_GSET_TO_UNION";
  85.         hints[26]="FACT";
  86.         hints[27]="FIRST_ROWS";
  87.         hints[28]="FORCE_SAMPLE_BLOCK";
  88.         hints[29]="FULL";
  89.         hints[30]="GBY_CONC_ROLLUP";
  90.         hints[31]="GLOBAL_TABLE_HINTS";
  91.         hints[32]="HASH";
  92.         hints[33]="HASH_AJ";
  93.         hints[34]="HASH_SJ";
  94.         hints[35]="HWM_BROKERED";
  95.         hints[36]="IGNORE_ON_CLAUSE";
  96.         hints[37]="IGNORE_WHERE_CLAUSE";
  97.         hints[38]="INDEX_ASC";
  98.         hints[39]="INDEX_COMBINE";
  99.         hints[40]="INDEX_DESC";
  100.         hints[41]="INDEX_FFS";
  101.         hints[42]="INDEX_JOIN";
  102.         hints[43]="INDEX_RRS";
  103.         hints[44]="INDEX_SS";
  104.         hints[45]="INDEX_SS_ASC";
  105.         hints[46]="INDEX_SS_DESC";
  106.         hints[47]="INLINE";
  107.         hints[48]="LEADING";
  108.         hints[49]="LIKE_EXPAND";
  109.         hints[50]="LOCAL_INDEXES";
  110.         hints[51]="MATERIALIZE";
  111.         hints[52]="MERGE";
  112.         hints[53]="MERGE_AJ";
  113.         hints[54]="MERGE_SJ";
  114.         hints[55]="MV_MERGE";
  115.         hints[56]="NESTED_TABLE_GET_REFS";
  116.         hints[57]="NESTED_TABLE_SET_REFS";
  117.         hints[58]="NESTED_TABLE_SET_SETID";
  118.         hints[59]="NL_AJ";
  119.         hints[60]="NL_SJ";
  120.         hints[61]="NO_ACCESS";
  121.         hints[62]="NO_BUFFER";
  122.         hints[63]="NO_EXPAND";
  123.         hints[64]="NO_EXPAND_GSET_TO_UNION";
  124.         hints[65]="NO_FACT";
  125.         hints[66]="NO_FILTERING";
  126.         hints[67]="NO_INDEX";
  127.         hints[68]="NO_MERGE";
  128.         hints[69]="NO_MONITORING";
  129.         hints[70]="NO_ORDER_ROLLUPS";
  130.         hints[71]="NO_PRUNE_GSETS";
  131.         hints[72]="NO_PUSH_PRED";
  132.         hints[73]="NO_PUSH_SUBQ";
  133.         hints[74]="NO_QKN_BUFF";
  134.         hints[75]="NO_SEMIJOIN";
  135.         hints[76]="NO_STATS_GSETS";
  136.         hints[77]="NO_UNNEST";
  137.         hints[78]="NOAPPEND";
  138.         hints[79]="NOCACHE";
  139.         hints[80]="NOCPU_COSTING";
  140.         hints[81]="NOPARALLEL";
  141.         hints[82]="NOPARALLEL_INDEX";
  142.         hints[83]="NOREWRITE";
  143.         hints[84]="OR_EXPAND";
  144.         hints[85]="ORDERED";
  145.         hints[86]="ORDERED_PREDICATES";
  146.         hints[87]="OVERFLOW_NOMOVE";
  147.         hints[88]="PARALLEL";
  148.         hints[89]="PARALLEL_INDEX";
  149.         hints[90]="PIV_GB";
  150.         hints[91]="PIV_SSF";
  151.         hints[92]="PQ_DISTRIBUTE";
  152.         hints[93]="PQ_MAP";
  153.         hints[94]="PQ_NOMAP";
  154.         hints[95]="PUSH_PRED";
  155.         hints[96]="PUSH_SUBQ";
  156.         hints[97]="REMOTE_MAPPED";
  157.         hints[98]="RESTORE_AS_INTERVALS";
  158.         hints[99]="REWRITE";
  159.         hints[100]="RULE";
  160.         hints[101]="SAVE_AS_INTERVALS";
  161.         hints[102]="SCN_ASCENDING";
  162.         hints[103]="SELECTIVITY";
  163.         hints[104]="SEMIJOIN";
  164.         hints[105]="SEMIJOIN_DRIVER";
  165.         hints[106]="SKIP_EXT_OPTIMIZER";
  166.         hints[107]="SQLLDR";
  167.         hints[108]="STAR";
  168.         hints[109]="STAR_TRANSFORMATION";
  169.         hints[110]="SWAP_JOIN_INPUTS";
  170.         hints[111]="SYS_DL_CURSOR";
  171.         hints[112]="SYS_PARALLEL_TXN";
  172.         hints[113]="SYS_RID_ORDER";
  173.         hints[114]="TIV_GB";
  174.         hints[115]="TIV_SSF";
  175.         hints[116]="UNNEST";
  176.         hints[117]="USE_ANTI";
  177.         hints[118]="USE_CONCAT";
  178.         hints[119]="USE_HASH";
  179.         hints[120]="USE_MERGE";
  180.         hints[121]="USE_NL";
  181.         hints[122]="USE_SEMI";
  182.         hints[123]="USE_TTT_FOR_GSETS";
  183.         hints[124]="BYPASS_RECURSIVE_CHECK";
  184.         hints[125]="BYPASS_UJVC";
  185.         hints[126]="CACHE_CB";
  186.         hints[127]="CACHE_TEMP_TABLE";
  187.         hints[128]="CIV_GB";
  188.         hints[129]="COLLECTIONS_GET_REFS";
  189.         hints[130]="CUBE_GB";
  190.         hints[131]="CURSOR_SHARING_EXACT";
  191.         hints[132]="DEREF_NO_REWRITE";
  192.         hints[133]="DML_UPDATE";
  193.         hints[134]="DOMAIN_INDEX_NO_SORT";
  194.         hints[135]="DOMAIN_INDEX_SORT";
  195.         hints[136]="DYNAMIC_SAMPLING";
  196.         hints[137]="DYNAMIC_SAMPLING_EST_CDN";
  197.         hints[138]="EXPAND_GSET_TO_UNION";
  198.         hints[139]="FORCE_SAMPLE_BLOCK";
  199.         hints[140]="GBY_CONC_ROLLUP";
  200.         hints[141]="GLOBAL_TABLE_HINTS";
  201.         hints[142]="HWM_BROKERED";
  202.         hints[143]="IGNORE_ON_CLAUSE";
  203.         hints[144]="IGNORE_WHERE_CLAUSE";
  204.         hints[145]="INDEX_RRS";
  205.         hints[146]="INDEX_SS";
  206.         hints[147]="INDEX_SS_ASC";
  207.         hints[148]="INDEX_SS_DESC";
  208.         hints[149]="LIKE_EXPAND";
  209.         hints[150]="LOCAL_INDEXES";
  210.         hints[151]="MV_MERGE";
  211.         hints[152]="NESTED_TABLE_GET_REFS";
  212.         hints[153]="NESTED_TABLE_SET_REFS";
  213.         hints[154]="NESTED_TABLE_SET_SETID";
  214.         hints[155]="NO_EXPAND_GSET_TO_UNION";
  215.         hints[156]="NO_FACT";
  216.         hints[157]="NO_FILTERING";
  217.         hints[158]="NO_ORDER_ROLLUPS";
  218.         hints[159]="NO_PRUNE_GSETS";
  219.         hints[160]="NO_STATS_GSETS";
  220.         hints[161]="NO_UNNEST";
  221.         hints[162]="NOCPU_COSTING";
  222.         hints[163]="OVERFLOW_NOMOVE";
  223.         hints[164]="PIV_GB";
  224.         hints[165]="PIV_SSF";
  225.         hints[166]="PQ_MAP";
  226.         hints[167]="PQ_NOMAP";
  227.         hints[168]="REMOTE_MAPPED";
  228.         hints[169]="RESTORE_AS_INTERVALS";
  229.         hints[170]="SAVE_AS_INTERVALS";
  230.         hints[171]="SCN_ASCENDING";
  231.         hints[172]="SKIP_EXT_OPTIMIZER";
  232.         hints[173]="SQLLDR";
  233.         hints[174]="SYS_DL_CURSOR";
  234.         hints[175]="SYS_PARALLEL_TXN";
  235.         hints[176]="SYS_RID_ORDER";
  236.         hints[177]="TIV_GB";
  237.         hints[178]="TIV_SSF";
  238.         hints[179]="UNNEST";
  239.         hints[180]="USE_TTT_FOR_GSETS";


  240.         //sql1 =    "select /*+" + orahint + "("+ +") */ * from dual";
  241.         //fuzzData[38]=null;

  242.         /*
  243.         numberFuzzData[0]=-1;
  244.         numberFuzzData[1]=-2;
  245.         numberFuzzData[2]=0;
  246.         numberFuzzData[3]=1;
  247.         numberFuzzData[4]=2;
  248.         numberFuzzData[5]=2147483647;
  249.         numberFuzzData[6]=-2147483647;
  250.         numberFuzzData[7]=2147483648l;
  251.         numberFuzzData[8]=-2147483648;
  252.         numberFuzzData[9]=Long.MAX_VALUE;
  253.         numberFuzzData[10]=Long.MIN_VALUE;

  254.         fuzzData[0]=loopCreateString("''",1);
  255.         strFuzzData[1]=loopCreateString("/"",1);
  256.         strFuzzData[2]=loopCreateString("%s%s%s%s%s%s%s",1);
  257.         strFuzzData[3]=loopCreateString("%x%x%x%x%x%x",1);
  258.         strFuzzData[4]=loopCreateString("%d%d%d%d%d%d",1);
  259.         strFuzzData[5]=loopCreateString("A",30);
  260.         strFuzzData[6]=loopCreateString("A",100);
  261.         strFuzzData[7]=loopCreateString("A",128);
  262.         strFuzzData[8]=loopCreateString("A",256);
  263.         strFuzzData[9]=loopCreateString("A",512);
  264.         strFuzzData[10]=loopCreateString("A",1024);
  265.         strFuzzData[11]=loopCreateString("A",2048);
  266.         strFuzzData[12]=loopCreateString("A",3000);
  267.         strFuzzData[13]=loopCreateString("A",4000);
  268.         strFuzzData[14]=loopCreateString("A",5000);
  269.         strFuzzData[15]=loopCreateString("A",6000);
  270.         strFuzzData[16]=loopCreateString("A",8000);
  271.         strFuzzData[17]=loopCreateString("A",10000);
  272.         strFuzzData[18]=loopCreateString("A",15000);
  273.         strFuzzData[19]=loopCreateString("A",20000);
  274.         strFuzzData[20]=loopCreateString("A",25000);
  275.         strFuzzData[21]=loopCreateString("A",30000);
  276.         strFuzzData[22]=loopCreateString("A",32767);
  277.         strFuzzData[23]=null;
  278.         strFuzzData[24]=loopCreateString("SYS",1);
  279.         strFuzzData[25]=loopCreateString("ROWID",1);
  280.         */
  281.     }
  282.     public void login(String host,int port,String user,String pass,String sid) throws SQLException, ClassNotFoundException{
  283.         Class.forName("oracle.jdbc.driver.OracleDriver");
  284.         String url="jdbc:oracle:thin:@"+host+":"+port+":"+sid;
  285.         this.url=url;
  286.         this.user = user;
  287.         this.pass = pass;
  288.         connection();
  289.     }
  290.     private void connection() throws SQLException{
  291.         conn = DriverManager.getConnection(url,user,pass);
  292.     }

  293.     public void logout(){
  294.         closeAll(conn,null,null);
  295.     }
  296.     private void closeAll(Connection con,Statement stmt,ResultSet rs){
  297.         if(rs!=null){try{rs.close();}catch (Exception e) {}}
  298.         if(stmt!=null){try{stmt.close();}catch (Exception e) {}}
  299.         if(con!=null){try{con.close();}catch (Exception e) {}}
  300.     }


  301.     public void fuzz(){
  302.         try {
  303.             stmt = conn.createStatement();
  304.         } catch (SQLException e) {
  305.             e.printStackTrace();
  306.         }
  307.         for(int hintsc = 40 ; hintsc<hints.length; hintsc++){
  308.             System.out.println("FUZZ : "+hints[hintsc]);
  309.             for(int fuzzDc = 0; fuzzDc< fuzzData.length;fuzzDc++){
  310.                 startFuzz(stmt,hints[hintsc]+"( "+ fuzzData[fuzzDc] +" )");
  311.             }
  312.         }
  313.     }
  314.     private void startFuzz(Statement fuzzstmt,String run){

  315.         try {
  316.             sql1 = "select /*+ "+run+"*/ * from dual";
  317.             fuzzstmt.execute(sql1);
  318.             Thread.sleep(1000);
  319.         } catch (Exception e) {
  320.             System.out.println(e.getMessage());
  321.             if(e.getMessage().indexOf("socket")>-1){
  322.                 try {
  323.                     connection();
  324.                     stmt = conn.createStatement();
  325.                 } catch (SQLException e1) {
  326.                     System.out.println("error crash");
  327.                 }
  328.             }
  329.             catch0day(e.getMessage(),sql1);
  330.         }
  331.     }
  332.     private void catch0day(String e,String run){
  333.         System.out.println(e+"---"+run);
  334.     }
  335.     public static void main(String[] args) throws SQLException, ClassNotFoundException{

  336.         SQLHintFuzzer shf = new SQLHintFuzzer();
  337.         shf.login("kj021320PC"1521"kj021320""kj021320""ORCL");
  338.         shf.fuzz();
  339.         shf.logout();
  340.     }
  341. }