char *CONF_SENDMAIL = 0;
char *CONF_HELP_EMAIL = 0;
char *CONF_AWAY = 0;
+char *CONF_TARGET_STRING = 0;
int CONF_SCANPORT = 0;
int CONF_PORT = 0;
{"SENDMAIL", TYPE_STRING, 0,0, &CONF_SENDMAIL },
{"HELP_EMAIL", TYPE_STRING, 1,0, &CONF_HELP_EMAIL },
{"AWAY", TYPE_STRING, 1,0, &CONF_AWAY },
+ {"TARGET_STRING", TYPE_STRING, 1,0, &CONF_TARGET_STRING },
{0, 0, 0,0, 0 },
};
time(&(conn->create_time)); /* Log create time of connection for timeouts */
conn->state = STATE_ESTABLISHED; /* Flag conn established (for write) */
fcntl(conn->fd, F_SETFL, O_NONBLOCK); /* Set socket non blocking */
- connect(conn->fd, (struct sockaddr *) &(conn->sockaddr), sizeof(conn->sockaddr)); /* Connect ! */
+ connect(conn->fd, (struct sockaddr *) &(conn->sockaddr), sizeof(conn->sockaddr)); /* Connect ! */
+
+ conn->data = malloc(SCANBUFFER * sizeof(char)); /* Allocate memory for the scan buffer */
+ conn->datasize = 0;
+
FD_USE++; /* Increase global FD Use counter */
}
void scan_readready(scan_struct *conn)
{
- scan_struct *ss;
+ char c;
- if((*conn->protocol->r_handler)(conn)) /* If read returns true, flag socket for closed and kline*/
- {
- irc_kline(conn->irc_addr, conn->addr);
+ while(1)
+ {
+ switch(read(conn->fd, &c, 1))
+ {
- if(CONF_DNSBL_FROM && CONF_DNSBL_TO && CONF_SENDMAIL && !conn->verbose)
- dnsbl_report(conn);
-
- log("SCAN -> %s: %s!%s@%s (%d)", conn->protocol->type , conn->irc_nick, conn->irc_user,
- conn->irc_addr, conn->protocol->port);
+ case 0:
+ case -1:
+ return;
+
+ default:
+ if(c == 0 || c == '\r')
+ continue;
+
+ if(c == '\n')
+ {
+ conn->data[conn->datasize] = 0;
+ conn->datasize = 0;
+ scan_read(conn);
+ continue;
+ }
+
+ if(conn->datasize < SCANBUFFER)
+ conn->data[++(conn->datasize) - 1] = c;
+ }
- irc_send("PRIVMSG %s :%s (%d): OPEN PROXY -> "
- "%s!%s@%s", CONF_CHANNELS,
- conn->protocol->type, conn->protocol->port,
- conn->irc_nick, conn->irc_user,
- conn->irc_addr);
+ }
+
+}
- conn->protocol->stat_numopen++; /* Increase number OPEN (insecure) of this type */
+/* Read one line in from remote, check line against
+ * target line.
+ */
- conn->state = STATE_CLOSED;
+void scan_read(scan_struct *conn)
+{
+ if(OPT_DEBUG >= 3)
+ log("SCAN -> Checking data from %s [%s:%d] against TARGET_STRING: %s", conn->addr,
+ conn->protocol->type, conn->protocol->port, conn->data);
+ if(strstr(conn->data, CONF_TARGET_STRING))
+ scan_openproxy(conn);
+}
- /* Flag connections with the same addr CLOSED aswell (if not verbose */
- if(!conn->verbose)
- {
- for(ss = CONNECTIONS;ss;ss = ss->next)
- {
- if(!strcmp(conn->irc_addr, ss->irc_addr))
- ss->state = STATE_CLOSED;
- }
- }
+/* Test proved positive for open proxy
+ *
+ */
- }
- else
- scan_negfail(conn);
-
-
-
+void scan_openproxy(scan_struct *conn)
+{
+ scan_struct *ss;
+
+ irc_kline(conn->irc_addr, conn->addr);
+
+ if(CONF_DNSBL_FROM && CONF_DNSBL_TO && CONF_SENDMAIL && !conn->verbose)
+ dnsbl_report(conn);
+
+ log("SCAN -> %s: %s!%s@%s (%d)", conn->protocol->type , conn->irc_nick, conn->irc_user,
+ conn->irc_addr, conn->protocol->port);
+
+ irc_send("PRIVMSG %s :%s (%d): OPEN PROXY -> "
+ "%s!%s@%s", CONF_CHANNELS,
+ conn->protocol->type, conn->protocol->port,
+ conn->irc_nick, conn->irc_user,
+ conn->irc_addr);
+
+ conn->protocol->stat_numopen++; /* Increase number OPEN (insecure) of this type */
+
+ conn->state = STATE_CLOSED;
+
+ /* Flag connections with the same addr CLOSED aswell (if not verbose */
+ if(!conn->verbose)
+ {
+ for(ss = CONNECTIONS;ss;ss = ss->next)
+ {
+ if(!strcmp(conn->irc_addr, ss->irc_addr))
+ ss->state = STATE_CLOSED;
+ }
+ }
}
/* Poll or select returned back that this connect
close(delconn->fd);
FD_USE--; /* 1 file descriptor freed up for use */
+ if(delconn->state != STATE_UNESTABLISHED) /* If it's established, free the scan buffer */
+ free(delconn->data);
+
lastss = 0;
for(ss = CONNECTIONS; ss; ss = ss->next)
char *irc_user; /* Username of user on IRC (for logging) */
char *conn_notice; /* original server notice for this connect, used
* for evidence */
+
+ char *data; /* Buffered data */
+ int datasize; /* Length of buffered data */
+
int fd; /* File descriptor of socket */
struct sockaddr_in sockaddr; /* holds information about remote host for socket() */
time_t create_time; /* Creation time, for timeout */
void scan_del(scan_struct *ss);
void scan_cycle();
void scan_check();
+ void scan_read(scan_struct *conn);
void scan_timer();
- void scan_readready();
- void scan_writeready();
- void scan_negfail();
-
- int scan_listsize();
-
+ void scan_readready(scan_struct *conn);
+ void scan_writeready(scan_struct *conn);
+ void scan_negfail(scan_struct *conn);
+ void scan_openproxy(scan_struct *conn);
+
int scan_w_squid(scan_struct *ss);
int scan_r_squid(scan_struct *ss);