|
21 | 21 |
|
22 | 22 | import java.util.Collections; |
23 | 23 | import java.util.HashMap; |
24 | | -import java.util.LinkedHashMap; |
25 | 24 | import java.util.Map; |
26 | 25 | import org.apache.logging.log4j.LogManager; |
27 | 26 | import org.apache.logging.log4j.Logger; |
|
38 | 37 | /** |
39 | 38 | * TODO: maybe implement a more specific UNION based check for Oracle (with table names) |
40 | 39 | * |
41 | | - * <p>The SqlInjectionOracleScanRule identifies Oracle specific SQL Injection vulnerabilities using |
42 | | - * Oracle specific syntax. If it doesn't use Oracle specific syntax, it belongs in the generic |
43 | | - * SQLInjection class! Note the ordering of checks, for efficiency is : 1) Error based (N/A) 2) |
44 | | - * Boolean Based (N/A - uses standard syntax) 3) UNION based (TODO) 4) Stacked (N/A - uses standard |
45 | | - * syntax) 5) Blind/Time Based (Yes) |
| 40 | + * <p>This scan rule identifies Oracle specific SQL Injection vulnerabilities using Oracle specific |
| 41 | + * syntax. If it doesn't use Oracle specific syntax, it belongs in the generic SQLInjection class! |
| 42 | + * Note the ordering of checks, for efficiency is : 1) Error based (N/A) 2) Boolean Based (N/A - |
| 43 | + * uses standard syntax) 3) UNION based (TODO) 4) Stacked (N/A - uses standard syntax) 5) Blind/Time |
| 44 | + * Based (Yes) |
46 | 45 | * |
47 | 46 | * <p>See the following for some great specific tricks which could be integrated here |
48 | 47 | * http://www.websec.ca/kb/sql_injection |
|
60 | 59 | * |
61 | 60 | * @author 70pointer |
62 | 61 | */ |
63 | | -public class SqlInjectionOracleScanRule extends AbstractAppParamPlugin |
| 62 | +public class SqlInjectionOracleTimingScanRule extends AbstractAppParamPlugin |
64 | 63 | implements CommonActiveScanRuleInfo { |
65 | 64 |
|
66 | 65 | private int expectedDelayInMs = 5000; |
67 | 66 |
|
68 | | - private boolean doUnionBased = false; // TODO: use in Union based, when we implement it |
69 | 67 | private boolean doTimeBased = false; |
70 | 68 |
|
71 | | - private int doUnionMaxRequests = 0; // TODO: use in Union based, when we implement it |
72 | 69 | private int doTimeMaxRequests = 0; |
73 | 70 |
|
74 | 71 | /** Oracle one-line comment */ |
75 | 72 | public static final String SQL_ONE_LINE_COMMENT = " -- "; |
76 | 73 |
|
77 | | - /** |
78 | | - * create a map of SQL related error message fragments, and map them back to the RDBMS that they |
79 | | - * are associated with keep the ordering the same as the order in which the values are inserted, |
80 | | - * to allow the more (subjectively judged) common cases to be tested first Note: these should |
81 | | - * represent actual (driver level) error messages for things like syntax error, otherwise we are |
82 | | - * simply guessing that the string should/might occur. |
83 | | - */ |
84 | | - private static final Map<String, String> SQL_ERROR_TO_DBMS = new LinkedHashMap<>(); |
85 | | - |
86 | | - static { |
87 | | - SQL_ERROR_TO_DBMS.put("oracle.jdbc", "Oracle"); |
88 | | - SQL_ERROR_TO_DBMS.put("SQLSTATE[HY", "Oracle"); |
89 | | - SQL_ERROR_TO_DBMS.put("ORA-00933", "Oracle"); |
90 | | - SQL_ERROR_TO_DBMS.put("ORA-06512", "Oracle"); // indicates the line number of an error |
91 | | - SQL_ERROR_TO_DBMS.put("SQL command not properly ended", "Oracle"); |
92 | | - SQL_ERROR_TO_DBMS.put("ORA-00942", "Oracle"); // table or view does not exist |
93 | | - SQL_ERROR_TO_DBMS.put("ORA-29257", "Oracle"); // host unknown |
94 | | - SQL_ERROR_TO_DBMS.put("ORA-00932", "Oracle"); // inconsistent datatypes |
95 | | - |
96 | | - // Note: only Oracle mappings here. |
97 | | - // TODO: is this all?? we need more error messages for Oracle for different languages. PHP |
98 | | - // (oci8), ASP, JSP(JDBC), etc |
99 | | - } |
100 | | - |
101 | 74 | /** the 5 second sleep function in Oracle SQL */ |
102 | 75 | private static String SQL_ORACLE_TIME_SELECT = |
103 | 76 | "SELECT UTL_INADDR.get_host_name('10.0.0.1') from dual union SELECT UTL_INADDR.get_host_name('10.0.0.2') from dual union SELECT UTL_INADDR.get_host_name('10.0.0.3') from dual union SELECT UTL_INADDR.get_host_name('10.0.0.4') from dual union SELECT UTL_INADDR.get_host_name('10.0.0.5') from dual"; |
@@ -167,7 +140,8 @@ public class SqlInjectionOracleScanRule extends AbstractAppParamPlugin |
167 | 140 | } |
168 | 141 |
|
169 | 142 | /** for logging. */ |
170 | | - private static final Logger LOGGER = LogManager.getLogger(SqlInjectionOracleScanRule.class); |
| 143 | + private static final Logger LOGGER = |
| 144 | + LogManager.getLogger(SqlInjectionOracleTimingScanRule.class); |
171 | 145 |
|
172 | 146 | @Override |
173 | 147 | public int getId() { |
@@ -212,23 +186,15 @@ public void init() { |
212 | 186 | if (this.getAttackStrength() == AttackStrength.LOW) { |
213 | 187 | doTimeBased = true; |
214 | 188 | doTimeMaxRequests = 3; |
215 | | - doUnionBased = true; |
216 | | - doUnionMaxRequests = 3; |
217 | 189 | } else if (this.getAttackStrength() == AttackStrength.MEDIUM) { |
218 | 190 | doTimeBased = true; |
219 | 191 | doTimeMaxRequests = 5; |
220 | | - doUnionBased = true; |
221 | | - doUnionMaxRequests = 5; |
222 | 192 | } else if (this.getAttackStrength() == AttackStrength.HIGH) { |
223 | 193 | doTimeBased = true; |
224 | 194 | doTimeMaxRequests = 10; |
225 | | - doUnionBased = true; |
226 | | - doUnionMaxRequests = 10; |
227 | 195 | } else if (this.getAttackStrength() == AttackStrength.INSANE) { |
228 | 196 | doTimeBased = true; |
229 | 197 | doTimeMaxRequests = 100; |
230 | | - doUnionBased = true; |
231 | | - doUnionMaxRequests = 100; |
232 | 198 | } |
233 | 199 | } |
234 | 200 |
|
@@ -256,7 +222,6 @@ public void scan(HttpMessage originalMessage, String paramName, String paramValu |
256 | 222 | long originalTimeUsed = msgTimeBaseline.getTimeElapsedMillis(); |
257 | 223 | // end of timing baseline check |
258 | 224 |
|
259 | | - int countUnionBasedRequests = 0; |
260 | 225 | int countTimeBasedRequests = 0; |
261 | 226 |
|
262 | 227 | LOGGER.debug( |
|
0 commit comments