Module: Cvss3Vectors

Included in:
Cvss3::Rating
Defined in:
lib/cvss_rating/cvss3_vectors.rb

Constant Summary collapse

VECTORS =
{
  'cvss' => 'cvss3=',
  'av' => 'av=',
  'ac' => 'ac=',
  'ui' => 'ui=',
  's' => 'sc=',
  'c' => 'ci=',
  'i' => 'ii=',
  'a' => 'ai=',
  'e' => 'ex=',
  'rl' => 'rl=',
  'rc' => 'rc=',
  'pr' => 'pr=',
  'cr' => 'cr=',
  'ir' => 'ir=',
  'ar' => 'ar=',
  'mav' => 'mav=',
  'mac' => 'mac=',
  'ms' => 'ms=',
  'mpr' => 'mpr=',
  'mui' => 'mui=',
  'mc' => 'mc=',
  'mi' => 'mi=',
  'ma' => 'ma='
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#acObject

Returns the value of attribute ac.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ac
  @ac
end

#aiObject

Returns the value of attribute ai.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ai
  @ai
end

#arObject

Returns the value of attribute ar.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ar
  @ar
end

#avObject

Returns the value of attribute av.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def av
  @av
end

#ciObject

Returns the value of attribute ci.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ci
  @ci
end

#crObject

Returns the value of attribute cr.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def cr
  @cr
end

#exObject

Returns the value of attribute ex.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ex
  @ex
end

#iiObject

Returns the value of attribute ii.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ii
  @ii
end

#irObject

Returns the value of attribute ir.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ir
  @ir
end

#prObject

Returns the value of attribute pr.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def pr
  @pr
end

#rcObject

Returns the value of attribute rc.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def rc
  @rc
end

#rlObject

Returns the value of attribute rl.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def rl
  @rl
end

#scObject

Returns the value of attribute sc.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def sc
  @sc
end

#uiObject

Returns the value of attribute ui.



2
3
4
# File 'lib/cvss_rating/cvss3_vectors.rb', line 2

def ui
  @ui
end

Instance Method Details

#cvss3=(cvss3) ⇒ Object



75
76
77
# File 'lib/cvss_rating/cvss3_vectors.rb', line 75

def cvss3=(cvss3)
  raise 'Bad CVSS 3.0 Vector String' if cvss3 != '3.0'
end

#get_key(vector, value) ⇒ Object



71
72
73
# File 'lib/cvss_rating/cvss3_vectors.rb', line 71

def get_key(vector, value)
  get_key = eval('::Cvss3::Metrics::' + vector + '_KEY')[(eval('::Cvss3::Metrics::' + vector).select { |_k, v| v == value }).keys[0]]
end

#init(ex = 'ND', rl = 'ND', rc = 'ND', _cd = 'ND', _td = 'ND', cr = 'ND', ir = 'ND', ar = 'ND', mav = 'ND', mac = 'ND', mpv = 'ND', mui = 'ND', mc = 'ND', mi = 'ND', ma = 'ND', ms = 'ND') ⇒ Object



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/cvss_rating/cvss3_vectors.rb', line 533

def init(ex = 'ND', rl = 'ND', rc = 'ND', _cd = 'ND', _td = 'ND', cr = 'ND', ir = 'ND', ar = 'ND',
         mav = 'ND', mac = 'ND', mpv = 'ND', mui = 'ND', mc = 'ND', mi = 'ND', ma = 'ND', ms = 'ND')
  self.ex = ex
  self.rl = rl
  self.rc = rc

  self.cr = cr
  self.ir = ir
  self.ar = ar

  self.mav = mav
  self.mac = mac
  self.mpr = mpv
  self.mui = mui

  self.mc = mc
  self.mi = mi
  self.ma = ma
end

#keyObject



66
67
68
69
# File 'lib/cvss_rating/cvss3_vectors.rb', line 66

def key
  set_key
  @key
end

#ma(raw = false) ⇒ Object



433
434
435
436
437
438
439
# File 'lib/cvss_rating/cvss3_vectors.rb', line 433

def ma(raw = false)
  if raw
    @ma ||= @ai
  else
    ma = get_key('CIA_IMPACT', @ma) unless @ma.nil?
    end
end

#ma=(ma) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/cvss_rating/cvss3_vectors.rb', line 418

def ma=(ma)
  @ma = case ma
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end
end

#mac(raw = false) ⇒ Object



276
277
278
279
280
281
282
# File 'lib/cvss_rating/cvss3_vectors.rb', line 276

def mac(raw = false)
  if raw
    @mac ||= @ac
  else
    mac = get_key('ATTACK_COMPLEXITY', @mac) unless @mac.nil?
     end
end

#mac=(mac) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/cvss_rating/cvss3_vectors.rb', line 263

def mac=(mac)
  @mac = case mac
         when 'high', 'H'
           ::Cvss3::Metrics::ATTACK_COMPLEXITY[:high]
         when 'low', 'L'
           ::Cvss3::Metrics::ATTACK_COMPLEXITY[:low]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end

#mav(raw = false) ⇒ Object



255
256
257
258
259
260
261
# File 'lib/cvss_rating/cvss3_vectors.rb', line 255

def mav(raw = false)
  if raw
    @mav ||= @av
  else
    mav = get_key('ATTACK_VECTOR', @mav) unless @mav.nil?
    end
end

#mav=(mav) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/cvss_rating/cvss3_vectors.rb', line 238

def mav=(mav)
  @mav = case mav
         when 'physical', 'P'
           ::Cvss3::Metrics::ATTACK_VECTOR[:physical]
         when 'local', 'L'
           ::Cvss3::Metrics::ATTACK_VECTOR[:local]
         when 'adjacent network', 'A'
           ::Cvss3::Metrics::ATTACK_VECTOR[:adjacent_network]
         when 'network', 'N'
           ::Cvss3::Metrics::ATTACK_VECTOR[:network]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end

#mc(raw = false) ⇒ Object



387
388
389
390
391
392
393
# File 'lib/cvss_rating/cvss3_vectors.rb', line 387

def mc(raw = false)
  if raw
    @mv ||= @ci
  else
    mc = get_key('CIA_IMPACT', @mc) unless @mc.nil?
    end
end

#mc=(mc) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/cvss_rating/cvss3_vectors.rb', line 372

def mc=(mc)
  @mc = case mc
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end
end

#mi(raw = false) ⇒ Object



410
411
412
413
414
415
416
# File 'lib/cvss_rating/cvss3_vectors.rb', line 410

def mi(raw = false)
  if raw
    @mi ||= @ii
  else
    mi = get_key('CIA_IMPACT', @mi) unless @mi.nil?
    end
end

#mi=(mi) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/cvss_rating/cvss3_vectors.rb', line 395

def mi=(mi)
  @mi = case mi
        when 'none', 'N'
          ::Cvss3::Metrics::CIA_IMPACT[:none]
        when 'low', 'L'
          ::Cvss3::Metrics::CIA_IMPACT[:low]
        when 'high', 'H'
          ::Cvss3::Metrics::CIA_IMPACT[:high]
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end
end

#mpr(raw = false) ⇒ Object



320
321
322
323
324
325
326
327
328
329
330
# File 'lib/cvss_rating/cvss3_vectors.rb', line 320

def mpr(raw = false)
  if raw
    @mpr ||= @pr
  else
    if @ms == 'changed'
      mpr = get_key('PRIVILEGE_REQUIRED_CHANGED', @mpr) unless @mpr.nil?
    else
      mpr = get_key('PRIVILEGE_REQUIRED', @mpr) unless @mpr.nil?
      end
    end
end

#mpr=(mpr) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/cvss_rating/cvss3_vectors.rb', line 305

def mpr=(mpr)
  @mpr = case mpr
         when 'none', 'N'
           ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:none]
         when 'low', 'L'
           ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:low]
         when 'high', 'H'
           ::Cvss3::Metrics::PRIVILEGE_REQUIRED[:high]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end

