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

Avoid hardcoded relative paths #578

Merged
merged 10 commits into from Apr 11, 2019
Merged

Avoid hardcoded relative paths #578

merged 10 commits into from Apr 11, 2019

Conversation

iamleot
Copy link
Contributor

@iamleot iamleot commented Apr 6, 2019

Status

READY

Description

Describe what is changed by your Pull Request. If this PR is related to the open issue (bug/feature/new module) please attach issue number.

Verification

Provide steps to test or reproduce the PR.

  1. Install routersploit, e.g. via pkgsrc wip/routersploit
  2. Start ./rsf.py
  3. use scanners/autopwn
  4. set target 192.168.1.1
  5. run

...then watch threads ~suddendly terminating without invoking any module:

[...]
[*] Running module...
-
[*] Starting vulnerablity check...
[*] thread-0 thread is starting...
[*] thread-1 thread is starting...
[...]
[*] thread-0 thread is terminated.
[*] thread-1 thread is terminated.
[...]
-
[*] Elapsed time: 0.0001952648162841797 seconds
-
[*] Starting default credentials check...
[*] thread-0 thread is starting...
[*] thread-1 thread is starting...
[...]
[*] thread-0 thread is terminated.
[*] thread-1 thread is terminated.
[...]
-
[*] Elapsed time: 0.00017380714416503906 seconds
[...]

At least ktruss-ing it reveals that several open("routersploit/...")
fails due ENOENT. If the $PWD is ${PYSITELIB} (e.g.
/usr/pkg/lib/python3.7/site-packages/, where routersploit/...
installed hierarcy is present) and then directly invoking routersploit
in the python interpreter via:

>>> from routersploit.interpreter import RoutersploitInterpreter
>>> rsf = RoutersploitInterpreter()
>>> rsf.start()

routersploit works!

Proposed commits should avoid uses of hardcoded relative paths and
fixes this problem.

Checklist

  • Write module/feature

@iamleot
Copy link
Contributor Author

iamleot commented Apr 6, 2019

Copypasting relevant lines of the failed tests:

+make lint tests
python3 -m flake8 --exclude=.git,rsf.py --ignore=E501,F405,F403,W504 .
./routersploit/core/bluetooth/btle/btle_device.py:33:12: F632 use ==/!= to compare str, bytes, and int literals
./routersploit/core/exploit/shell.py:41:16: F632 use ==/!= to compare str, bytes, and int literals
./routersploit/core/exploit/utils.py:216:54: E252 missing whitespace around parameter equals
./routersploit/core/exploit/utils.py:216:55: E252 missing whitespace around parameter equals
./routersploit/modules/exploits/routers/ipfire/ipfire_oinkcode_rce.py:78:12: F632 use ==/!= to compare str, bytes, and int literals
make: *** [lint] Error 1
The command "./.travis/run.sh" exited with 2.

...I am blameful for ./routersploit/core/exploit/utils.py:216 whitespace policy ones! (I will fix them ASAP!)

- Introduce a RESOURCES_DIR similar to other *_DIR
- Add a resources_directory parameter to lookup_vendor() to avoid possible
  hardcoded directory and - if not provided - pick up the default
  RESOURCES_DIR.
(Otherwise ssh_keys are tried to picked up in in ${PWD} (and mostly
likely failing))
Commit id 9380c04 (probably
accidentally) removed EXPLOITS_DIR use leading to loading
routersploit/modules/exploits relative to the current directory
instead of the installed ones in MODULES_DIR.
@iamleot
Copy link
Contributor Author

iamleot commented Apr 7, 2019

...relevant part of failed tests:

+make lint tests
python3 -m flake8 --exclude=.git,rsf.py --ignore=E501,F405,F403,W504 .
./routersploit/core/bluetooth/btle/btle_device.py:33:12: F632 use ==/!= to compare str, bytes, and int literals
./routersploit/core/exploit/shell.py:41:16: F632 use ==/!= to compare str, bytes, and int literals
./routersploit/modules/exploits/routers/ipfire/ipfire_oinkcode_rce.py:78:12: F632 use ==/!= to compare str, bytes, and int literals

(None of them were touched by this pull request though.)

@lucyoa
Copy link
Contributor

lucyoa commented Apr 7, 2019

These errors have been fixed with #580, please just trigger build again

@iamleot
Copy link
Contributor Author

iamleot commented Apr 7, 2019 via email

@iamleot
Copy link
Contributor Author

iamleot commented Apr 8, 2019

I'm not happy about commit 4278012 and hopefully I'll refactor it ASAP (next few minutes!).

@iamleot
Copy link
Contributor Author

iamleot commented Apr 8, 2019

I think that also routersploit/core/exploit/payloads.py needs to be adjusted similarly (and, at least according a grep it should be the last affected hard-coded use).

@iamleot
Copy link
Contributor Author

iamleot commented Apr 8, 2019

Unfortunately I have not tested the routersploit/core/exploit/payloads.py (becouse I was not able to trigger it). I will keep an eye on the test results but a review for that is appreciated! Thanks!

@iamleot
Copy link
Contributor Author

iamleot commented Apr 9, 2019

All hardcoded relative paths should be addressed now (and tests seems to pass!).

routersploit/core/exploit/payloads.py Outdated Show resolved Hide resolved
routersploit/core/exploit/shell.py Outdated Show resolved Hide resolved
Spotted by @lucyoa, thanks!
payloads should be listed/selected as `<architecture>/<payload>', not
`payloads.<architecture>.<payload>'.

Thanks to @lucyoa!
@lucyoa
Copy link
Contributor

lucyoa commented Apr 11, 2019

Awesome, thanks!

@lucyoa lucyoa merged commit c7ad64f into threat9:master Apr 11, 2019
@iamleot
Copy link
Contributor Author

iamleot commented Apr 11, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants