Added a `--no-checksum` option to the add-source command and an optional
"checksum" in SourceConfiguration class for add-sources and
enabled-sources.
Also, a check is added to skip downloading the checksum URL if the
source is configured with checksum false.
Vagisha Gupta [Mon, 10 Jun 2019 19:33:09 +0000 (01:03 +0530)]
Redo variable and function names reserved for Python
Changed the conflicting variable name `filter` and function name
`filter()` accordingly which suricata-update uses as it is reserved
for use in Python standard modules.
Vagisha Gupta [Mon, 5 Aug 2019 09:05:55 +0000 (14:35 +0530)]
Separate log messages to stderr and stdout
Currently, all the messages in suricata-update are logged to stderr.
Changes are made to split between log messages where regular
output (INFO, DEBUG) goes to stdout whereas ERRORS, WARNINGS and
CRITICAL messages goes to stderr.
Vagisha Gupta [Tue, 28 May 2019 07:20:29 +0000 (12:50 +0530)]
Improve permission warning
Improve permission warning when Suricata-update runs with the wrong user
When suricata-update runs with a non-root user, it gives an ugly traceback.
To avoid those ugly tracebacks, try except block is put around the operation
that are being performed on the file i.e. shutil.copyfile(src, dest) and
exit cleanly with an error in the log.
Also, to avoid ugly tracebacks for permission of suricata.yaml, try-except
is put around where it is accessed and exit cleanly.
Vrinda Narayan [Thu, 28 Mar 2019 12:02:48 +0000 (17:32 +0530)]
Fix TypeError : Failure with missing rule params
Bug #2867 : Failure with missing rule params
If sometimes a rule is not parsed correctly and sid or gid are of
NoneType the program shows a TypeError. While parsing the rule, the sid
can be checked to make sure that sid is not of type None, and if it is,
raise a BadSidError and log it, the rule is not added to the list of
final rules.
Vrinda Narayan [Wed, 13 Mar 2019 09:53:43 +0000 (15:23 +0530)]
Catch Keyboard Interrupt and exit cleanly.
Optimization #2878 https://redmine.openinfosecfoundation.org/issues/2878
Can be done by importing python library signal, and defining a function
signal_handler which will print a message if keyboard interrupt is
detected and exit the program.
Vagisha Gupta [Mon, 3 Jun 2019 08:53:24 +0000 (14:23 +0530)]
Log a warning on duplicate SID
Currently when suricata-update encounters a rule with duplicate SIDs,
it silently uses the one with the higher revision without logging the
warnings.
On duplicate SID, warnings are logged for equal as well as different
revisions.
Thus, changing the parser to load these files in alphabetical order by sorting the filenames before starting to work on them fixes the issue. Now the output generated on running
```
suricata-update -v
```
is
```
24/3/2019 -- 10:34:24 - <Debug> -- Parsing rules/botcc.rules.
24/3/2019 -- 10:34:24 - <Debug> -- Parsing rules/ciarmy.rules.
24/3/2019 -- 10:34:24 - <Debug> -- Parsing rules/compromised.rules.
24/3/2019 -- 10:34:24 - <Debug> -- Parsing rules/drop.rules.
24/3/2019 -- 10:34:24 - <Debug> -- Parsing rules/dshield.rules.
24/3/2019 -- 10:34:24 - <Debug> -- Parsing rules/emerging-activex.rules.
```
Rules files are now parsed in sorted order.
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.