Class: Mdm::Workspace

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/mdm/workspace.rb

Constant Summary collapse

DEFAULT =

CONSTANTS

'default'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



78
79
80
# File 'app/models/mdm/workspace.rb', line 78

def self.default
  find_or_create_by_name(DEFAULT)
end

Instance Method Details

#allow_actions_on?(ips) ⇒ Boolean

If limit_to_network is disabled, this will always return true. Otherwise, return true only if all of the given IPs are within the project boundaries.

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/mdm/workspace.rb', line 50

def allow_actions_on?(ips)
  return true unless limit_to_network
  return true unless boundary
  return true if boundary.empty?
  boundaries = Shellwords.split(boundary)
  return true if boundaries.empty? # It's okay if there is no boundary range after all
  given_range = Rex::Socket::RangeWalker.new(ips)
  return false unless given_range # Can't do things to nonexistant IPs
  allowed = false
  boundaries.each do |boundary_range|
    ok_range = Rex::Socket::RangeWalker.new(boundary)
    allowed = true if ok_range.include_range? given_range
  end
  return allowed
end

#boundary_must_be_ip_rangeObject



66
67
68
# File 'app/models/mdm/workspace.rb', line 66

def boundary_must_be_ip_range
  errors.add(:boundary, "must be a valid IP range") unless valid_ip_or_range?(boundary)
end

#credsObject



70
71
72
73
74
75
76
# File 'app/models/mdm/workspace.rb', line 70

def creds
  Mdm::Cred.find(
      :all,
      :include => {:service => :host},
      :conditions => ["hosts.workspace_id = ?", self.id]
  )
end

#default?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/models/mdm/workspace.rb', line 82

def default?
  name == DEFAULT
end

#each_cred(&block) ⇒ Object

This method iterates the creds table calling the supplied block with the cred instance of each entry.



90
91
92
93
94
# File 'app/models/mdm/workspace.rb', line 90

def each_cred(&block)
  creds.each do |cred|
    block.call(cred)
  end
end

#each_host_tag(&block) ⇒ Object



96
97
98
99
100
# File 'app/models/mdm/workspace.rb', line 96

def each_host_tag(&block)
  host_tags.each do |host_tag|
    block.call(host_tag)
  end
end

#host_tagsObject



102
103
104
105
106
107
108
# File 'app/models/mdm/workspace.rb', line 102

def host_tags
  Mdm::Tag.find(
      :all,
      :include => :hosts,
      :conditions => ["hosts.workspace_id = ?", self.id]
  )
end

#unique_web_formsObject



157
158
159
160
161
162
163
164
165
166
167
# File 'app/models/mdm/workspace.rb', line 157

def unique_web_forms
  query = <<-EOQ
        SELECT DISTINCT web_forms.web_site_id, web_forms.path, web_forms.method, web_forms.query  
          FROM hosts, services, web_sites, web_forms  
          WHERE hosts.workspace_id = #{id} AND        
          services.host_id = hosts.id AND         
          web_sites.service_id = services.id AND  
          web_forms.web_site_id = web_sites.id
  EOQ
  Mdm::WebForm.find_by_sql(query)
end

#web_formsObject



110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/mdm/workspace.rb', line 110

def web_forms
  query = <<-EOQ
        SELECT DISTINCT web_forms.*
        FROM hosts, services, web_sites, web_forms
        WHERE hosts.workspace_id = #{id} AND
          services.host_id = hosts.id AND
          web_sites.service_id = services.id AND
          web_forms.web_site_id = web_sites.id
  EOQ
  Mdm::WebForm.find_by_sql(query)
end

#web_pagesObject



122
123
124
125
126
127
128
129
130
131
132
# File 'app/models/mdm/workspace.rb', line 122

def web_pages
  query = <<-EOQ
        SELECT DISTINCT web_pages.*
          FROM hosts, services, web_sites, web_pages
          WHERE hosts.workspace_id = #{id} AND
          services.host_id = hosts.id AND
          web_sites.service_id = services.id AND
          web_pages.web_site_id = web_sites.id
  EOQ
  Mdm::WebPage.find_by_sql(query)
end

#web_sitesObject



134
135
136
137
138
139
140
141
142
143
# File 'app/models/mdm/workspace.rb', line 134

def web_sites
  query = <<-EOQ
        SELECT DISTINCT web_sites.*
          FROM hosts, services, web_sites
          WHERE hosts.workspace_id = #{id} AND
          services.host_id = hosts.id AND
          web_sites.service_id = services.id
  EOQ
  Mdm::WebSite.find_by_sql(query)
end

#web_unique_forms(addrs = nil) ⇒ Object



169
170
171
172
173
174
175
# File 'app/models/mdm/workspace.rb', line 169

def web_unique_forms(addrs=nil)
  forms = unique_web_forms
  if addrs
    forms.reject!{|f| not addrs.include?( f.web_site.service.host.address ) }
  end
  forms
end

#web_vulnsObject



145
146
147
148
149
150
151
152
153
154
155
# File 'app/models/mdm/workspace.rb', line 145

def web_vulns
  query = <<-EOQ
        SELECT DISTINCT web_vulns.*
        FROM hosts, services, web_sites, web_vulns
          WHERE hosts.workspace_id = #{id} AND
          services.host_id = hosts.id AND
          web_sites.service_id = services.id AND
          web_vulns.web_site_id = web_sites.id
  EOQ
  Mdm::WebVuln.find_by_sql(query)
end