From: jason@perfinion.com (Jason Zaman)
To: linux-security-module@vger.kernel.org
Subject: [PATCH v1] shebang: restrict python interactive prompt/interpreter
Date: Sat, 10 Jun 2017 00:43:15 +0800 [thread overview]
Message-ID: <20170609164315.GA1141@meriadoc.perfinion.com> (raw)
In-Reply-To: <754b78d1-f7f9-58bd-bf74-fea9e105649a@nmatt.com>
On Fri, Jun 09, 2017 at 12:37:50PM -0400, Matt Brown wrote:
> On 6/9/17 11:41 AM, Tetsuo Handa wrote:
> > Matt Brown wrote:
> >>> What about execution via ld-linux ?
> >>>
> >>> $ /lib64/ld-linux-x86-64.so.2 /usr/bin/python2
> >>>
> >>
> >> Just tested this and you are correct, this allows you to bypass the
> >> protection.
> >>
> >> I was able to fix this bypass by including /lib64/ld-linux-x86-64.so.2
> >> in the list of interpreters.
> >
> > And there is also PYTHONINSPECT environment variable. ;-)
> >
> > # echo '#!/usr/bin/python2' > run-python
> > # chmod 755 run-python
> > # ./run-python
> > # PYTHONINSPECT=yes ./run-python
> >>>> print "hello"
> > hello
> >>>>
>
> While this bypass works against this LSM alone, when combined with
> Trusted Path Execution this is prevented for non-root/untrusted user.
> This is why I feel like this is such a great feature to combine with TPE
> as I said here:
>
> http://www.openwall.com/lists/kernel-hardening/2017/06/09/13
>
> Results from my test:
>
> $ PYTHONINSPECT=yes ./run-python
>
>
> -bash: ./run-python: /usr/bin/python2: bad interpreter: Operation not
> permitted
>
> and in the dmesg log:
> TPE: Denied exec of /home/test/run-python Reason: file in non-root-owned
> directory
What if you just use any existing python script on the system?
jason at meriadoc ~ $ PYTHONINSPECT=yes /usr/bin/emerge
emerge: command-line interface to the Portage system
Usage:
emerge [ options ] [ action ] [ ebuild | tbz2 | file | @set | atom ] [ ... ]
emerge [ options ] [ action ] < @system | @world >
emerge < --sync | --metadata | --info >
emerge --resume [ --pretend | --ask | --skipfirst ]
emerge --help
Options: -[abBcCdDefgGhjkKlnNoOpPqrsStuvVw]
[ --color < y | n > ] [ --columns ]
[ --complete-graph ] [ --deep ]
[ --jobs JOBS ] [ --keep-going ] [ --load-average LOAD ]
[ --newrepo ] [ --newuse ] [ --noconfmem ] [ --nospinner ]
[ --oneshot ] [ --onlydeps ] [ --quiet-build [ y | n ] ]
[ --reinstall changed-use ] [ --with-bdeps < y | n > ]
Actions: [ --depclean | --list-sets | --search | --sync | --version ]
For more help consult the man page.
Traceback (most recent call last):
File "/usr/lib/python-exec/python3.4/emerge", line 79, in <module>
sys.exit(retval)
SystemExit: 1
>>>
-- Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-06-09 16:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-09 13:22 [PATCH v1] shebang: restrict python interactive prompt/interpreter Mimi Zohar
2017-06-09 14:02 ` Tetsuo Handa
2017-06-09 14:50 ` Matt Brown
2017-06-09 15:41 ` Tetsuo Handa
2017-06-09 16:37 ` Matt Brown
2017-06-09 16:43 ` Jason Zaman [this message]
2017-06-09 17:23 ` Matt Brown
2017-06-09 23:04 ` Tetsuo Handa
2017-06-10 1:56 ` Kees Cook
2017-06-10 5:27 ` Tetsuo Handa
2017-06-12 0:34 ` Matt Brown
[not found] ` <d9aca46b-97c6-4faf-b559-484feb4aa640@digikod.net>
2017-06-12 2:32 ` Mimi Zohar
2017-06-12 14:27 ` Mimi Zohar
2017-06-14 14:10 ` Alan Cox
2017-06-14 20:37 ` [kernel-hardening] " Boris Lukashev
[not found] ` <8a2300ef-1462-0e1f-2d6a-81e6020bc71f@digikod.net>
2017-06-13 21:44 ` Casey Schaufler
2017-06-10 1:49 ` Tetsuo Handa
2017-06-09 15:06 ` Mimi Zohar
2017-06-09 15:23 ` Tetsuo Handa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170609164315.GA1141@meriadoc.perfinion.com \
--to=jason@perfinion.com \
--cc=linux-security-module@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).