use fenir::facilities::configure_terminal;
use fenir::no_argument_and_exit;
use fenir::package::errors::write_error_message_and_exit;
use get_cve::common_options;
use std::env;
use std::process::exit;
#[cfg(target_os = "linux")]
use fenir::os::{OSFamily, SupportedOs};
#[cfg(target_os = "linux")]
use get_cve::special_options;
#[cfg(target_os = "linux")]
fn help() {
println!();
println!("> Specific linux distribution <");
if SupportedOs::supported_os() == OSFamily::Debian {
help_debian();
} else if SupportedOs::supported_os() == OSFamily::RedHat {
help_redhat();
}
}
#[cfg(target_os = "linux")]
fn help_debian() {
println!(
"Get fixed cve for a given product as parameter. This product must be installed on the current system.
Usage:
get-cve <product>[=<version>] [--next] [--filter <argument>] [-L or --long [--sort_by <field>] [--to_csv [with_headers]]]: get the cve list for the given product. In option the product version can be specified.
Options:
<version>: specific version for the given product.
--filter <argument>: CVE filtering according to <argument>. Eg: get-cve less --filter 2022.
--next: search the next <product> release available from the repositories.
-L or --long [--sort_by <field>] [--to_csv [with_headers]]: shows a details sum up about the cve. If --sort_by is specified with a field, the long format will be sorted according to this <field>.
See common help for more details. With --to_csv show data in csv format. With with_headers, data are showing with headers.
"
);
}
#[cfg(target_os = "linux")]
fn help_redhat() {
println!(
"Get fixed cve for a given product as parameter. This product must be installed on the current system.
Usage:
get-cve <product>[=<version>] [--filter <argument>] [-L or --long [--sort_by <field>] [--to_csv [with_headers]]]: get the cve list for the given product. In option the product version can be specified.
Options:
<version>: specific version for the given product.
--filter <argument>: CVE filtering according to <argument>. Eg: get-cve less --filter 2022.
-L or --long [--sort_by <field>] [--to_csv [with_headers]]: shows a details sum up about the cve. If --sort_by is specified with a field, the long format will be sorted according to this <field>.
See common help for more details. With --to_csv show data in csv format. With with_headers, data are showing with headers.
"
);
}
fn common_help() {
println!(
"Common usage and options.
Usage:
get-cve [Options]
Options:
h or help: show this help.
<cve> [<selectors>]: get data about the given <cve> (forms: cve-yyyy-n0...nN in lower or upper cases). This data is showing in json mode.
The <selectors> arguments can be a combination of the following options:
-f or --cpe: shows the associated cpe descriptions if they exist,
-d or --desc [<lang>]: shows the CVE description. The <lang> parameter must corresponding to one parameter given by nvd api.
-K or --doc: shows the list of associated documentation for the CVE.
-l or --lang: shows the lang list available for descriptions.
-L or --long [--sort_by <field>][--to_csv [with_headers]]: shows a details sum up about the cve. If --sort_by is specified with a field, the long format will be sorted according to this <field>.
The list of <field> are the following:
- cpe
- description
- score [v3 (default)|v4],
- weaknesses,
- with no option, sort by cve that is the default value.
The --to_csv allows to export the showing data in csv on the standard output. If with_headers is specified, the export will export the headers with all data.
-s or --score [v3|v4] [-D|--data]: shows the CVE score (v3 and v4). With 'v3' option shows only v3 score if exists. With 'v4' option shows only v4 score if exists.
If -D or --data is specified the details of data are showing for the selected score,
-S or --schema: shows the schema for this CVE. If the cwe is existing for this CVE, all weaknesses and attacks path will be shown,
-w or --cwe: shows the list of CWE.
c or check: verify if the NVD NIST link is available or not.
e or exploited [-L or --long [--sort_by <field>]][--filter <value>] [--to_csv [with_headers]]: known exploited vulnerabilities CVE list. See above for long format support.
--filter: CVE filtering according to <argument>. Eg: get-cve exploited --filter 2022.
f or for-cpe '<cpe_string>' [-v or --vul [-L or --long [--sort_by <field>]][--filter <value>] [--to_csv [with_headers]]: CVE list that's corresponding to the CPE string. The CPE string criteria must be surrounded with the simple quote string. If -v or --vul is specified, shows only the list of CVE for which this CWE is marked as vulnerable. See above for long format support.
--filter: CVE filtering according to <argument>. Eg: get-cve for-cpe --filter 2022.
n or new [<date_start>] [<date_end>] [-L or --long [--sort_by <field>]][--filter <value>] [--to_csv [with_headers]]: shows only new cve between <date_start> and <date_end>. If not set, they're corresponding to the current date. Dates format is: YYYY-MM-DD. See above for long format support.
--filter: CVE filtering according to <argument>. Eg: get-cve new --filter 2022.
u or updated [<date_start>] [<date_end>] [-L or --long [--sort_by <field>]][--filter <value>] [--to_csv [with_headers]]: shows only updated cve between <date_start> and <date_end>. If not set, they're corresponding to the current date. Dates format is: YYYY-MM-DD. See above for long format support.
--filter: CVE filtering according to <argument>. Eg: get-cve updated --filter 2022.
v or version: show the current version.
s or search [-S or --strict [-L or --long [--sort_by <field>]]][--filter <value>] [--to_csv [with_headers]] <string1> [<string2>...<stringN>]: search the list of CVE that are containing the list of <string> values. If -S or --strict argument is given, search strictly the whole strings as an alone argument. See above for long format support.
--filter: CVE filtering according to <argument>. Eg: get-cve search --filter 2022 <string1> [<string2>...<stringN>].
w or cwe <cwe> [-L or --long [--sort_by <field>]][--filter <value>] [--to_csv [with_headers]]: get the list of CVE that's corresponding to the <cwe>. See above for long format support.
--filter: CVE filtering according to <argument>. Eg: get-cve cwe <cwe_value> --filter 2022.
If you want to specify your NVD api key, set the NVD_API_KEY environment variable with your api key.
");
}
fn main() {
configure_terminal();
let mut args: Vec<String> = env::args().collect();
args.remove(0);
if args.is_empty() {
no_argument_and_exit!();
}
if args.iter().any(|a| a == "help" || a == "h") {
common_help();
#[cfg(target_os = "linux")]
help();
} else {
common_options(&mut args);
#[cfg(target_os = "linux")]
special_options(&args);
}
exit(0);
}