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
|
/* Analyse traffic for logging mode */
/* - by: Brecht Claerhout */
const unsigned char *data;
memcpy(&tcphead,header,sizeof(struct TCP_header));
dummy_pointer=search_dynam(filename, TCP);
if(dummy_pointer!=NULL) status=1;
if(status==0) /* make a new entry unless it's reset */
{
if(finish!=TCP_FINISH)
if((dummy_pointer=add_dynam(filename, TCP, 0,ntohl(tcphead.seq_nr),info.DATA_len))==NULL)
return;
};
if(finish==TCP_FINISH) /* let's reset the connection */
{delete_dynam(filename, TCP, 0);}
/*** return before using any search or pointer!!!!!!!! ***/
/* Connections with FIN have deleted entries! */
dummy=ntohs(tcphead.offset_flag);
if(LOGPARAM & LOGPARAM_RAW) /* Raw logging */
{
if(dummy&SYN) print_conn(filename,"Connection initiated. (SYN)");
if(dummy&FIN) print_conn(filename,"Connection ending. (FIN)");
if(dummy&RST) print_conn(filename,"Connection reset. (RST)");
return;
};
data = sp+PROTO_HEAD+info.IP_len+info.TCP_len;
if(LOGPARAM & LOGPARAM_NORM) /* NORM logging */
{
if(search_dynam(filename2, TCP)==NULL)
{
if(dummy&SYN) print_conn(filename,"Connection initiated.");
if(dummy&FIN) print_conn(filename2,"Connection closed.");
if(dummy&RST) print_conn(filename2,"Connection closed.");
};
};
if((dummy&FIN)||(dummy&RST)) return; /* needed, cauz entry don't exist */
/*** TELNET *****************************************************************/
if(LOGPARAM & LOGPARAM_TELNET)
{
dummy_pointer=search_dynam(filename, TCP);
/* don't forget to check dummy_pointer!!! */
if( (ntohs(tcphead.source) == 23)&&(dummy_pointer!=NULL))/* from telnet */
{
sbuf_update(dummy_pointer,ntohl(tcphead.seq_nr),data,info.DATA_len);
/* detect login */
strlower(dummy_pointer->scroll_buf);
if((dummy_pointer->log!=LOG_NO_DETECT)&&
(strstr(dummy_pointer->scroll_buf,"login")!=NULL))
{
dummy_pointer->log=LOG_NO_DETECT;
dummy_pointer=search_dynam(filename2, TCP);
if(dummy_pointer!=NULL)
{
dummy_pointer->log=LOG_LOGIN;
dummy_pointer->bytes=0;
dummy_pointer->buffer=malloc(LOG_PASS_BUF);
if(dummy_pointer->buffer==NULL) exit(1);
dummy_pointer->buffer[0]=0;
}
else
{print_conn(filename2,"Password missed due to overload.");};\
#ifdef DEBUG_ONSCREEN
printf("Login detected, data initialised.\n");
#endif
}
}
if( (ntohs(tcphead.destination) == 23)&&(dummy_pointer!=NULL))/* TO telnet */
{
if(dummy_pointer->log==LOG_LOGIN) /* log login */
{
record_buf(dummy_pointer,ntohl(tcphead.seq_nr),data,info.DATA_len,0);
if(dummy_pointer->log==LOG_LOGIN_RECORDED) /* login recorded */
{
print_login(filename,dummy_pointer->buffer);
dummy_pointer->log=LOG_PWD; dummy_pointer->bytes=0;
dummy_pointer->buffer[0]=0;
}
}
else
{
if(dummy_pointer->log==LOG_PWD) /* log pwd */
{
record_buf(dummy_pointer,ntohl(tcphead.seq_nr),data,info.DATA_len,0);
if(dummy_pointer->log==LOG_PWD_RECORDED) /* passwd recorded */
{
print_pwd(filename,dummy_pointer->buffer);
dummy_pointer->log=LOG_NO_LOG; dummy_pointer->bytes=0;
dummy_pointer->buffer[0]=0;
}
}
}
}
}
/*** END TELNET - LOGIN ***************************************************/
/*** FTP *******************************************************************/
if(LOGPARAM & LOGPARAM_FTP) /* loglevel 12 */
{
dummy_pointer=search_dynam(filename, TCP);
/* don't forget to check dummy_pointer!!! */
if( (ntohs(tcphead.destination) == 21) &&
(dummy_pointer!=NULL))/* to FTP */
{
sbuf_update(dummy_pointer,ntohl(tcphead.seq_nr),data,info.DATA_len);
/* detect USER en PASS */
if((help=strstr(dummy_pointer->scroll_buf,"USER"))!=NULL)
{
help+=strlen("USER ");
for(i=0;i<SCBUF;i++)
if(dummy_pointer->scroll_buf[i]==FTP_ENTER)
dummy_pointer->scroll_buf[i]=0;
print_ftp_user(filename,help);
for(i=0;i<SCBUF;i++) dummy_pointer->scroll_buf[i]=' ';
}
if((help=strstr(dummy_pointer->scroll_buf,"PASS"))!=NULL)
{
help+=strlen("PASS ");
for(i=0;i<SCBUF;i++)
if(dummy_pointer->scroll_buf[i]==FTP_ENTER)
dummy_pointer->scroll_buf[i]=0;
print_ftp_pass(filename,help);
for(i=0;i<SCBUF;i++) dummy_pointer->scroll_buf[i]=' ';
}
}
}
/*** END FTP ***************************************************************/
/*** MAIL ******************************************************************/
if(LOGPARAM & LOGPARAM_MAIL) /* loglevel 12 */
{
/* dummy_pointer=search_dynam(filename, TCP); */
/* don't forget to check dummy_pointer!!! */
if( (ntohs(tcphead.destination) == 25) ) /* to MAIL */
{
if(info.DATA_len!=0)
{
char workbuf1[MTU];
char *wb_dummy;
char *p;
size_t len = info.DATA_len <= MTU-1 ? info.DATA_len : MTU-1;
strncpy(workbuf1,data,len);
workbuf1[len]=0;
strlower(workbuf1);
if((p=strstr(workbuf1,"mail from"))!=NULL)
{
char workbuf2[MTU];
strcpy(workbuf2, p);
if(strchr(workbuf2,13)!=NULL) /* remove trailing enter */
{wb_dummy=strchr(workbuf2,13); *wb_dummy=0;}
if(strchr(workbuf2,10)!=NULL)
{wb_dummy=strchr(workbuf2,10); *wb_dummy=0;}
print_mail(filename,workbuf2);
}
if((p=strstr(workbuf1,"rcpt to"))!=NULL)
{
char workbuf2[MTU];
strcpy(workbuf2, p);
if(strchr(workbuf2,13)!=NULL) /* remove trailing enter */
{wb_dummy=strchr(workbuf2,13); *wb_dummy=0;}
if(strchr(workbuf2,10)!=NULL)
{wb_dummy=strchr(workbuf2,10); *wb_dummy=0;}
print_mail(filename,workbuf2);
}
}
}
}
/*** END MAIL **************************************************************/
if( (dummy_pointer=search_dynam(filename, TCP)) !=NULL)
{
if(ntohl(tcphead.seq_nr)==dummy_pointer->exp_seq)
dummy_pointer->exp_seq+=info.DATA_len;
/* if we miss a packet... no probs seq nr's get updated */
/* cauz' we can't rely on ACK's from other side */
/* it's pretty good this way */
if(ntohl(tcphead.seq_nr)>dummy_pointer->exp_seq)
dummy_pointer->exp_seq=ntohl(tcphead.seq_nr)+info.DATA_len;
}
return;
return; /* DON'T FORGET THEM!!!! */
|