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