PDA

Bekijk Volledige Versie : PFinger 0.7.8 format string vulnerability (#NISR16122002B)



NGSSoftware Insight Security Research
16/12/02, 21:38
NGSSoftware Insight Security Research Advisory

Name: PFinger Format String vulnerability
Systems: PFinger version 0.7.8 and earlier
Severity: High Risk
Vendor URL: http://www.xelia.ch/unix/pfinger/
Author: David Litchfield (david@ngssoftware.com)
Advisory URL: http://www.ngssoftware.com/advisories/pfinger.txt
Date: 16th December 2002
Advisory number: #NISR16122002B


Description
***********
PFinger is an open-source replacement of the GNU Finger daemon. PFinger
suffers from a format string vulnerability that, when exploited, can allow
the remote execution of arbitrary code.

Details
*******
The format string vulnerability arises due to an unsafe call to syslog() in
the log() function of log.c

...
syslog(level, syslog_mem);
...

To make this safe a format string should be specified:

...
syslog(level,"%s", syslog_mem);
...

Due to the way requests are logged the only way to exploit this
vulnerability is through setting the DNS name of the fingering host to the
attacker supplied format string.


h_ent = gethostbyaddr((char *)&remaddr.sin_addr, sizeof(remaddr.sin_addr),
AF_INET);

if (h_ent)
conn.hostname = strdup(h_ent->h_name);
else
conn.hostname = "(remote)";

log(LOG_INFO, "Connection from %s
(%s)",conn.hostname,inet_ntoa(remaddr.sin_addr));


This code looks up the Domain name of the fingering host and logs the
connection information. This appears to be the only place where user
controlled data is logged. For exploitation to succeed the attacker must
either control their own DNS, the DNS server of the target host or
alternatively spoof the DNS reply. This makes exploitation more difficult
but by no means impossible.


Fix Information
***************
NGSSoftware alerted the author of PFinger with this problem on the 27th of
November, 2002. The author has responded and assured NGS that a fix will be
implemented shortly. Those who are comfortable with C and cc/gcc can fix
this themselves by editing log.c in the manner described in the "Details"
section above.

A check for this issue has been added to Typhon III, NGSSoftware's advanced
vulnerability assessment tool, of which, more information is available at
the NGSSite: http://www.ngssoftware.com/

For more information about format string vulnerabilities please read

http://www.nextgenss.com/papers/win32format.doc
http://julianor.tripod.com/usfs.html

About NGSSoftware
*****************
NGSSoftware design, research and develop intelligent, advanced application
security assessment scanners. Based in the United Kingdom, NGSSoftware have
offices in the South of London and the East Coast of Scotland. NGSSoftware's
sister company NGSConsulting, offers best of breed security consulting
services, specialising in application, host and network security
assessments.

http://www.ngssoftware.com/
http://www.ngsconsulting.com/

Telephone +44 208 401 0070
Fax +44 208 401 0076

enquiries@ngssoftware.com

Stefan Esser
16/12/02, 21:57
Hello,

> Due to the way requests are logged the only way to exploit this
> vulnerability is through setting the DNS name of the fingering host to the
> attacker supplied format string.

I really wonder how you want to exploit this... Last time I checked
all tested resolvers (Linux/BSD/Solaris) did not allow % within domain
names and so your format string vulnerability is not exploitable at all...

Stefan Esser

Stefan Esser
17/12/02, 19:04
--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 16, 2002 at 11:56:10PM -0500, Valdis.Kletnieks@vt.edu wrote:
>=20
> *ON THE WIRE*, all 256 byte codes are legal, since DNS uses a length-data

Yes noone said it is not, but fact is, the libc resolvers simply do not
allow them, so you can send through the wire whatever you want it will
not find its way to the fingerd.

Stefan Esser


--SUOF0GtieIMvvwua
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Weitere Infos: siehe http://www.gnupg.org

iD8DBQE9/sYj1rB3BM9srmkRAv3lAJ9BEoOS+s0MsPkW2qCXVDlpKeuEAwC gqzyu
LX2mNFtW5XIsni1nWxwCDDY=
=Qdss
-----END PGP SIGNATURE-----

--SUOF0GtieIMvvwua--

der Mouse
17/12/02, 20:25
>> *ON THE WIRE*, all 256 byte codes are legal, since [...]

> Yes noone said it is not, but fact is, the libc resolvers simply do
> not allow them, so you can send through the wire whatever you want it
> will not find its way to the fingerd.

This does not match my experience.

I control rDNS for my house network (my provider has installed CNAMEs
pointing into my domain for my address space); I tried picking a
currently-unused address and giving it a PTR record pointing to
"Host-%-sign.Rodents.Montreal.QC.CA". I then told my nameserver to
reload the zone.

Using "host" on the address then printed the name I'd given,
Host-%-sign.Rodents.Montreal.QC.CA. The resolver never even blinked.
(If you want to try your own resolver on it, I've left it up; the
address is 216.46.5.13. I expect I'll be able to leave it up for at
least a month or so, but of course can't actually commit to that.)

/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B

der Mouse
17/12/02, 20:38
>> Due to the way requests are logged the only way to exploit this
>> vulnerability is through setting the DNS name of the fingering host
>> to the attacker supplied format string.

> I really wonder how you want to exploit this... Last time I checked
> all tested resolvers (Linux/BSD/Solaris) did not allow % within
> domain names and so your format string vulnerability is not
> exploitable at all...

If your resolver does not allow "funny characters" in domains, it is
broken. If nothing else, that sort of crippling makes it approximately
impossible to investigate abuse that involves using such domain names.
(At least one spammer outfit is known to use domain names containing
control characters and I think at least one other unusual character,
prseumably in an attempt to make it harder to investigate their spam.)

0x00 octets in domain labels won't work well with APIs that use C
strings, but the resolver shouldn't misbehave when encountering them
internally - and breaking on any of the other 255 octets is a Very Bad
Idea. (At least in the resolver. Other software and protocols may of
course impose their own restrictions, of varying degrees of sanity.
But the resolver infrastructure has to support all uses of the DNS,
including "unusual" uses.)

/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B

Valdis.Kletnieks@vt.edu
17/12/02, 20:57
--==_Exmh_303288982P
Content-Type: text/plain; charset=us-ascii

On Mon, 16 Dec 2002 21:39:32 +0100, Stefan Esser <s.esser@e-matters.de> said:
>
> Hello,
>
> > Due to the way requests are logged the only way to exploit this
> > vulnerability is through setting the DNS name of the fingering host to the
> > attacker supplied format string.
>
> I really wonder how you want to exploit this... Last time I checked
> all tested resolvers (Linux/BSD/Solaris) did not allow % within domain
> names and so your format string vulnerability is not exploitable at all...

Gotta read them RFC's carefully. ;)

*ON THE WIRE*, all 256 byte codes are legal, since DNS uses a length-data
encoding. Currently, there's restrictions on what chars are legal *for use*,
but there's no reason to suppose that with i18n and UTF-8 possibly appearing in
domain names, this will change.

Now ponder the fun you can have with a PTR entry - as that is what needs to
be returned for "setting the DNS name of the fingering host". What? You can't
get that into a BIND 9 zone file? Try grepping through the source
for "check-names" and ponder the possibilities. You don't even need to
hack the source code for this one....
--
Valdis Kletnieks
Computer Systems Senior Engineer
Virginia Tech


--==_Exmh_303288982P
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Exmh version 2.5 07/13/2001

iD8DBQE9/q5qcC3lWbTT17ARAgoyAKDzmF8Mkd1wjsVGISjMVA4TcfsQOAC gkPXH
h7eY9ZmPD+XecTubAwvKCIc=
=tCcu
-----END PGP SIGNATURE-----

--==_Exmh_303288982P--

Andreas Borchert
18/12/02, 21:00
On Tue, Dec 17, 2002 at 07:37:23AM +0100, Stefan Esser wrote:
> Yes noone said it is not, but fact is, the libc resolvers simply do not
> allow them, so you can send through the wire whatever you want it will
> not find its way to the fingerd.

Any resolver who disallows a % or any other character _by default_
is in violation of RFC 2181, section 11:

``Similarly, any binary string can serve as the value of any record
that includes a domain name as some or all of its value (SOA, NS, MX,
PTR, CNAME, and any others that may be added). Implementations of the
DNS protocols must not place any restrictions on the labels that can
be used. In particular, DNS servers must not refuse to serve a zone
because it contains labels that might not be acceptable to some DNS
client programs. A DNS server may be configurable to issue warnings
when loading, or even to refuse to load, a primary zone containing
labels that might be considered questionable, however this should
not happen by default.''
[http://www.rfc-editor.org/rfc/rfc2181.txt]

See also RFC 1123, section 6.1.3.5:

``The DNS defines domain name syntax very generally -- a string of
labels each containing up to 63 8-bit octets, separated by dots,
and with a maximum total of 255 octets.''
[http://www.rfc-editor.org/rfc/rfc1123.txt]

A conforming resolver is part of the djbdns package, see
http://cr.yp.to/djbdns/blurb/library.html
and http://cr.yp.to/djbdns/idn.html

BIND provides an option ``no-check-names'' in /etc/resolv.conf to
switch off the filtering function for its resolver library:

394. [feature] add RES_NOCHECKNAME and "options no-check-names" (in
resolv.conf) to turn off modern host/mail name checks.
[http://www.isc.org/ml-archives/bind-users/1999/01/msg00136.html]

This is supported since release 8.2-T1A.

Andreas Borchert

Andreas Tscharner
27/12/02, 16:02
--=.jbO'a0rc6s)nRL
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Mon, 16 Dec 2002 19:55:05 -0000
"NGSSoftware Insight Security Research" <nisr@nextgenss.com> wrote:

> NGSSoftware Insight Security Research Advisory
>
> Name: PFinger Format String vulnerability
> Systems: PFinger version 0.7.8 and earlier
> Severity: High Risk
> Vendor URL: http://www.xelia.ch/unix/pfinger/
> Author: David Litchfield (david@ngssoftware.com)
> Advisory URL: http://www.ngssoftware.com/advisories/pfinger.txt
> Date: 16th December 2002
> Advisory number: #NISR16122002B

For those who haven't noticed:
The author has fixed the bug and released a new version 0.7.9

Best regards
Andreas
--
Andreas Tscharner starfire@dplanet.ch
----------------------------------------------------------------------
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe trying
to produce bigger and better idiots. So far, the Universe is winning."
-- Rich Cook

--=.jbO'a0rc6s)nRL
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+C33Id6icl+PTsS8RAvhQAJ4hgYMF+cg69RaQ0eD+K6 qZwVRktACgnqLZ
kYFmHgqapAMAYdlhATb2yzQ=
=xWNd
-----END PGP SIGNATURE-----

--=.jbO'a0rc6s)nRL--