Class: Ronin::Code::SQL::Injection
- Inherits:
-
StatementList
- Object
- StatementList
- Ronin::Code::SQL::Injection
- Defined in:
- lib/ronin/code/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 ⇒ :integer, ...
readonly
The type of element to escape out of.
-
#expression ⇒ InjectionExpr
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(escape: :integer, place_holder: PLACE_HOLDERS.fetch(escape)) {|(injection)| ... } ⇒ Injection
constructor
Initializes a new SQL injection.
-
#or {|(expr)| ... } ⇒ self
Appends an
OR
expression to the injection. -
#to_sql(terminate: false, **kwargs) ⇒ 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, #order_by, #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, #sleep, #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(escape: :integer, place_holder: PLACE_HOLDERS.fetch(escape)) {|(injection)| ... } ⇒ Injection
Initializes a new SQL injection.
77 78 79 80 81 82 83 84 |
# File 'lib/ronin/code/sql/injection.rb', line 77 def initialize(escape: :integer, place_holder: PLACE_HOLDERS.fetch(escape), &block) @escape = escape @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::Code::SQL::Fields
Instance Attribute Details
#escape ⇒ :integer, ... (readonly)
The type of element to escape out of
53 54 55 |
# File 'lib/ronin/code/sql/injection.rb', line 53 def escape @escape end |
#expression ⇒ InjectionExpr (readonly)
The expression that will be injected
58 59 60 |
# File 'lib/ronin/code/sql/injection.rb', line 58 def expression @expression end |
Instance Method Details
#and {|(expr)| ... } ⇒ self
Appends an AND
expression to the injection.
98 99 100 101 |
# File 'lib/ronin/code/sql/injection.rb', line 98 def and(&block) @expression.and(&block) return self end |
#or {|(expr)| ... } ⇒ self
Appends an OR
expression to the injection.
115 116 117 118 |
# File 'lib/ronin/code/sql/injection.rb', line 115 def or(&block) @expression.or(&block) return self end |
#to_sql(terminate: false, **kwargs) ⇒ String
Converts the SQL injection to SQL.
132 133 134 135 136 137 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 |
# File 'lib/ronin/code/sql/injection.rb', line 132 def to_sql(terminate: false, **kwargs) emitter = emitter(**kwargs) sql = @expression.to_sql(**kwargs) 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 << ';' << emitter.emit_comment else sql = sql[0..-2] end # balance the quotes sql = sql[1..] else if terminate # terminate the expression sql << ';' << emitter.emit_comment end end return sql end |