4 #include "../core/config.h"
5 #include "../core/schedule.h"
6 #include "../lib/irc_string.h"
7 #include "../lib/splitline.h"
8 #include "../lib/strlfunc.h"
9 #include "../localuser/localuserchannel.h"
12 #include <mysql/mysql.h>
13 #include <mysql/mysql_version.h>
21 #define TROJANSCAN_VERSION "2.61"
23 #define TROJANSCAN_MAX_HOST_GLINE 5
25 #define TROJANSCAN_MAX_HOST_GLINE 5
27 #define TROJANSCAN_CLONE_MAX 150
28 #define TROJANSCAN_WATCHCLONE_MAX 100
29 #define TROJANSCAN_CLONE_TOTAL TROJANSCAN_CLONE_MAX + TROJANSCAN_WATCHCLONE_MAX
31 #define TROJANSCAN_POOLSIZE 1000
32 #define TROJANSCAN_MINPOOLSIZE 500 /* 500 */
34 #define TROJANSCAN_MINIMUM_HOSTS_BEFORE_POOL 5000 /* 500 */
36 #define TROJANSCAN_DEFAULT_MAXCHANS 750
37 #define TROJANSCAN_DEFAULT_CYCLETIME 800
39 #define TROJANSCAN_DEFAULT_MINIMUM_CHANNEL_SIZE 100 /* 100 */
41 #define TROJANSCAN_NICKCHANGE_ODDS 8
42 #define TROJANSCAN_INVISIBLE_ODDS 8
44 #define TROJANSCAN_DEFAULT_PARTTIME 100
45 #define TROJANSCAN_DEFAULT_MAXUSERS 20
47 #define TROJANSCAN_POOL_REGENERATION 3600
49 #define TROJANSCAN_HOST_POOL 0x00
50 #define TROJANSCAN_STEAL_HOST 0x01
52 #define TROJANSCAN_EPIDEMIC_MULTIPLIER 40
54 #define TROJANSCAN_HOST_MODE TROJANSCAN_STEAL_HOST
56 #define TROJANSCAN_MAX_CLONE_COUNT 5
58 #define TROJANSCAN_CAT "./trojanscan/cat.txt"
60 #define TROJANSCAN_CHANNEL "#qnet.sec.trj"
61 #define TROJANSCAN_OPERCHANNEL "#twilightzone"
62 #define TROJANSCAN_PEONCHANNEL "#qnet.trj"
64 #define TROJANSCAN_URL_PREFIX "http://trojanscan.quakenet.org/?"
66 #define TROJANSCAN_MMAX(a, b) a > b ? a : b
67 #define TROJANSCAN_MMIN(a, b) a > b ? b : a
69 #define TROJANSCAN_NORMAL_CLONES 0
70 #define TROJANSCAN_WATCH_CLONES 1
72 #define TROJANSCAN_QUERY_TEMP_BUF_SIZE 1040
73 #define TROJANSCAN_QUERY_BUF_SIZE 5040
75 #define TROJANSCAN_FIRST_OFFENSE 12
76 #define TROJANSCAN_IPLEN 20
78 #define TROJANSCAN_VERSION_DETECT "\001VERSION"
79 #define TROJANSCAN_CLONE_VERSION_REPLY "mIRC v6.16 Khaled Mardam-Bey"
81 typedef struct trojanscan_clones
{
82 int remaining
, sitting
, index
;
87 typedef struct trojanscan_channels
{
90 } trojanscan_channels
;
92 typedef struct trojanscan_worms
{
95 unsigned glinehost
: 1;
96 unsigned glineuser
: 1;
100 unsigned hitchans
: 1;
101 unsigned epidemic
: 1;
104 typedef struct trojanscan_phrases
{
108 trojanscan_worms
*worm
;
109 } trojanscan_phrases
;
111 typedef struct trojanscan_db
{
112 int total_channels
, total_phrases
, total_worms
, detections
, glines
;
113 trojanscan_channels
*channels
;
114 trojanscan_phrases
*phrases
;
115 trojanscan_worms
*worms
;
118 typedef struct trojanscan_prechannels
{
121 struct trojanscan_clones
*watch_clone
;
122 struct trojanscan_prechannels
*next
;
124 } trojanscan_prechannels
;
126 typedef struct trojanscan_realchannels
{
128 struct trojanscan_clones
*clone
;
129 struct trojanscan_realchannels
*next
;
133 } trojanscan_realchannels
;
135 typedef struct trojanscan_userflags
{
136 unsigned unauthed
: 1;
138 unsigned website
: 1;
140 unsigned teamleader
: 1;
141 unsigned developer
: 1;
142 } trojanscan_userflags
;
144 typedef union trojanscan_userlevel
{
146 struct trojanscan_userflags values
;
147 } trojanscan_userlevel
;
149 typedef struct trojanscan_flagmodification
{
152 } trojanscan_flagmodification
;
154 typedef struct trojanscan_rejoinlist
{
156 trojanscan_clones
*clone
;
158 struct trojanscan_realchannels
*rp
;
159 struct trojanscan_rejoinlist
*next
;
160 } trojanscan_rejoinlist
;
162 typedef struct trojanscan_inchannel
{
164 struct trojanscan_clones
*watch_clone
;
165 } trojanscan_inchannel
;
167 typedef struct trojanscan_templist
{
168 struct trojanscan_clones
*watch_clone
;
169 char active
; /* required as copy of trojanscan_inchannel could be nil unfortunatly */
170 } trojanscan_templist
;
172 typedef MYSQL_RES trojanscan_database_res
;
173 typedef MYSQL_ROW trojanscan_database_row
;
174 typedef MYSQL trojanscan_database_connection
;
176 #define TROJANSCAN_FLAG_MASK "%s%s%s%s%s"
178 #define TrojanscanIsCat(x) (x.values.cat)
179 #define TrojanscanIsWebsite(x) (x.values.website)
180 #define TrojanscanIsStaff(x) (x.values.staff)
181 #define TrojanscanIsDeveloper(x) (x.values.developer)
182 #define TrojanscanIsTeamLeader(x) (x.values.teamleader)
184 #define TrojanscanIsLeastTeamLeader(x) ((TrojanscanIsTeamLeader(x) | TrojanscanIsDeveloper(x)))
185 #define TrojanscanIsLeastWebsite(x) ((TrojanscanIsWebsite(x) | TrojanscanIsDeveloper(x)))
186 #define TrojanscanIsLeastStaff(x) ((TrojanscanIsStaff(x) | TrojanscanIsTeamLeader(x) | TrojanscanIsDeveloper(x)))
188 #define TrojanscanFlagsInfo(flags) TrojanscanIsDeveloper(flags) ? "d" : "", TrojanscanIsTeamLeader(flags) ? "t" : "", TrojanscanIsStaff(flags) ? "s" : "", TrojanscanIsWebsite(flags) ? "w" : "", TrojanscanIsCat(flags) ? "c" : ""
190 #define TROJANSCAN_ACL_UNAUTHED 0x01
191 #define TROJANSCAN_ACL_STAFF 0x02
192 #define TROJANSCAN_ACL_OPER 0x04
193 #define TROJANSCAN_ACL_DEVELOPER 0x08
194 #define TROJANSCAN_ACL_CAT 0x10
195 #define TROJANSCAN_ACL_WEBSITE 0x20
196 #define TROJANSCAN_ACL_TEAMLEADER 0x40
198 int trojanscan_status(void *sender
, int cargc
, char **cargv
);
199 int trojanscan_showcommands(void *sender
, int cargc
, char **cargv
);
200 int trojanscan_help(void *sender
, int cargc
, char **cargv
);
201 int trojanscan_hello(void *sender
, int cargc
, char **cargv
);
202 int trojanscan_userjoin(void *sender
, int cargc
, char **cargv
);
203 int trojanscan_changelev(void *sender
, int cargc
, char **cargv
);
204 int trojanscan_deluser(void *sender
, int cargc
, char **cargv
);
205 int trojanscan_rehash(void *sender
, int cargc
, char **cargv
);
206 int trojanscan_mew(void *sender
, int cargc
, char **cargv
);
207 int trojanscan_cat(void *sender
, int cargc
, char **cargv
);
208 int trojanscan_reschedule(void *sender
, int cargc
, char **cargv
);
209 int trojanscan_chanlist(void *sender
, int cargc
, char **cargv
);
210 int trojanscan_whois(void *sender
, int cargc
, char **cargv
);
211 int trojanscan_listusers(void *sender
, int cargc
, char **cargv
);
213 char trojanscan_getmtfrommessagetype(int input
);
215 void trojanscan_handlemessages(nick
*target
, int messagetype
, void **args
);
216 void trojanscan_clonehandlemessages(nick
*target
, int messagetype
, void **args
);
217 void trojanscan_mainchanmsg(char *message
, ...);
218 void trojanscan_peonchanmsg(char *message
, ...);
219 void trojanscan_reply(nick
*target
, char *message
, ... );
220 void trojanscan_privmsg_chan_or_nick(channel
*cp
, nick
*np
, char *text
, ...);
222 void trojanscan_connect(void *arg
);
223 void trojanscan_dojoin(void *arg
);
224 void trojanscan_dopart(void *arg
);
225 void trojanscan_donickchange(void *arg
);
226 void trojanscan_registerclones(void *arg
);
227 void trojanscan_fill_channels(void *arg
);
228 void trojanscan_rehash_schedule(void *arg
);
229 void trojanscan_rejoin_channel(void *arg
);
231 void trojanscan_read_database(int first_time
);
232 void trojanscan_free_database(void);
234 struct trojanscan_realchannels
*trojanscan_allocaterc(char *chan
);
235 void trojanscan_join(trojanscan_realchannels
*rc
);
236 struct trojanscan_clones
*trojanscan_selectclone(char type
);
237 void trojanscan_free_channels(void);
238 int trojanscan_add_ll(struct trojanscan_prechannels
**head
, struct trojanscan_prechannels
*newitem
);
239 int trojanscan_keysort(const void *v1
, const void *v2
);
241 int trojanscan_user_level_by_authname(char *authname
);
242 int trojanscan_user_id_by_authname(char *authname
);
243 struct trojanscan_worms
*trojanscan_find_worm_by_id(int id
);
244 char *trojanscan_getuser(int id
);
246 int trojanscan_minmaxrand(float min
, float max
);
247 char *trojanscan_iptostr(char *buf
, int buflen
, unsigned int ip
);
249 int trojanscan_database_connect(char *dbhost
, char *dbuser
, char *dbpass
, char *db
, unsigned int port
);
250 void trojanscan_database_close(void);
251 void trojanscan_database_escape_string(char *dest
, char *source
, size_t length
);
252 int trojanscan_database_query(char *format
, ...);
253 int trojanscan_database_num_rows(trojanscan_database_res
*res
);
254 trojanscan_database_res
*trojanscan_database_store_result();
255 trojanscan_database_row
trojanscan_database_fetch_row(trojanscan_database_res
*res
);
256 void trojanscan_database_free_result(trojanscan_database_res
*res
);
257 nick
*trojanscan_selectuser(void);
259 int trojanscan_is_not_octet(char *begin
, int length
);
260 void trojanscan_genreal(char *ptc
, char size
);
261 char trojanscan_genchar(int ty
);
262 void trojanscan_gennick(char *ptc
, char size
);
263 void trojanscan_genident(char *ptc
, char size
);
264 void trojanscan_genhost(char *ptc
, char size
, long *fakeip
);
266 int trojanscan_generatepool(void);
267 void trojanscan_watch_clone_update(struct trojanscan_prechannels
*hp
, int count
);
268 void trojanscan_repool(void *arg
);
270 void trojanscan_generatehost(char *buf
, int maxsize
, long *fakeip
);
271 void trojanscan_generatenick(char *buf
, int maxsize
);
272 void trojanscan_generateident(char *buf
, int maxsize
);
273 void trojanscan_generaterealname(char *buf
, int maxsize
);
275 sstring
*trojanscan_getsstring(char *string
, int length
);
276 int trojanscan_strip_codes(char *buf
, size_t max
, char *original
);
277 int trojanscan_isip(char *host
);
279 struct trojanscan_clones trojanscan_swarm
[TROJANSCAN_CLONE_TOTAL
];
280 struct trojanscan_db trojanscan_database
;
282 sstring
*trojanscan_hostpool
[TROJANSCAN_POOLSIZE
], *trojanscan_tailpool
[TROJANSCAN_POOLSIZE
];
283 struct trojanscan_inchannel
*trojanscan_chans
= NULL
;
285 unsigned int trojanscan_cycletime
, trojanscan_maxchans
, trojanscan_part_time
, trojanscan_activechans
= 0, trojanscan_tailpoolsize
= 0, trojanscan_hostpoolsize
= 0, trojanscan_channumber
= 0, trojanscan_maxusers
;
286 int trojanscan_watchclones_count
= 0;
288 int trojanscan_errorcode
;
289 struct trojanscan_realchannels
*trojanscan_realchanlist
;
290 char trojanscan_hostmode
;
292 void *trojanscan_schedule
, *trojanscan_connect_schedule
;
293 void *trojanscan_initialschedule
, *trojanscan_rehashschedule
, *trojanscan_poolschedule
, *trojanscan_cloneschedule
;
295 int trojanscan_minchansize
, trojanscan_min_hosts
;
296 int trojanscan_swarm_created
= 0;
298 nick
*trojanscan_nick
;
299 CommandTree
*trojanscan_cmds
;
300 trojanscan_database_connection trojanscan_sql
;
301 struct trojanscan_rejoinlist
*trojanscan_schedulerejoins
= NULL
;