This repository was archived by the owner on Nov 13, 2025. It is now read-only.
forked from psotnic/gay-psotnic
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse-bot.cpp
More file actions
314 lines (275 loc) · 9.34 KB
/
Copy pathparse-bot.cpp
File metadata and controls
314 lines (275 loc) · 9.34 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/***************************************************************************
* Copyright (C) 2003-2005 by Grzegorz Rusin *
* grusin@gmail.com *
* Copyright (C) 2009-2010 psotnic.com development team *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "prots.h"
#include "global-var.h"
static char arg[10][MAX_LEN];
static char *reason;
void emulateIRCDIntro(inetconn *c);
void parse_bot(inetconn *c, char *data)
{
reason = NULL;
if(!c)
return;
if(!data || *data == '\0')
return;
str2words(arg[0], data, 10, MAX_LEN);
/* REGISTER CONNECTION */
if(!(c->status & STATUS_REGISTERED))
{
switch(c->tmpint)
{
case 1:
{
if(!strcmp(arg[0], config.botnetword) && c->listener_opt & (LISTEN_ALL | LISTEN_BOTS))
{
c->enableCrypt((const char *) config.botnetword, strlen(config.botnetword));
c->tmpstr = (char *) malloc(AUTHSTR_LEN + 1);
++c->tmpint;
MD5CreateAuthString(c->tmpstr, AUTHSTR_LEN);
c->tmpstr[32] = '\0';
c->send("%s", c->tmpstr);
return;
}
/* maybe that's owner */
if(/*config.bottype == BOT_MAIN &&*/ c->listener_opt & (LISTEN_ALL | LISTEN_USERS))
{
if(!strncmp(data, "CAP LS", 6))
return;
if(!strcmp(data, "JOIN :")) {
// irssi compatibility
c->sendRaw(":%s 451 * :You have not registered", (const char*)config.partyline_servername);
return;
}
if(!strcmp(arg[0], "PASS") && strlen(arg[1]))
{
// it's an irc client
// format: PASS username:password
// -- patrick
char *ownerpass, *handle, *pass, *p;
HANDLE *h;
if(arg[1][0] == ':')
strcpy(arg[1], arg[1]+1);
if((ownerpass=strtok_r(arg[1], ":", &p))
&& (handle=strtok_r(NULL, ":", &p))
&& (pass=strtok_r(NULL, ":", &p)))
{
if(config.checkOwnerpass(ownerpass))
{
mem_strcpy(c->name, handle);
if ((h = userlist.checkPartylinePass(c->name, pass, HAS_P)))
{
if(!h->addr->match(c->getPeerIpName()))
{
reason = push(NULL, c->name, ": invalid ip", NULL);
break;
}
c->status |= STATUS_CONNECTED | STATUS_PARTY | STATUS_REGISTERED | STATUS_TELNET;
c->status &= ~STATUS_BOT;
c->tmpint = 0;
c->killTime = 0;
c->handle = h;
if (c->tmpstr) free(c->tmpstr);
c->tmpstr = NULL;
//c->echo(1);
emulateIRCDIntro(c);
c->status |= STATUS_IRCCLIENT;
sendLogo(c);
ignore.removeHit(c->getPeerIp4());
return;
}
else
reason = push(NULL, "invalid username or password", NULL);
}
else
reason = push(NULL, "bad ownerpass", NULL);
}
else
reason = push(NULL, "invalid PASS (syntax error)", NULL);
break;
}
if(config.checkOwnerpass(arg[0]))
{
c->status |= STATUS_CONNECTED | STATUS_PARTY | STATUS_TELNET;
c->status &= ~STATUS_BOT;
c->tmpint = 1;
c->killTime = NOW + set.AUTH_TIMEOUT;
c->send("");
c->send("Welcome %s", c->getPeerIpName());
c->send("");
c->send("Enter your login.");
return;
}
}
DEBUG(printf("[D] telnet creep: %s [%d]\n", arg[0], strlen(arg[0])));
reason = push(NULL, "telnet creep", NULL);
break;
}
case 2:
{
if(strlen(arg[1]))
{
struct sockaddr_in peer;
HANDLE *h = userlist.findHandle(arg[0]);
if(h && net.findConn(h))
{
reason = push(NULL, arg[0], ": duplicate connection",NULL);
break;
}
// let leafs link to main -- patrick
if(h && config.bottype == BOT_MAIN && !userlist.isSlave(h) && !userlist.isLeaf(h))
{
reason = push(NULL, arg[0], ": neither a slave nor a leaf", NULL);
break;
}
if(h && config.bottype == BOT_SLAVE && !userlist.isLeaf(h))
{
reason = push(NULL, arg[0], ": not a leaf", NULL);
break;
}
socklen_t peersize = sizeof(struct sockaddr_in);
getpeername(c->fd, (sockaddr *) &peer, &peersize);
if(!h)
{
if(isRealStr(arg[0]) && strlen(arg[0]) <= MAX_HANDLE_LEN)
reason = push(NULL, arg[0], ": not a bot", NULL);
else
reason = push(NULL, "(crap here): not a bot", NULL);
break;
}
if(!h->pass)
{
reason = push(NULL, arg[0], ": no password set", NULL);
break;
}
if(!h->ip || peer.sin_addr.s_addr == h->ip || (h->addr->data.entries() && h->addr->match(c->getPeerIpName())))
{
if(MD5HexValidate(arg[1], c->tmpstr, strlen(c->tmpstr), h->pass, 16))
{
++c->tmpint;
c->handle = h;
free(c->tmpstr);
c->tmpstr = NULL;
return;
}
else
{
reason = push(NULL, arg[0], ": wrong botpass", NULL);
break;
}
}
else
{
reason = push(NULL, arg[0], ": invalid botip", NULL);
break;
}
}
reason = push(NULL, "This should not happen (1)", NULL);
break;
}
case 3:
{
if(strlen(arg[0]))
{
char hash[33];
++c->tmpint;
MD5HexHash(hash, arg[0], AUTHSTR_LEN, c->handle->pass, 16);
c->send("%s %s %s", (const char *) config.handle, userlist.first->next->creation->print(), hash);
return;
}
reason = push(NULL, "This should not happen (2)", NULL);
break;
}
case 4:
{
/* S_REGISTER <S_VERSION> <userlist.SN> [ircnick [irc server] ] */
if(!strcmp(arg[0], S_REGISTER) && strlen(arg[2]))
{
//if(strcmp(arg[1], S_VERSION))
//{
// net.send(HAS_N, "[!] %s has different version: %s", c->handle->name, arg[1]);
//}
mem_strcpy(c->name, arg[3]);
mem_strcpy(c->origin, arg[4]);
c->status |= STATUS_CONNECTED | STATUS_REGISTERED | STATUS_BOT;
c->tmpint = 0;
c->killTime = NOW + set.CONN_TIMEOUT;
c->lastPing = NOW;
c->send("%s %s", S_REGISTER, (const char *) ME.nick);
c->enableCrypt(c->handle->pass, 16);
/* update ul */
if(userlist.SN != strtoull(arg[2], NULL, 10))
{
net.send(HAS_N, "%s is linked (sending userlist)", c->handle->name);
userlist.send(c);
}
else net.send(HAS_N, "%s is linked and operational", c->handle->name);
/* send list of bots */
net.sendBotListTo(c);
net.propagate(c, "%s %s %s", S_BJOIN, c->name, c->origin);
/* check bot host */
if(config.bottype == BOT_MAIN)
c->send("%s *", S_CHKHOST);
ignore.removeHit(c->getPeerIp4());
return;
}
if(!strcmp(arg[0], S_IUSEMODULES))
return;
reason = push(NULL, "This should not happen (3)", NULL);
break;
}
default:
break;
}
/* HUH */
if(!reason)
reason = push(NULL, "Unknown error", NULL);
c->close(reason);
free(reason);
return;
}
/* PARSE DATA FROM REGISTERED BOT */
c->killTime = NOW + set.CONN_TIMEOUT;
if(!strcmp(arg[0], S_UL_UPLOAD_START))
{
c->close("Go fuck yourself");
return;
}
if(!strcmp(arg[0], S_ULOK))
{
net.send(HAS_N, "%s is operational", c->handle->name);
return;
}
parse_botnet(c, data);
}
/** missing.
*
* \author patrick <patrick@psotnic.com>
*/
void emulateIRCDIntro(inetconn *c)
{
c->sendRaw(":%s 001 %s :Welcome to the Internet Relay Network %s!%s@%s", (const char*)config.partyline_servername, (const char*)c->name, c->name, c->name, c->getPeerIpName());
c->sendRaw(":%s 002 %s :Your host is %s, running version %s", (const char*)config.partyline_servername, (const char*)c->name, S_BOTNAME, S_VERSION);
c->sendRaw(":%s 003 %s :This server was created ...", (const char*)config.partyline_servername, (const char*)c->name);
c->sendRaw(":%s 004 %s %s %s %s %s", (const char*)config.partyline_servername, (const char*)c->name, (const char*)config.partyline_servername, S_VERSION, "oirw", "abeIiklmnopqstv");
c->sendRaw(":%s 251 %s :There are 0 users and 0 invisible on 1 servers", (const char*)config.partyline_servername, (const char*)c->name);
c->sendRaw(":%s 255 %s :I have 0 clients, 0 services and 0 servers", (const char*)config.partyline_servername, (const char*)c->name);
c->sendRaw(":%s 422 %s :MOTD File is missing", (const char*)config.partyline_servername, (const char*)c->name);
}