FreeBSD: Cryptographic bypass and MITM-based compromise against russian/gd, ukrainian/gd, and ukrainian/webalizer ports reddit / BSD ---------------------------------------------------------------------- TheGrandSchlonging · 2019-05-21 04:39 [Feel free to send this to the FreeBSD lists, the FreeBSD bug tracker, the port maintainers, or whatever to get it fixed.] One of the many problems with the highly complex FreeBSD ports machinery is that users don't have a simple assurance: **During the pre-configure stages, the *only* downloaded files are those listed in distinfo files, and *all* downloaded files are cryptographically verified before *any* further use.** This is a reasonable user expectation, with later cryptographic verification of downloaded files being largely the responsibility of third-party developers. Unfortunately, the FreeBSD ports machinery keeps providing mechanisms to thwart this expectation, whether overtly (such as the IGNOREFILES checksum-bypass mechanism, which existed until 20140623) or covertly (such as various hooking mechanisms and the dependency-target mechanism, which invite poor use). There's a cryptographic bypass and MITM-based compromise available against users of the russian/gd, ukrainian/gd, and ukrainian/webalizer ports. The problem is in the russian/gd and ukrainian/gd ports, but ukrainian/webalizer has ukrainian/gd as a dependency. The Makefile for ukrainian/gd (the Makefile for russian/gd is similar) contains this: BUILD_DEPENDS= ${NONEXISTENT}:x11-fonts/geminifonts:fetch GD_FONTS= ${DISTDIR}/x-koi8u.tgz koi6x10.bdf koi6x13.bdf \ koi10x16b.bdf koi9x15.bdf koi10x20.bdf As you can see, there's a dependency on x11-fonts/geminifonts with a dependency target of 'fetch' rather than 'checksum', meaning the x-koi8u.tgz distfile for x11-fonts/geminifonts may be downloaded without cryptographic verification. The parent port is graphics/gd, and it will use the GD_FONTS variable as follows: cd ${WRKFONTS} && ${SH} ${FILESDIR}/makefonts extract ${GD_FONTS} [...] cd ${WRKFONTS} && ${SH} ${FILESDIR}/makefonts configure ${GD_FONTS} [...] cd ${WRKFONTS} && ${SH} ${FILESDIR}/makefonts build ${GD_FONTS} The graphics/gd/files/makefonts script will hand the potentially malicious x-koi8u.tgz to tar (with all its libarchive glory) when running the 'extract' target, which is a problem in itself, but the real fun begins with the 'build' target: build) set -x for font in ${fonts} do f=`echo "${font}" | tr -d [[:lower:]] | tr [[:upper:]] [[:lower:]]` perl ./bdftogd "gdFont${font}" "font${f}" < "${1}" shift done ;; esac Here we have potentially malicious koi6x10.bdf, koi6x13.bdf, koi10x16b.bdf, koi9x15.bdf, and koi10x20.bdf files being passed to the bdftogd script on stdin. bdftogd will use these bdf files to generate a number of .c and .h files, and it's trivial for a malicious bdf file to inject malicious C code into those generated files: $ printf "FONT x\nFONTBOUNDINGBOX 1 1 0 0\nCOPYRIGHT */ malicious_C_code /*\n" | bdftogd FontLarge gdfontl $ grep -C1 malicious_C_code gdfontl.c The original bdf was holding following copyright: */ malicious_C_code /* */ The master site for x11-fonts/geminifonts is the following: http://www.brama.com/compute/unix/ So x-koi8u.tgz is downloaded via HTTP, facilitating MITM-based delivery of a malicious distfile, a moot point because Mk/bsd.port.mk disables SSL verification for non-makesum targets anyway: .if !make(makesum) FETCH_ENV?= SSL_NO_VERIFY_PEER=1 SSL_NO_VERIFY_HOSTNAME=1 .endif (This is fine when distfiles are actually cryptographically verified.) ---------------------------------------------------------------------- qci · 2019-05-21 05:01 From what I learned it's very simple to get the ports makefiles fixed by FreeBSD porters. Also, they should extend portlint to catch deps on fetch target. ---------------------------------------------------------------------- icantthinkofone · 2019-05-21 10:55 > [Feel free to send this to the FreeBSD lists, the FreeBSD bug tracker, the port maintainers, or whatever to get it fixed.] No. You do it. Of all the places to report an issue, you did it on reddit?!! ---------------------------------------------------------------------- xmjEE · 2019-08-12 16:00 >Of all the places to report an issue, you did it on reddit?!! Karma trumps responsible disclosure ---------------------------------------------------------------------- mvanbaak · 2019-08-13 11:08 >12:46 @mat │ if anyone has a reddit account, can they say on [ht tps://www.reddit.com/r/BSD/comments/br62hm/freebsd\_cryptographic\_byp ass\_and\_mitmbased/](https://www.reddit.com/r/BSD/comments/br62hm/fre ebsd_cryptographic_bypass_and_mitmbased/) that the improbable issue was fixed. 12:48 @mat │ (in [https://svnweb.freebsd.org/changeset/ports/5088 19](https://svnweb.freebsd.org/changeset/ports/508819) )