forked from DataSoft/Nova
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNowjsMethods.js
1604 lines (1352 loc) · 43.4 KB
/
NowjsMethods.js
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//============================================================================
// Name : NowjsMethods.js
// Copyright : DataSoft Corporation 2011-2013
// Nova 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 3 of the License, or
// (at your option) any later version.
//
// Nova 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 Nova. If not, see <http://www.gnu.org/licenses/>.
// Description : Nowjs remote callabale functions
//============================================================================
var dns = require('dns');
var fs = require('fs');
var exec = require('child_process').exec;
var child_process = require('child_process');
var sanitizeCheck = require('validator').sanitize;
var NovaCommon = require('./NovaCommon.js');
var LOG = NovaCommon.LOG;
var NovaHomePath = NovaCommon.config.GetPathHome();
var NovaSharedPath = NovaCommon.config.GetPathShared();
var NowjsMethods = function(everyone) {
function objCopy(src, dst)
{
for(var member in src)
{
if(typeof src[member] == 'function')
{
dst[member] = src[member]();
}
// Need to think about this
// else if ( typeof src[member] == 'object' )
// {
// copyOver(src[member], dst[member]);
// }
else
{
dst[member] = src[member];
}
}
}
everyone.now.shutdownQuasar = function() {
LOG("ALERT", "Quasar is exiting due to user issued shutdown command on the web interface");
process.exit(1);
};
everyone.now.changeGroup = function(group, cb)
{
var res = NovaCommon.config.SetGroup(group);
cb && cb(res);
};
everyone.now.ChangeNodeInterfaces = function(nodes, newIntf, cb)
{
NovaCommon.honeydConfig.ChangeNodeInterfaces(nodes, newIntf);
cb && cb();
};
everyone.now.GetProfileNames = function(cb)
{
var res = NovaCommon.honeydConfig.GetProfileNames();
cb && cb(res);
};
everyone.now.GetLeafProfileNames = function(cb)
{
var res = NovaCommon.honeydConfig.GetLeafProfileNames();
cb && cb(res);
};
everyone.now.addScriptOptionValue = function (script, key, value, cb) {
NovaCommon.honeydConfig.AddScriptOptionValue(script, key, value);
NovaCommon.honeydConfig.SaveAll();
cb && cb();
};
everyone.now.deleteScriptOptionValue = function (script, key, value, cb) {
NovaCommon.honeydConfig.DeleteScriptOptionValue(script, key, value);
NovaCommon.honeydConfig.SaveAll();
cb && cb();
};
everyone.now.createHoneydNodes = function(ipType, ip1, ip2, ip3, ip4, profile, portSet, vendor, ethinterface, count, cb)
{
var ipAddress;
if(ipType == "DHCP")
{
ipAddress = "DHCP";
}
else
{
ipAddress = ip1 + "." + ip2 + "." + ip3 + "." + ip4;
}
var result = null;
if(!NovaCommon.honeydConfig.AddNodes(profile, portSet, vendor, ipAddress, ethinterface, Number(count)))
{
result = "Unable to create new nodes";
}
if(!NovaCommon.honeydConfig.SaveAll())
{
result = "Unable to save honeyd configuration";
}
cb && cb(result);
};
everyone.now.checkVendor = function(vendorName, cb) {
var vendors = NovaCommon.vendorToMacDb.GetVendorNames();
if(vendorName == '')
{
cb && cb(false);
return;
}
var ok = false;
for(var i in vendors)
{
if(vendors[i] == vendorName)
{
ok = true;
}
}
cb && cb(ok);
}
everyone.now.SaveDoppelganger = function(node, cb)
{
var ipAddress = node.ip;
if(node.ipType == "DHCP")
{
ipAddress = "DHCP";
}
if(!NovaCommon.honeydConfig.SaveDoppelganger(node.profile, node.portSet, ipAddress, node.mac, node.intface))
{
cb && cb("SaveDoppelganger Failed");
return;
}
else
{
if(!NovaCommon.honeydConfig.SaveAll())
{
cb && cb("Unable to save honeyd configuration");
}
else
{
cb && cb(null);
}
}
};
everyone.now.SaveHoneydNode = function(node, cb)
{
var ipAddress = node.ip;
if(node.ipType == "DHCP")
{
ipAddress = "DHCP";
}
// Delete the old node and then add the new one
NovaCommon.honeydConfig.DeleteNode(node.oldName);
if(node.oldName == "doppelganger")
{
if(!NovaCommon.honeydConfig.SetDoppelganger(node.profile, parseInt(node.portSet), ipAddress, node.mac, node.intface))
{
cb && cb("doppelganger Failed");
return;
}
else
{
NovaCommon.config.WriteSetting('DOPPELGANGER_IP', ipAddress);
NovaCommon.config.WriteSetting('DOPPELGANGER_INTERFACE', node.intface);
if(!NovaCommon.honeydConfig.SaveAll())
{
cb && cb("Unable to save honeyd configuration");
}
else
{
cb && cb(null);
}
}
}
else
{
if(!NovaCommon.honeydConfig.AddNode(node.profile, parseInt(node.portSet), ipAddress, node.mac, node.intface))
{
cb && cb("AddNode Failed");
return;
}
else
{
if(!NovaCommon.honeydConfig.SaveAll())
{
cb && cb("Unable to save honeyd configuration");
}
else
{
cb && cb(null);
}
}
}
};
everyone.now.ClearAllSuspects = function (cb)
{
NovaCommon.nova.CheckConnection();
NovaCommon.nova.ClearAllSuspects();
};
everyone.now.ClearSuspect = function (suspectIp, ethinterface, cb)
{
NovaCommon.nova.CheckConnection();
var result = NovaCommon.nova.ClearSuspect(suspectIp, ethinterface);
if (cb != undefined)
{
cb(result);
}
};
everyone.now.GetInheritedEthernetList = function (parent, cb)
{
var prof = NovaCommon.honeydConfig.GetProfile(parent);
if (prof == null)
{
console.log("ERROR Getting profile " + parent);
cb(null);
}
else
{
cb(prof.GetVendors(), prof.GetVendorCounts());
}
};
everyone.now.RestartHaystack = function(cb)
{
NovaCommon.StopHaystack(function() {
// Note: the other honeyd may be shutting down still,
// but the slight overlap doesn't cause problems
NovaCommon.StartHaystack(function() {
cb && cb();
});
});
};
everyone.now.StartHaystack = function()
{
if(!NovaCommon.nova.IsHaystackUp())
{
NovaCommon.StartHaystack(false);
}
setTimeout(function(){
if(!NovaCommon.nova.IsHaystackUp())
{
everyone.now.HaystackStartFailed();
}
else
{
try
{
everyone.now.updateHaystackStatus(NovaCommon.nova.IsHaystackUp())
}
catch(err)
{};
}
}, 1000);
};
everyone.now.StopHaystack = function()
{
NovaCommon.StopHaystack(function() {
try
{
everyone.now.updateHaystackStatus(NovaCommon.nova.IsHaystackUp());
}
catch(err)
{};
});
};
everyone.now.IsHaystackUp = function(cb)
{
cb(NovaCommon.nova.IsHaystackUp());
};
everyone.now.IsNovadConnected = function(cb)
{
cb(NovaCommon.nova.IsNovadConnected());
};
everyone.now.StartNovad = function()
{
var result = NovaCommon.StartNovad(false);
setTimeout(function(){
result = NovaCommon.nova.CheckConnection();
try
{
everyone.now.updateNovadStatus(NovaCommon.nova.IsNovadConnected());
}
catch(err){};
}, 1000);
};
everyone.now.StopNovad = function(cb)
{
if(NovaCommon.StopNovad() == false)
{
cb && cb('false');
return;
}
NovaCommon.nova.CloseNovadConnection();
try
{
everyone.now.updateNovadStatus(NovaCommon.nova.IsNovadConnected());
}
catch(err){};
};
everyone.now.HardStopNovad = function(passwd)
{
NovaCommon.nova.HardStopNovad(passwd);
NovaCommon.nova.CloseNovadConnection();
try
{
everyone.now.updateNovadStatus(NovaCommon.nova.IsNovadConnected());
}
catch(err){};
};
everyone.now.sendSuspect = function (ethinterface, ip, cb)
{
var suspect = NovaCommon.nova.sendSuspect(ethinterface, ip);
if(suspect.GetIdString === undefined)
{
console.log("Failed to get suspect");
return;
}
var s = new Object();
objCopy(suspect, s);
cb(s);
};
// Deletes a honeyd node
everyone.now.deleteNodes = function (nodeNames, cb)
{
var nodeName;
for(var i = 0; i < nodeNames.length; i++)
{
nodeName = nodeNames[i];
if(nodeName != null && !NovaCommon.honeydConfig.DeleteNode(nodeName))
{
cb(false, "Failed to delete node " + nodeName);
return;
}
}
if(!NovaCommon.honeydConfig.SaveAll())
{
cb(false, "Failed to save XML templates");
return;
}
cb(true, "");
};
everyone.now.deleteProfiles = function (profileNames, cb)
{
var profileName;
for(var i = 0; i < profileNames.length; i++)
{
profileName = profileNames[i];
if(!NovaCommon.honeydConfig.DeleteProfile(profileName))
{
cb(false, "Failed to delete profile " + profileName);
return;
}
if(!NovaCommon.honeydConfig.SaveAll())
{
cb(false, "Failed to save XML templates");
return;
}
}
cb(true, "");
};
everyone.now.addWhitelistEntry = function(ethinterface, entry, cb)
{
entry = entry.replace(/\s+/g, '');
var individualIp = new RegExp('^((((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){3,3})(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}))$');
individualIp.global = false;
var subnetRangeIp = new RegExp('^((((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){3,3})(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\/[1-3]?[0-9])$');
subnetRangeIp.global = false;
var slashSubnetMaskIp = new RegExp('^((((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){3,3})(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}))\\/((((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){3,3})(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}))$');
slashSubnetMaskIp.global = false;
if((individualIp.test(entry) || subnetRangeIp.test(entry) || slashSubnetMaskIp.test(entry)) && NovaCommon.whitelistConfig.AddEntry(ethinterface + "," + entry))
{
cb(true, "");
}
else
{
cb(true, "Attempt to add whitelist entry failed");
}
};
everyone.now.deleteWhitelistEntry = function (whitelistEntryNames, cb)
{
var whitelistEntryName;
for(var i = 0; i < whitelistEntryNames.length; i++)
{
whitelistEntryName = whitelistEntryNames[i];
if(!NovaCommon.whitelistConfig.DeleteEntry(whitelistEntryName))
{
cb(false, "Failed to delete whitelistEntry " + whitelistEntryName);
return;
}
}
cb(true, "");
};
everyone.now.GetScript = function (scriptName, cb)
{
var script = NovaCommon.honeydConfig.GetScript(scriptName);
var methodlessScript = {};
objCopy(script, methodlessScript);
cb(methodlessScript);
};
everyone.now.GetVendors = function (profileName, cb)
{
var profile = NovaCommon.honeydConfig.GetProfile(profileName);
if(profile == null)
{
console.log("ERROR Getting profile " + profileName);
cb(null);
return;
}
var ethVendorList = [];
var profVendors = profile.GetVendors();
var profDists = profile.GetVendorCounts();
for(var i = 0; i < profVendors.length; i++)
{
var element = {
vendor: "",
count: ""
};
element.vendor = profVendors[i];
element.count = parseFloat(profDists[i]);
ethVendorList.push(element);
}
cb(profVendors, profDists);
};
function jsProfileToHoneydProfile(profile)
{
var honeydProfile = new NovaCommon.novaconfig.HoneydProfileBinding(profile.parentProfile, profile.name);
//Set Ethernet vendors
var ethVendors = [];
var ethDists = [];
for(var i in profile.ethernet)
{
ethVendors.push(profile.ethernet[i].vendor);
ethDists.push(parseFloat(Number(profile.ethernet[i].count)));
}
honeydProfile.SetVendors(ethVendors, ethDists);
// Move the Javascript object values to the C++ object
honeydProfile.SetUptimeMin(Number(profile.uptimeMin));
honeydProfile.SetUptimeMax(Number(profile.uptimeMax));
honeydProfile.SetDropRate(Number(profile.dropRate));
honeydProfile.SetPersonality(profile.personality);
honeydProfile.SetCount(profile.count);
honeydProfile.SetIsPersonalityInherited(Boolean(profile.isPersonalityInherited));
honeydProfile.SetIsDropRateInherited(Boolean(profile.isDropRateInherited));
honeydProfile.SetIsUptimeInherited(Boolean(profile.isUptimeInherited));
// Add new ports
honeydProfile.ClearPorts();
var portName;
for(var i = 0; i < profile.portSets.length; i++)
{
//Make a new port set
honeydProfile.AddPortSet();
honeydProfile.SetPortSetBehavior(i, "tcp", profile.portSets[i].TCPBehavior);
honeydProfile.SetPortSetBehavior(i, "udp", profile.portSets[i].UDPBehavior);
honeydProfile.SetPortSetBehavior(i, "icmp", profile.portSets[i].ICMPBehavior);
for(var j = 0; j < profile.portSets[i].PortExceptions.length; j++)
{
var scriptConfigKeys = new Array();
var scriptConfigValues = new Array();
for(var key in profile.portSets[i].PortExceptions[j].scriptConfiguration)
{
scriptConfigKeys.push(key);
scriptConfigValues.push(profile.portSets[i].PortExceptions[j].scriptConfiguration[key]);
}
honeydProfile.AddPort(i,
profile.portSets[i].PortExceptions[j].behavior,
profile.portSets[i].PortExceptions[j].protocol,
Number(profile.portSets[i].PortExceptions[j].portNum),
profile.portSets[i].PortExceptions[j].scriptName,
scriptConfigKeys,
scriptConfigValues);
}
}
honeydProfile.ClearBroadcasts();
for (var i = 0; i < profile.broadcasts.length; i++)
{
honeydProfile.AddBroadcast(profile.broadcasts[i].script, Number(profile.broadcasts[i].srcPort), Number(profile.broadcasts[i].dstPort), Number(profile.broadcasts[i].time));
}
honeydProfile.ClearProxies();
for (var i = 0; i < profile.proxies.length; i++) {
honeydProfile.AddProxy(profile.proxies[i].protocol, Number(profile.proxies[i].honeypotPort), profile.proxies[i].proxyIP, Number(profile.proxies[i].proxyPort));
}
return honeydProfile;
}
everyone.now.DeletePortSet = function(profile, portSetIndex, cb)
{
var error = NovaCommon.honeydConfig.DeletePortSet(profile, portSetIndex);
NovaCommon.honeydConfig.SaveAll();
cb && cb(!error);
}
everyone.now.AddPortSet = function(profile, cb)
{
var error = NovaCommon.honeydConfig.AddPortSet(profile);
NovaCommon.honeydConfig.SaveAll();
cb && cb(!error);
}
//portSets = A 2D array. (array of portSets, which are arrays of Ports)
everyone.now.SaveProfile = function (profile, newProfile, cb)
{
// Check input
var profileNameRegexp = new RegExp("[a-zA-Z]+[a-zA-Z0-9 ]*");
var match = profileNameRegexp.exec(profile.name);
if(match != profile.name)
{
var err = "ERROR: Attempt to save a profile with an invalid name. Must be alphanumeric and not begin with a number.";
cb(err);
return;
}
// Check for duplicate profile
if(newProfile)
{
var existingProfile = NovaCommon.honeydConfig.GetProfile(profile.name);
if(existingProfile != null)
{
cb && cb("ERROR: Profile with name already exists");
return;
}
}
// Check we have ethernet vendors
if(profile.ethernet.length == 0)
{
var err = "ERROR: Must have at least one ethernet vendor!";
cb && cb(err);
return;
}
// Check for valid drop percentage
if(isNaN(parseInt(profile.dropRate)))
{
cb && cb("ERROR: Can't convert drop rate to integer");
return;
}
profile.dropRate = parseInt(profile.dropRate);
if(profile.dropRate < 0 || profile.dropRate > 100)
{
cb && cb("ERROR: Droprate must be between 0 and 100");
return;
}
// Check uptimes
if(profile.uptimeValueMax < 0 || profile.uptimeValueMin < 0)
{
cb && cb("ERROR: Uptime must be a positive integer");
return;
}
// Check that we have the scriptnames set for profiles that need scripts
for(var i = 0; i < profile.portSets.length; i++)
{
for(var j = 0; j < profile.portSets[i].PortExceptions.length; j++)
{
var port = profile.portSets[i].PortExceptions[j];
if(isNaN(parseInt(port.portNum)))
{
cb && cb("ERROR: unable to parse port into an integer!");
return;
}
if(parseInt(port.portNum) <= 0 || parseInt(port.portNum) > 65535)
{
cb && cb("ERROR: Unable to save profile with invalid port number!");
return;
}
if(port.behavior == "script" || port.behavior == "tarpit script")
{
if(port.scriptName == "" || port.scriptName == "NA")
{
var err = "ERROR: Attempt to save a profile with an invalid port script value.";
cb && cb(err);
return;
}
}
}
}
var honeydProfile = jsProfileToHoneydProfile(profile);
honeydProfile.Save();
// Save the profile
if(!NovaCommon.honeydConfig.SaveAll())
{
result = "Unable to save honeyd configuration";
}
cb();
};
everyone.now.ShowAutoConfig = function (nodeInterface, numNodesType, numNodes, subnets, groupName, append, cb, route)
{
if(!(new RegExp('^[a-zA-Z0-9 \\-_]+$')).test(groupName))
{
cb && cb("Haystack name must not be blank and must contain only letters, numbers, and hyphens. Invalid haystack name given.");
return;
}
var executionString = 'haystackautoconfig';
var hhconfigArgs = new Array();
hhconfigArgs.push('--nodeinterface');
hhconfigArgs.push(nodeInterface);
if(numNodesType == "fixed")
{
if(numNodes !== undefined)
{
hhconfigArgs.push('-n');
hhconfigArgs.push(numNodes);
}
}
else if(numNodesType == "ratio")
{
if(numNodes !== undefined)
{
hhconfigArgs.push('-r');
hhconfigArgs.push(numNodes);
}
}
else if(numNodesType == 'range')
{
if(numNodes !== undefined)
{
hhconfigArgs.push('e');
hhconfigArgs.push(numNodes);
}
}
if(subnets !== undefined && subnets.length > 0)
{
hhconfigArgs.push('-a');
hhconfigArgs.push(subnets);
}
if(!append)
{
hhconfigArgs.push('-t');
hhconfigArgs.push(groupName);
NovaCommon.honeydConfig.AddConfiguration(groupName, 'false', '');
NovaCommon.config.SetCurrentConfig(groupName);
}
else
{
hhconfigArgs.push('-t');
hhconfigArgs.push(groupName);
}
var util = require('util');
var spawn = require('child_process').spawn;
console.log("Running: " + executionString.toString());
console.log("Args: " + hhconfigArgs);
autoconfig = spawn(executionString.toString(), hhconfigArgs);
autoconfig.stdout.on('data', function (data)
{
if(typeof cb == 'function')
{
cb(null, '' + data);
}
});
autoconfig.stderr.on('data', function (data)
{
if(/^execvp\(\)/.test(data))
{
console.log("haystackautoconfig failed to start.");
var response = "haystackautoconfig failed to start.";
everyone.now.SwitchConfigurationTo('default');
if(typeof route == 'function')
{
route("/autoConfig", response);
}
}
});
autoconfig.on('exit', function (code, signal)
{
console.log("autoconfig exited with code " + code);
var response = "autoconfig exited with code " + code;
try
{
if(fs.statSync(NovaHomePath + '/data/hhconfig.lock').isFile())
{
fs.unlinkSync(NovaHomePath + '/data/hhconfig.lock');
}
}
catch(err)
{
}
if(typeof route == 'function' && signal != 'SIGTERM')
{
route("/honeydConfigManage", response);
}
else if(signal == 'SIGTERM')
{
response = "autoconfig scan terminated early";
route("/autoConfig", response);
}
else if(signal == 'SIGSEGV')
{
response = "autoconfig experienced a segmentation fault";
route("/honeydConfigManage", response);
}
});
};
everyone.now.CancelAutoScan = function(groupName)
{
try
{
autoconfig.kill();
autoconfig = undefined;
everyone.now.RemoveConfiguration(groupName);
everyone.now.SwitchConfigurationTo('default');
}
catch(e)
{
LOG("ERROR", "CancelAutoScan threw an error: " + e);
}
};
everyone.now.WriteHoneydConfig = function(cb)
{
NovaCommon.honeydConfig.WriteHoneydConfiguration(NovaCommon.config.GetPathConfigHoneydHS());
if(typeof cb == 'function')
{
cb();
}
};
everyone.now.GetConfigSummary = function(configName, cb)
{
NovaCommon.honeydConfig.LoadAllTemplates();
var scriptProfileBindings = NovaCommon.GetPorts();
var profiles = NovaCommon.honeydConfig.GetProfileNames();
var profileObj = {};
for(var i = 0; i < profiles.length; i++)
{
if(profiles[i] != undefined && profiles[i] != '')
{
var prof = NovaCommon.honeydConfig.GetProfile(profiles[i]);
var obj = {};
var vendorNames = prof.GetVendors();
var vendorDist = prof.GetVendorCounts();
obj.name = prof.GetName();
obj.parent = prof.GetParentProfile();
obj.os = prof.GetPersonality();
obj.packetDrop = prof.GetDropRate();
obj.vendors = [];
for(var j = 0; j < vendorNames.length; j++)
{
var push = {};
push.name = vendorNames[j];
push.count = vendorDist[j];
obj.vendors.push(push);
}
if(prof.GetUptimeMin() == prof.GetUptimeMax())
{
obj.fixedOrRange = 'fixed';
obj.uptimeValue = prof.GetUptimeMin();
}
else
{
obj.fixedOrRange = 'range';
obj.uptimeValueMin = prof.GetUptimeMin();
obj.uptimeValueMax = prof.GetUptimeMax();
}
//obj.defaultTCP = prof.GetTcpAction();
//obj.defaultUDP = prof.GetUdpAction();
//obj.defaultICMP = prof.GetIcmpAction();
profileObj[profiles[i]] = obj;
}
}
var nodeNames = NovaCommon.honeydConfig.GetNodeMACs();
var nodeList = [];
for(var i = 0; i < nodeNames.length; i++)
{
var node = NovaCommon.honeydConfig.GetNode(nodeNames[i]);
var push = NovaCommon.cNodeToJs(node);
nodeList.push(push);
}
nodeNames = null;
if(typeof cb == 'function')
{
cb(scriptProfileBindings, profileObj, profiles, nodeList);
}
};
everyone.now.SwitchConfigurationTo = function(configName, cb)
{
NovaCommon.honeydConfig.SwitchConfiguration(configName);
NovaCommon.config.WriteSetting('CURRENT_CONFIG', configName);
cb && cb();
};
everyone.now.RemoveConfiguration = function(configName, cb)
{
if(configName == 'default')
{
console.log('Cannot delete default haystack');
}
NovaCommon.honeydConfig.RemoveConfiguration(configName);
if(typeof cb == 'function')
{
cb(configName);
}
};
everyone.now.RemoveScript = function(scriptName, cb)
{
NovaCommon.honeydConfig.RemoveScript(scriptName);
NovaCommon.honeydConfig.SaveAllTemplates();
if(typeof cb == 'function')
{
cb();
}
};
everyone.now.GetLocalIP = function (iface, cb)
{
cb(NovaCommon.nova.GetLocalIP(iface));
};
everyone.now.GetSubnetFromInterface = function (iface, index, cb)
{
cb(iface, NovaCommon.nova.GetSubnetFromInterface(iface), index);
};
everyone.now.RemoveScriptFromProfiles = function(script, cb)
{
NovaCommon.honeydConfig.DeleteScriptFromPorts(script);
NovaCommon.honeydConfig.SaveAllTemplates();
if(typeof cb == 'function')
{
cb();
}
};
everyone.now.GenerateMACForVendor = function(vendor, cb)
{
cb(NovaCommon.honeydConfig.GenerateRandomUnusedMAC(vendor));
};
everyone.now.restoreDefaultSettings = function(cb)
{
var source = NovaSharedPath + "/../userFiles/config/NOVAConfig.txt";
var destination = NovaHomePath + "/config/NOVAConfig.txt";
exec('cp -f ' + source + ' ' + destination, function(err)
{
cb();
});
};
everyone.now.reverseDNS = function(ip, cb)
{
dns.reverse(ip, cb);
};
everyone.now.addTrainingPoint = function(ip, ethinterface, features, hostility, cb)
{
if(hostility != '0' && hostility != '1')
{
cb("Error: Invalid hostility. Should be 0 or 1");
return;
}
if(features.toString().split(" ").length != NovaCommon.nova.GetDIM()) {
cb("Error: Invalid number of features!")
return;
}
var point = features.toString() + " " + hostility + "\n";
fs.appendFile(NovaHomePath + "/config/training/data.txt", point, function(err)
{
if(err)
{
console.log("Error: " + err);
cb(err);
return;
}
var d = new Date();
var trainingDbString = "";
trainingDbString += hostility + ' "User customized training point for suspect ' + ip + " added on " + d.toString() + '"\n';
trainingDbString += "\t" + features.toString();
trainingDbString += "\n\n";
fs.appendFile(NovaHomePath + "/config/training/training.db", trainingDbString, function(err)
{
if(!NovaCommon.nova.ReclassifyAllSuspects())