Changeset 1389
- Timestamp:
- 09/22/07 22:05:09 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
honeytrap/trunk/src/modules/htm_cspm/connectback.c
r1387 r1389 1 /* connectback.c 2 * Copyright (C) 2007 Tillmann Werner <tillmann.werner@gmx.de> 3 * 4 * This file is free software; as a special exception the author gives 5 * unlimited permission to copy and/or distribute it, with or without 6 * modifications, as long as this notice is preserved. 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 10 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 13 #include <arpa/inet.h> 14 #include <errno.h> 15 #include <netdb.h> 1 16 #include <stdio.h> 2 17 #include <stdlib.h> 3 18 #include <string.h> 4 19 #include <strings.h> 5 #include <netdb.h>6 20 #include <sys/socket.h> 7 #include <arpa/inet.h> 21 #include <sys/time.h> 22 #include <sys/types.h> 8 23 #include <unistd.h> 9 #include <errno.h>10 24 11 25 #include <logging.h> … … 15 29 #include "honeytrap.h" 16 30 #include "sc_action.h" 31 #include "signals.h" 17 32 #include "sock.h" 18 33 #include "tcpip.h" … … 20 35 21 36 int connectback(struct sc_action* sa, int haskey) { 22 int sockfd, t, bytes_read, total_bytes;23 fd_set read_fds;24 struct timeval st;25 struct sockaddr_in sock;26 u_char buffer[BUFSIZ], *attack_string;27 Attack *a;37 int sockfd, t, bytes_read, total_bytes; 38 fd_set rfds; 39 struct timeval st; 40 struct sockaddr_in sock; 41 u_char buffer[BUFSIZ], *attack_string; 42 Attack *a; 28 43 29 44 if ((a = new_virtattack(*(struct in_addr*) &sa->m_localhost, *(struct in_addr*) &sa->m_action.m_connectback.m_remotehost, … … 52 67 return(0); 53 68 } 54 logmsg(LOG_INFO, 1, "CSPM - Connected back to %s:%d.\n",69 logmsg(LOG_INFO, 1, "CSPM - Successfully connected back to %s:%d.\n", 55 70 inet_ntoa(*(struct in_addr *)&sa->m_action.m_connectback.m_remotehost), 56 71 sa->m_action.m_connectback.m_remoteport); … … 64 79 /* send key */ 65 80 if (haskey) { 81 logmsg(LOG_INFO, 1, "CSPM - Sending key.\n"); 66 82 if (write(sockfd, &sa->m_action.m_connectback.m_key, sizeof(sa->m_action.m_connectback.m_key)) < 67 83 sizeof(sa->m_action.m_connectback.m_key)) { … … 75 91 /* read data */ 76 92 for(;;) { 77 FD_ZERO(&r ead_fds);78 FD_SET(sockfd, &r ead_fds);93 FD_ZERO(&rfds); 94 FD_SET(sockfd, &rfds); 79 95 80 96 st.tv_sec = 10; 81 97 st.tv_usec = 0; 82 98 83 switch (t = select(FD_SETSIZE, &read_fds, NULL, NULL, &st)) { 84 case -1: 85 fprintf(stderr, "Error with select(): %s.\n", strerror(errno)); 86 exit(1); 87 case 0: 88 break; 89 default: 99 switch (t = select(MAX(sigpipe[0], sockfd), &rfds, NULL, NULL, &st)) { 100 case -1: 101 fprintf(stderr, "Error with select(): %s.\n", strerror(errno)); 102 exit(1); 103 case 0: 104 break; 105 default: 106 if (FD_ISSET(sigpipe[0], &rfds) && (check_sigpipe() == -1)) { 107 logmsg(LOG_ERR, 1, "Error - Signal handling failed in dynamic server process.\n"); 108 exit(EXIT_FAILURE); 109 } 110 if (FD_ISSET(sockfd, &rfds)) { 90 111 if ((bytes_read = read(sockfd, buffer, BUFSIZ)) < 0) { 91 112 logmsg(LOG_ERR, 1, "CSPM - Error while reading data from connectback socket: %s.\n", … … 124 145 // process data 125 146 return(process_data(attack_string, total_bytes, NULL, 0, a->a_conn.l_port, a)); 147 } 126 148 } 127 149 }
