News for hackers. Stuff that matters.
Re:#include </etc/shadow> by fwsgonzo on Tuesday December 17, 2019 @04:56AM (#21812156)
You can compile and execute C/C++ code in my little hobby project: https://droplet.fwsnet.net/

It's something I use to measure certain things, like how many instructions does a C++ exception add etc.

It's run in a docker container, and I think I strip out any slashes from includes. I'm pretty sure the container is not executing stuff as root as well. Still, probably not bulletproof.

Re:#include </etc/shadow> by shawabawa3 on Tuesday December 17, 2019 @06:52AM (#21812647)
You aren't stripping slashes.

I tried `#include </dev/urandom>` and it eventually crashes the container failing to allocate memory (looks like they have a 4GB limit?)

Re:#include &lt;/etc/shadow&gt; by fwsgonzo on Tuesday December 17, 2019 @08:00AM (#21813026)
Haha, that's clever. Yes, it's a 4GB limit. Guess I'll try to fix that again. EDIT: fixed
Re:#include &lt;/etc/shadow&gt; by ajor on Tuesday December 17, 2019 @09:03AM (#21813482)
Still some workarounds to the slash-stripping:

  #include "\
  /etc/passwd"

  program221/code.cpp:1:11: warning: backslash-newline at end of file
      1 | #include "\
        |            
  In file included from program221/code.cpp:2:
  /etc/passwd:1:5: error: found ':' in nested-name-specifier, expected '::'
      1 | root:x:0:0:root:/root:/bin/bash
        |     ^
        |     ::
  /etc/passwd:1:1: error: 'root' does not name a type
      1 | root:x:0:0:root:/root:/bin/bash
        | ^~~~

Is it possible to restrict the compiler's access to only files in "/usr/include" instead? Seems like it'd be hard to cover every case with just pattern matching.
Re:#include &lt;/etc/shadow&gt; by fwsgonzo on Tuesday December 17, 2019 @09:10AM (#21813549)
It would be awesome if you could place restrictions on the compiler, but I don't know of any such features atm. Still, the compilation happens in the container (which is just a default Ubuntu image with a cross compiler in it). I don't know how much information there is to disclose. Not taking it lightly though, I guess I will have to find a way to really handle the preprocessor stuff, but I still want people to be able to include system headers.
Re:#include &lt;/etc/shadow&gt; by blattimwind on Tuesday December 17, 2019 @09:11AM (#21813560)
> Is it possible to restrict the compiler's access to only files in "/usr/include" instead? Seems like it'd be hard to cover every case with just pattern matching.

chroot into a build environment

Re:#include &lt;/etc/shadow&gt; by sherincall on Tuesday December 17, 2019 @10:04AM (#21814080)
You can LD_PRELOAD an .so that overrides `open` and family of functions, and drop opens based on a whitelist/blacklist.
Re:#include &lt;/etc/shadow&gt; by hag on Tuesday December 17, 2019 @05:02AM (#21812181)
`#include </etc/lsb-release>` gave some interesting errors. Looks like it's running Ubuntu.
Re:#include &lt;/etc/shadow&gt; by mnw21cam on Tuesday December 17, 2019 @07:00AM (#21812681)
Yeah, that's definitely a big "Here, hack me" post you just put up there.