Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
routersploit
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
czos-dpend
routersploit
Commits
d77f961b
Commit
d77f961b
authored
May 03, 2016
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iter_modules function
parent
d933773d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
33 deletions
+19
-33
interpreter.py
routersploit/interpreter.py
+2
-32
utils.py
routersploit/utils.py
+17
-1
No files found.
routersploit/interpreter.py
View file @
d77f961b
...
@@ -3,11 +3,9 @@ import os
...
@@ -3,11 +3,9 @@ import os
import
sys
import
sys
import
traceback
import
traceback
import
atexit
import
atexit
import
importlib
from
routersploit.exceptions
import
RoutersploitException
from
routersploit.exceptions
import
RoutersploitException
from
routersploit
import
utils
from
routersploit
import
utils
from
routersploit
import
modules
as
rsf_modules
if
sys
.
platform
==
"darwin"
:
if
sys
.
platform
==
"darwin"
:
import
gnureadline
as
readline
import
gnureadline
as
readline
...
@@ -157,9 +155,8 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -157,9 +155,8 @@ class RoutersploitInterpreter(BaseInterpreter):
self
.
module_prompt_template
=
None
self
.
module_prompt_template
=
None
self
.
prompt_hostname
=
'rsf'
self
.
prompt_hostname
=
'rsf'
modules_directory
=
rsf_modules
.
__path__
[
0
]
self
.
modules
=
utils
.
index_modules
()
self
.
modules
=
utils
.
index_modules
(
modules_directory
)
self
.
main_modules_dirs
=
[
module
for
module
in
os
.
listdir
(
utils
.
MODULES_DIR
)
if
not
module
.
startswith
(
"__"
)]
self
.
main_modules_dirs
=
[
module
for
module
in
os
.
listdir
(
modules_directory
)
if
not
module
.
startswith
(
"__"
)]
self
.
__parse_prompt
()
self
.
__parse_prompt
()
...
@@ -179,33 +176,6 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -179,33 +176,6 @@ class RoutersploitInterpreter(BaseInterpreter):
Total module count: {modules_count}
Total module count: {modules_count}
"""
.
format
(
modules_count
=
len
(
self
.
modules
))
"""
.
format
(
modules_count
=
len
(
self
.
modules
))
# def load_modules(self):
# self.main_modules_dirs = [module for module in os.listdir(self.modules_directory) if not module.startswith("__")]
# self.modules = []
# self.modules_with_errors = {}
#
# for root, dirs, files in os.walk(self.modules_directory):
# _, package, root = root.rpartition('routersploit/modules/'.replace('/', os.sep))
# root = root.replace(os.sep, '.')
# files = filter(lambda x: not x.startswith("__") and x.endswith('.py'), files)
# self.modules.extend(map(lambda x: '.'.join((root, os.path.splitext(x)[0])), files))
#
# exploits = map(lambda x: '.'.join([module_path.split('.', 2).pop(), x[0]]), exploits)
#
# for module_path in self.modules:
# print(module_path)
# try:
# module = importlib.import_module(module_path)
# except ImportError as error:
# self.modules_with_errors[module_path] = error
# else:
# klasses = inspect.getmembers(module, inspect.isclass)
# exploits = filter(lambda x: issubclass(x[1], Exploit), klasses)
# # exploits = map(lambda x: '.'.join([module_path.split('.', 2).pop(), x[0]]), exploits)
# # self.modules.extend(exploits)
# if exploits:
# self.modules.append(module_path.split('.', 2).pop())
def
__parse_prompt
(
self
):
def
__parse_prompt
(
self
):
raw_prompt_default_template
=
"
\001\033
[4m
\002
{host}
\001\033
[0m
\002
> "
raw_prompt_default_template
=
"
\001\033
[4m
\002
{host}
\001\033
[0m
\002
> "
raw_prompt_template
=
os
.
getenv
(
"RSF_RAW_PROMPT"
,
raw_prompt_default_template
)
.
replace
(
'
\\
033'
,
'
\033
'
)
raw_prompt_template
=
os
.
getenv
(
"RSF_RAW_PROMPT"
,
raw_prompt_default_template
)
.
replace
(
'
\\
033'
,
'
\033
'
)
...
...
routersploit/utils.py
View file @
d77f961b
...
@@ -13,8 +13,11 @@ import importlib
...
@@ -13,8 +13,11 @@ import importlib
import
requests
import
requests
from
.exceptions
import
RoutersploitException
from
.exceptions
import
RoutersploitException
from
.
import
modules
as
rsf_modules
MODULES_DIR
=
rsf_modules
.
__path__
[
0
]
print_lock
=
threading
.
Lock
()
print_lock
=
threading
.
Lock
()
colors
=
{
colors
=
{
...
@@ -25,8 +28,9 @@ colors = {
...
@@ -25,8 +28,9 @@ colors = {
}
}
def
index_modules
(
modules_directory
):
def
index_modules
(
modules_directory
=
MODULES_DIR
):
""" Return list of all exploits modules """
""" Return list of all exploits modules """
modules
=
[]
modules
=
[]
for
root
,
dirs
,
files
in
os
.
walk
(
modules_directory
):
for
root
,
dirs
,
files
in
os
.
walk
(
modules_directory
):
_
,
package
,
root
=
root
.
rpartition
(
'routersploit/modules/'
.
replace
(
'/'
,
os
.
sep
))
_
,
package
,
root
=
root
.
rpartition
(
'routersploit/modules/'
.
replace
(
'/'
,
os
.
sep
))
...
@@ -55,6 +59,18 @@ def import_exploit(path):
...
@@ -55,6 +59,18 @@ def import_exploit(path):
)
)
def
iter_modules
(
modules_directory
=
MODULES_DIR
):
""" Iterate over valid modules """
modules
=
index_modules
(
modules_directory
)
modules
=
map
(
lambda
x
:
""
.
join
([
'routersploit.modules.'
,
x
]),
modules
)
for
path
in
modules
:
try
:
yield
import_exploit
(
path
)
except
RoutersploitException
:
pass
def
pythonize_path
(
path
):
def
pythonize_path
(
path
):
""" Replace argument to valid python dotted notation.
""" Replace argument to valid python dotted notation.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment