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
4126a8d8
Commit
4126a8d8
authored
Apr 14, 2016
by
fwkz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding debug command.
parent
eb2b21ab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
13 deletions
+60
-13
interpreter.py
routersploit/interpreter.py
+12
-4
test_completer.py
routersploit/test/test_completer.py
+2
-2
test_interpreter.py
routersploit/test/test_interpreter.py
+46
-7
No files found.
routersploit/interpreter.py
View file @
4126a8d8
...
@@ -160,6 +160,7 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -160,6 +160,7 @@ class RoutersploitInterpreter(BaseInterpreter):
self
.
prompt_hostname
=
'rsf'
self
.
prompt_hostname
=
'rsf'
self
.
modules_directory
=
rsf_modules
.
__path__
[
0
]
self
.
modules_directory
=
rsf_modules
.
__path__
[
0
]
self
.
modules
=
[]
self
.
modules
=
[]
self
.
modules_with_errors
=
{}
self
.
main_modules_dirs
=
[]
self
.
main_modules_dirs
=
[]
self
.
__parse_prompt
()
self
.
__parse_prompt
()
...
@@ -184,6 +185,7 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -184,6 +185,7 @@ class RoutersploitInterpreter(BaseInterpreter):
def
load_modules
(
self
):
def
load_modules
(
self
):
self
.
main_modules_dirs
=
[
module
for
module
in
os
.
listdir
(
self
.
modules_directory
)
if
not
module
.
startswith
(
"__"
)]
self
.
main_modules_dirs
=
[
module
for
module
in
os
.
listdir
(
self
.
modules_directory
)
if
not
module
.
startswith
(
"__"
)]
self
.
modules
=
[]
self
.
modules
=
[]
self
.
modules_with_errors
=
{}
for
root
,
dirs
,
files
in
os
.
walk
(
self
.
modules_directory
):
for
root
,
dirs
,
files
in
os
.
walk
(
self
.
modules_directory
):
_
,
package
,
root
=
root
.
rpartition
(
'routersploit'
)
_
,
package
,
root
=
root
.
rpartition
(
'routersploit'
)
...
@@ -192,8 +194,8 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -192,8 +194,8 @@ class RoutersploitInterpreter(BaseInterpreter):
for
module_path
in
modules
:
for
module_path
in
modules
:
try
:
try
:
module
=
importlib
.
import_module
(
module_path
)
module
=
importlib
.
import_module
(
module_path
)
except
ImportError
:
except
ImportError
as
error
:
pass
self
.
modules_with_errors
[
module_path
]
=
error
else
:
else
:
klasses
=
inspect
.
getmembers
(
module
,
inspect
.
isclass
)
klasses
=
inspect
.
getmembers
(
module
,
inspect
.
isclass
)
exploits
=
filter
(
lambda
x
:
issubclass
(
x
[
1
],
Exploit
),
klasses
)
exploits
=
filter
(
lambda
x
:
issubclass
(
x
[
1
],
Exploit
),
klasses
)
...
@@ -257,9 +259,9 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -257,9 +259,9 @@ class RoutersploitInterpreter(BaseInterpreter):
:return: list of most accurate command suggestions
:return: list of most accurate command suggestions
"""
"""
if
self
.
current_module
:
if
self
.
current_module
:
return
[
'run'
,
'back'
,
'set '
,
'show '
,
'check'
]
return
[
'run'
,
'back'
,
'set '
,
'show '
,
'check'
,
'debug'
]
else
:
else
:
return
[
'use '
]
return
[
'use '
,
'debug'
]
def
command_back
(
self
,
*
args
,
**
kwargs
):
def
command_back
(
self
,
*
args
,
**
kwargs
):
self
.
current_module
=
None
self
.
current_module
=
None
...
@@ -374,3 +376,9 @@ class RoutersploitInterpreter(BaseInterpreter):
...
@@ -374,3 +376,9 @@ class RoutersploitInterpreter(BaseInterpreter):
utils
.
print_error
(
"Target is not vulnerable"
)
utils
.
print_error
(
"Target is not vulnerable"
)
else
:
else
:
utils
.
print_status
(
"Target could not be verified"
)
utils
.
print_status
(
"Target could not be verified"
)
def
command_debug
(
self
,
*
args
,
**
kwargs
):
for
key
,
value
in
self
.
modules_with_errors
.
iteritems
():
utils
.
print_info
(
key
)
utils
.
print_error
(
value
,
'
\n
'
)
routersploit/test/test_completer.py
View file @
4126a8d8
...
@@ -30,7 +30,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
...
@@ -30,7 +30,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
def
test_raw_commands_no_module
(
self
):
def
test_raw_commands_no_module
(
self
):
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
self
.
raw_prompt
,
'use '
)
self
.
assertPrompt
(
'debug use
\r\n
'
,
self
.
raw_prompt
)
def
test_complete_use_raw
(
self
):
def
test_complete_use_raw
(
self
):
self
.
rsf
.
send
(
"u
\t\t
"
)
self
.
rsf
.
send
(
"u
\t\t
"
)
...
@@ -87,7 +87,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
...
@@ -87,7 +87,7 @@ class RoutersploitCompleterTest(unittest.TestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'back check run set show
\r\n
'
,
'back check
debug
run set show
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
self
.
module_prompt
(
'FTP Bruteforce'
)
)
)
...
...
routersploit/test/test_interpreter.py
View file @
4126a8d8
...
@@ -197,14 +197,14 @@ class RoutersploitInterpreterTest(unittest.TestCase):
...
@@ -197,14 +197,14 @@ class RoutersploitInterpreterTest(unittest.TestCase):
def
test_suggested_commands_with_loaded_module
(
self
):
def
test_suggested_commands_with_loaded_module
(
self
):
self
.
assertEqual
(
self
.
assertEqual
(
self
.
interpreter
.
suggested_commands
(),
self
.
interpreter
.
suggested_commands
(),
[
'run'
,
'back'
,
'set '
,
'show '
,
'check'
]
# Extra space at the end because of following param
[
'run'
,
'back'
,
'set '
,
'show '
,
'check'
,
'debug'
]
# Extra space at the end because of following param
)
)
def
test_suggested_commands_without_loaded_module
(
self
):
def
test_suggested_commands_without_loaded_module
(
self
):
self
.
interpreter
.
current_module
=
None
self
.
interpreter
.
current_module
=
None
self
.
assertEqual
(
self
.
assertEqual
(
self
.
interpreter
.
suggested_commands
(),
# Extra space at the end because of following param
self
.
interpreter
.
suggested_commands
(),
# Extra space at the end because of following param
[
'use '
]
[
'use '
,
'debug'
]
)
)
@mock.patch
(
'importlib.import_module'
)
@mock.patch
(
'importlib.import_module'
)
...
@@ -247,7 +247,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
...
@@ -247,7 +247,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
@mock.patch
(
'importlib.import_module'
)
@mock.patch
(
'importlib.import_module'
)
@mock.patch
(
'routersploit.utils.print_error'
)
@mock.patch
(
'routersploit.utils.print_error'
)
def
test_command_unknown_module
(
self
,
mocked_print_error
,
mocked_import_module
):
def
test_command_u
se_u
nknown_module
(
self
,
mocked_print_error
,
mocked_import_module
):
""" Testing command_use()
""" Testing command_use()
* Unknown module
* Unknown module
...
@@ -267,7 +267,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
...
@@ -267,7 +267,7 @@ class RoutersploitInterpreterTest(unittest.TestCase):
@mock.patch
(
'importlib.import_module'
)
@mock.patch
(
'importlib.import_module'
)
@mock.patch
(
'routersploit.utils.print_error'
)
@mock.patch
(
'routersploit.utils.print_error'
)
def
test_command_unknown_extension
(
self
,
mocked_print_error
,
mocked_import_module
):
def
test_command_u
se_u
nknown_extension
(
self
,
mocked_print_error
,
mocked_import_module
):
""" Testing command_use()
""" Testing command_use()
* Unknown Exploit
* Unknown Exploit
...
@@ -489,9 +489,10 @@ class RoutersploitInterpreterTest(unittest.TestCase):
...
@@ -489,9 +489,10 @@ class RoutersploitInterpreterTest(unittest.TestCase):
mock_walk
.
return_value
=
(
mock_walk
.
return_value
=
(
(
'/Abs/Path/routersploit/routersploit/modules'
,
[
'asmax'
,
'creds'
],
[
'__init__.py'
,
'__init__.pyc'
]),
(
'/Abs/Path/routersploit/routersploit/modules'
,
[
'asmax'
,
'creds'
],
[
'__init__.py'
,
'__init__.pyc'
]),
(
'/Abs/Path/routersploit/routersploit/modules/creds'
,
[],
[
'__init__.py'
,
'__init__.pyc'
,
'ftp_bruteforce.py'
,
'ftp_bruteforce.pyc'
]),
(
'/Abs/Path/routersploit/routersploit/modules/creds'
,
[],
[
'__init__.py'
,
'__init__.pyc'
,
'ftp_bruteforce.py'
,
'ftp_bruteforce.pyc'
]),
(
'/Abs/Path/routersploit/routersploit/modules/exploits/asmax'
,
[],
[
'__init__.py'
,
'__init__.pyc'
,
'asmax_exploit.py'
,
'asmax_exploit.pyc'
]),
(
'/Abs/Path/routersploit/routersploit/modules/exploits/asmax'
,
[],
[
'__init__.py'
,
'__init__.pyc'
,
'asmax_exploit.py'
,
'asmax_exploit.pyc'
,
'asmax_multi.py'
,
'asmax_multi.pyc'
]),
)
)
mock_import_module
.
side_effect
=
[
1
,
2
,
ImportError
,
4
,
5
]
import_error
=
ImportError
(
"No module doopaa"
)
mock_import_module
.
side_effect
=
[
1
,
2
,
import_error
,
4
,
5
,
import_error
]
mock_getmembers
.
side_effect
=
[
mock_getmembers
.
side_effect
=
[
[],
[],
[],
[],
...
@@ -509,7 +510,8 @@ class RoutersploitInterpreterTest(unittest.TestCase):
...
@@ -509,7 +510,8 @@ class RoutersploitInterpreterTest(unittest.TestCase):
mock
.
call
(
'routersploit.modules.creds.__init__'
),
mock
.
call
(
'routersploit.modules.creds.__init__'
),
mock
.
call
(
'routersploit.modules.creds.ftp_bruteforce'
),
mock
.
call
(
'routersploit.modules.creds.ftp_bruteforce'
),
mock
.
call
(
'routersploit.modules.exploits.asmax.__init__'
),
mock
.
call
(
'routersploit.modules.exploits.asmax.__init__'
),
mock
.
call
(
'routersploit.modules.exploits.asmax.asmax_exploit'
)
mock
.
call
(
'routersploit.modules.exploits.asmax.asmax_exploit'
),
mock
.
call
(
'routersploit.modules.exploits.asmax.asmax_multi'
)
]
]
)
)
self
.
assertEqual
(
self
.
assertEqual
(
...
@@ -528,5 +530,42 @@ class RoutersploitInterpreterTest(unittest.TestCase):
...
@@ -528,5 +530,42 @@ class RoutersploitInterpreterTest(unittest.TestCase):
]
]
)
)
self
.
assertEqual
(
self
.
interpreter
.
modules_with_errors
,
{
"routersploit.modules.creds.ftp_bruteforce"
:
import_error
,
'routersploit.modules.exploits.asmax.asmax_multi'
:
import_error
,
}
)
@mock.patch
(
'routersploit.utils.print_info'
)
@mock.patch
(
'routersploit.utils.print_error'
)
def
test_command_debug
(
self
,
mocked_print_error
,
mocked_print_info
,
):
self
.
interpreter
.
modules_with_errors
=
{
"foo.bar.exploit"
:
"foo foo error"
,
"foo.baz.exploit"
:
"foo baz error"
,
"doo.paa.exploit"
:
"doo paa error"
,
}
self
.
interpreter
.
command_debug
()
self
.
assertItemsEqual
(
mocked_print_info
.
mock_calls
,
[
mock
.
call
(
"foo.baz.exploit"
),
mock
.
call
(
"foo.bar.exploit"
),
mock
.
call
(
"doo.paa.exploit"
),
]
)
self
.
assertItemsEqual
(
mocked_print_error
.
mock_calls
,
[
mock
.
call
(
"doo paa error"
,
'
\n
'
),
mock
.
call
(
"foo foo error"
,
'
\n
'
),
mock
.
call
(
"foo baz error"
,
'
\n
'
),
]
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
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