Skip to content

Commit 05cfe7c

Browse files
authored
Land rapid7#19401, Add a mixin to get SPIP version and make use of it
2 parents bd681f8 + d86e85a commit 05cfe7c

File tree

3 files changed

+64
-45
lines changed

3 files changed

+64
-45
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf
4+
module Exploit::Remote::HTTP::Spip
5+
6+
include Msf::Exploit::Remote::HttpClient
7+
8+
def initialize(info = {})
9+
super
10+
11+
register_options([
12+
OptString.new('TARGETURI', [true, 'Path to Spip install', '/'])
13+
])
14+
end
15+
16+
# Determine Spip version
17+
#
18+
# @return [Rex::Version] Version as Rex::Version
19+
def spip_version
20+
res = send_request_cgi(
21+
'method' => 'GET',
22+
'uri' => normalize_uri(target_uri.path, "spip.php")
23+
)
24+
25+
return unless res
26+
27+
version = nil
28+
29+
version_string = res.get_html_document.at('head/meta[@name="generator"]/@content')&.text
30+
if version_string =~ /SPIP (.*)/
31+
version = ::Regexp.last_match(1)
32+
end
33+
34+
if version.nil? && res.headers['Composed-By'] =~ /SPIP (.*)/
35+
version = ::Regexp.last_match(1)
36+
end
37+
38+
if version.nil?
39+
return nil
40+
end
41+
42+
return Rex::Version.new(version)
43+
end
44+
45+
end
46+
end

modules/exploits/unix/webapp/spip_connect_exec.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class MetasploitModule < Msf::Exploit::Remote
77
Rank = ExcellentRanking
88

99
include Msf::Exploit::Remote::HttpClient
10+
include Msf::Exploit::Remote::HTTP::Spip
1011

1112
def initialize(info = {})
1213
super(update_info(info,
@@ -49,30 +50,19 @@ def initialize(info = {})
4950
end
5051

5152
def check
52-
version = nil
53-
uri = normalize_uri(target_uri.path, "spip.php")
54-
55-
res = send_request_cgi({ 'uri' => "#{uri}" })
56-
57-
if res and res.code == 200 and res.body =~ /<meta name="generator" content="SPIP (.*) \[/
58-
version = $1
59-
end
60-
61-
if version.nil? and res.code == 200 and res.headers["Composed-By"] =~ /SPIP (.*) @/
62-
version = $1
63-
end
53+
version = spip_version()
6454

6555
if version.nil?
6656
return Exploit::CheckCode::Unknown
6757
end
6858

69-
vprint_status("SPIP Version detected: #{version}")
59+
print_status("SPIP Version detected: #{version}")
7060

71-
if version =~ /^2\.0/ and version < "2.0.21"
61+
if version.between?(Rex::Version::new("2.0.0"), Rex::Version::new("2.0.21"))
7262
return Exploit::CheckCode::Appears
73-
elsif version =~ /^2\.1/ and version < "2.1.16"
63+
elsif version.between?(Rex::Version::new("2.2.0"), Rex::Version::new("2.1.16"))
7464
return Exploit::CheckCode::Appears
75-
elsif version =~ /^3\.0/ and version < "3.0.3"
65+
elsif version.between?(Rex::Version::new("3.0.0"), Rex::Version::new("3.0.03"))
7666
return Exploit::CheckCode::Appears
7767
end
7868

modules/exploits/unix/webapp/spip_rce_form.rb

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class MetasploitModule < Msf::Exploit::Remote
99
include Msf::Exploit::CmdStager
1010
include Msf::Exploit::Remote::HttpClient
1111
prepend Msf::Exploit::Remote::AutoCheck
12+
include Msf::Exploit::Remote::HTTP::Spip
1213

1314
def initialize(info = {})
1415
super(
@@ -83,38 +84,20 @@ def check
8384
res = send_request_cgi({ 'uri' => uri.to_s })
8485

8586
return Exploit::CheckCode::Unknown('Target is unreachable.') unless res
86-
return Exploit::CheckCode::Unknown("Target responded with unexpected HTTP response code: #{res.code}") unless res.code == 200
8787

88-
version_string = res.get_html_document.at('head/meta[@name="generator"]/@content')&.text
89-
return Exploit::CheckCode::Unknown('Unable to find the version string on the page: spip.php') unless version_string =~ /SPIP (.*)/
88+
rversion = spip_version
89+
return Exploit::CheckCode::Unknown('Unable to determine the version of SPIP') unless rversion
9090

91-
version = ::Regexp.last_match(1)
91+
print_status("SPIP Version detected: #{rversion}")
9292

93-
if version.nil? && res.headers['Composed-By'] =~ /SPIP (.*) @/
94-
version = ::Regexp.last_match(1)
95-
end
96-
97-
return Exploit::CheckCode::Unknown('Unable to determine the version of SPIP') unless version
98-
99-
print_status("SPIP Version detected: #{version}")
100-
101-
rversion = Rex::Version.new(version)
102-
if rversion >= Rex::Version.new('4.2.0')
103-
if rversion < Rex::Version.new('4.2.1')
104-
return Exploit::CheckCode::Appears
105-
end
106-
elsif rversion >= Rex::Version.new('4.1.0')
107-
if rversion < Rex::Version.new('4.1.18')
108-
return Exploit::CheckCode::Appears
109-
end
110-
elsif rversion >= Rex::Version.new('4.0.0')
111-
if rversion < Rex::Version.new('4.0.10')
112-
return Exploit::CheckCode::Appears
113-
end
114-
elsif rversion >= Rex::Version.new('3.2.0')
115-
if rversion < Rex::Version.new('3.2.18')
116-
return Exploit::CheckCode::Appears
117-
end
93+
if rversion.between?(Rex::Version.new('4.2.0'), Rex::Version.new('4.2.1'))
94+
return Exploit::CheckCode::Appears
95+
elsif rversion.between?(Rex::Version.new('4.1.0'), Rex::Version.new('4.1.18'))
96+
return Exploit::CheckCode::Appears
97+
elsif rversion.between?(Rex::Version.new('4.0.0'), Rex::Version.new('4.0.10'))
98+
return Exploit::CheckCode::Appears
99+
elsif rversion.between?(Rex::Version.new('3.2.0'), Rex::Version.new('3.2.18'))
100+
return Exploit::CheckCode::Appears
118101
end
119102

120103
return Exploit::CheckCode::Safe

0 commit comments

Comments
 (0)