#ms(raw = false) ⇒ Object



360
361
362
363
364
365
366
367
368
369
370
# File 'lib/cvss_rating/cvss3_vectors.rb', line 360

def ms(raw = false)
  if raw
    @ms ||= @sc
  else
    if @ms.nil?
      ms = ::Cvss3::Metrics::SCOPE_KEY[@sc.to_sym] unless @sc.nil?
    else
      ms = ::Cvss3::Metrics::SCOPE_KEY[@ms.to_sym] unless @ms.nil?
    end
  end
end

#ms=(ms) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/cvss_rating/cvss3_vectors.rb', line 332

def ms=(ms)
  @ms = case ms
        when 'changed', 'C'
          'changed'
        when 'unchanged', 'U'
          'unchanged'
        when 'not_defined', 'ND'
          nil
        else
          raise 'Bad Argument'
    end

  if @ms == 'changed'
    @mpr = case get_key('PRIVILEGE_REQUIRED', mpr(true)).nil? ? get_key('PRIVILEGE_REQUIRED_CHANGED', mpr(true)) : get_key('PRIVILEGE_REQUIRED', mpr(true))
           when 'none', 'N',
             ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:none]
           when 'low', 'L'
             ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:low]
           when 'high', 'H'
             ::Cvss3::Metrics::PRIVILEGE_REQUIRED_CHANGED[:high]
           else
             raise 'Bad Argument'
    end
  else
    self.mpr = get_key('PRIVILEGE_REQUIRED', mpr(true)).nil? ? get_key('PRIVILEGE_REQUIRED_CHANGED', mpr(true)) : get_key('PRIVILEGE_REQUIRED', mpr(true))
   end
