Class: Ronin::SQL::Injection
- Inherits:
-
StatementList
- Object
- StatementList
- Ronin::SQL::Injection
- Defined in:
- lib/ronin/sql/injection.rb
Overview
Represents a SQL injection (SQLi).
Constant Summary collapse
- PLACE_HOLDERS =
Default place holder values.
{ integer: 1, decimal: 1.0, string: '1', list: [nil], column: :id }
Instance Attribute Summary collapse
-
#escape ⇒ Object
readonly
The type of element to escape out of.
-
#expression ⇒ Object
readonly
The expression that will be injected.
Attributes inherited from StatementList
Instance Method Summary collapse
-
#and {|(expr)| ... } ⇒ self
Appends an
AND
expression to the injection. -
#initialize(options = {}) {|(injection)| ... } ⇒ Injection
constructor
Initializes a new SQL injection.
-
#or {|(expr)| ... } ⇒ self
Appends an
OR
expression to the injection. -
#to_sql(options = {}) ⇒ String
Converts the SQL injection to SQL.
Methods included from Clauses
#clause, #clauses, #default_values, #from, #full_join, #group_by, #having, #indexed_by, #inner_join, #into, #join, #left_join, #limit, #not_indexed, #offset, #on, #right_join, #set, #top, #union, #union_all, #values, #where
Methods included from Literals
Methods inherited from StatementList
Methods included from Emittable
Methods included from Statements
#delete, #drop_table, #insert, #select, #statement, #update
Methods included from Functions
#abs, #acos, #ascii, #asin, #atan, #atan2, #avg, #bin, #bit_and, #bit_count, #bit_length, #bit_or, #ceil, #ceiling, #char, #char_length, #character_length, #concat, #concat_ws, #conv, #cos, #cot, #count, #degrees, #elt, #exp, #export_set, #field, #find_in_set, #floor, #format, #glob, #greatest, #hex, #insert, #instr, #interval, #lcase, #least, #left, #length, #like, #load_file, #locate, #log, #log10, #lower, #lpad, #ltrim, #make_set, #max, #mid, #min, #mod, #oct, #octet_length, #ord, #pi, #position, #pow, #power, #quote, #radians, #rand, #random, #repeat, #replace, #reverse, #right, #round, #rpad, #rtrim, #sign, #sin, #soundex, #space, #sqrt, #std, #stddev, #strcmp, #substring, #substring_index, #sum, #tan, #trim, #truncate, #ucase, #unhex, #upper
Methods included from Fields
#method_missing, #respond_to_missing?, #to_ary
Constructor Details
#initialize(options = {}) {|(injection)| ... } ⇒ Injection
Initializes a new SQL injection.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ronin/sql/injection.rb', line 80 def initialize(={},&block) @escape = .fetch(:escape,:integer) place_holder = .fetch(:place_holder) do PLACE_HOLDERS.fetch(@escape) end @expression = InjectionExpr.new(place_holder) super(&block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ronin::SQL::Fields
Instance Attribute Details
#escape ⇒ Object (readonly)
The type of element to escape out of
52 53 54 |
# File 'lib/ronin/sql/injection.rb', line 52 def escape @escape end |
#expression ⇒ Object (readonly)
The expression that will be injected
55 56 57 |
# File 'lib/ronin/sql/injection.rb', line 55 def expression @expression end |
Instance Method Details
#and {|(expr)| ... } ⇒ self
Appends an AND
expression to the injection.
104 105 106 107 |
# File 'lib/ronin/sql/injection.rb', line 104 def and(&block) @expression.and(&block) return self end |
#or {|(expr)| ... } ⇒ self
Appends an OR
expression to the injection.
121 122 123 124 |
# File 'lib/ronin/sql/injection.rb', line 121 def or(&block) @expression.or(&block) return self end |
#to_sql(options = {}) ⇒ String
Converts the SQL injection to SQL.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ronin/sql/injection.rb', line 138 def to_sql(={}) emitter = emitter() sql = @expression.to_sql() unless clauses.empty? sql << emitter.space << emitter.emit_clauses(clauses) end unless statements.empty? sql << ';' << emitter.space << emitter.emit_statement_list(self) end case @escape when :string, :list if ([:terminate] || (sql[0,1] != sql[-1,1])) # terminate the expression sql << ';--' else sql = sql[0..-2] end # balance the quotes sql = sql[1..-1] else if [:terminate] # terminate the expression sql << ';--' end end return sql end |