mirror of
https://github.com/konstruktoid/hardening.git
synced 2026-04-26 01:05:56 +03:00
[GH-ISSUE #59] Noticed Some Weirdness #25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ghost on GitHub (Jan 23, 2020).
Original GitHub issue: https://github.com/konstruktoid/hardening/issues/59
Hi,
I'm looking through some of your code now, and have some things like I'd like to address:
File:
ubuntu.shThere are a lot of, and I'd wager the same in other scripts, redundant processes. So many process make this very inefficient and only serve to raise the dependency count. You're using Bash, so I recommend using Bash. ;) For example,
printfis more than capable of telling and storing the time and date, makingdateredundant in most cases.You have a lot of error messages, but none of them seem to redirect to STDERR; is that by design? Also, since you're repeating the same code over and over, that's a good opportunity to make use of a function. For example:
You seem to be needlessly storing command locations (determined by
$PATHanyway, hencecommand) only to go ahead and use the variables. It's a lot of work and code for no gain, at least that I can see. Am I missing something here? If it's a security issue, you're already using$PATH, as mentioned, so I don't see the gain there.You have 53 functions running in this file, as sourced by 53 other files. All that extra processing and hassle -- I feel like there's a better way, which will reduce the hassle. Perhaps a function library within the one file, then the main code in the other? That seems to be a fairly common approach.
I get the impression that you're a long-time shell programmer who's got much more experience with Bourne shell programming. The reason, is because I see a lot of Bourne-isms, I guess you could say. Bash has made a lot of that stuff entirely unnecessary. For example, there's
$USER, instead of using yet another process forid -un. There's$UIDinstead of yet another process forid -u, and one more example, there's$HOSTNAMEmakinghostnameredundant in probably most cases. I suggest you read up on the Bash manual; it'll change your world.Lines 88-93, you have a for loop iterating over files to be sourced, but you're only checking 'they' exist, not what they actually are; they could be directories, links, block specials, FIFOs, etc. I recommend using
-finstead. It's usually good to be more specific than just-e.This isn't too big a deal, at least how I've seen you use
echo, but I would strongly recommend you ditchecho, saving it only for quick terminal stuff, asprintfis more feature-rich (especially in Bash) and far more reliable and consistent.While there are at least two naming conventions to things like variables and functions, there is one which is typically shunned, and that's the all-caps way. I actually did the same thing for a very long time, until I finally stopped being so stubborn. :P I'm glad I did, because ThisMethod is a lot easier to read.
Hope this helps. Let me know if you'd be interested in some pull requests.
BTW, this is some seriously awesome stuff! Must have taken a lot of research.
@konstruktoid commented on GitHub (Jan 24, 2020):
Hi @terminalforlife, and thanks for your comments!
dateis used inhttps://github.com/konstruktoid/hardening/blob/master/scripts/18_sshdconfig#L9 as a simple way to create a backup since the SSH configuration file is the one file most people are nervous about messing with.
At https://github.com/konstruktoid/hardening/blob/master/scripts/18_sshdconfig#L107-L109 it's used to create a dump file, could use
mktempthere of course.https://github.com/konstruktoid/hardening/blob/master/ubuntu.sh#L41 is about filling the
CHANGEME=variable, could be just any random string instead of date.Nothing bad about
printfbut it's overly complicated is many situations.Do you mean a lot of error messages because of incorrect code or as a result of e.g. missing packages on the host?
Which code is that?
Are you referring to https://github.com/konstruktoid/hardening/blob/master/ubuntu.cfg#L14-L42? Those a the configuration files, as variables as they may change.
I can't find an occasion where I use
command -vwith a full path.Splitting up the functions is just an easier way for me to find the code that messes with a specific thing, and also reducing the number of lines of code in one file.
And the functions are include at https://github.com/konstruktoid/hardening/blob/master/ubuntu.sh#L88-L93. See below.
Are you referring to https://github.com/konstruktoid/hardening/blob/master/ubuntu.sh#L40? That will catch the using logged in, not the user (since
sudois used) running the script.$HOSTNAMEonly returns the hostname, not FQDN but sure, it could be used at https://github.com/konstruktoid/hardening/blob/master/ubuntu.sh#L152.Absolutly.
Feel free to submit a PR with
printfimproved code.https://google.github.io/styleguide/shell.xml#Naming_Conventions, so the variables names is in need of a touching up.
Thanks for the comments and I'm always interested in pull requests.
Thanks!