hash key ordering should not be relied upon, as this may pose
a security issue. Depending on the hash size and machine, the
perl interpreter might optimize the hash variable by changing the
key order. In more recent perls (5.18+), the hash keys order is
randomized at every run to make programs more secure. This means
the order of exploits shown was not guaranteed to be the same
for every user, or even for the same user on different runs of
the script. This patch sorts the keys, forcing them to always
be displayed on the same order.
now if the user provides a partial kernel such as "2.6" or
"2.", the script will understand it's a partial kernel and
show all matches, including the full vulnerable kernel version
next to the kernel name!
some exploits work with several different kernel versions. This
patch optimizes the code to move on to the next vuln after it
finds out that the current exploit works with the provided kernel.
This should provide a nice performance increase :)
This is a minor maintainability update for the code. It provides
the get_kernel() and get_exploits() functions, and moves main()
to the top of the script. As such, developers are able to see
the complete logic of the code just by opening the file and
looking at the very first lines. The 'exit' at the end of the
code also guarantees that no extra data is processed, and the
rest are just auxiliary functions, created to provide extra
readability and maintainability.
As a good practice, post conditionals are used when there is
just a simple condition and a single result.
Also, Perl 5 recommends you call functions as 'name()' and not
as '&name', which is legacy from the very very *very*
old Perl 4 syntax (pre-1995), preserved simply for backwards
compatibility purposes.
double quotes require the parser to look if there are variables to
interpolate. Using single quotes when there are none is a good
practice both for the visual hint to the developer and as a
parsing hint to the perl interpreter.
Also, sequential 'print' statements might require extra IO and
clutter the code. It is recommended to either concatenate the
strings (as this patch does) or, if the text is too big, using
heredocs.
This patch makes the code much easier to read by applying perltidy
on the source. In particular, it makes the big exploit hash not
only easier to figure out but also to extend and even debug.
No code changes were made on this patch, just identation.
when 'alt', 'cve' or 'mil' data is not available, the variables
contain the undefined value. As such, calling length() on them
trigger a warning. This patch changes the validation to simply
check if the variables are defined.
'strict' forces the developer to declare variables before use,
thus spotting some pretty hard to debug issues. 'warnings' trigger
warning (non-fatal) messages whenever perl things the code is
doing something that the developer did not intend, making the code
more maintainable.
The perl parser stops parsing after it finds an __END__ tag.
Moving the "pod" to the end should make things slightly faster
on slower machines. It also provides for better organization,
since you now get "code first, docs later" in your file.