@@ -15,6 +15,12 @@ def start_element(name=nil,attrs=[])
15
15
attrs = normalize_attrs ( attrs )
16
16
block = @block
17
17
@state [ :current_tag ] [ name ] = true
18
+
19
+ unless @text . nil?
20
+ @state [ :text_backup ] = @text
21
+ @text = nil
22
+ end
23
+
18
24
case name
19
25
when "host"
20
26
@state [ :has_text ] = true
@@ -25,97 +31,90 @@ def start_element(name=nil,attrs=[])
25
31
def end_element ( name = nil )
26
32
block = @block
27
33
case name
28
- when " name"
29
- return if not in_tag ( " result" )
30
- @state [ :has_text ] = true
31
- @state [ :vuln_name ] = @text . strip if @text
32
- @text = nil
33
- when " description"
34
+ when ' name'
35
+ if in_tag ( ' result' )
36
+ @state [ :has_text ] = true
37
+ @state [ :vuln_name ] = @text . strip if @text
38
+ end
39
+ when ' description'
34
40
@state [ :has_text ] = true
35
41
@state [ :vuln_desc ] = @text . strip if @text
36
- @text = nil
37
- when "bid"
38
- return if not in_tag ( "result" )
39
- return if not in_tag ( "nvt" )
40
- @state [ :has_text ] = true
41
- @state [ :bid ] = @text . strip if @text
42
- @text = nil
43
- when "cve"
44
- return if not in_tag ( "result" )
45
- return if not in_tag ( "nvt" )
46
- @state [ :has_text ] = true
47
- @state [ :cves ] = @text . strip if @text
48
- @text = nil
49
- when "risk_factor"
50
- return if not in_tag ( "result" )
51
- return if not in_tag ( "nvt" )
52
-
53
- #we do this to clean out the buffer so to speak
54
- #if we don't set text to nil now, the text will show up later
55
- @state [ :has_text ] = true
56
- @text = nil
57
- when "cvss_base"
58
- return if not in_tag ( "result" )
59
- return if not in_tag ( "nvt" )
60
- @state [ :has_text ] = true
61
- @text = nil
62
- when "subnet"
63
- @state [ :has_text ] = true
64
- @text = nil
65
- when "result"
66
- return if not in_tag ( "results" )
67
- record_vuln
68
- when "threat"
69
- return if not in_tag ( "ports" )
70
- return if not in_tag ( "port" )
71
- @state [ :has_text ] = true
72
-
73
- if not @text . index ( '(' )
74
- @state [ :name ] = nil
75
- @state [ :port ] = nil
76
- @state [ :proto ] = nil
77
- @text = nil
78
- return
42
+ when 'bid'
43
+ if in_tag ( 'result' ) && in_tag ( 'nvt' )
44
+ @state [ :has_text ] = true
45
+ @state [ :bid ] = @text . strip if @text
79
46
end
80
-
81
- @state [ :name ] = @text . split ( ' ' ) [ 0 ] if @text
82
- @state [ :port ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 0 ] if @text
83
- @state [ :proto ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 1 ] . split ( ')' ) [ 0 ] if @text
84
-
85
- @text = nil
86
- when "host"
47
+ when 'cve'
48
+ if in_tag ( 'result' ) && in_tag ( 'nvt' )
49
+ @state [ :has_text ] = true
50
+ @state [ :cves ] = @text . strip if @text
51
+ end
52
+ when 'risk_factor'
53
+ if in_tag ( 'result' ) && in_tag ( 'nvt' )
54
+ #we do this to clean out the buffer so to speak
55
+ #if we don't set text to nil now, the text will show up later
56
+ @state [ :has_text ] = true
57
+ end
58
+ when 'cvss_base'
59
+ if in_tag ( 'result' ) && in_tag ( 'nvt' )
60
+ @state [ :has_text ] = true
61
+ end
62
+ when 'subnet'
63
+ @state [ :has_text ] = true
64
+ when 'result'
65
+ record_vuln if in_tag ( 'results' )
66
+ when 'threat'
67
+ @state [ :has_text ] = true if in_tag ( 'ports' ) && in_tag ( 'port' )
68
+ when 'host'
87
69
if in_tag ( 'result' )
88
70
@state [ :has_text ] = true
89
71
@state [ :host ] = @text . strip if @text
90
- @text = nil
91
- elsif in_tag ( 'ports' )
92
- return if not in_tag ( 'port' )
72
+ elsif in_tag ( 'ports' ) && in_tag ( 'port' )
93
73
@state [ :has_text ] = true
94
74
@state [ :host ] = @text . strip if @text
95
- @text = nil
96
75
end
97
- when " port"
76
+ when ' port'
98
77
if in_tag ( 'result' )
99
78
@state [ :has_text ] = true
100
- if not @text . index ( '(' )
79
+ if @text && @text . index ( '(' )
80
+ @state [ :proto ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 1 ] . gsub ( /\) / , '' )
81
+ @state [ :port ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 0 ] . gsub ( /\) / , '' )
82
+ elsif @text && @text . index ( '/' )
83
+ @state [ :proto ] = @text . split ( '/' ) [ 1 ] . strip
84
+ @state [ :port ] = @text . split ( '/' ) [ 0 ] . strip
85
+ else
86
+ @state [ :proto ] = nil
87
+ @state [ :port ] = nil
88
+ end
89
+
90
+ if @state [ :port ] && @state [ :port ] == 'general'
101
91
@state [ :proto ] = nil
102
92
@state [ :port ] = nil
103
- @text = nil
104
- return
105
93
end
106
- @state [ :proto ] = @text . split ( '(' ) [ 0 ] . strip if @text
107
- @state [ :port ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 0 ] . gsub ( /\) / , '' ) if @text
108
- @text = nil
109
94
elsif in_tag ( 'ports' )
110
- record_service
95
+ if @text && @text . index ( '(' )
96
+ @state [ :name ] = @text . split ( ' ' ) [ 0 ]
97
+ @state [ :port ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 0 ]
98
+ @state [ :proto ] = @text . split ( '(' ) [ 1 ] . split ( '/' ) [ 1 ] . split ( ')' ) [ 0 ]
99
+ record_service unless @state [ :name ] . nil?
100
+ elsif @text && @text . index ( '/' )
101
+ @state [ :port ] = @text . split ( '/' ) [ 0 ]
102
+ @state [ :proto ] = @text . split ( '/' ) [ 1 ]
103
+ record_service unless @state [ :port ] == 'general'
104
+ end
111
105
end
112
- when " name"
113
- return if not in_tag ( " result" )
106
+ when ' name'
107
+ return if not in_tag ( ' result' )
114
108
@state [ :has_text ] = true
115
- @text = nil
109
+ end
110
+
111
+ if @state [ :text_backup ]
112
+ @text = @state [ :text_backup ]
113
+ @state [ :text_backup ] = nil
116
114
else
117
115
@text = nil
118
116
end
117
+
119
118
@state [ :current_tag ] . delete name
120
119
end
121
120
@@ -153,8 +152,6 @@ def record_vuln
153
152
end
154
153
155
154
def record_service
156
- return if not @state [ :name ]
157
-
158
155
service_info = { }
159
156
service_info [ :host ] = @state [ :host ]
160
157
service_info [ :name ] = @state [ :name ]
0 commit comments