oss-sec mailing list archives

Re: chroots & uid sharing


From: "Jason A. Donenfeld" <Jason () zx2c4 com>
Date: Thu, 6 Jun 2013 15:31:25 +0200

Alright that one-liner killed kittens. Sorry. Here we go:

frisell zx2c4 # cat find-bad-chroots.py
#!/usr/bin/env python2

import os

chroots = { }

for pid in os.listdir("/proc/"):
        if not pid.isdigit():
                continue
        try:
                uid = os.stat("/proc/" + pid).st_uid
                root = os.readlink("/proc/" + pid + "/root")
        except:
                continue
        if uid not in chroots:
                chroots[uid] = [root]
        elif root not in chroots[uid]:
                chroots[uid].append(root)

for uid in chroots:
        if len(chroots[uid]) > 1:
                print "UID: %d" % uid
                for root in chroots[uid]:
                        print "\t%s" % root

frisell zx2c4 # ./find-bad-chroots.py
UID: 25
        /var/empty
        /


Current thread: