Guest User

Untitled

a guest
Sep 25th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * grsec_acl_evade1.c andrewg 1/12/05
  3.  *   trivial, stupid example of evading / bypassing grsecurity acl's on
  4.  *   binaries that allow execution of the linker (pretty much /all/ dynamic
  5.  *   binaries).
  6.  * Tested / written on:
  7.  * grsecurity-2.1.7-2.6.14.3-200511291802.patch.gz
  8.  * gradm-2.1.7-200511041858.tar.gz
  9.  *
  10.  * Given this is a design problem (not distingushing between mmap() execute,
  11.  * and execve execute) it's most likely that all previous acl enabled versions
  12.  * are "vulnerable" to this.
  13.  * Perhaps a better demonstration is required. Take an acl like
  14.  *
  15.  * subject /home/andrewg/bin/evade o {
  16.  *       /                               h
  17.  *       /dev                            h
  18.  *       /dev/urandom                    r
  19.  *       /etc                            h
  20.  *       /etc/ld.so.cache                r
  21.  *       /home                           h
  22.  *       /home/andrewg/bin/evade         rx
  23.  *       /lib                            rx
  24.  *       -CAP_ALL
  25.  *       bind    disabled
  26.  *       connect disabled
  27.  * }
  28.  * Let's assume evade was exploitable (had some overflow that allowed you to
  29.  * execute some arbitary code or whatever).
  30.  * Based on the above ruleset, there isn't too much you can do with it straight
  31.  * away.
  32.  * However, since /lib/ld-2.3.5.so is executable (pretty much any dynamic
  33.  * binary will have this library as executable in acl's), you can use that to
  34.  * evade the acl execute restrictions by execve'ing it. To test this out, you
  35.  * can do /lib/ld-linux.so.2 /bin/ps for example. (Which worked on acl enabled
  36.  * 2.6.14.3-grsec..)
  37.  * What happens afterwards depends on the rest of the acl system, however, I
  38.  * would imagine most cases would allow you to execute code. Useful for the
  39.  * below type acl setups
  40.  * subject /bin/passwd o {
  41.  *        /                               r
  42.  *        /dev                            h
  43.  *        /dev/console                    rw
  44.  *        /dev/urandom                    r
  45.  *        /lib                            rx
  46.  *        /proc
  47.  *        /proc/kcore                     h
  48.  *        /proc/sys                       h
  49.  *        /proc/bus                       h
  50.  *        /usr                            h
  51.  *        /usr/lib/cracklib_dict.hwm      r
  52.  *        /usr/lib/cracklib_dict.pwd      r
  53.  *        /usr/lib/cracklib_dict.pwi      r
  54.  *        /var                            h
  55.  *        /var/run
  56.  *        /var/run/utmp                   rw
  57.  *        /etc                            rwcd
  58.  *        /etc/pam.d
  59.  *        /etc/pam.d/other                r
  60.  *        /etc/pam.d/passwd               r
  61.  *        /etc/pam.d/system-auth          r
  62.  *        /etc/ssh                        h
  63.  *        /etc/shadow-                    h
  64.  *        /etc/gshadow                    h
  65.  *        /etc/gshadow-                   h
  66.  *        /sys                            h
  67.  *        -CAP_ALL
  68.  *        +CAP_CHOWN
  69.  *        +CAP_FSETID
  70.  *        bind    disabled
  71.  *        connect disabled
  72.  * }
  73.  * If there was some execution control ability in passwd, the shellcode just
  74.  * needs a execve("/lib/ld-linux.so.2", [ "/bin/sh", "/bin/sh", NULL ], NULL);
  75.  * assert(sizeof(comments) > sizeof(code))
  76.  * To test this, create an appropriate learning type acl program with no
  77.  * parameters, then try running it with a parameter. /bin/ps should run.
  78.  * Work arounds:
  79.  * If the acl gives a lot of privileges (modifying /etc/ is a fair amount)
  80.  *- Compile the binary statically (dietlibc might help here)
  81.  * If the acl takes away a lot of privileges, and you don't want it to
  82.  * escape:
  83.  *- use inherited mode for your binaries. This may not be
  84.  *  applicable in all cases, however. Make sure you're not
  85.  *  allowing interpreters though if you can avoid it. (bash,
  86.  *  python, perl, etc.). Also, some programs don't make sense to
  87.  *  run in inherited mode (opensshd for example.)
  88.  *If what they get doesn't matter, then sleep tight :)
  89.  */
  90. #include <stdlib.h>
  91. #include <unistd.h>
  92. #include <stdio.h>
  93. #include <string.h>
  94. #include <sys/types.h>
  95.  
  96. int main(int argc, char **argv, char **envp) {
  97. char *args[] = { "/bin/ps", "/bin/ps", NULL };  // can use, other shit here to.. i have, used other binarys anyow .. -xd
  98. if(argc != 1) {
  99. execve("/lib/ld-2.3.5.so", args, envp);
  100. printf("Failed to execve()\n");
  101. }
  102. }
Add Comment
Please, Sign In to add comment