Class: Watobo::Scanner3::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/watobo/core/scanner3.rb

Constant Summary collapse

STATE_IDLE =
0x00
STATE_RUNNING =
0x01
STATE_WAIT_FOR_LOGIN =
0x02

Constants included from Constants

Constants::AC_GROUP_APACHE, Constants::AC_GROUP_DOMINO, Constants::AC_GROUP_ENUMERATION, Constants::AC_GROUP_FILE_INCLUSION, Constants::AC_GROUP_FLASH, Constants::AC_GROUP_GENERIC, Constants::AC_GROUP_JBOSS, Constants::AC_GROUP_JOOMLA, Constants::AC_GROUP_SAP, Constants::AC_GROUP_SQL, Constants::AC_GROUP_TYPO3, Constants::AC_GROUP_XSS, Constants::AUTH_TYPE_BASIC, Constants::AUTH_TYPE_DIGEST, Constants::AUTH_TYPE_NONE, Constants::AUTH_TYPE_NTLM, Constants::CHAT_SOURCE_AUTO_SCAN, Constants::CHAT_SOURCE_FUZZER, Constants::CHAT_SOURCE_INTERCEPT, Constants::CHAT_SOURCE_MANUAL, Constants::CHAT_SOURCE_MANUAL_SCAN, Constants::CHAT_SOURCE_PROXY, Constants::CHAT_SOURCE_UNDEF, Constants::DEFAULT_PORT_HTTP, Constants::DEFAULT_PORT_HTTPS, Constants::FINDING_TYPE_HINT, Constants::FINDING_TYPE_INFO, Constants::FINDING_TYPE_UNDEFINED, Constants::FINDING_TYPE_VULN, Constants::FIRST_TIME_FILE, Constants::GUI_REGULAR_FONT_SIZE, Constants::GUI_SMALL_FONT_SIZE, Constants::ICON_PATH, Constants::LOG_DEBUG, Constants::LOG_INFO, Constants::SCAN_CANCELED, Constants::SCAN_FINISHED, Constants::SCAN_PAUSED, Constants::SCAN_STARTED, Constants::TE_CHUNKED, Constants::TE_COMPRESS, Constants::TE_DEFLATE, Constants::TE_GZIP, Constants::TE_IDENTITY, Constants::TE_NONE, Constants::VULN_RATING_CRITICAL, Constants::VULN_RATING_HIGH, Constants::VULN_RATING_INFO, Constants::VULN_RATING_LOW, Constants::VULN_RATING_MEDIUM, Constants::VULN_RATING_UNDEFINED

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_queue, logged_out_queue, prefs) ⇒ Worker

Returns a new instance of Worker.


124
125
126
127
128
129
130
131
132
133
# File 'lib/watobo/core/scanner3.rb', line 124

def initialize(task_queue, logged_out_queue, prefs)
  @engine = nil
  @tasks = task_queue
  @logged_out_queue = logged_out_queue
  @prefs = prefs
  @relogin_count = 0
  @state_mutex = Mutex.new
  @state = STATE_IDLE

end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine


38
39
40
# File 'lib/watobo/core/scanner3.rb', line 38

def engine
  @engine
end

Instance Method Details

#runObject


52
53
54
55
# File 'lib/watobo/core/scanner3.rb', line 52

def run
  @state_mutex.synchronize do @state = STATE_RUNNING; end
  Thread.new{ @engine.run }
end

#running?Boolean

Returns:

  • (Boolean)

117
118
119
120
121
122
# File 'lib/watobo/core/scanner3.rb', line 117

def running?
  @state_mutex.synchronize do
    running = ( @state == STATE_RUNNING )
  end
  running
end

#startObject


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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/watobo/core/scanner3.rb', line 57

def start
  @engine = Thread.new(@tasks, @logged_out_queue, @prefs){ |tasks, logged_out_queue, prefs|
    relogin_count = 0
    loop do
      task = tasks.deq
      begin
        #puts "RUNNING #{task[:module]}"
        request, response = task[:check].call()
        
        
        unless prefs[:logout_signatures].empty? or prefs[:auto_login] == false
          logged_out = false
          prefs[:logout_signatures].each do |sig|
            logged_out = true if response.join =~ /#{sig}/
          end
          
          if logged_out 
            @state_mutex.synchronize do @state = STATE_WAIT_FOR_LOGIN; end
            logged_out_queue.push self
            # stop current thread, will be waked-up by scanner
            Thread.stop
            relogin_count += 1
            @state_mutex.synchronize do @state = STATE_RUNNING; end
            unless relogin_count > 5
               request, response = task[:check].call()
            end 
          end
        end
        
        unless prefs[:scanlog_name].nil?
          chat = Chat.new(request, response, :id => 0, :chat_source => prefs[:chat_source])
          Watobo::DataStore.add_scan_log(chat, prefs[:scanlog_name])
        end
      rescue => bang
        puts "!!! #{task[:module]} !!!"
        puts bang
        puts bang.backtrace if $DEBUG
      ensure
        #puts "FINISHED #{task[:module]}"
        notify(:task_finished, task[:module])
      end
      Thread.exit if relogin_count > 5
      relogin_count = 0
    end
  }
end

#stateObject


44
45
46
47
48
49
50
# File 'lib/watobo/core/scanner3.rb', line 44

def state
  state = nil
  @state_mutex.synchronize do 
    state = @state
  end
  state
end

#stopObject


104
105
106
107
# File 'lib/watobo/core/scanner3.rb', line 104

def stop
  @state = STATE_IDLE
  Thread.kill @engine if @engine.alive?
end

#wait_for_login?Boolean

Returns:

  • (Boolean)

109
110
111
112
113
114
115
# File 'lib/watobo/core/scanner3.rb', line 109

def wait_for_login?
  state = false
  @state_mutex.synchronize do
    state = ( @state == STATE_WAIT_FOR_LOGIN )
  end
  state
end