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
ac339a95
Commit
ac339a95
authored
8 years ago
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring 'show' command.
parent
a2e5282a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
24 deletions
+33
-24
interpreter.py
routersploit/interpreter.py
+18
-11
test_interpreter.py
routersploit/test/test_interpreter.py
+15
-13
No files found.
routersploit/interpreter.py
View file @
ac339a95
...
@@ -352,17 +352,14 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -352,17 +352,14 @@ class RoutersploitInterpreter(BaseInterpreter):
else
:
else
:
yield
opt_key
,
opt_value
,
opt_description
yield
opt_key
,
opt_value
,
opt_description
@utils.module_required
def
_show_info
(
self
,
*
args
,
**
kwargs
):
def
command_show
(
self
,
*
args
,
**
kwargs
):
info
,
options
,
devices
=
'info'
,
'options'
,
'devices'
sub_command
=
args
[
0
]
if
sub_command
==
info
:
utils
.
pprint_dict_in_order
(
utils
.
pprint_dict_in_order
(
self
.
module_metadata
,
self
.
module_metadata
,
(
"name"
,
"description"
,
"devices"
,
"authors"
,
"references"
),
(
"name"
,
"description"
,
"devices"
,
"authors"
,
"references"
),
)
)
utils
.
print_info
()
utils
.
print_info
()
elif
sub_command
==
options
:
def
_show_options
(
self
,
*
args
,
**
kwargs
):
target_opts
=
{
'port'
,
'target'
}
target_opts
=
{
'port'
,
'target'
}
module_opts
=
set
(
self
.
current_module
.
options
)
-
target_opts
module_opts
=
set
(
self
.
current_module
.
options
)
-
target_opts
headers
=
(
"Name"
,
"Current settings"
,
"Description"
)
headers
=
(
"Name"
,
"Current settings"
,
"Description"
)
...
@@ -375,8 +372,9 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -375,8 +372,9 @@ class RoutersploitInterpreter(BaseInterpreter):
utils
.
print_table
(
headers
,
*
self
.
get_opts
(
*
module_opts
))
utils
.
print_table
(
headers
,
*
self
.
get_opts
(
*
module_opts
))
utils
.
print_info
()
utils
.
print_info
()
elif
sub_command
==
devices
:
if
devices
in
self
.
current_module
.
_Exploit__info__
.
keys
():
def
_show_devices
(
self
,
*
args
,
**
kwargs
):
# TODO: cover with tests
try
:
devices
=
self
.
current_module
.
_Exploit__info__
[
'devices'
]
devices
=
self
.
current_module
.
_Exploit__info__
[
'devices'
]
print
(
"
\n
Target devices:"
)
print
(
"
\n
Target devices:"
)
...
@@ -388,10 +386,19 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -388,10 +386,19 @@ class RoutersploitInterpreter(BaseInterpreter):
print
(
" {} - {}"
.
format
(
i
,
device
))
print
(
" {} - {}"
.
format
(
i
,
device
))
i
+=
1
i
+=
1
print
()
print
()
else
:
except
KeyError
:
print
(
"
\n
Target devices are not defined"
)
print
(
"
\n
Target devices are not defined"
)
else
:
print
(
"Unknown command 'show {}'. You want to 'show {}' or 'show {}'?"
.
format
(
sub_command
,
info
,
options
))
@utils.module_required
def
command_show
(
self
,
*
args
,
**
kwargs
):
sub_commands
=
(
'info'
,
'options'
,
'devices'
)
sub_command
=
args
[
0
]
try
:
getattr
(
self
,
"_show_{}"
.
format
(
sub_command
))(
*
args
,
**
kwargs
)
except
AttributeError
:
utils
.
print_error
(
"Unknown 'show' sub-command '{}'. "
"What do you want to show?
\n
"
"Possible choices are: {}"
.
format
(
sub_command
,
sub_commands
))
@utils.stop_after
(
2
)
@utils.stop_after
(
2
)
def
complete_show
(
self
,
text
,
*
args
,
**
kwargs
):
def
complete_show
(
self
,
text
,
*
args
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
routersploit/test/test_interpreter.py
View file @
ac339a95
...
@@ -356,7 +356,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -356,7 +356,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self
.
assertEqual
(
self
.
interpreter
.
current_module
,
None
)
self
.
assertEqual
(
self
.
interpreter
.
current_module
,
None
)
@mock.patch
(
'__builtin__.print'
)
@mock.patch
(
'__builtin__.print'
)
def
test_
command_
show_info
(
self
,
mock_print
):
def
test_show_info
(
self
,
mock_print
):
metadata
=
{
metadata
=
{
'devices'
:
'target_desc'
,
'devices'
:
'target_desc'
,
'authors'
:
'authors_desc'
,
'authors'
:
'authors_desc'
,
...
@@ -368,7 +368,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -368,7 +368,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self
.
interpreter
.
current_module
.
__doc__
=
description
self
.
interpreter
.
current_module
.
__doc__
=
description
self
.
interpreter
.
current_module
.
_MagicMock__info__
=
metadata
self
.
interpreter
.
current_module
.
_MagicMock__info__
=
metadata
self
.
interpreter
.
command_show
(
'info'
)
self
.
interpreter
.
_show_info
(
)
self
.
assertEqual
(
self
.
assertEqual
(
mock_print
.
mock_calls
,
mock_print
.
mock_calls
,
[
[
...
@@ -392,7 +392,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -392,7 +392,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self
.
interpreter
.
current_module
.
__doc__
=
description
self
.
interpreter
.
current_module
.
__doc__
=
description
self
.
interpreter
.
current_module
.
_MagicMock__info__
=
metadata
self
.
interpreter
.
current_module
.
_MagicMock__info__
=
metadata
self
.
interpreter
.
command_show
(
'info'
)
self
.
interpreter
.
_show_info
(
)
self
.
assertEqual
(
self
.
assertEqual
(
mock_print
.
mock_calls
,
mock_print
.
mock_calls
,
[
[
...
@@ -400,7 +400,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -400,7 +400,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
)
)
@mock.patch
(
'__builtin__.print'
)
@mock.patch
(
'__builtin__.print'
)
def
test_
command_
show_options
(
self
,
mock_print
):
def
test_show_options
(
self
,
mock_print
):
exploit_attributes
=
{
exploit_attributes
=
{
'target'
:
'target_desc'
,
'target'
:
'target_desc'
,
'port'
:
'port_desc'
,
'port'
:
'port_desc'
,
...
@@ -417,7 +417,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -417,7 +417,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self
.
interpreter
.
current_module
.
target
=
'127.0.0.1'
self
.
interpreter
.
current_module
.
target
=
'127.0.0.1'
self
.
interpreter
.
current_module
.
port
=
22
self
.
interpreter
.
current_module
.
port
=
22
self
.
interpreter
.
command_show
(
'options'
)
self
.
interpreter
.
_show_options
(
)
self
.
assertEqual
(
self
.
assertEqual
(
mock_print
.
mock_calls
,
mock_print
.
mock_calls
,
[
[
...
@@ -452,7 +452,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -452,7 +452,7 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
self
.
interpreter
.
current_module
.
target
=
'127.0.0.1'
self
.
interpreter
.
current_module
.
target
=
'127.0.0.1'
self
.
interpreter
.
current_module
.
port
=
22
self
.
interpreter
.
current_module
.
port
=
22
self
.
interpreter
.
command_show
(
'options'
)
self
.
interpreter
.
_show_options
(
)
self
.
assertEqual
(
self
.
assertEqual
(
mock_print
.
mock_calls
,
mock_print
.
mock_calls
,
[
[
...
@@ -467,15 +467,17 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
...
@@ -467,15 +467,17 @@ class RoutersploitInterpreterTest(RoutersploitTestCase):
]
]
)
)
@mock.patch
(
'__builtin__.print'
)
def
test_command_show
(
self
):
def
test_command_show_unknown_sub_command
(
self
,
mock_print
):
with
mock
.
patch
.
object
(
self
.
interpreter
,
"_show_options"
)
as
mock_show_options
:
help_text
=
"Unknown command 'show unknown_sub_command'. You want to 'show info' or 'show options'?"
self
.
interpreter
.
command_show
(
"options"
)
mock_show_options
.
assert_called_once_with
(
"options"
)
@mock.patch
(
'routersploit.utils.print_error'
)
def
test_command_show_unknown_sub_command
(
self
,
mock_print_error
):
self
.
interpreter
.
command_show
(
'unknown_sub_command'
)
self
.
interpreter
.
command_show
(
'unknown_sub_command'
)
self
.
assertEqual
(
mock_print_error
.
assert_called_once_with
(
"Unknown 'show' sub-command 'unknown_sub_command'. "
mock_print
.
mock_calls
,
"What do you want to show?
\n
"
[
mock
.
call
(
help_text
)]
"Possible choices are: ('info', 'options', 'devices')"
)
)
def
test_if_command_run_has_module_required_decorator
(
self
):
def
test_if_command_run_has_module_required_decorator
(
self
):
self
.
assertIsDecorated
(
self
.
assertIsDecorated
(
...
...
This diff is collapsed.
Click to expand it.
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