Module: BScan

Includes:
BscanHelper, Mailer
Defined in:
lib/bscan.rb

Constant Summary

Constants included from Mailer

Mailer::ATTACHMENT, Mailer::BODY, Mailer::HEADERS, Mailer::MARKER, Mailer::MESSAGE, Mailer::SIMPLE

Instance Attribute Summary

Attributes included from BscanHelper

#activity, #bscan_config, #modules_only, #stat

Instance Method Summary collapse

Methods included from Mailer

#pv, #send_email, #sv, #ver, #zip_encode

Methods included from BscanHelper

#Log, #add_multi, #copy_vars, #do_scan, #esc, #get_par, #get_url_host_port, #init_internals, #init_stat, #is_module_static, #log, #make_request_socket, #msg_end, #open_in_path, #prop, #read_response_socket, #redirect, #redirect?, #run_modules, #search_path, #search_path_file, #send_only, #send_req, #set_len, #verify_response, #write_issue_state

Instance Method Details

#evt_application_closingObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bscan.rb', line 64

def evt_application_closing
  begin
    Log 2,"BScan.evt_application_closing #{@bscan_config['bscan.smtp.server']} #{@bscan_config['bscan.smtp.to']}"
    @istream.close if @istream
    @stat['end_time'] = Time.now.strftime("%Y-%m-%d %H:%M:%S") 
    send_email if @bscan_config['bscan.smtp.server'] and @bscan_config['bscan.smtp.to']
    @log.close if @log
  rescue Exception => e
    Log 0, "BScan.evt_application_closing Exception: #{e.message}"
    Log 0, e.backtrace.join("\n")
 end
end

#evt_commandline_args(args) ⇒ Object



16
17
18
# File 'lib/bscan.rb', line 16

def evt_commandline_args args
    init_internals JSON.parse(args[0])
end

#evt_http_message(tool_name, is_request, message_info) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bscan.rb', line 22

def evt_http_message(tool_name, is_request, message_info)
  super(tool_name, is_request, message_info)
  if tool_name == 'Scanner'
    if is_request
      Log 2, "#"*70, "# BScan.evt_http_message REQUEST: #{message_info.url.toString}, tool: #{tool_name}", "#"*70
      Log 3, "BScan.evt_http_message #{message_info.req_str}", ""
    else
      Log 2, "# BScan.evt_http_message RESPONSE CODE: #{message_info.statusCode}", ""
      Log 3, "BScan.evt_http_message #{message_info.rsp_str}", ""
    end
  end
  if tool_name == 'Spider'
   if not is_request
      @activity[0] = true
      https = message_info.getProtocol() == "https" ? true : false
      Log 2, "BScan.evt_http_message Passively scanning: #{message_info.url.to_string}"
      do_passive_scan(message_info.getHost(), message_info.getPort(), https, message_info.getRequest(),  message_info.getResponse())
      if (is_in_scope(message_info.url))
        Log 2, "BScan.evt_http_message Actively scanning: #{message_info.url.to_string}"
        isqi = do_active_scan(message_info.getHost(), message_info.getPort(), https, message_info.getRequest(), [])
        @queue.push(isqi)
        run_modules self, message_info
      end
   end
  end  
end

#evt_register_callbacks(cb) ⇒ Object



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/bscan.rb', line 77

def evt_register_callbacks cb
  super(cb)
  @burp ||= self
  begin
    Log 2, "="*30, "BScan.evt_register_callbacks registring, log = #{@cmd_params['logfile']}  ", "="*30 

        
    @queue ||= []
    @inactivity_to = @bscan_config['bscan.inactivity_to']
    @inactivity_to ||= '30'
    @inactivity_to = @inactivity_to.to_i
    # Will exit if @activity = 0  and @queue is empty two times
    if @monitor == nil
      Log 2, "="*30, "BScan.evt_register_callbacks Starting Monitor", "="*30 
      @monitor = Thread.new(@queue, @activity) {|q,a|
        cnt=0;
        while (true) 
          sleep(@inactivity_to/2)        
          q.delete_if {|e| e.getPercentageComplete() == 100}
          if q.length == 0 and not a[0] 
            cnt += 1
          else
            cnt = 0
#            Log 2, "BScan.evt_register_callbacks QUEUE: #{q.length}, Activity: #{a[0]}"
          end
          if cnt > 1
#            Log 2, "BScan.evt_register_callbacks Scanning complete"
            exit_suite
            break
          end
          a[0] = false
        end
      }
    end  
   
    Log 2, '='*30, 'BScan.evt_register_callbacks Params', '='*30
    params = save_config
    params['target.scopeinclude0']='**empty**' # burp can store the previous scope somehow, thus need to clean
    @burp_config.each_pair do |k,v|
      params[k] = v
    end  
    load_config params
    params.each_pair {|k,v| Log 2,"#{k}:#{v}"} # if k =~ /^(scanner|spider)/}
   
#      run_modules
#      exit_suite

    urls = @bscan_config['bscan.url']
    Log 2, "BScan.evt_register_callbacks urls: #{@modules_only} #{urls}"

    if not urls
     Log 0, "BScan.evt_register_callbacks No URL's provided in config. Use bscan.url param. Multiple entries are OK"
     exit_suite 
    end
    
    urls = [urls] if not urls.kind_of?(Array)
    
    urls.each do |u|
      Log 2, "BScan.evt_register_callbacks checking url: #{u}"
      if not is_in_scope(u)
        Log 2, "BScan.evt_register_callbacks including url: #{u}"
        include_in_scope(u)
      end
      Log 2, "BScan.evt_register_callbacks Sending to spider: #{u}"
      send_to_spider(u)
    end
  end
rescue Exception => e
      Log 0, "BScan.evt_register_callbacks Exception: #{e.message}"
      Log 0,  e.backtrace.join("\n")
      exit_suite
end

#evt_scan_issue(issue) ⇒ Object



50
51
52
53
54
# File 'lib/bscan.rb', line 50

def evt_scan_issue issue
  super(issue)
#    Buby::HttpRequestResponseHelper.implant(issue.http_messages)
  write_issue_state issue
end

#sync_save_state(issue) ⇒ Object



56
57
58
59
60
61
# File 'lib/bscan.rb', line 56

def sync_save_state issue
  @sync_state_mutex ||= Mutex.new
  @sync_state_mutex.synchronize {
    save_state(@sstream) if @sstream and issue.severity =~ /(High)/
  }
end