Class: Zapr::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/zapr/zap.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, zap_path, timeout) ⇒ Proxy

Returns a new instance of Proxy.



12
13
14
15
# File 'lib/zapr/zap.rb', line 12

def initialize(target, zap_path, timeout)
  @proxy = Zap.new(:target => target, :zap => zap_path)
  @timeout = timeout
end

Instance Method Details

#alertsObject



47
48
49
50
# File 'lib/zapr/zap.rb', line 47

def alerts
  alerts = JSON.parse(@proxy.alerts.view)['alerts']
  alerts.sort_by! { |item| item["risk"] }
end

#attackObject



32
33
34
35
36
37
# File 'lib/zapr/zap.rb', line 32

def attack
  Timeout.timeout(@timeout) do
    @proxy.ascan.start
    sleep(1) until (JSON.parse(@proxy.status_for(:ascan))['status'] == '100')
  end
end

#exit_codeObject



52
53
54
55
56
57
58
# File 'lib/zapr/zap.rb', line 52

def exit_code
  high = 0
  alerts.each do |alert|
    high += 1 if alert['risk'] == 'High'
  end
  return high
end

#pretty_alertsObject



43
44
45
# File 'lib/zapr/zap.rb', line 43

def pretty_alerts
  JSON.pretty_generate(alerts)
end

#shutdownObject



39
40
41
# File 'lib/zapr/zap.rb', line 39

def shutdown
  @proxy.shutdown
end

#spiderObject



25
26
27
28
29
30
# File 'lib/zapr/zap.rb', line 25

def spider
  Timeout.timeout(@timeout) do
    @proxy.spider.start
    sleep(1) until (JSON.parse(@proxy.status_for(:spider))['status'] == '100')
  end
end

#startObject



17
18
19
20
21
22
# File 'lib/zapr/zap.rb', line 17

def start
  Timeout.timeout(@timeout) do
    @proxy.start(:daemon => true)
    sleep(1) until @proxy.running?
  end
end

#summaryObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zapr/zap.rb', line 60

def summary
  sorted = alerts.group_by { |item| item["alert"] }
  Terminal::Table.new :headings => ['Alert', 'Risk', 'URL'] do |t|
    sorted.each_with_index do |(alert_name, grouped_alerts), index|
      urls = []
      grouped_alerts.each do |alert|
        urls << alert['url']
      end
      t.add_separator unless index == 0
      t.add_row [alert_name, grouped_alerts[0]['risk'], urls.join("\n")]
    end
  end
end