Class: Watobo::Scanner3::Worker

Inherits:
Object
  • Object
show all
Includes:
Constants, Watobo::Subscriber
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::AUTH_TYPE_UNKNOWN, 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

Methods included from Watobo::Subscriber

#clearEvents, #notify, #subscribe

Constructor Details

#initialize(task_queue, logged_out_queue, prefs) ⇒ Worker

Returns a new instance of Worker.



118
119
120
121
122
123
124
125
126
127
# File 'lib/watobo/core/scanner3.rb', line 118

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.



17
18
19
# File 'lib/watobo/core/scanner3.rb', line 17

def engine
  @engine
end

Instance Method Details

#runObject



30
31
32
33
# File 'lib/watobo/core/scanner3.rb', line 30

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

#running?Boolean

Returns:

  • (Boolean)


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

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

#startObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
# File 'lib/watobo/core/scanner3.rb', line 35

def start
  @engine = Thread.new(@prefs){ |prefs|
    relogin_count = 0
    loop do
      Thread.current[:pos] = "wait for task"
      task = @tasks.deq
      begin
        #puts "RUNNING #{task[:module]}"
        request, response = task[:check].call()

        next if response.nil?

        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
            Thread.current[:pos] = "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
            Thread.current[:pos] = "set state"
            @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? or prefs[:scanlog_name].empty?
          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]}"
        Thread.current[:pos] = "scan_finished"
        notify(:task_finished, task[:module])
      end
      Thread.exit if relogin_count > 5
      relogin_count = 0
    end
  }
end

#stateObject



22
23
24
25
26
27
28
# File 'lib/watobo/core/scanner3.rb', line 22

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

#stopObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/watobo/core/scanner3.rb', line 87

def stop
  @state_mutex.synchronize{ @state = STATE_IDLE }
  begin
    return false if @engine.nil?
    if @engine.alive?
      puts "[#{self}] got stopped"
      Thread.kill @engine
    end
    @engine = nil
  rescue => bang
    puts "!!! could not stop worker !!!"
    puts bang
    puts bang.backtrace
  end
end

#wait_for_login?Boolean

Returns:

  • (Boolean)


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

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