w00p. We on a roll now girls. libopm works. Detects Open Proxies. Cleans up after itself. Now have toadd new /msg opsb set interface etc... leave that for another day... I'm melting now!

This commit is contained in:
Fish 2003-10-28 12:45:28 +00:00
parent 7cb4295207
commit 48daac5382
3 changed files with 50 additions and 31 deletions

6
opsb.c
View file

@ -217,7 +217,6 @@ int __Bot_Message(char *origin, char **argv, int argc)
scandata = malloc(sizeof(scaninfo));
scandata->doneban = 0;
scandata->u = u;
scandata->socks = NULL;
if ((u2 = finduser(argv[2])) != NULL) {
/* don't scan users from my server */
if (!strcasecmp(u2->server->name, me.name)) {
@ -843,7 +842,6 @@ static int ScanNick(char **av, int ac) {
scandata = malloc(sizeof(scaninfo));
scandata->u = NULL;
scandata->doneban = 0;
scandata->socks = NULL;
strncpy(scandata->who, u->nick, MAXHOST);
strncpy(scandata->lookup, u->hostname, MAXHOST);
strncpy(scandata->server, u->server->name, MAXHOST);
@ -1034,10 +1032,12 @@ void dnsblscan(char *data, adns_answer *a) {
do_ban(scandata);
#endif
checkqueue();
} else
} else {
if (scandata->u) prefmsg(scandata->u->nick, s_opsb, "%s does not appear in DNS black list", scandata->lookup);
nlog(LOG_DEBUG1, LOG_MOD, "Got Negative OPM lookup for %s (%s)", scandata->who, scandata->lookup);
scandata->dnsstate = NOOPMLIST;
}
check_scan_free(scandata);
break;
default:
nlog(LOG_WARNING, LOG_MOD, "Warning, Unknown Status in dnsblscan()");

18
opsb.h
View file

@ -16,7 +16,6 @@
typedef struct proxy_types {
char *type;
int port;
int (*scan)(int sock);
int nofound;
int noopen;
} proxy_types;
@ -43,7 +42,6 @@ struct scanq {
struct in_addr ipaddr;
User *u;
int doreport;
list_t *socks;
time_t started;
int doneban;
char connectstring[BUFSIZE];
@ -72,14 +70,6 @@ struct opsb {
int opmhits;
} opsb;
struct sockinfo {
int sock;
int (*function)(int sock);
int flags;
int type;
int bytes;
char buf[2048];
};
typedef struct sockinfo socklist;
@ -122,12 +112,8 @@ list_t *exempt;
#define GOTOPENPROXY 0x0010
#define OPMLIST 0x0020
#define NOOPMLIST 0x0040
#define FIN_SCAN 0x0080
/* this is some socklist flags */
#define CONNECTING 0x0001
#define SOCKCONNECTED 0x0002
#define UNCONNECTED 0x0004
#define OPENPROXY 0x0008
/* opsb.c */
int findscan(const void *key1, const void *key2);
@ -139,6 +125,6 @@ void addtocache(unsigned long ipaddr);
/* proxy.c */
void start_proxy_scan(lnode_t *scannode);
void send_status(User *u);
void check_scan_free(scaninfo *scandata);
#endif /* OPSB_H */

55
proxy.c
View file

@ -84,6 +84,20 @@ int init_libopm() {
opm_config(scanner, OPM_CONFIG_MAX_READ, &opsb.maxbytes);
opm_addtype(scanner, OPM_TYPE_HTTP, 8080);
opm_addtype(scanner, OPM_TYPE_HTTP, 80);
opm_addtype(scanner, OPM_TYPE_HTTP, 3128);
opm_addtype(scanner, OPM_TYPE_HTTP, 31);
opm_addtype(scanner, OPM_TYPE_HTTP, 8000);
opm_addtype(scanner, OPM_TYPE_HTTPPOST, 8080);
opm_addtype(scanner, OPM_TYPE_HTTPPOST, 80);
opm_addtype(scanner, OPM_TYPE_HTTPPOST, 3128);
opm_addtype(scanner, OPM_TYPE_HTTPPOST, 31);
opm_addtype(scanner, OPM_TYPE_HTTPPOST, 8000);
opm_addtype(scanner, OPM_TYPE_WINGATE, 23);
opm_addtype(scanner, OPM_TYPE_ROUTER, 23);
opm_addtype(scanner, OPM_TYPE_SOCKS4, 1080);
opm_addtype(scanner, OPM_TYPE_SOCKS5, 1080);
/* add the sock poll interface into neo */
@ -119,10 +133,10 @@ void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused)
fclose(fp);
#endif
/* no point continuing the scan if they are found open */
scandata->state = GOTOPENPROXY;
opm_end(scanner, remote);
#if 0
if (scandata->dnsstate == OPMLIST) {
scandata->doneban = 1;
@ -145,7 +159,6 @@ void negfailed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused)
if (scandata->u) {
prefmsg(scandata->u->nick, s_opsb, "Negitiation failed for protocol %d (%d)", remote->protocol, remote->port);
}
/*XXX Do anything.. I dont think so */
}
void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused) {
@ -157,7 +170,6 @@ void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused) {
if (scandata->u) {
prefmsg(scandata->u->nick, s_opsb, "Timeout on Protocol %d (%d)", remote->protocol, remote->port);
}
/*XXX Do anything? I don't think so */
}
void scan_end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused) {
@ -169,7 +181,8 @@ void scan_end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *unused) {
if (scandata->u) {
prefmsg(scandata->u->nick, s_opsb, "scan finished %d %d", remote->protocol, remote->port);
}
/*XXX we have to cleanup here */
if (scandata->state != GOTOPENPROXY) scandata->state = FIN_SCAN;
check_scan_free(scandata);
}
void scan_error(OPM_T *scanner, OPM_REMOTE_T *remote, int opmerr, void *unused) {
@ -190,9 +203,8 @@ void scan_error(OPM_T *scanner, OPM_REMOTE_T *remote, int opmerr, void *unused)
#endif
scandata = remote->data;
if (scandata->u) {
prefmsg(scandata->u->nick, s_opsb, "scan error on Protocol %d (%d)", remote->protocol, remote->port);
prefmsg(scandata->u->nick, s_opsb, "scan error on Protocol %d (%d) - %d", remote->protocol, remote->port, opmerr);
}
/*XXX cleanup */
}
@ -273,20 +285,41 @@ void start_proxy_scan(lnode_t *scannode) {
scandata->started = time(NULL);
if ((opsb.doscan == 1) || (scandata->u)) {
nlog(LOG_DEBUG2, LOG_MOD, "Starting Scan on %s", inet_ntoa(scandata->ipaddr));
remote = opm_remote_create(inet_ntoa(scandata->ipaddr));
remote->data = scandata;
switch(i = opm_scan(scanner, remote))
{
case OPM_SUCCESS:
nlog(LOG_DEBUG2, LOG_MOD, "Starting Scan on %s", inet_ntoa(scandata->ipaddr));
break;
case OPM_ERR_BADADDR:
printf("Bad address\n");
nlog(LOG_WARNING, LOG_MOD, "Scan of %s %s Failed. Bad Address?", scandata->who, inet_ntoa(scandata->ipaddr));
opm_remote_free(remote);
/* XXX do what else ? */
default:
printf("Unknown Error %d\n", i);
scandata->state = FIN_SCAN;
check_scan_free(scandata);
}
}
}
void check_scan_free(scaninfo *scandata) {
lnode_t *scannode;
if ((scandata->dnsstate == DO_OPM_LOOKUP) || (scandata->dnsstate == GET_NICK_IP) || (scandata->state == DOING_SCAN)) {
nlog(LOG_DEBUG2, LOG_MOD, "Not Cleaning up Scaninfo for %s yet. Scan hasn't completed", scandata->who);
return;
}
if ((scandata->dnsstate != OPMLIST) && (scandata->state != GOTOPENPROXY)) {
addtocache(scandata->ipaddr.s_addr);
nlog(LOG_DEBUG1, LOG_MOD, "%s's Host is clean. Adding to Cache", scandata->who);
}
scannode = list_find(opsbl, scandata->who, findscan);
if (scannode) {
nlog(LOG_DEBUG1, LOG_MOD, "%s scan finished. Cleaning up", scandata->who);
list_delete(opsbl, scannode);
lnode_destroy(scannode);
scandata->u = NULL;
free(scandata);
} else {
nlog(LOG_WARNING, LOG_MOD, "Damn, Can't find ScanNode %s. Something is fubar", scandata->who);
}
checkqueue();
}