Vidushi Agrawal [Fri, 15 Mar 2019 21:56:04 +0000 (03:26 +0530)]
Fix default for the --ignore flag
suricata-update doesn't properly load some sections in update.yaml file.
Example:
Even after setting the following in update.yaml
```
ignore:
- "*deleted.rules"
- "*pop3.rules"
```
```
$ ./bin/suricata-update -v
```
generates
```
16/3/2019 -- 03:14:59 - <Debug> -- Parsing rules/emerging-pop3.rules.
16/3/2019 -- 03:15:01 - <Debug> -- Parsing rules/emerging-deleted.rules.
```
which means the files do not get ignored. It seems that the code loading command line parameters override previous settings even when no parameters are given.
Thus changing the default for the --ignore flag from "[]" to "None", fixes the issue.
Vagisha Gupta [Wed, 13 Mar 2019 14:57:20 +0000 (20:27 +0530)]
Fix Failure with --no-merge
UnboundLocalError: local variable 'rule' referenced before assignment
'suricata-update --no-merge' runs into an error.
'rule.id' is changed to 'key' variable to fix this issue because 'rule' is
not used in the loop. Appended 'key' to the added list i.e. List of rule IDs
that have been added.
Shivani Bhardwaj [Tue, 22 Jan 2019 15:49:37 +0000 (21:19 +0530)]
Add timeout of 30 sec for all GET requests
suricata-update has been reported to get hung in case the download fails
for a particular source. Add a timeout parameter to urllib to avoid that
and continue further processing after a timeout of 30 seconds.
Shivani Bhardwaj [Fri, 22 Feb 2019 12:50:15 +0000 (18:20 +0530)]
Fix null pointer dereference issue detected by coverity
Coverity scan of the current code raised the following issue:
```
>>> CID 327298: Null pointer dereferences (FORWARD_NULL)
>>> Accessing a property of null-like value "val".
271 if val.find("noalert") > -1:
```
Shivani Bhardwaj [Mon, 14 Jan 2019 17:22:49 +0000 (22:52 +0530)]
Avoid failure in case of obsoletion of attribute
`platform` is currently (Py3.7) shipped with `linux_distribution`
attribute but it has been Deprecated since Py3.5. In future when it
becomes obsolete, suricata-update will break while creating User-Agent
header. In order to avoid this, check for the attribute before adding it
to User-Agent.
Shivani Bhardwaj [Fri, 21 Dec 2018 09:14:53 +0000 (14:44 +0530)]
Make header an optional argument
header was being used as a required argument in SourceConfiguration
class. Since SourceConfiguration class has been used multiple times
across commands, not all the commands require header argument and thus
it breaks. Fix it by making header an optional argument.
Shivani Bhardwaj [Tue, 18 Dec 2018 10:31:40 +0000 (16:01 +0530)]
Fix the broken sys import of distutils
Newer distutils versions allow to list and work with `sys` as it is
imported in the `__init__.py` however, the older versions of disutils
does not contain anything other than the version and revision strings.
The current installation procedure relied on the former method which is
only adapted in the new versions so make it compatible to the older
versions by importing `sys` from `distutils.core`.
Jason Ish [Thu, 13 Dec 2018 14:45:14 +0000 (08:45 -0600)]
version: hide git revision if unknown
This happens when suricata-update is installed bundled with
Suricata. This is more a relic from the earlier days
of Suricata-Update when more users were likely to install
it directly from git anyways.
Shivani Bhardwaj [Fri, 23 Nov 2018 14:55:29 +0000 (20:25 +0530)]
Install requirements if using pip
Current setup was using distutils which does not allow to define the
requirements of a package. Check if the installation of
`suricata-update` is being done with `pip` and if it is, install the
requirements while installing the package.
This way distutils will not throw a warning of the `install_requires`
option being unrecognized, however, it would still not install the
requirements.
Now, with the installation of `suricata-update` package, all the
requirements are installed as well if it is installed with `pip`.
Shivani Bhardwaj [Wed, 31 Oct 2018 15:38:02 +0000 (21:08 +0530)]
Add --free argument to list-sources command
Add the functionality of being able to list only the free sources with
the `list-sources` command. This patch differentiates a free source from
a non-free source based on the availability of "subscription-url" for a
particular source.
This argument is also available in the help section of `list-sources`
command.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Be more verbose
-q, --quiet Be quiet, warning and error messages only
-D <directory>, --data-dir <directory>
Data directory (default: /var/lib/suricata)
-c <filename>, --config <filename>
configuration file (default:
/etc/suricata/update.yaml)
--suricata-conf <filename>
configuration file (default:
/etc/suricata/suricata.yaml)
--suricata <path> Path to Suricata program
--suricata-version <version>
Override Suricata version
--user-agent <user-agent>
Set custom user-agent string
--no-check-certificate
Disable server SSL/TLS certificate verification
-V, --version Display version
--free List all freely available sources
```
`suricata-update` sends a User Agent as a part of the request header to
get some basic information about the user system like the suricata-update
version, python version, etc. However, some users do not like this
behavior and are facililated with a `--user-agent` option whereby they
can modify the `User-Agent` header to a custom string. Although, in some
cases, it has been observed that the `User-Agent` header can be set to
nothing. In some other cases, users wish to set it to an empty string.
Jason Ish [Tue, 30 Oct 2018 19:35:16 +0000 (13:35 -0600)]
Show error on failure to create output directory.
Previously:
Output directory does not exist and could not be created:
/var/lib/suricata/rules
Now:
Failed to create directory /var/lib/suricata/rules:
[Errno 13] Permission denied: '/var/lib/suricata
Use assertEqual instead of deprecated assertEquals
Replace the use of assertEquals in all places with assertEqual as the
former was deprecated in https://bugs.python.org/issue9424
assertEquals goes well with Python 2.7 alongwith Python 3.x so this does
not break any existing test cases.
Current tox configuration was missing Python 3.7 because of which tests were
never run for a Python 3.7 environment. Fix that by adding py37 to the configurations.
Jason Ish [Mon, 23 Jul 2018 21:31:52 +0000 (15:31 -0600)]
add-source: fix prompt for required fields
The command had the code to prompt the user for the required
fields but the argument parser was forcing them to be set
on the command line. Make the name and url optional for
the argument parser, and prompt if not provided.
Jason Ish [Wed, 25 Apr 2018 20:48:16 +0000 (14:48 -0600)]
attempt to load defaults from a defaults module
The defaults module is installed by suricata into the
and contains compile time values such as sysconfdir,
and the directory where distribution provided rules
are found.
Jason Ish [Sun, 25 Mar 2018 14:34:30 +0000 (08:34 -0600)]
fail safe if ssl.create_default_context doesn't exist
fall back to the default SSL handler when create_default_context
doesn't exist as on Python versions prior to 2.7.9 where it hasn't
been backported (Ubuntu Trusty).
The downside is no certificate verification is done.
Jason Ish [Mon, 26 Feb 2018 17:33:27 +0000 (11:33 -0600)]
validate rule vars, disabling rules on error
If the Suricata config is available, suricata-update will check
that all rule vars are defined. If a rule uses a var that is
not defined a warning message will be logged, and the rule
will be disabled.
Jason Ish [Thu, 14 Dec 2017 21:42:23 +0000 (15:42 -0600)]
on download failure, return cached version (if exists)
Previously if a download failed, an error would be logged and
the rules that were downloaded were processed. This could lead
to an output that was no expected (missing rules).
Now if the download fails, check if we have the previous download.
If we do, log a warning and return the cached files.
If we don't have the previous download, log an error and process
what rules we do have.