end

#mui(raw = false) ⇒ Object



297
298
299
300
301
302
303
# File 'lib/cvss_rating/cvss3_vectors.rb', line 297

def mui(raw = false)
  if raw
    @mui ||= @ui
  else
    mui = get_key('USER_INTERACTION', @mui) unless @mui.nil?
    end
end

#mui=(mui) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/cvss_rating/cvss3_vectors.rb', line 284

def mui=(mui)
  @mui = case mui
         when 'none', 'N'
           ::Cvss3::Metrics::USER_INTERACTION[:none]
         when 'required', 'R'
           ::Cvss3::Metrics::USER_INTERACTION[:required]
         when 'not_defined', 'ND'
           nil
         else
           raise 'Bad Argument'
    end
end

#parse(vector) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cvss_rating/cvss3_vectors.rb', line 30

def parse(vector)
  string = vector.split('/')
  len = string.length

  init

  @originalkey = vector

  string.each do |section|
    tmp = section.split(':')
    send(VECTORS[tmp[0].downcase].to_sym, tmp[1])
  end
end

#set_keyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cvss_rating/cvss3_vectors.rb', line 44

def set_key
  @key = format('AV:%s/AC:%s/PR:%s/UI:%s/C:%s/I:%s/A:%s', av, ac, pr, ui, ci, ii, ai)

  @key += format('/E:%s', ex) unless @ex.nil?
  @key += format('/RL:%s', rl) unless @rl.nil?
  @key += format('/RC:%s', rc) unless @rc.nil?

  @key += format('/CR:%s', cr) unless @cr.nil?
  @key += format('/IR:%s', ir) unless @ir.nil?
  @key += format('/AR:%s', ar) unless @ar.nil?

  @key += format('/MAV:%s', mav) unless @mav.nil?
  @key += format('/MAC:%s', mac) unless @mac.nil?
  @key += format('/MPR:%s', mpr) unless @mpr.nil?
  @key += format('/MUI:%s', mui) unless @mui.nil?
  @key += format('/MS:%s', ms) unless @ms.nil?

  @key += format('/MC:%s', mc) unless @mc.nil?
  @key += format('/MI:%s', mi) unless @mi.nil?
  @key += format('/MA:%s', ma) unless @ma.nil?
end