Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change open call to three-parameter form #11

Open
jawaad-ahmad opened this issue Aug 2, 2020 · 0 comments
Open

Change open call to three-parameter form #11

jawaad-ahmad opened this issue Aug 2, 2020 · 0 comments

Comments

@jawaad-ahmad
Copy link

Reference: https://perlmaven.com/open-files-in-the-old-way

Current code calls open on known_hosts as:

open(HOSTFILE, "$knownhostFile") || die "Cannot open $knownhostFile";

Recommend changing to the following to make explicit that we're opening the file as read-only and also to prevent any intentional or unintentional malicious use:

open(HOSTFILE, "<", "$knownhostFile") || die "Cannot open $knownhostFile";

As an alternative, consider removing the file name option and the open logic, and instead take the input from standard input:

$ ./known_hosts_bruteforcer.pl < ~/.ssh/known_hosts

This simplifies the logic of the script and also allows users the flexibility to pass in whatever they want into the script without having to make any temporary files beforehand e.g.

$ tail -3 ~/.ssh/known_hosts | ./known_hosts_bruteforcer.pl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant