Class: Ronin::Code::SQL::Injection

Inherits:
Program
  • Object
show all
Defined in:
lib/ronin/code/sql/injection.rb

Instance Attribute Summary collapse

Attributes inherited from Program

#dialect, #less_parenthesis, #lowercase, #multiline, #newline, #space

Instance Method Summary collapse

Methods inherited from Program

compile, #select, #symbols

Constructor Details

#initialize(options = {}, &block) ⇒ Injection

Returns a new instance of Injection.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ronin/code/sql/injection.rb', line 49

def initialize(options={},&block)
  if options.has_key?(:comment_evasion)
    @comment_evasion = options[:comment_evasion]
  else
    @comment_evasion = false
  end

  if options.has_key?(:case_evasion)
    @case_evasion = options[:case_evasion]
  else
    @case_evasion = false
  end

  @escape = options[:escape]

  if options.has_key?(:close_string)
    @close_string = options[:close_string]
  else
    @close_string = false
  end

  if options.has_key?(:close_parens)
    @close_parens = options[:close_parens]
  else
    @close_parens = false
  end

  if options.has_key?(:end_statement)
    @end_statement = options[:end_statement]
  else
    @end_statement = false
  end

  super(options) do
    @expression = InjectedStatement.new(@dialect)
  end

  instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object (protected)

Relays missed method calls to the injected expression.



192
193
194
195
196
197
198
# File 'lib/ronin/code/sql/injection.rb', line 192

def method_missing(name,*arguments,&block)
  if @expression.public_methods(false).include?(name.to_s)
    return @expression.send(name,*arguments,&block)
  end

  return super(name,*arguments,&block)
end

Instance Attribute Details

#case_evasionObject

Swapcase-Obfusciation



35
36
37
# File 'lib/ronin/code/sql/injection.rb', line 35

def case_evasion
  @case_evasion
end

#close_parensObject

Specifies whether or not to close an open parenthesis



44
45
46
# File 'lib/ronin/code/sql/injection.rb', line 44

def close_parens
  @close_parens
end

#close_stringObject

Specifies whether or not to close an open string



41
42
43
# File 'lib/ronin/code/sql/injection.rb', line 41

def close_string
  @close_string
end

#comment_evasionObject

Comment-Obfustication



32
33
34
# File 'lib/ronin/code/sql/injection.rb', line 32

def comment_evasion
  @comment_evasion
end

#end_statementObject

Specifies whether or not to end a previous statement



47
48
49
# File 'lib/ronin/code/sql/injection.rb', line 47

def end_statement
  @end_statement
end

#escapeObject

Data to escape a previous expression with



38
39
40
# File 'lib/ronin/code/sql/injection.rb', line 38

def escape
  @escape
end

Instance Method Details

#compileObject Also known as: to_s



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ronin/code/sql/injection.rb', line 103

def compile
  injection = super.rstrip

  comment = lambda { [injection, '--'].join(space_token) }

  if (@close_parens && @close_string)
    if injection =~ /'\s*\)$/
      return injection.gsub(/'\s*\)$/,'')
    else
      return comment.call
    end
  end

  if @close_string
    if injection[-1..-1] == "'"
      return injection.chop
    else
      return comment.call
    end
  end

  return injection
end

#expression(&block) ⇒ Object

Returns the expression that will be injected into the effected statement. If a block is given, it will be evaluated within the expression.



94
95
96
97
# File 'lib/ronin/code/sql/injection.rb', line 94

def expression(&block)
  @expression.instance_eval(&block) if block
  return @expression
end

#sql(&block) ⇒ Object



99
100
101
# File 'lib/ronin/code/sql/injection.rb', line 99

def sql(&block)
  @dialect.instance_eval(&block) if block
end