From 571f989fa28a5acbd465819060e07a934f062894 Mon Sep 17 00:00:00 2001 From: Fish <> Date: Wed, 29 Oct 2003 11:07:23 +0000 Subject: [PATCH] almost complete. Need to just setup the port save feature, and port to Marks new string functions --- .gitattributes | 1 + opsb.Settings | 10 ++ opsb.c | 129 +++++++++++++++++- opsb.h | 22 +++- opsb_help.c | 352 ++++++++++++++++++++++++++----------------------- proxy.c | 110 ++++++++++++---- 6 files changed, 423 insertions(+), 201 deletions(-) create mode 100644 opsb.Settings diff --git a/.gitattributes b/.gitattributes index 0f1b8ca..399faac 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,6 +33,7 @@ libopm/snprintf.c -text libopm/snprintf.h -text libopm/test.c -text /modconfig.h.in -text +/opsb.Settings -text /opsb.c -text /opsb.h -text /opsb_help.c -text diff --git a/opsb.Settings b/opsb.Settings new file mode 100644 index 0000000..1ea5241 --- /dev/null +++ b/opsb.Settings @@ -0,0 +1,10 @@ +g = { + OPSB: = { + HTTP (S) = "80 8080 8000 3128"; + HTTPPOST (S) = "80 8080 8000 3128"; + ROUTER (S) = "23"; + SOCKS4 (S) = "1080"; + SOCKS5 (S) = "1080"; + WINGATE (S) = "23"; + } +} diff --git a/opsb.c b/opsb.c index 4e57730..2dd208f 100644 --- a/opsb.c +++ b/opsb.c @@ -53,6 +53,7 @@ extern const char *opsb_help_status[]; extern const char *opsb_help_set[]; extern const char *opsb_help_exclude[]; extern const char *opsb_help_remove[]; +extern const char *opsb_help_ports[]; int online; @@ -83,7 +84,23 @@ int findscan(const void *key1, const void *key2) { return (strcasecmp(chan1->who, key2)); } - +int ports_sort(const void *key1, const void *key2) { + port_list *pl1 = (port_list *)key1; + port_list *pl2 = (port_list *)key2; + if (pl1->type == pl2->type) { + if (pl1->port == pl2->port) { + return 0; + } else if (pl1->port > pl2->port) { + return 1; + } else { + return -1; + } + } else if (pl1->type > pl2->type) { + return 1; + } else { + return -1; + } +} int __Bot_Message(char *origin, char **argv, int argc) @@ -92,6 +109,7 @@ int __Bot_Message(char *origin, char **argv, int argc) lnode_t *lnode; scaninfo *scandata; exemptinfo *exempts; + port_list *pl; int lookuptype, i; char *buf; @@ -118,6 +136,8 @@ int __Bot_Message(char *origin, char **argv, int argc) privmsg_list(u->nick, s_opsb, opsb_help_status); } else if ((!strcasecmp(argv[2], "set") && UserLevel(u) >= 100)) { privmsg_list(u->nick, s_opsb, opsb_help_set); + } else if ((!strcasecmp(argv[2], "ports") && UserLevel(u) >= 100)) { + privmsg_list(u->nick, s_opsb, opsb_help_ports); } else if ((!strcasecmp(argv[2], "exclude") && UserLevel(u) > 100)) { privmsg_list(u->nick, s_opsb, opsb_help_exclude); } else if ((!strcasecmp(argv[2], "remove") && UserLevel(u) > 40)) { @@ -334,6 +354,95 @@ int __Bot_Message(char *origin, char **argv, int argc) prefmsg(u->nick, s_opsb, "Syntax Error. /msg %s help exclude", s_opsb); return 0; } + } else if (!strcasecmp(argv[1], "PORTS")) { + if (UserLevel(u) < 100) { + prefmsg(u->nick, s_opsb, "Access Denied"); + chanalert(s_opsb, "%s tried to use ports, but is not an operator", u->nick); + return 1; + } + if (argc < 3) { + prefmsg(u->nick, s_opsb, "Syntax Error. /msg %s help ports", s_opsb); + return 0; + } + if (!strcasecmp(argv[2], "LIST")) { + lnode = list_first(opsb.ports); + i = 1; + prefmsg(u->nick, s_opsb, "Port List:"); + while (lnode) { + pl = lnode_get(lnode); + prefmsg(u->nick, s_opsb, "%d) %s Port: %d", i, type_of_proxy(pl->type), pl->port); + ++i; + lnode = list_next(opsb.ports, lnode); + } + prefmsg(u->nick, s_opsb, "End of List."); + chanalert(s_opsb, "%s requested Port List", u->nick); + } else if (!strcasecmp(argv[2], "ADD")) { + if (argc < 5) { + prefmsg(u->nick, s_opsb, "Syntax Error. /msg %s help ports", s_opsb); + return 0; + } + if (list_isfull(opsb.ports)) { + prefmsg(u->nick, s_opsb, "Error, Ports list is full", s_opsb); + return 0; + } + if (!atoi(argv[4])) { + prefmsg(u->nick, s_opsb, "Port field does not contain a vaild port"); + return 0; + } + if (get_proxy_by_name(argv[3]) < 1) { + prefmsg(u->nick, s_opsb, "Unknown Proxy type %s", argv[3]); + return 0; + } + pl = malloc(sizeof(port_list)); + pl->type = get_proxy_by_name(argv[3]); + pl->port = atoi(argv[4]); + lnode = lnode_create(pl); + list_append(opsb.ports, lnode); + list_sort(opsb.ports, ports_sort); +#if 0 + save_ports(); +#endif + add_port(pl->type, pl->port); + prefmsg(u->nick, s_opsb, "Added Port %d for Protocol %s to Ports list", pl->port, argv[3]); + chanalert(s_opsb, "%s added port %d for protocol %s to Ports list", u->nick, pl->port, argv[3]); + } else if (!strcasecmp(argv[2], "DEL")) { + if (argc < 3) { + prefmsg(u->nick, s_opsb, "Syntax Error. /msg %s help ports", s_opsb); + return 0; + } + if (atoi(argv[3]) != 0) { + lnode = list_first(opsb.ports); + i = 1; + while (lnode) { + if (i == atoi(argv[3])) { + /* delete the entry */ + pl = lnode_get(lnode); + list_delete(opsb.ports, lnode); + prefmsg(u->nick, s_opsb, "Deleted Port %d of Protocol %s out of Ports list", pl->port, type_of_proxy(pl->type)); + prefmsg(u->nick, s_opsb, "You need to Restart OPSB for the changes to take effect"); + chanalert(s_opsb, "%s deleted port %d of Protocol %s out of Ports list", u->nick, pl->port, type_of_proxy(pl->type)); + free(pl); + /* just to be sure, lets sort the list */ + list_sort(opsb.ports, ports_sort); +#if 0 + save_ports(); +#endif + return 1; + } + ++i; + lnode = list_next(opsb.ports, lnode); + } + /* if we get here, then we can't find the entry */ + prefmsg(u->nick, s_opsb, "Error, Can't find entry %d. /msg %s ports list", atoi(argv[3]), s_opsb); + return 0; + } else { + prefmsg(u->nick, s_opsb, "Error, Out of Range"); + return 0; + } + } else { + prefmsg(u->nick, s_opsb, "Syntax Error. /msg %s help ports", s_opsb); + return 0; + } } else if (!strcasecmp(argv[1], "SET")) { if (argc < 3) { prefmsg(u->nick, s_opsb, "Syntax Error. /msg %s help set", s_opsb); @@ -541,16 +650,15 @@ int Online(char **av, int ac) { SET_SEGV_LOCATION(); - init_libopm(); if (init_bot(s_opsb,"opsb",me.name,"Proxy Scanning Bot", "+S", __module_info.module_name) == -1 ) { /* Nick was in use!!!! */ s_opsb = strcat(s_opsb, "_"); init_bot(s_opsb,"opsb",me.name,"Proxy Scanning Bot", "+S", __module_info.module_name); } loadcache(); - if (opsb.confed == 0) add_mod_timer("unconf", "Un_configured_warn", "opsb", 60); - unconf(); if (opsb.confed == 0) { + add_mod_timer("unconf", "Un_configured_warn", "opsb", 60); + unconf(); getpeername(servsock, (struct sockaddr *)&sa, (socklen_t*)&ulen); snprintf(opsb.targethost, MAXHOST, "%s", inet_ntoa(sa.sin_addr)); } @@ -729,7 +837,6 @@ void loadcache() { if (!fp) { nlog(LOG_WARNING, LOG_MOD, "OPSB: Warning, Can not open Cache file for Reading"); - chanalert(s_opsb, "Warning, Can not open Cache file for Reading"); return; } fgets(buf, 512, fp); @@ -1124,6 +1231,8 @@ int __ModInit(int modnum, int apiver) exempt = list_create(MAX_EXEMPTS); + opsb.ports = list_create(MAX_PORTS); + online = 0; sprintf(opsb.opmdomain, "%s", "opm.blitzed.org"); sprintf(opsb.targethost, "%s", me.uplink); @@ -1141,6 +1250,16 @@ int __ModInit(int modnum, int apiver) opsb.opmhits = 1; snprintf(opsb.lookforstring, 512, "*** Looking up your hostname..."); snprintf(opsb.scanmsg, 512, "Your Host is being Scanned for Open Proxies"); + + loadcache(); + + if (load_ports() != 1) { + nlog(LOG_WARNING, LOG_MOD, "Can't Load opsb. No Ports Defined for Scanned. Did you install Correctly?"); + return -1; + } + init_libopm(); + + return 1; } diff --git a/opsb.h b/opsb.h index 119816b..3694875 100644 --- a/opsb.h +++ b/opsb.h @@ -12,14 +12,14 @@ #define OPSB_H #include "modconfig.h" +#include "opm_types.h" -typedef struct proxy_types { - char *type; +typedef struct port_list { + int type; int port; int nofound; int noopen; -} proxy_types; - +} port_list; char *s_opsb; @@ -31,7 +31,8 @@ char *s_opsb; #define MAX_QUEUE MAX_SCANS * 100 /* max no of exempt entries */ #define MAX_EXEMPTS 20 - +/* max no of ports to scan */ +#define MAX_PORTS 50 struct scanq { char who[MAXHOST]; @@ -68,6 +69,7 @@ struct opsb { int doscan; int cachehits; int opmhits; + list_t *ports; } opsb; @@ -100,6 +102,15 @@ struct exempts { typedef struct exempts exemptinfo; + +typedef struct proxy_type { + int type; + char name[MAXNICK]; +} proxy_type; + + + + /* this is the list of exempted hosts/servers */ list_t *exempt; @@ -126,5 +137,6 @@ void addtocache(unsigned long ipaddr); void start_proxy_scan(lnode_t *scannode); void send_status(User *u); void check_scan_free(scaninfo *scandata); +int init_libopm(); #endif /* OPSB_H */ diff --git a/opsb_help.c b/opsb_help.c index 129cbb8..4112256 100644 --- a/opsb_help.c +++ b/opsb_help.c @@ -23,166 +23,192 @@ #include "stats.h" -const char *opsb_help[] = { - "\2Open Proxy Scanning Bot\2 scans the network for insecure", - "clients. For more info \2/msg opsb info\2", - "", - "The following commands can be used with opsb", - "", - " LOOKUP Lookup DNS record", - " INFO Information about opsb", - NULL -}; - -const char *opsb_help_oper[] = { - "", - "Additional commands for Operators", - "", - " CHECK Scan a selected user", - " STATUS View opsb state information", - " SET Change opsb configuration options", - " EXCLUDE Exclude a host from scanning", - " REMOVE Remove an akill set by opsb", - NULL -}; - -const char *opsb_help_on_help[] = { - "", - "To use a command, type", - " \2/msg opsb command\2", - "For for more information on a command, type", - " \2/msg opsb HELP command\2.", - NULL -}; - - -const char *opsb_help_lookup[] = { - "Syntax: \2LOOKUP \2", - "", - "This command allows you to lookup DNS records on the", - "Internet. Different types of records can be looked up", - "by specifying different flags", - "", - "The Flags are:", - " txt - Lookup Text Records", - " rp - Lookup the Responsible Person for this record", - " ns - Lookup the Name Servers for this record", - " soa - Lookup the SOA for this Record", - "", - "If you do not specify a flag, it defaults to looking up", - "either the IP address for Hostnames, or the Hostname for", - "IP addresses", - NULL -}; - -const char *opsb_help_info[] = { - "\2Open Proxy Scanning Bot Information\2", - "", - "This bot is intended to scan clients connecting to this", - "network for insecure proxies. Insecure proxies are often", - "used to attack networks or channel with \2clone\2 bots", - "This check scans the following ports:", - " 3128, 8080, 80 23 and 1080", - "If you have Firewall, or IDS software, please ignore any", - "errors that this scan may generate", - "", - "If you have any further questions, please contact network", - "administration staff", - NULL -}; - -const char *opsb_help_check[] = { - "Syntax: \2CHECK \2", - "", - "This option will scan either a user connected to your", - "network, an IP address, or Hostname for Insecure proxies,", - "and report the status to you. If an Insecure proxy is", - "found, the host will be banned from the network", - NULL -}; - -const char *opsb_help_status[] = { - "Syntax: \2STATUS\2", - "", - "View detailed information about the state of the Open", - "Proxy Scanning Bot", - NULL -}; - -const char *opsb_help_set[] = { - "Syntax: \2SET