-
Notifications
You must be signed in to change notification settings - Fork 576
/
suricata_interfaces_edit.php
2653 lines (2354 loc) · 106 KB
/
suricata_interfaces_edit.php
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
<?php
/*
* suricata_interfaces_edit.php
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2006-2023 Rubicon Communications, LLC (Netgate)
* Copyright (c) 2003-2004 Manuel Kasper
* Copyright (c) 2005 Bill Marquette
* Copyright (c) 2009 Robert Zelaya Sr. Developer
* Copyright (c) 2023 Bill Meeks
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once("guiconfig.inc");
require_once("/usr/local/pkg/suricata/suricata.inc");
global $g, $rebuild_rules;
$suricatadir = SURICATADIR;
$suricatalogdir = SURICATALOGDIR;
// Define an array of native-mode netmap compatible NIC drivers
$netmapifs = array('cc', 'cxl', 'cxgbe', 'em', 'igb', 'lem', 'ix', 'ixgbe', 'ixl', 're', 'vtnet');
if (pfs_version_compare(false, 2.4, $g['product_version'])) {
/* add FreeBSD 12 iflib(4) supported devices */
$netmapifs = array_merge($netmapifs, array('ena', 'ice', 'igc', 'bnxt', 'vmx'));
sort($netmapifs);
}
$a_rule = config_get_path('installedpackages/suricata/rule', []);
if (isset($_POST['id']) && is_numericint($_POST['id']))
$id = $_POST['id'];
elseif (isset($_GET['id']) && is_numericint($_GET['id']));
$id = htmlspecialchars($_GET['id'], ENT_QUOTES | ENT_HTML401);
if (is_null($id)) {
header("Location: /suricata/suricata_interfaces.php");
exit;
}
if (isset($_POST['action']))
$action = htmlspecialchars($_POST['action'], ENT_QUOTES | ENT_HTML401);
elseif (isset($_GET['action']))
$action = htmlspecialchars($_GET['action'], ENT_QUOTES | ENT_HTML401);
else
$action = "";
$pconfig = array();
if (!config_path_enabled('installedpackages/suricata/rule', $id)) {
/* Adding a new interface, so generate new UUID and flag rules to rebuild. */
$pconfig['uuid'] = suricata_generate_id();
$rebuild_rules = true;
$new_interface = true;
}
else {
$pconfig['uuid'] = $a_rule[$id]['uuid'];
$pconfig['descr'] = $a_rule[$id]['descr'];
$rebuild_rules = false;
$new_interface = false;
}
$suricata_uuid = $pconfig['uuid'];
// Get the physical configured interfaces on the firewall
$interfaces = get_configured_interface_with_descr();
// Footnote real interface associated with each configured interface
foreach ($interfaces as $if => $desc) {
$interfaces[$if] = $interfaces[$if] . " (" . get_real_interface($if) . ")";
}
// Add a special "Unassigned" interface selection at end of list
$interfaces["Unassigned"] = gettext("Unassigned");
// See if interface is already configured, and use its $config values if set
if (isset($id) && isset($a_rule[$id])) {
/* old options from config.xml */
$if_friendly = convert_friendly_interface_to_friendly_descr($a_rule[$id]['interface']);
$pconfig = $a_rule[$id];
if (empty($pconfig['uuid']))
$pconfig['uuid'] = $suricata_uuid;
if (get_real_interface($pconfig['interface']) == "") {
$pconfig['interface'] = gettext("Unassigned");
$pconfig['enable'] = "off";
}
}
elseif (isset($_POST['interface']) && !isset($a_rule[$id])) {
// Saving first Suricata interface
$pconfig['interface'] = $_POST['interface'];
$if_friendly = convert_friendly_interface_to_friendly_descr($pconfig['interface']);
}
elseif (isset($id) && !isset($a_rule[$id])) {
// Must be a new interface, so try to pick next available physical interface to use
$ifaces = get_configured_interface_list();
$ifrules = array();
// Populate the $ifrules array with all existing configured Suricata interfaces
foreach(config_get_path('installedpackages/suricata/rule', []) as $r)
$ifrules[] = $r['interface'];
// Walk pfSense-configured interfaces, and take first one not already in our Suricata list
foreach ($ifaces as $i) {
if (!in_array($i, $ifrules)) {
$pconfig['interface'] = $i;
$if_friendly = convert_friendly_interface_to_friendly_descr($i);
// If the interface is a VLAN, use the VLAN description
// if set, otherwise default to the friendly description.
if ($vlan = interface_is_vlan(get_real_interface($i))) {
if (strlen($vlan['descr']) > 0) {
$pconfig['descr'] = $vlan['descr'];
}
else {
$pconfig['descr'] = convert_friendly_interface_to_friendly_descr($i);
}
}
else {
$pconfig['descr'] = convert_friendly_interface_to_friendly_descr($i);
}
$pconfig['enable'] = 'on';
$pconfig['inspect_recursion_limit'] = '3000';
break;
}
}
if (count($ifrules) == count($ifaces)) {
$input_errors[] = gettext("No more available interfaces to configure for Suricata!");
$interfaces = array();
$pconfig = array();
}
}
// Get real interface where this Suricata instance runs
$if_real = get_real_interface($pconfig['interface']);
// Set defaults for any empty key parameters
if (empty($pconfig['blockoffendersip']))
$pconfig['blockoffendersip'] = "both";
if (empty($pconfig['blockoffenderskill']))
$pconfig['blockoffenderskill'] = "on";
if (empty($pconfig['ips_mode']))
$pconfig['ips_mode'] = 'ips_mode_legacy';
if (empty($pconfig['ips_netmap_threads']))
$pconfig['ips_netmap_threads'] = 'auto';
if (empty($pconfig['block_drops_only']))
$pconfig['block_drops_only'] = "off";
if (empty($pconfig['runmode']))
$pconfig['runmode'] = "autofp";
if (empty($pconfig['autofp_scheduler']))
$pconfig['autofp_scheduler'] = "hash";
if (empty($pconfig['max_pending_packets']))
$pconfig['max_pending_packets'] = "1024";
if (empty($pconfig['detect_eng_profile']))
$pconfig['detect_eng_profile'] = "medium";
if (empty($pconfig['mpm_algo']))
$pconfig['mpm_algo'] = "auto";
if (empty($pconfig['sgh_mpm_context']))
$pconfig['sgh_mpm_context'] = "auto";
if (empty($pconfig['enable_stats_collection']))
$pconfig['enable_stats_collection'] = "off";
if (empty($pconfig['enable_http_log']))
$pconfig['enable_http_log'] = "on";
if (empty($pconfig['http_log_filetype']))
$pconfig['http_log_filetype'] = "regular";
if (empty($pconfig['append_http_log']))
$pconfig['append_http_log'] = "on";
if (empty($pconfig['http_log_extended']))
$pconfig['http_log_extended'] = "on";
if (empty($pconfig['tls_log_extended']))
$pconfig['tls_log_extended'] = "on";
if (empty($pconfig['append_tls_log']))
$pconfig['append_tls_log'] = "on";
if (empty($pconfig['tls_log_filetype']))
$pconfig['tls_log_filetype'] = "regular";
if (empty($pconfig['stats_upd_interval']))
$pconfig['stats_upd_interval'] = "10";
if (empty($pconfig['max_pcap_log_size']))
$pconfig['max_pcap_log_size'] = "32";
if (empty($pconfig['max_pcap_log_files']))
$pconfig['max_pcap_log_files'] = "100";
if (empty($pconfig['pcap_log_conditional']))
$pconfig['pcap_log_conditional'] = "alerts";
if (empty($pconfig['alertsystemlog_facility']))
$pconfig['alertsystemlog_facility'] = "local1";
if (empty($pconfig['alertsystemlog_priority']))
$pconfig['alertsystemlog_priority'] = "notice";
if (empty($pconfig['eve_output_type']))
$pconfig['eve_output_type'] = "regular";
if (empty($pconfig['eve_systemlog_facility']))
$pconfig['eve_systemlog_facility'] = "local1";
if (empty($pconfig['eve_systemlog_priority']))
$pconfig['eve_systemlog_priority'] = "notice";
if (empty($pconfig['eve_log_ethernet']))
$pconfig['eve_log_ethernet'] = "no";
if (empty($pconfig['eve_log_drops']))
$pconfig['eve_log_drops'] = "on";
if (empty($pconfig['eve_log_alert_drops']))
$pconfig['eve_log_alert_drops'] = "on";
if (empty($pconfig['eve_log_alerts']))
$pconfig['eve_log_alerts'] = "on";
if (empty($pconfig['eve_log_alerts_payload']))
$pconfig['eve_log_alerts_payload'] = "on";
if (empty($pconfig['eve_log_alerts_packet']))
$pconfig['eve_log_alerts_packet'] = "on";
if (empty($pconfig['eve_log_alerts_http']))
$pconfig['eve_log_alerts_http'] = "on";
if (empty($pconfig['eve_log_alerts_metadata']))
$pconfig['eve_log_alerts_metadata'] = "on";
if (empty($pconfig['eve_log_alerts_xff']))
$pconfig['eve_log_alerts_xff'] = "off";
if (empty($pconfig['eve_log_alerts_xff_mode']))
$pconfig['eve_log_alerts_xff_mode'] = "extra-data";
if (empty($pconfig['eve_log_alerts_xff_deployment']))
$pconfig['eve_log_alerts_xff_deployment'] = "reverse";
if (empty($pconfig['eve_log_alerts_xff_header']))
$pconfig['eve_log_alerts_xff_header'] = "X-Forwarded-For";
if (empty($pconfig['eve_log_http']))
$pconfig['eve_log_http'] = "on";
if (empty($pconfig['eve_log_dns']))
$pconfig['eve_log_dns'] = "on";
if (empty($pconfig['eve_log_tls']))
$pconfig['eve_log_tls'] = "on";
if (empty($pconfig['eve_log_dhcp']))
$pconfig['eve_log_dhcp'] = "on";
if (empty($pconfig['eve_log_nfs']))
$pconfig['eve_log_nfs'] = "on";
if (empty($pconfig['eve_log_smb']))
$pconfig['eve_log_smb'] = "on";
if (empty($pconfig['eve_log_krb5']))
$pconfig['eve_log_krb5'] = "on";
if (empty($pconfig['eve_log_ikev2']))
$pconfig['eve_log_ikev2'] = "on";
if (empty($pconfig['eve_log_quic']))
$pconfig['eve_log_quic'] = "on";
if (empty($pconfig['eve_log_tftp']))
$pconfig['eve_log_tftp'] = "on";
if (empty($pconfig['eve_log_rdp']))
$pconfig['eve_log_rdp'] = "off";
if (empty($pconfig['eve_log_sip']))
$pconfig['eve_log_sip'] = "off";
if (empty($pconfig['eve_log_files']))
$pconfig['eve_log_files'] = "on";
if (empty($pconfig['eve_log_ssh']))
$pconfig['eve_log_ssh'] = "on";
if (empty($pconfig['eve_log_smtp']))
$pconfig['eve_log_smtp'] = "on";
if (empty($pconfig['eve_log_flow']))
$pconfig['eve_log_flow'] = "off";
if (empty($pconfig['eve_log_netflow']))
$pconfig['eve_log_netflow'] = "off";
if (empty($pconfig['eve_log_stats']))
$pconfig['eve_log_stats'] = "off";
if (empty($pconfig['eve_log_stats_totals']))
$pconfig['eve_log_stats_totals'] = "on";
if (empty($pconfig['eve_log_stats_deltas']))
$pconfig['eve_log_stats_deltas'] = "off";
if (empty($pconfig['eve_log_stats_threads']))
$pconfig['eve_log_stats_threads'] = "off";
if (empty($pconfig['eve_log_anomaly']))
$pconfig['eve_log_anomaly'] = "off";
if (empty($pconfig['eve_log_anomaly_type_decode']))
$pconfig['eve_log_anomaly_type_decode'] = "off";
if (empty($pconfig['eve_log_anomaly_type_stream']))
$pconfig['eve_log_anomaly_type_stream'] = "off";
if (empty($pconfig['eve_log_anomaly_type_applayer']))
$pconfig['eve_log_anomaly_type_applayer'] = "on";
if (empty($pconfig['eve_log_anomaly_packethdr']))
$pconfig['eve_log_anomaly_packethdr'] = "off";
if (empty($pconfig['eve_log_drop'])) {
$pconfig['eve_log_drop'] = "on";
}
if (empty($pconfig['eve_log_snmp'])) {
$pconfig['eve_log_snmp'] = "on";
}
if (empty($pconfig['eve_log_mqtt'])) {
$pconfig['eve_log_mqtt'] = "on";
}
if (empty($pconfig['eve_log_ftp'])) {
$pconfig['eve_log_ftp'] = "on";
}
if (empty($pconfig['eve_log_http2'])) {
$pconfig['eve_log_http2'] = "on";
}
if (empty($pconfig['eve_log_rfb'])) {
$pconfig['eve_log_rfb'] = "on";
}
if (empty($pconfig['eve_log_http_extended']))
$pconfig['eve_log_http_extended'] = $pconfig['http_log_extended'];
if (empty($pconfig['eve_log_tls_extended']))
$pconfig['eve_log_tls_extended'] = $pconfig['tls_log_extended'];
if (empty($pconfig['eve_log_dhcp_extended']))
$pconfig['eve_log_dhcp_extended'] = "off";
if (empty($pconfig['eve_log_smtp_extended']))
$pconfig['eve_log_smtp_extended'] = $pconfig['smtp_log_extended'];
if (empty($pconfig['eve_log_http_extended_headers']))
$pconfig['eve_log_http_extended_headers'] = "accept, accept-charset, accept-datetime, accept-encoding, accept-language, accept-range, age, allow, authorization, cache-control, connection, content-encoding, content-language, content-length, content-location, content-md5, content-range, content-type, cookie, date, dnt, etags, from, last-modified, link, location, max-forwards, origin, pragma, proxy-authenticate, proxy-authorization, range, referrer, refresh, retry-after, server, set-cookie, te, trailer, transfer-encoding, upgrade, vary, via, warning, www-authenticate, x-authenticated-user, x-flash-version, x-forwarded-proto, x-requested-with";
if (empty($pconfig['eve_log_smtp_extended_fields']))
$pconfig['eve_log_smtp_extended_fields'] = "received, x-mailer, x-originating-ip, relays, reply-to, bcc";
if (empty($pconfig['eve_log_tls_extended_headers']))
$pconfig['eve_log_tls_extended_headers'] = "subject, issuer, session_resumed, serial, fingerprint, sni, version, not_before, not_after, certificate, chain, ja3, ja3s";
if (empty($pconfig['eve_log_files_magic']))
$pconfig['eve_log_files_magic'] = "off";
if (empty($pconfig['eve_log_files_hash']))
$pconfig['eve_log_files_hash'] = "none";
if (empty($pconfig['eve_redis_server']))
$pconfig['eve_redis_server'] = "127.0.0.1";
if (empty($pconfig['eve_redis_port']))
$pconfig['eve_redis_port'] = "6379";
if (empty($pconfig['eve_redis_mode']))
$pconfig['eve_redis_mode'] = "list";
if (empty($pconfig['eve_redis_key']))
$pconfig['eve_redis_key'] = "suricata";
if (empty($pconfig['intf_promisc_mode']))
$pconfig['intf_promisc_mode'] = "on";
if (empty($pconfig['intf_snaplen']))
$pconfig['intf_snaplen'] = "1518";
if (empty($pconfig['file_store_logdir']))
$pconfig['file_store_logdir'] = base64_encode("{$suricatalogdir}suricata_{$if_real}{$suricata_uuid}/filestore");
// See if creating a new interface by duplicating an existing one
if (strcasecmp($action, 'dup') == 0) {
// Try to pick the next available physical interface to use
$ifaces = get_configured_interface_list();
$ifrules = array();
foreach(config_get_path('installedpackages/suricata/rule', []) as $r)
$ifrules[] = $r['interface'];
foreach ($ifaces as $i) {
if (!in_array($i, $ifrules)) {
$pconfig['interface'] = $i;
$pconfig['enable'] = 'on';
$pconfig['descr'] = strtoupper($i);
$pconfig['inspect_recursion_limit'] = '3000';
break;
}
}
if (count($ifrules) == count($ifaces)) {
$input_errors[] = gettext("No more available interfaces to configure for Suricata!");
$interfaces = array();
$pconfig = array();
}
// Set Home Net, External Net, Suppress List and Pass List to defaults
unset($pconfig['suppresslistname']);
unset($pconfig['passlistname']);
unset($pconfig['homelistname']);
unset($pconfig['externallistname']);
}
if ($_REQUEST['ajax'] == 'ajax') {
print("At least we got that straight!");
exit;
}
if (isset($_POST["save"]) && !$input_errors) {
if (!isset($_POST['interface']))
$input_errors[] = gettext("Choosing an Interface is mandatory!");
/* See if assigned interface is already in use */
if (isset($_POST['interface'])) {
foreach (config_get_path('installedpackages/suricata/rule', []) as $k => $v) {
if (($v['interface'] == $_POST['interface']) && ($id != $k)) {
$input_errors[] = gettext("The '{$_POST['interface']}' interface is already assigned to another Suricata instance.");
break;
}
}
}
if ($_POST['ips_mode'] == 'ips_mode_inline') {
$is_netmap = false;
$realint = get_real_interface($_POST['interface']);
foreach ($netmapifs as $if) {
if (substr($realint, 0, strlen($if)) == $if) {
$is_netmap = true;
break;
}
}
if (!$is_netmap) {
$input_errors[] = gettext("The '{$_POST['interface']}' interface does not support Inline IPS Mode with native netmap.");
}
}
// If Suricata is disabled on this interface, stop any running instance,
// on an active interface, save the change, and exit.
if ($_POST['enable'] != 'on' && config_path_enabled('installedpackages/suricata/rule', $id)) {
$a_rule[$id]['enable'] = $_POST['enable'] ? 'on' : 'off';
config_set_path('installedpackages/suricata/rule', $a_rule);
suricata_stop($a_rule[$id], get_real_interface($a_rule[$id]['interface']));
write_config("Suricata pkg: disabled Suricata on " . convert_friendly_interface_to_friendly_descr($a_rule[$id]['interface']));
$rebuild_rules = false;
sync_suricata_package_config();
header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );
header("Location: /suricata/suricata_interfaces.php");
exit;
}
// Validate inputs
if (isset($_POST['stats_upd_interval']) && !is_numericint($_POST['stats_upd_interval']))
$input_errors[] = gettext("The value for Stats Update Interval must contain only digits and evaluate to an integer.");
if ($_POST['max_pending_packets'] < 1 || $_POST['max_pending_packets'] > 65000)
$input_errors[] = gettext("The value for Maximum-Pending-Packets must be between 1 and 65,000!");
if (isset($_POST['max_pcap_log_size']) && !is_numeric($_POST['max_pcap_log_size']))
$input_errors[] = gettext("The value for 'Max Packet Log Size' must be numbers only. Do not include any alphabetic characters.");
if (isset($_POST['max_pcap_log_files']) && !is_numeric($_POST['max_pcap_log_files']))
$input_errors[] = gettext("The value for 'Max Packet Log Files' must be numbers only.");
if (!empty($_POST['inspect_recursion_limit']) && !is_numeric($_POST['inspect_recursion_limit']))
$input_errors[] = gettext("The value for Inspect Recursion Limit can either be blank or contain only digits evaluating to an integer greater than or equal to 0.");
if ($_POST['intf_snaplen'] < 1 || !is_numeric($_POST['intf_snaplen']))
$input_errors[] = gettext("The value for Interface Snaplen must contain only digits evaluating to an integer value greater than or equal to 1.");
if (!empty($_POST['eve_redis_server']) && !is_ipaddr($_POST['eve_redis_server']))
$input_errors[] = gettext("The value for 'EVE REDIS Server' must be an IP address.");
if (!empty($_POST['eve_redis_port']) && !is_port($_POST['eve_redis_port']))
$input_errors[] = gettext("The value for 'EVE REDIS Server' must have a valid TCP port.");
if (!empty($_POST['eve_redis_key']) && !preg_match('/^[A-Za-z0-9]+$/',$_POST['eve_redis_key']))
$input_errors[] = gettext("The value for 'EVE REDIS Key' must be alphanumeric.");
if ($_POST['enable_telegraf_stats'] == "on" && empty($_POST['suricata_telegraf_unix_socket_name']))
$input_errors[] = gettext("You must specify the Unix Socket name when enabling Telegraf stats output!");
// if no errors, generate and save the interface configuration
if (!$input_errors) {
$natent = array();
// Grab the existing configuration for modifications if it exists
if (config_path_enabled('installedpackages/suricata/rule', $id)) {
$natent = $a_rule[$id];
}
$natent['interface'] = $_POST['interface'];
$natent['enable'] = $_POST['enable'] ? 'on' : 'off';
$natent['uuid'] = $pconfig['uuid'];
if ($_POST['descr']) $natent['descr'] = htmlspecialchars($_POST['descr']); else $natent['descr'] = strtoupper($natent['interface']);
if ($_POST['enable_verbose_logging'] == "on") { $natent['enable_verbose_logging'] = 'on'; }else{ $natent['enable_verbose_logging'] = 'off'; }
if ($_POST['max_pcap_log_size']) $natent['max_pcap_log_size'] = $_POST['max_pcap_log_size']; else unset($natent['max_pcap_log_size']);
if ($_POST['max_pcap_log_files']) $natent['max_pcap_log_files'] = $_POST['max_pcap_log_files']; else unset($natent['max_pcap_log_files']);
if ($_POST['pcap_log_conditional']) $natent['pcap_log_conditional'] = $_POST['pcap_log_conditional'];
if ($_POST['enable_stats_collection'] == "on") { $natent['enable_stats_collection'] = 'on'; }else{ $natent['enable_stats_collection'] = 'off'; }
if ($_POST['enable_stats_log'] == "on") { $natent['enable_stats_log'] = 'on'; }else{ $natent['enable_stats_log'] = 'off'; }
if ($_POST['append_stats_log'] == "on") { $natent['append_stats_log'] = 'on'; }else{ $natent['append_stats_log'] = 'off'; }
if ($_POST['stats_upd_interval'] >= 1) $natent['stats_upd_interval'] = $_POST['stats_upd_interval']; else $natent['stats_upd_interval'] = "10";
if ($_POST['enable_telegraf_stats'] == "on") $natent['enable_telegraf_stats'] = 'on'; else $natent['enable_telegraf_stats'] = 'off';
if ($_POST['suricata_telegraf_unix_socket_name']) $natent['suricata_telegraf_unix_socket_name'] = base64_encode($_POST['suricata_telegraf_unix_socket_name']);
if ($_POST['enable_http_log'] == "on") { $natent['enable_http_log'] = 'on'; }else{ $natent['enable_http_log'] = 'off'; }
if ($_POST['append_http_log'] == "on") { $natent['append_http_log'] = 'on'; }else{ $natent['append_http_log'] = 'off'; }
if ($_POST['enable_tls_log'] == "on") { $natent['enable_tls_log'] = 'on'; }else{ $natent['enable_tls_log'] = 'off'; }
if ($_POST['append_tls_log'] == "on") { $natent['append_tls_log'] = 'on'; }else{ $natent['append_tls_log'] = 'off'; }
if ($_POST['enable_tls_store'] == "on") { $natent['enable_tls_store'] = 'on'; }else{ $natent['enable_tls_store'] = 'off'; }
if ($_POST['http_log_extended'] == "on") { $natent['http_log_extended'] = 'on'; }else{ $natent['http_log_extended'] = 'off'; }
if ($_POST['tls_log_extended'] == "on") { $natent['tls_log_extended'] = 'on'; }else{ $natent['tls_log_extended'] = 'off'; }
if ($_POST['tls_session_resumption'] == "on") { $natent['tls_session_resumption'] = 'on'; }else{ $natent['tls_session_resumption'] = 'off'; }
if ($_POST['enable_pcap_log'] == "on") { $natent['enable_pcap_log'] = 'on'; }else{ $natent['enable_pcap_log'] = 'off'; }
if ($_POST['pcap_use_stream_depth'] == "on") { $natent['pcap_use_stream_depth'] = 'on'; }else{ $natent['pcap_use_stream_depth'] = 'off'; }
if ($_POST['pcap_honor_pass_rules'] == "on") { $natent['pcap_honor_pass_rules'] = 'on'; }else{ $natent['pcap_honor_pass_rules'] = 'off'; }
if ($_POST['enable_file_store'] == "on") { $natent['enable_file_store'] = 'on'; }else{ $natent['enable_file_store'] = 'off'; }
if ($natent['enable_file_store'] == "on") {
if ($_POST['file_store_logdir']) { $natent['file_store_logdir'] = base64_encode($_POST['file_store_logdir']); }else{ $natent['file_store_logdir'] = $pconfig['file_store_logdir']; }
}
if ($_POST['tls_log_filetype']) $natent['tls_log_filetype'] = $_POST['tls_log_filetype']; else unset($natent['tls_log_filetype']);
if ($natent['tls_log_filetype'] == "unix_dgram" || $natent['tls_log_filetype'] == "unix_stream") {
if ($_POST['tls_log_socket']) { $natent['tls_log_socket'] = base64_encode($_POST['tls_log_socket']); }else{ $natent['tls_log_socket'] = $pconfig['tls_log_socket']; }
}
if ($_POST['http_log_filetype']) $natent['http_log_filetype'] = $_POST['http_log_filetype']; else unset($natent['http_log_filetype']);
if ($natent['http_log_filetype'] == "unix_dgram" || $natent['http_log_filetype'] == "unix_stream") {
if ($_POST['http_log_socket']) { $natent['http_log_socket'] = base64_encode($_POST['http_log_socket']); }else{ $natent['http_log_socket'] = $pconfig['tls_log_socket']; }
}
if ($_POST['runmode']) $natent['runmode'] = $_POST['runmode']; else unset($natent['runmode']);
if ($_POST['autofp_scheduler']) $natent['autofp_scheduler'] = $_POST['autofp_scheduler']; else unset($natent['autofp_scheduler']);
if ($_POST['max_pending_packets']) $natent['max_pending_packets'] = $_POST['max_pending_packets']; else unset($natent['max_pending_packets']);
if ($_POST['inspect_recursion_limit'] >= '0') $natent['inspect_recursion_limit'] = $_POST['inspect_recursion_limit']; else unset($natent['inspect_recursion_limit']);
if ($_POST['intf_snaplen'] > '0') $natent['intf_snaplen'] = $_POST['intf_snaplen']; else $natent['inspect_recursion_limit'] = "1518";
if ($_POST['detect_eng_profile']) $natent['detect_eng_profile'] = $_POST['detect_eng_profile']; else unset($natent['detect_eng_profile']);
if ($_POST['mpm_algo']) $natent['mpm_algo'] = $_POST['mpm_algo']; else unset($natent['mpm_algo']);
if ($_POST['sgh_mpm_context']) $natent['sgh_mpm_context'] = $_POST['sgh_mpm_context']; else unset($natent['sgh_mpm_context']);
if ($_POST['blockoffenders'] == "on") $natent['blockoffenders'] = 'on'; else $natent['blockoffenders'] = 'off';
if ($_POST['ips_mode']) $natent['ips_mode'] = $_POST['ips_mode']; else unset($natent['ips_mode']);
if ($_POST['ips_netmap_threads']) $natent['ips_netmap_threads'] = $_POST['ips_netmap_threads']; else $natent['ips_netmap_threads'] = "auto";
if ($_POST['blockoffenderskill'] == "on") $natent['blockoffenderskill'] = 'on'; else $natent['blockoffenderskill'] = 'off';
if ($_POST['block_drops_only'] == "on") $natent['block_drops_only'] = 'on'; else $natent['block_drops_only'] = 'off';
if ($_POST['blockoffendersip']) $natent['blockoffendersip'] = $_POST['blockoffendersip']; else unset($natent['blockoffendersip']);
if ($_POST['passlistname']) $natent['passlistname'] = $_POST['passlistname']; else unset($natent['passlistname']);
if ($_POST['homelistname']) $natent['homelistname'] = $_POST['homelistname']; else unset($natent['homelistname']);
if ($_POST['externallistname']) $natent['externallistname'] = $_POST['externallistname']; else unset($natent['externallistname']);
if ($_POST['suppresslistname']) $natent['suppresslistname'] = $_POST['suppresslistname']; else unset($natent['suppresslistname']);
if ($_POST['alertsystemlog'] == "on") { $natent['alertsystemlog'] = 'on'; }else{ $natent['alertsystemlog'] = 'off'; }
if ($_POST['alertsystemlog_facility']) $natent['alertsystemlog_facility'] = $_POST['alertsystemlog_facility'];
if ($_POST['alertsystemlog_priority']) $natent['alertsystemlog_priority'] = $_POST['alertsystemlog_priority'];
if ($_POST['enable_eve_log'] == "on") { $natent['enable_eve_log'] = 'on'; }else{ $natent['enable_eve_log'] = 'off'; }
if ($_POST['eve_output_type']) $natent['eve_output_type'] = $_POST['eve_output_type'];
if ($natent['eve_output_type'] == "unix_dgram" || $natent['eve_output_type'] == "unix_stream") {
if ($_POST['eve_output_socket']) { $natent['eve_output_socket'] = base64_encode($_POST['eve_output_socket']); }else{ $natent['eve_output_socket'] = $pconfig['eve_output_socket']; }
}
if ($_POST['eve_systemlog_facility']) $natent['eve_systemlog_facility'] = $_POST['eve_systemlog_facility'];
if ($_POST['eve_systemlog_priority']) $natent['eve_systemlog_priority'] = $_POST['eve_systemlog_priority'];
if ($_POST['eve_log_ethernet'] == "yes") { $natent['eve_log_ethernet'] = 'yes'; }else{ $natent['eve_log_ethernet'] = 'no'; }
if ($_POST['eve_log_alerts'] == "on") { $natent['eve_log_alerts'] = 'on'; }else{ $natent['eve_log_alerts'] = 'off'; }
if ($_POST['eve_log_alerts_payload']) { $natent['eve_log_alerts_payload'] = $_POST['eve_log_alerts_payload']; }else{ $natent['eve_log_alerts_payload'] = 'off'; }
if ($_POST['eve_log_alerts_packet'] == "on") { $natent['eve_log_alerts_packet'] = 'on'; }else{ $natent['eve_log_alerts_packet'] = 'off'; }
if ($_POST['eve_log_alerts_metadata'] == "on") { $natent['eve_log_alerts_metadata'] = 'on'; }else{ $natent['eve_log_alerts_metadata'] = 'off'; }
if ($_POST['eve_log_alerts_http'] == "on") { $natent['eve_log_alerts_http'] = 'on'; }else{ $natent['eve_log_alerts_http'] = 'off'; }
if ($_POST['eve_log_alerts_xff'] == "on") { $natent['eve_log_alerts_xff'] = 'on'; }else{ $natent['eve_log_alerts_xff'] = 'off'; }
if ($_POST['eve_log_alerts_xff_mode']) { $natent['eve_log_alerts_xff_mode'] = $_POST['eve_log_alerts_xff_mode']; }else{ $natent['eve_log_alert_xff_mode'] = 'extra-data'; }
if ($_POST['eve_log_alerts_xff_deployment']) { $natent['eve_log_alerts_xff_deployment'] = $_POST['eve_log_alerts_xff_deployment']; }else{ $natent['eve_log_alert_xff_deployment'] = 'reverse'; }
if ($_POST['eve_log_alerts_xff_header']) { $natent['eve_log_alerts_xff_header'] = $_POST['eve_log_alerts_xff_header']; }else{ $natent['eve_log_alert_xff_mode'] = 'X-Forwarded-For'; }
if ($_POST['eve_log_alerts_verdict'] == "on") { $natent['eve_log_alerts_verdict'] = 'on'; }else{ $natent['eve_log_alerts_verdict'] = 'off'; }
if ($_POST['eve_log_alerts_tagged'] == "on") { $natent['eve_log_alerts_tagged'] = 'on'; }else{ $natent['eve_log_alerts_tagged'] = 'off'; }
if ($_POST['eve_log_drops'] == "on") { $natent['eve_log_drops'] = 'on'; }else{ $natent['eve_log_drops'] = 'off'; }
if ($_POST['eve_log_alert_drops'] == "on") { $natent['eve_log_alert_drops'] = 'on'; }else{ $natent['eve_log_alert_drops'] = 'off'; }
if ($_POST['eve_log_drops_verdict'] == "on") { $natent['eve_log_drops_verdict'] = 'on'; }else{ $natent['eve_log_drops_verdict'] = 'off'; }
if ($_POST['eve_log_drops_flows']) $natent['eve_log_drops_flows'] = $_POST['eve_log_drops_flows'];
if ($_POST['eve_log_anomaly'] == "on") { $natent['eve_log_anomaly'] = 'on'; }else{ $natent['eve_log_anomaly'] = 'off'; }
if ($_POST['eve_log_anomaly_type_decode'] == "on") { $natent['eve_log_anomaly_type_decode'] = 'on'; }else{ $natent['eve_log_anomaly_type_decode'] = 'off'; }
if ($_POST['eve_log_anomaly_type_stream'] == "on") { $natent['eve_log_anomaly_type_stream'] = 'on'; }else{ $natent['eve_log_anomaly_type_stream'] = 'off'; }
if ($_POST['eve_log_anomaly_type_applayer'] == "on") { $natent['eve_log_anomaly_type_applayer'] = 'on'; }else{ $natent['eve_log_anomaly_type_applayer'] = 'off'; }
if ($_POST['eve_log_anomaly_packethdr'] == "on") { $natent['eve_log_anomaly_packethdr'] = 'on'; }else{ $natent['eve_log_anomaly_packethdr'] = 'off'; }
if ($_POST['eve_log_http'] == "on") { $natent['eve_log_http'] = 'on'; }else{ $natent['eve_log_http'] = 'off'; }
if ($_POST['eve_log_dns'] == "on") { $natent['eve_log_dns'] = 'on'; }else{ $natent['eve_log_dns'] = 'off'; }
if ($_POST['eve_log_tls'] == "on") { $natent['eve_log_tls'] = 'on'; }else{ $natent['eve_log_tls'] = 'off'; }
if ($_POST['eve_log_dhcp'] == "on") { $natent['eve_log_dhcp'] = 'on'; }else{ $natent['eve_log_dhcp'] = 'off'; }
if ($_POST['eve_log_nfs'] == "on") { $natent['eve_log_nfs'] = 'on'; }else{ $natent['eve_log_nfs'] = 'off'; }
if ($_POST['eve_log_smb'] == "on") { $natent['eve_log_smb'] = 'on'; }else{ $natent['eve_log_smb'] = 'off'; }
if ($_POST['eve_log_krb5'] == "on") { $natent['eve_log_krb5'] = 'on'; }else{ $natent['eve_log_krb5'] = 'off'; }
if ($_POST['eve_log_ikev2'] == "on") { $natent['eve_log_ikev2'] = 'on'; }else{ $natent['eve_log_ikev2'] = 'off'; }
if ($_POST['eve_log_tftp'] == "on") { $natent['eve_log_tftp'] = 'on'; }else{ $natent['eve_log_tftp'] = 'off'; }
if ($_POST['eve_log_bittorrent'] == "on") { $natent['eve_log_bittorrent'] = 'on'; }else{ $natent['eve_log_bittorrent'] = 'off'; }
if ($_POST['eve_log_pgsql'] == "on") { $natent['eve_log_pgsql'] = 'on'; }else{ $natent['eve_log_pgsql'] = 'off'; }
if ($_POST['eve_log_quic'] == "on") { $natent['eve_log_quic'] = 'on'; }else{ $natent['eve_log_quic'] = 'off'; }
if ($_POST['eve_log_rdp'] == "on") { $natent['eve_log_rdp'] = 'on'; }else{ $natent['eve_log_rdp'] = 'off'; }
if ($_POST['eve_log_sip'] == "on") { $natent['eve_log_sip'] = 'on'; }else{ $natent['eve_log_sip'] = 'off'; }
if ($_POST['eve_log_files'] == "on") { $natent['eve_log_files'] = 'on'; }else{ $natent['eve_log_files'] = 'off'; }
if ($_POST['eve_log_ssh'] == "on") { $natent['eve_log_ssh'] = 'on'; }else{ $natent['eve_log_ssh'] = 'off'; }
if ($_POST['eve_log_smtp'] == "on") { $natent['eve_log_smtp'] = 'on'; }else{ $natent['eve_log_smtp'] = 'off'; }
if ($_POST['eve_log_stats'] == "on") { $natent['eve_log_stats'] = 'on'; }else{ $natent['eve_log_stats'] = 'off'; }
if ($_POST['eve_log_flow'] == "on") { $natent['eve_log_flow'] = 'on'; }else{ $natent['eve_log_flow'] = 'off'; }
if ($_POST['eve_log_netflow'] == "on") { $natent['eve_log_netflow'] = 'on'; }else{ $natent['eve_log_netflow'] = 'off'; }
if ($_POST['eve_log_snmp'] == "on") { $natent['eve_log_snmp'] = 'on'; }else{ $natent['eve_log_snmp'] = 'off'; }
if ($_POST['eve_log_mqtt'] == "on") { $natent['eve_log_mqtt'] = 'on'; }else{ $natent['eve_log_mqtt'] = 'off'; }
if ($_POST['eve_log_ftp'] == "on") { $natent['eve_log_ftp'] = 'on'; }else{ $natent['eve_log_ftp'] = 'off'; }
if ($_POST['eve_log_http2'] == "on") { $natent['eve_log_http2'] = 'on'; }else{ $natent['eve_log_http2'] = 'off'; }
if ($_POST['eve_log_rfb'] == "on") { $natent['eve_log_rfb'] = 'on'; }else{ $natent['eve_log_rfb'] = 'off'; }
if ($_POST['eve_log_stats_totals'] == "on") { $natent['eve_log_stats_totals'] = 'on'; }else{ $natent['eve_log_stats_totals'] = 'off'; }
if ($_POST['eve_log_stats_deltas'] == "on") { $natent['eve_log_stats_deltas'] = 'on'; }else{ $natent['eve_log_stats_deltas'] = 'off'; }
if ($_POST['eve_log_stats_threads'] == "on") { $natent['eve_log_stats_threads'] = 'on'; }else{ $natent['eve_log_stats_threads'] = 'off'; }
if ($_POST['eve_log_http_extended'] == "on") { $natent['eve_log_http_extended'] = 'on'; }else{ $natent['eve_log_http_extended'] = 'off'; }
if ($_POST['eve_log_tls_extended'] == "on") { $natent['eve_log_tls_extended'] = 'on'; }else{ $natent['eve_log_tls_extended'] = 'off'; }
if ($_POST['eve_log_dhcp_extended'] == "on") { $natent['eve_log_dhcp_extended'] = 'on'; }else{ $natent['eve_log_dhcp_extended'] = 'off'; }
if ($_POST['eve_log_smtp_extended'] == "on") { $natent['eve_log_smtp_extended'] = 'on'; }else{ $natent['eve_log_smtp_extended'] = 'off'; }
if ($_POST['eve_log_http_extended_headers']) { $natent['eve_log_http_extended_headers'] = implode(", ",$_POST['eve_log_http_extended_headers']); }else{ $natent['eve_log_http_extended_headers'] = ""; }
if ($_POST['eve_log_smtp_extended_fields']) { $natent['eve_log_smtp_extended_fields'] = implode(", ",$_POST['eve_log_smtp_extended_fields']); }else{ $natent['eve_log_smtp_extended_fields'] = ""; }
if ($_POST['eve_log_tls_extended_fields']) { $natent['eve_log_tls_extended_fields'] = implode(", ",$_POST['eve_log_tls_extended_fields']); }else{ $natent['eve_log_tls_extended_fields'] = ""; }
if ($_POST['eve_log_files_magic'] == "on") { $natent['eve_log_files_magic'] = 'on'; }else{ $natent['eve_log_files_magic'] = 'off'; }
if ($_POST['eve_log_files_hash']) { $natent['eve_log_files_hash'] = $_POST['eve_log_files_hash']; }else{ $natent['eve_log_files_hash'] = 'none'; }
if ($_POST['eve_log_drop'] == "on") { $natent['eve_log_drop'] = 'on'; }else{ $natent['eve_log_drop'] = 'off'; }
if ($_POST['delayed_detect'] == "on") { $natent['delayed_detect'] = 'on'; }else{ $natent['delayed_detect'] = 'off'; }
if ($_POST['intf_promisc_mode'] == "on") { $natent['intf_promisc_mode'] = 'on'; }else{ $natent['intf_promisc_mode'] = 'off'; }
if ($_POST['configpassthru']) $natent['configpassthru'] = base64_encode(str_replace("\r\n", "\n", $_POST['configpassthru'])); else unset($natent['configpassthru']);
if ($_POST['eve_redis_server']) $natent['eve_redis_server'] = $_POST['eve_redis_server'];
if ($_POST['eve_redis_port']) $natent['eve_redis_port'] = $_POST['eve_redis_port'];
if ($_POST['eve_redis_mode']) $natent['eve_redis_mode'] = $_POST['eve_redis_mode'];
if ($_POST['eve_redis_key']) $natent['eve_redis_key'] = $_POST['eve_redis_key'];
// Check if EVE OUTPUT TYPE is 'syslog' and auto-enable Suricata syslog output if true.
if ($natent['eve_output_type'] == "syslog" && $natent['alertsystemlog'] == "off") {
$natent['alertsystemlog'] = "on";
$savemsg1 = gettext("EVE Output to syslog requires Suricata alerts to be copied to the system log, so 'Send Alerts to System Log' has been auto-enabled.");
}
// Check if Inline IPS mode is enabled. Auto-enable 'Live Rule Swap' and display a message
// about potential incompatibilities with Netmap and some NIC hardware drivers.
if ($natent['ips_mode'] == "ips_mode_inline") {
$savemsg2 = gettext("Inline IPS Mode is selected. Live Rule Swap will be automatically enabled to prevent netmap interfaces from cycling offline/online during future rules updates. " .
"For better performance with Inline IPS Mode operation, consider changing the runmode setting to workers. " .
"Please note that not all hardware NIC drivers support Netmap operation- which is required for Inline IPS Mode. If problems are experienced, switch to Legacy Mode instead.");
config_set_path('installedpackages/suricata/config/0/live_swap_updates', "on");
}
$if_real = get_real_interface($natent['interface']);
if (isset($id) && $a_rule[$id] && $action == '') {
// See if moving an existing Suricata instance to another physical interface
if ($natent['interface'] != $a_rule[$id]['interface']) {
$oif_real = get_real_interface($a_rule[$id]['interface']);
if (suricata_is_running($a_rule[$id]['uuid'], $oif_real)) {
suricata_stop($a_rule[$id], $oif_real);
$suricata_start = true;
}
else
$suricata_start = false;
@rename("{$suricatalogdir}suricata_{$oif_real}{$a_rule[$id]['uuid']}", "{$suricatalogdir}suricata_{$if_real}{$a_rule[$id]['uuid']}");
@rename("{$suricatadir}suricata_{$a_rule[$id]['uuid']}_{$oif_real}", "{$suricatadir}suricata_{$a_rule[$id]['uuid']}_{$if_real}");
}
$a_rule[$id] = $natent;
}
elseif (strcasecmp($action, 'dup') == 0) {
// Duplicating an existing interface to a new interface, so set flag to build new rules
$rebuild_rules = true;
// Duplicating an interface, so need to generate a new UUID for the cloned interface
$natent['uuid'] = suricata_generate_id();
// Add the new duplicated interface configuration to the [rule] array in config
$a_rule[] = $natent;
}
else {
// Adding new interface, so set interface configuration parameter defaults
$natent['ip_max_frags'] = "65535";
$natent['ip_frag_timeout'] = "60";
$natent['frag_memcap'] = '33554432';
$natent['defrag_memcap_policy'] = 'ignore';
$natent['ip_max_trackers'] = '65535';
$natent['frag_hash_size'] = '65536';
$natent['flow_memcap'] = '134217728';
$natent['flow_memcap_policy'] = 'ignore';
$natent['flow_prealloc'] = '10000';
$natent['flow_hash_size'] = '65536';
$natent['flow_emerg_recovery'] = '30';
$natent['flow_prune'] = '5';
$natent['flow_tcp_new_timeout'] = '60';
$natent['flow_tcp_established_timeout'] = '3600';
$natent['flow_tcp_closed_timeout'] = '120';
$natent['flow_tcp_emerg_new_timeout'] = '10';
$natent['flow_tcp_emerg_established_timeout'] = '300';
$natent['flow_tcp_emerg_closed_timeout'] = '20';
$natent['flow_udp_new_timeout'] = '30';
$natent['flow_udp_established_timeout'] = '300';
$natent['flow_udp_emerg_new_timeout'] = '10';
$natent['flow_udp_emerg_established_timeout'] = '100';
$natent['flow_icmp_new_timeout'] = '30';
$natent['flow_icmp_established_timeout'] = '300';
$natent['flow_icmp_emerg_new_timeout'] = '10';
$natent['flow_icmp_emerg_established_timeout'] = '100';
$natent['stream_memcap'] = '268435456';
$natent['stream_prealloc_sessions'] = '32768';
$natent['reassembly_memcap'] = '131217728';
$natent['reassembly_depth'] = '1048576';
$natent['reassembly_to_server_chunk'] = '2560';
$natent['reassembly_to_client_chunk'] = '2560';
$natent['max_synack_queued'] = '5';
$natent['enable_midstream_sessions'] = 'off';
$natent['stream_memcap_policy'] = 'ignore';
$natent['reassembly_memcap_policy'] = 'ignore';
$natent['midstream_policy'] = 'ignore';
$natent['stream_checksum_validation'] = "off";
$natent['enable_async_sessions'] = 'off';
$natent['stream_bypass'] = "off";
$natent['stream_drop_invalid'] = "off";
$natent['delayed_detect'] = 'off';
$natent['intf_promisc_mode'] = 'on';
$natent['intf_snaplen'] = '1518';
$natent['app_layer_error_policy'] = "ignore";
$natent['asn1_max_frames'] = '256';
$natent['bittorrent_parser'] = "yes";
$natent['dcerpc_parser'] = "yes";
$natent['dhcp_parser'] = "yes";
$natent['dns_global_memcap'] = "16777216";
$natent['dns_state_memcap'] = "524288";
$natent['dns_request_flood_limit'] = "500";
$natent['dns_parser_udp'] = "yes";
$natent['dns_parser_tcp'] = "yes";
$natent['dns_parser_udp_ports'] = "53";
$natent['dns_parser_tcp_ports'] = "53";
$natent['enip_parser'] = "yes";
$natent['ftp_parser'] = "yes";
$natent['ftp_data_parser'] = "on";
$natent['http_parser'] = "yes";
$natent['http_parser_memcap'] = "67108864";
$natent['http2_parser'] = "yes";
$natent['ikev2_parser'] = "yes";
$natent['imap_parser'] = "detection-only";
$natent['krb5_parser'] = "yes";
$natent['mqtt_parser'] = "yes";
$natent['msn_parser'] = "detection-only";
$natent['nfs_parser'] = "yes";
$natent['ntp_parser'] = "yes";
$natent['pgsql_parser'] = "no";
$natent['quic_parser'] = "yes";
$natent['rdp_parser'] = "yes";
$natent['rfb_parser'] = "yes";
$natent['sip_parser'] = "yes";
$natent['smb_parser'] = "yes";
$natent['smtp_parser'] = "yes";
$natent['smtp_parser_decode_mime'] = "off";
$natent['smtp_parser_decode_base64'] = "on";
$natent['smtp_parser_decode_quoted_printable'] = "on";
$natent['smtp_parser_extract_urls'] = "on";
$natent['smtp_parser_compute_body_md5'] = "off";
$natent['snmp_parser'] = "yes";
$natent['ssh_parser'] = "yes";
$natent['telnet_parser'] = "yes";
$natent['tftp_parser'] = "yes";
$natent['tls_parser'] = "yes";
$natent['tls_detect_ports'] = "443";
$natent['tls_encrypt_handling'] = "default";
$natent['tls_ja3_fingerprint'] = "off";
$natent['enable_iprep'] = "off";
$natent['host_memcap'] = "33554432";
$natent['host_hash_size'] = "4096";
$natent['host_prealloc'] = "1000";
$default = array( "name" => "default", "bind_to" => "all", "policy" => "bsd" );
array_init_path($natent, 'host_os_policy/item');
$natent['host_os_policy']['item'][] = $default;
$default = array( "name" => "default", "bind_to" => "all", "personality" => "IDS",
"request-body-limit" => 4096, "response-body-limit" => 4096,
"double-decode-path" => "no", "double-decode-query" => "no",
"uri-include-all" => "no", "meta-field-limit" => 18432 );
array_init_path($natent, 'libhtp_policy/item');
$natent['libhtp_policy']['item'][] = $default;
// Enable the basic default rules for the interface
$natent['rulesets'] = implode("||", SURICATA_DEFAULT_RULES);
// Adding a new interface, so set flag to build new rules
$rebuild_rules = true;
// Add the new interface configuration to the [rule] array in config
$a_rule[] = $natent;
}
// If Suricata is disabled on this interface, stop any running instance
if ($natent['enable'] != 'on')
suricata_stop($natent, $if_real);
// Save configuration changes
config_set_path('installedpackages/suricata/rule', $a_rule);
write_config("Suricata pkg: modified interface configuration for " . convert_friendly_interface_to_friendly_descr($natent['interface']));
// Update suricata.conf and suricata.sh files for this interface
sync_suricata_package_config();
// Refresh page fields with just-saved values
$pconfig = $natent;
$new_interface = false;
} else {
// Restore the existing parameters so the user can fix the detected error
$pconfig = $_POST;
if ($_POST['eve_log_http_extended_headers']) {
$pconfig['eve_log_http_extended_headers'] = implode(", ",$_POST['eve_log_http_extended_headers']);
} else {
$pconfig['eve_log_http_extended_headers'] = "";
}
if ($_POST['eve_log_smtp_extended_fields']) {
$pconfig['eve_log_smtp_extended_fields'] = implode(", ",$_POST['eve_log_smtp_extended_fields']);
} else {
$pconfig['eve_log_smtp_extended_fields'] = "";
}
if ($_POST['eve_log_tls_extended_fields']) {
$pconfig['eve_log_tls_extended_fields'] = implode(", ",$_POST['eve_log_tls_extended_fields']);
} else {
$pconfig['eve_log_tls_extended_fields'] = "";
}
}
}
/**************************************************************/
/* This function builds an array of lists based on the $lists */
/* parameter. Valid list types are 'suppress' and 'passlist' */
/* */
/* Returns: array of list names matching specified type */
/**************************************************************/
function suricata_get_config_lists($lists) {
$list = array();
foreach (config_get_path("installedpackages/suricata/{$lists}/item", []) as $value) {
$ilistname = $value['name'];
$list[$ilistname] = htmlspecialchars($ilistname);
}
return(['default' => 'default'] + $list);
}
$pglinks = array("", "/suricata/suricata_interfaces.php", "@self");
$pgtitle = array("Services", "Suricata", "{$if_friendly} - Interface Settings");
include_once("head.inc");
/* Display Alert message */
if ($input_errors) {
print_input_errors($input_errors);
}
if ($savemsg1) {
print_info_box($savemsg1);
}
if ($savemsg2) {
print_info_box($savemsg2);
}
// If using Inline IPS, check that CSO, TSO and LRO are all disabled
if ($pconfig['enable'] == 'on' && $pconfig['ips_mode'] == 'ips_mode_inline' && (!config_path_enabled('system','disablechecksumoffloading') || !config_path_enabled('system', 'disablesegmentationoffloading') || !config_path_enabled('system', 'disablelargereceiveoffloading'))) {
print_info_box(gettext('WARNING! IPS inline mode requires that Hardware Checksum Offloading, Hardware TCP Segmentation Offloading and Hardware Large Receive Offloading ' .
'all be disabled for proper operation. This firewall currently has one or more of these Offloading settings NOT disabled. Visit the ') . '<a href="/system_advanced_network.php">' .
gettext('System > Advanced > Networking') . '</a>' . gettext(' tab and ensure all three of these Offloading settings are disabled.'));
}
$tab_array = array();
$tab_array[] = array(gettext("Interfaces"), true, "/suricata/suricata_interfaces.php");
$tab_array[] = array(gettext("Global Settings"), false, "/suricata/suricata_global.php");
$tab_array[] = array(gettext("Updates"), false, "/suricata/suricata_download_updates.php");
if ($new_interface) {
$tab_array[] = array(gettext("Alerts"), false, "/suricata/suricata_alerts.php");
} else {
$tab_array[] = array(gettext("Alerts"), false, "/suricata/suricata_alerts.php?instance={$id}");
}
$tab_array[] = array(gettext("Blocks"), false, "/suricata/suricata_blocked.php");
$tab_array[] = array(gettext("Files"), false, "/suricata/suricata_files.php?instance={$id}");
$tab_array[] = array(gettext("Pass Lists"), false, "/suricata/suricata_passlist.php");
$tab_array[] = array(gettext("Suppress"), false, "/suricata/suricata_suppress.php");
$tab_array[] = array(gettext("Logs View"), false, "/suricata/suricata_logs_browser.php?instance={$id}");
$tab_array[] = array(gettext("Logs Mgmt"), false, "/suricata/suricata_logs_mgmt.php");
$tab_array[] = array(gettext("SID Mgmt"), false, "/suricata/suricata_sid_mgmt.php");
$tab_array[] = array(gettext("Sync"), false, "/pkg_edit.php?xml=suricata/suricata_sync.xml");
$tab_array[] = array(gettext("IP Lists"), false, "/suricata/suricata_ip_list_mgmt.php");
display_top_tabs($tab_array, true);
$tab_array = array();
$menu_iface=($if_friendly?substr($if_friendly,0,5)." ":"Iface ");
$tab_array[] = array($menu_iface . gettext("Settings"), true, "/suricata/suricata_interfaces_edit.php?id={$id}");
if (!$new_interface) {
$tab_array[] = array($menu_iface . gettext("Categories"), false, "/suricata/suricata_rulesets.php?id={$id}");
$tab_array[] = array($menu_iface . gettext("Rules"), false, "/suricata/suricata_rules.php?id={$id}");
$tab_array[] = array($menu_iface . gettext("Flow/Stream"), false, "/suricata/suricata_flow_stream.php?id={$id}");
$tab_array[] = array($menu_iface . gettext("App Parsers"), false, "/suricata/suricata_app_parsers.php?id={$id}");
$tab_array[] = array($menu_iface . gettext("Variables"), false, "/suricata/suricata_define_vars.php?id={$id}");
$tab_array[] = array($menu_iface . gettext("IP Rep"), false, "/suricata/suricata_ip_reputation.php?id={$id}");
}
display_top_tabs($tab_array, true);
$form = new Form;
$section = new Form_Section('General Settings');
$section->addInput(new Form_Checkbox(
'enable',
'Enable',
'Checking this box enables Suricata inspection on the interface.',
$pconfig['enable'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Select(
'interface',
'Interface',
$pconfig['interface'],
$interfaces
))->setHelp('Choose which interface this Suricata instance applies to. In most cases, you will want to choose LAN here if this is the first Suricata-configured interface.');
$section->addInput(new Form_Input(
'descr',
'Description',
'text',
$pconfig['descr']
))->setHelp('Enter a meaningful description here for your reference. The default is the pfSense interface friendly description.');
$form->add($section);
$section = new Form_Section('Logging Settings');
$section->addInput(new Form_Checkbox(
'alertsystemlog',
'Send Alerts to System Log',
'Suricata will send Alerts from this interface to the firewall\'s system log.',
$pconfig['alertsystemlog'] == 'on' ? true:false,
'on'
))->setHelp('NOTE: the FreeBSD syslog daemon will automatically truncate exported messages to 480 bytes max.');
$section->addInput(new Form_Select(
'alertsystemlog_facility',
'Log Facility',
$pconfig['alertsystemlog_facility'],
array( "auth" => "AUTH", "authpriv" => "AUTHPRIV", "daemon" => "DAEMON", "kern" => "KERN", "security" => "SECURITY",
"syslog" => "SYSLOG", "user" => "USER", "local0" => "LOCAL0", "local1" => "LOCAL1", "local2" => "LOCAL2",
"local3" => "LOCAL3", "local4" => "LOCAL4", "local5" => "LOCAL5", "local6" => "LOCAL6", "local7" => "LOCAL7" )
))->setHelp('Select system log Facility to use for reporting. Default is LOCAL1.');
$section->addInput(new Form_Select(
'alertsystemlog_priority',
'Log Priority',
$pconfig['alertsystemlog_priority'],
array( "emergency" => "EMERG", "critical" => "CRIT", "alert" => "ALERT", "error" => "ERR", "warning" => "WARNING", "notice" => "NOTICE", "info" => "INFO", "debug" => "DEBUG" )
))->setHelp('Select system log Priority (Level) to use for reporting. Default is NOTICE.');
$section->addInput(new Form_Checkbox(
'enable_stats_collection',
'Enable Stats Collection',
'Suricata will periodically gather performance statistics for this interface. Default is Not Checked.',
$pconfig['enable_stats_collection'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Input(
'stats_upd_interval',
'Stats Update Interval',
'text',
$pconfig['stats_upd_interval']
))->setHelp('Enter the update interval in seconds for collection of performance statistics. Default is 10 seconds.');
$section->addInput(new Form_Checkbox(
'enable_stats_log',
'Enable Stats Log',
'Suricata will periodically log statistics for this interface to a CSV text log file. Default is Not Checked.',
$pconfig['enable_stats_log'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Checkbox(
'append_stats_log',
'Append Stats Log',
'Suricata will append-to instead of clearing the stats log file when restarting. Default is Not Checked.',
$pconfig['append_stats_log'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Checkbox(
'enable_telegraf_stats',
'Enable Telegraf Stats',
'Suricata will periodically log statistics for this interface to Telegraf via a Unix socket. Default is Not Checked.',
$pconfig['enable_telegraf_stats'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Input(
'suricata_telegraf_unix_socket_name',
'Telegraf Unix Socket',
'text',
base64_decode($pconfig['suricata_telegraf_unix_socket_name'])
))->setHelp('Enter the full Unix socket name configured in Telegraf. This value must match exactly what is configured in the Telegraf input.suricata plugin! Note that Suricata will not create this socket. It must be created by Telegraf.');
$section->addInput(new Form_Checkbox(
'enable_http_log',
'Enable HTTP Log',
'Suricata will log decoded HTTP traffic for the interface. Default is Checked.',
$pconfig['enable_http_log'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Select(
'http_log_filetype',
'HTTP Log File Type',
$pconfig['http_log_filetype'],
array("regular" => "Regular", "unix_dgram" => "UNIX Datagram Socket", "unix_stream"=>"UNIX Stream Socket")
))->setHelp('Select "Regular" to log to a conventional file, or choose UNIX "Datagram" or "Stream" Socket to log to an existing UNIX socket. Default is "Regular"');
$section->addInput(new Form_Input(
'http_log_socket',
'HTTP Log Socket Name',
'text',
base64_decode($pconfig['http_log_socket'])
))->setHelp('Enter the UNIX socket name where TLS logs should be output. The user is responsible for creating the socket. It is NOT created by Suricata.');
$section->addInput(new Form_Checkbox(
'append_http_log',
'Append HTTP Log',
'Suricata will append-to instead of clearing HTTP log file when restarting. Default is Checked.',
$pconfig['append_http_log'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Checkbox(
'http_log_extended',
'Log Extended HTTP Info',
'Suricata will log extended HTTP information. Default is Checked.',
$pconfig['http_log_extended'] == 'on' ? true:false,
'on'
));
$section->addInput(new Form_Checkbox(