-
Notifications
You must be signed in to change notification settings - Fork 6
/
wpvulnerability-cli.php
844 lines (758 loc) · 26 KB
/
wpvulnerability-cli.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
<?php
/**
* CLI functions
*
* @package WPVulnerability
*
* @version 2.0.0
*/
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
/**
* Registers a WP-CLI command for WPVulnerability plugin.
*
* @since 2.0.0
*
* @return void
*/
if ( defined( 'WP_CLI' ) && WP_CLI ) {
/**
* Core section in WP-CLI command
*
* @since 2.0.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output, either 'table' or 'json'.
*
* @return void
*/
function wpvulnerability_cli_core( $args, $format ) {
// Validate the format.
switch ( $format ) {
case 'table':
$format = 'table';
break;
case 'json':
$format = 'json';
break;
default:
WP_CLI::error( "'$format' is not a valid format.\nAvailable formats: table, json" );
break;
}
$core_vulnerabilities = array();
if ( wpvulnerability_analyze_filter( 'core' ) ) {
// Get core vulnerabilities.
$core_vulnerabilities = wpvulnerability_core_get_vulnerabilities();
}
$core_complete = array();
$vulnerabilities = array();
if ( $core_vulnerabilities && is_array( $core_vulnerabilities ) ) {
// Loop through each core vulnerability.
foreach ( $core_vulnerabilities as $vulnerability ) {
$core_complete_temp = array();
// Process version.
$core_complete_temp['version'] = trim( html_entity_decode( wp_kses( (string) $vulnerability['name'], 'strip' ) ) );
// Process severity.
$core_complete_temp['severity'] = null;
if ( isset( $vulnerability['impact']['cvss']['severity'] ) ) {
$core_complete_temp['severity'] = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] );
}
// Process CWE details.
$core_complete_temp['cwe'] = array();
if ( isset( $vulnerability['impact']['cwe'] ) && count( $vulnerability['impact']['cwe'] ) ) {
foreach ( $vulnerability['impact']['cwe'] as $vulnerability_cwe ) {
$core_complete_temp['cwe'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $vulnerability_cwe['name'], 'strip' ) ) ),
'description' => trim( html_entity_decode( wp_kses( (string) $vulnerability_cwe['description'], 'strip' ) ) ),
);
}
}
// Process CVSS score.
$core_complete_temp['score'] = null;
if ( isset( $vulnerability['impact']['cvss']['score'] ) ) {
$core_complete_temp['score'] = number_format( (float) $vulnerability['impact']['cvss']['score'], 1, '.', '' );
}
// Process sources.
$core_complete_temp['source'] = array();
if ( isset( $vulnerability['source'] ) && count( $vulnerability['source'] ) ) {
foreach ( $vulnerability['source'] as $vulnerability_source ) {
$core_complete_temp['source'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $vulnerability_source['name'], 'strip' ) ) ),
'link' => esc_url_raw( (string) $vulnerability_source['link'], 'strip' ),
);
}
}
$core_complete[] = $core_complete_temp;
unset( $core_complete_temp );
}
}
// Format output based on the selected format.
if ( 'table' === $format ) {
foreach ( $core_complete as $c_vuln ) {
$v_version = $c_vuln['version'];
$v_score = $c_vuln['score'];
$v_severity = $c_vuln['severity'];
// Compile CWE descriptions.
$v_description_array = array();
foreach ( $c_vuln['cwe'] as $c_cwe ) {
if ( isset( $c_cwe['name'] ) ) {
$v_description_array[] = $c_cwe['name'];
}
}
$v_description = trim( implode( ' + ', $v_description_array ) );
// Add to vulnerabilities array for table output.
array_push(
$vulnerabilities,
array(
'version' => $v_version,
'score' => $v_score,
'severity' => $v_severity,
'description' => $v_description,
)
);
}
// Format and output the vulnerabilities in a table.
WP_CLI\Utils\format_items(
'table',
$vulnerabilities,
array( 'version', 'score', 'severity', 'description' )
);
} elseif ( 'json' === $format ) {
// Format and output the vulnerabilities in JSON.
echo wp_json_encode( $core_complete );
}
}
/**
* Plugin section in WP-CLI command
*
* This function retrieves and displays plugin vulnerabilities
* based on the specified format (table or JSON).
*
* @since 2.0.0
*
* @param array $args The arguments passed from the command line.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_plugins( $args, $format ) {
// Validate the format.
switch ( $format ) {
case 'table':
$format = 'table';
break;
case 'json':
$format = 'json';
break;
default:
WP_CLI::error( "'$format' is not a valid format.\nAvailable formats: table, json" );
break;
}
$plugin_vulnerabilities = array();
if ( wpvulnerability_analyze_filter( 'plugins' ) ) {
// Get plugin vulnerabilities.
$plugin_vulnerabilities = wpvulnerability_plugin_get_vulnerabilities();
}
$plugins_complete = array();
$vulnerabilities = array();
// Loop through each plugin vulnerability.
foreach ( $plugin_vulnerabilities as $plugin ) {
if ( 1 === $plugin['vulnerable'] ) {
$plugins_complete_temp = array();
$plugins_complete_temp_vulnerabilities = array();
// Process plugin name and slug.
$plugins_complete_temp['name'] = trim( html_entity_decode( wp_kses( (string) $plugin['Name'], 'strip' ) ) );
$plugins_complete_temp['slug'] = trim( html_entity_decode( wp_kses( (string) $plugin['slug'], 'strip' ) ) );
// Prepare the vulnerabilities array for table format output.
foreach ( $plugin['vulnerabilities'] as $vulnerability ) {
$plugins_complete_temp_vulnerabilities['severity'] = null;
if ( isset( $vulnerability['impact']['cvss']['severity'] ) ) {
$plugins_complete_temp_vulnerabilities['severity'] = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] );
}
// Process vulnerability details.
$plugins_complete_temp_vulnerabilities['version'] = trim( html_entity_decode( wp_kses( (string) $vulnerability['versions'], 'strip' ) ) );
$plugins_complete_temp_vulnerabilities['name'] = trim( html_entity_decode( wp_kses( (string) $vulnerability['name'], 'strip' ) ) );
$plugins_complete_temp_vulnerabilities['closed'] = (int) $vulnerability['closed'];
$plugins_complete_temp_vulnerabilities['unfixed'] = (int) $vulnerability['unfixed'];
// Process CWE details.
$plugins_complete_temp_vulnerabilities['cwe'] = array();
if ( isset( $vulnerability['impact']['cwe'] ) && count( $vulnerability['impact']['cwe'] ) ) {
foreach ( $vulnerability['impact']['cwe'] as $vulnerability_cwe ) {
$plugins_complete_temp_vulnerabilities['cwe'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $vulnerability_cwe['name'], 'strip' ) ) ),
'description' => trim( html_entity_decode( wp_kses( (string) $vulnerability_cwe['description'], 'strip' ) ) ),
);
}
}
// Process CVSS score.
$plugins_complete_temp_vulnerabilities['score'] = null;
if ( isset( $vulnerability['impact']['cvss']['score'] ) ) {
$plugins_complete_temp_vulnerabilities['score'] = number_format( (float) $vulnerability['impact']['cvss']['score'], 1, '.', '' );
}
// Process sources.
$plugins_complete_temp_vulnerabilities['source'] = array();
if ( isset( $vulnerability['source'] ) && count( $vulnerability['source'] ) ) {
foreach ( $vulnerability['source'] as $vulnerability_source ) {
$plugins_complete_temp_vulnerabilities['source'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $vulnerability_source['name'], 'strip' ) ) ),
'link' => esc_url_raw( (string) $vulnerability_source['link'], 'strip' ),
);
}
}
$plugins_complete_temp['vulnerabilities'][] = $plugins_complete_temp_vulnerabilities;
unset( $plugins_complete_temp_vulnerabilities, $vulnerability );
}
$plugins_complete[] = $plugins_complete_temp;
unset( $plugins_complete_temp );
}
unset( $plugin );
}
// Format output based on the selected format.
if ( 'table' === $format ) {
foreach ( $plugins_complete as $p_vuln ) {
$v_name = $p_vuln['slug'];
foreach ( $p_vuln['vulnerabilities'] as $p_vul ) {
$v_version = $p_vul['version'];
// Determine if vulnerability is fixed.
switch ( $p_vul['unfixed'] ) {
default:
case 0:
$v_fixed = 'yes';
break;
case 1:
$v_fixed = 'no';
break;
}
// Determine if plugin is closed.
switch ( $p_vul['closed'] ) {
default:
case 0:
$v_closed = 'no';
break;
case 1:
$v_closed = 'yes';
break;
}
$v_score = $p_vul['score'];
$v_severity = $p_vul['severity'];
// Compile CWE descriptions.
$v_description_array = array();
foreach ( $p_vul['cwe'] as $p_cwe ) {
if ( isset( $p_cwe['name'] ) ) {
$v_description_array[] = $p_cwe['name'];
}
}
$v_description = trim( implode( ' + ', $v_description_array ) );
// Add to vulnerabilities array for table output.
array_push(
$vulnerabilities,
array(
'name' => $v_name,
'version' => $v_version,
'fixed' => $v_fixed,
'closed' => $v_closed,
'score' => $v_score,
'severity' => $v_severity,
'description' => $v_description,
)
);
}
}
// Format and output the vulnerabilities in a table.
WP_CLI\Utils\format_items(
'table',
$vulnerabilities,
array( 'name', 'version', 'fixed', 'closed', 'score', 'severity', 'description' )
);
} elseif ( 'json' === $format ) {
// Format and output the vulnerabilities in JSON.
echo wp_json_encode( $plugins_complete );
}
}
/**
* Theme section in WP-CLI command
*
* This function retrieves and displays theme vulnerabilities
* based on the specified format (table or JSON).
*
* @since 2.0.0
*
* @param array $args The arguments passed from the command line.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_themes( $args, $format ) {
// Validate the format.
switch ( $format ) {
case 'table':
$format = 'table';
break;
case 'json':
$format = 'json';
break;
default:
WP_CLI::error( "'$format' is not a valid format.\nAvailable formats: table, json" );
break;
}
$theme_vulnerabilities = array();
if ( wpvulnerability_analyze_filter( 'themes' ) ) {
// Get theme vulnerabilities.
$theme_vulnerabilities = wpvulnerability_theme_get_vulnerabilities();
}
$themes_complete = array();
$vulnerabilities = array();
// Loop through each theme vulnerability.
foreach ( $theme_vulnerabilities as $theme ) {
if ( 1 === $theme['wpvulnerability']['vulnerable'] ) {
$themes_complete_temp = array();
$themes_complete_temp_vulnerabilities = array();
// Process theme name and slug.
$themes_complete_temp['name'] = trim( html_entity_decode( wp_kses( (string) $theme['wpvulnerability']['name'], 'strip' ) ) );
$themes_complete_temp['slug'] = trim( html_entity_decode( wp_kses( (string) $theme['wpvulnerability']['slug'], 'strip' ) ) );
// Prepare the vulnerabilities array for table format output.
foreach ( $theme['wpvulnerability']['vulnerabilities'] as $vulnerability ) {
$themes_complete_temp_vulnerabilities['severity'] = null;
if ( isset( $vulnerability['impact']['cvss']['severity'] ) ) {
$themes_complete_temp_vulnerabilities['severity'] = wpvulnerability_severity( $vulnerability['impact']['cvss']['severity'] );
}
// Process vulnerability details.
$themes_complete_temp_vulnerabilities['version'] = trim( html_entity_decode( wp_kses( (string) $vulnerability['versions'], 'strip' ) ) );
$themes_complete_temp_vulnerabilities['name'] = trim( html_entity_decode( wp_kses( (string) $vulnerability['name'], 'strip' ) ) );
$themes_complete_temp_vulnerabilities['closed'] = (int) $vulnerability['closed'];
$themes_complete_temp_vulnerabilities['unfixed'] = (int) $vulnerability['unfixed'];
// Process CWE details.
$themes_complete_temp_vulnerabilities['cwe'] = array();
if ( isset( $vulnerability['impact']['cwe'] ) && count( $vulnerability['impact']['cwe'] ) ) {
foreach ( $vulnerability['impact']['cwe'] as $vulnerability_cwe ) {
$themes_complete_temp_vulnerabilities['cwe'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $vulnerability_cwe['name'], 'strip' ) ) ),
'description' => trim( html_entity_decode( wp_kses( (string) $vulnerability_cwe['description'], 'strip' ) ) ),
);
}
}
// Process CVSS score.
$themes_complete_temp_vulnerabilities['score'] = null;
if ( isset( $vulnerability['impact']['cvss']['score'] ) ) {
$themes_complete_temp_vulnerabilities['score'] = number_format( (float) $vulnerability['impact']['cvss']['score'], 1, '.', '' );
}
// Process sources.
$themes_complete_temp_vulnerabilities['source'] = array();
if ( isset( $vulnerability['source'] ) && count( $vulnerability['source'] ) ) {
foreach ( $vulnerability['source'] as $vulnerability_source ) {
$themes_complete_temp_vulnerabilities['source'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $vulnerability_source['name'], 'strip' ) ) ),
'link' => esc_url_raw( (string) $vulnerability_source['link'], 'strip' ),
);
}
}
$themes_complete_temp['vulnerabilities'][] = $themes_complete_temp_vulnerabilities;
unset( $themes_complete_temp_vulnerabilities, $vulnerability );
}
$themes_complete[] = $themes_complete_temp;
unset( $themes_complete_temp );
}
unset( $theme );
}
// Format output based on the selected format.
if ( 'table' === $format ) {
foreach ( $themes_complete as $t_vuln ) {
$v_name = $t_vuln['slug'];
foreach ( $t_vuln['vulnerabilities'] as $t_vul ) {
$v_version = $t_vul['version'];
// Determine if vulnerability is fixed.
switch ( $t_vul['unfixed'] ) {
default:
case 0:
$v_fixed = 'yes';
break;
case 1:
$v_fixed = 'no';
break;
}
// Determine if theme is closed.
switch ( $t_vul['closed'] ) {
default:
case 0:
$v_closed = 'no';
break;
case 1:
$v_closed = 'yes';
break;
}
$v_score = $t_vul['score'];
$v_severity = $t_vul['severity'];
// Compile CWE descriptions.
$v_description_array = array();
foreach ( $t_vul['cwe'] as $t_cwe ) {
if ( isset( $t_cwe['name'] ) ) {
$v_description_array[] = $t_cwe['name'];
}
}
$v_description = trim( implode( ' + ', $v_description_array ) );
// Add to vulnerabilities array for table output.
array_push(
$vulnerabilities,
array(
'name' => $v_name,
'version' => $v_version,
'fixed' => $v_fixed,
'closed' => $v_closed,
'score' => $v_score,
'severity' => $v_severity,
'description' => $v_description,
)
);
}
}
// Format and output the vulnerabilities in a table.
WP_CLI\Utils\format_items(
'table',
$vulnerabilities,
array( 'name', 'version', 'fixed', 'closed', 'score', 'severity', 'description' )
);
} elseif ( 'json' === $format ) {
// Format and output the vulnerabilities in JSON.
echo wp_json_encode( $themes_complete );
}
}
/**
* Handles vulnerabilities for specified software in WP-CLI command.
*
* This function retrieves and displays vulnerabilities based on the specified format (table or JSON).
*
* @since 3.5.0
*
* @param string $software The software type (php, apache, nginx, mariadb, mysql).
* @param string $format The format for the output, either 'table' or 'json'.
*
* @return void
*/
function wpvulnerability_cli_software( $software, $format ) {
// Validate the format.
switch ( $format ) {
case 'table':
$format = 'table';
break;
case 'json':
$format = 'json';
break;
default:
WP_CLI::error( "'$format' is not a valid format.\nAvailable formats: table, json" );
break;
}
$vulnerabilities = array();
switch ( $software ) {
case 'php':
case 'apache':
case 'nginx':
case 'mariadb':
case 'mysql':
case 'imagemagick':
case 'curl':
case 'memcached':
case 'redis':
case 'sqlite':
$software_vulnerabilities = wpvulnerability_get_vulnerabilities( $software, wpvulnerability_get_software_version( $software ) );
break;
default:
$software_vulnerabilities = null;
}
$software_complete = array();
if ( isset( $software_vulnerabilities ) && is_array( $software_vulnerabilities ) ) {
// Loop through each vulnerability.
foreach ( $software_vulnerabilities as $item ) {
$complete_temp = array();
$complete_temp['version'] = trim( html_entity_decode( wp_kses( (string) $item['version'], 'strip' ) ) );
$complete_temp['affected'] = trim( html_entity_decode( wp_kses( (string) $item['versions'], 'strip' ) ) );
$complete_temp['unfixed'] = (int) $item['unfixed'];
// Process vulnerability sources.
$complete_temp['source'] = array();
if ( isset( $item['source'] ) && count( $item['source'] ) ) {
foreach ( $item['source'] as $source ) {
$complete_temp['source'][] = array(
'name' => trim( html_entity_decode( wp_kses( (string) $source['id'], 'strip' ) ) ),
'description' => trim( html_entity_decode( wp_kses( (string) $source['description'], 'strip' ) ) ),
'link' => esc_url_raw( (string) $source['link'], 'strip' ),
);
}
}
$software_complete[] = $complete_temp;
}
}
// Format output based on the selected format.
if ( 'table' === $format ) {
$vulnerabilities = array();
foreach ( $software_complete as $vuln ) {
$v_fixed = $vuln['unfixed'] ? 'no' : 'yes';
// Compile source descriptions.
$v_description_array = array();
foreach ( $vuln['source'] as $source ) {
$v_description_array[] = $source['name'] . ': ' . $source['description'];
}
$v_description = trim( implode( ' + ', $v_description_array ) );
// Add to vulnerabilities array for table output.
array_push(
$vulnerabilities,
array(
'version' => $vuln['version'],
'affected' => $vuln['affected'],
'fixed' => $v_fixed,
'description' => $v_description,
)
);
}
// Format and output the vulnerabilities in a table.
WP_CLI\Utils\format_items(
'table',
$vulnerabilities,
array( 'version', 'affected', 'fixed', 'description' )
);
} elseif ( 'json' === $format ) {
// Format and output the vulnerabilities in JSON.
echo wp_json_encode( $software_complete );
}
}
/**
* PHP section in WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_php( $args, $format ) {
wpvulnerability_cli_software( 'php', $format );
}
/**
* Apache HTTPD section in WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_apache( $args, $format ) {
wpvulnerability_cli_software( 'apache', $format );
}
/**
* Nginx section in WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_nginx( $args, $format ) {
wpvulnerability_cli_software( 'nginx', $format );
}
/**
* Handles the MariaDB section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_mariadb( $args, $format ) {
wpvulnerability_cli_software( 'mariadb', $format );
}
/**
* Handles the MySQL section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_mysql( $args, $format ) {
wpvulnerability_cli_software( 'mysql', $format );
}
/**
* Handles the ImageMagick section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_imagemagick( $args, $format ) {
wpvulnerability_cli_software( 'imagemagick', $format );
}
/**
* Handles the curl section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_curl( $args, $format ) {
wpvulnerability_cli_software( 'curl', $format );
}
/**
* Handles the memcached section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_memcached( $args, $format ) {
wpvulnerability_cli_software( 'memcached', $format );
}
/**
* Handles the Redis section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_redis( $args, $format ) {
wpvulnerability_cli_software( 'redis', $format );
}
/**
* Handles the SQLite section in the WP-CLI command.
*
* @since 3.5.0
*
* @param array $args Arguments passed to the command.
* @param string $format The format for the output.
*
* @return void
*/
function wpvulnerability_cli_sqlite( $args, $format ) {
wpvulnerability_cli_software( 'sqlite', $format );
}
/**
* Dispatches the WPVulnerability CLI command to show the list of detected vulnerabilities on the site.
*
* This function selects and executes the appropriate function based on the provided subcommand.
* It supports different output formats, such as 'table' and 'json', to display the vulnerabilities.
*
* @since 2.0.0
*
* @param array $args The subcommand to execute.
* Accepted values: 'core', 'plugins', 'themes', 'php', 'apache', 'nginx', 'mariadb', 'mysql'.
* @param array $assoc_args Associative arguments passed from the command line.
* 'format' (optional) - The format for the output. Defaults to 'table'.
* Accepted values: 'table', 'json'.
*
* @return void
*/
function wpvulnerability_cli_command( $args, $assoc_args ) {
$subcommand = $args[0];
$format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table';
// Select the correct function to execute based on the subcommand.
switch ( $subcommand ) {
case 'core':
wpvulnerability_cli_core( $args, $format );
break;
case 'plugins':
wpvulnerability_cli_plugins( $args, $format );
break;
case 'themes':
wpvulnerability_cli_themes( $args, $format );
break;
case 'php':
wpvulnerability_cli_php( $args, $format );
break;
case 'apache':
wpvulnerability_cli_apache( $args, $format );
break;
case 'nginx':
wpvulnerability_cli_nginx( $args, $format );
break;
case 'mariadb':
wpvulnerability_cli_mariadb( $args, $format );
break;
case 'mysql':
wpvulnerability_cli_mysql( $args, $format );
break;
case 'imagemagick':
wpvulnerability_cli_imagemagick( $args, $format );
break;
case 'curl':
wpvulnerability_cli_curl( $args, $format );
break;
case 'memcached':
wpvulnerability_cli_memcached( $args, $format );
break;
case 'redis':
wpvulnerability_cli_redis( $args, $format );
break;
case 'sqlite':
wpvulnerability_cli_sqlite( $args, $format );
break;
default:
// Display an error message for an invalid subcommand.
WP_CLI::error( "'$subcommand' is not a valid subcommand of 'wpvulnerability'.\nAvailable subcommands: core, plugins, themes, php, apache, nginx, mariadb, mysql, imagemagick, curl, memcached, redis, sqlite" );
break;
}
}
/**
* Registers a WP-CLI command to show the list of vulnerabilities detected on your site.
*
* EXAMPLES:
*
* - wp wpvulnerability core
* - wp wpvulnerability plugins
* - wp wpvulnerability themes
* - wp wpvulnerability php
* - wp wpvulnerability apache
* - wp wpvulnerability nginx
* - wp wpvulnerability mariadb
* - wp wpvulnerability mysql
* - wp wpvulnerability imagemagick
* - wp wpvulnerability curl
* - wp wpvulnerability memcached
* - wp wpvulnerability redis
* - wp wpvulnerability sqlite
*
* @param object $args Arguments passed from the command line.
*
* @return void
*/
WP_CLI::add_command(
'wpvulnerability',
'wpvulnerability_cli_command',
array(
'shortdesc' => 'Show the list of vulnerabilities detected on your site.',
'synopsis' => array(
array(
'type' => 'positional',
'name' => 'subcommand',
'description' => 'Type of vulnerability [ core | plugins | themes | php | apache | nginx | mariadb | mysql | imagemagick | curl ].',
'optional' => false,
),
array(
'type' => 'assoc',
'name' => 'format',
'description' => 'Format for the output [ table | json ].',
'optional' => true,
'default' => 'table',
),
),
'when' => 'after_wp_load',
'longdesc' => "EXAMPLES:\n\n - wp wpvulnerability core\n - wp wpvulnerability plugins\n - wp wpvulnerability themes\n - wp wpvulnerability php\n - wp wpvulnerability apache\n - wp wpvulnerability nginx\n - wp wpvulnerability mariadb\n - wp wpvulnerability mysql\n - wp wpvulnerability imagemagick\n - wp wpvulnerability curl\n - wp wpvulnerability memcached\n - wp wpvulnerability redis\n - wp wpvulnerability sqlite",
)
);
}