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
88551596
Commit
88551596
authored
Feb 05, 2018
by
Mariusz Kupidura
Committed by
Marcin Bury
Feb 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove `gnureadline` package. (#336)
LGTM
parent
09af20b4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
61 deletions
+66
-61
interpreter.py
routersploit/interpreter.py
+22
-10
test_completer.py
tests/test_completer.py
+44
-51
No files found.
routersploit/interpreter.py
View file @
88551596
from
__future__
import
print_function
import
atexit
import
atexit
import
itertools
import
itertools
import
os
import
os
...
@@ -13,10 +11,11 @@ from routersploit.exploits import Exploit, GLOBAL_OPTS
...
@@ -13,10 +11,11 @@ from routersploit.exploits import Exploit, GLOBAL_OPTS
from
routersploit.payloads
import
BasePayload
from
routersploit.payloads
import
BasePayload
from
routersploit.printer
import
PrinterThread
,
printer_queue
from
routersploit.printer
import
PrinterThread
,
printer_queue
if
sys
.
platform
==
"darwin"
:
import
readline
import
gnureadline
as
readline
else
:
import
readline
def
is_libedit
():
return
"libedit"
in
readline
.
__doc__
class
BaseInterpreter
(
object
):
class
BaseInterpreter
(
object
):
...
@@ -37,7 +36,9 @@ class BaseInterpreter(object):
...
@@ -37,7 +36,9 @@ class BaseInterpreter(object):
:return:
:return:
"""
"""
if
not
os
.
path
.
exists
(
self
.
history_file
):
if
not
os
.
path
.
exists
(
self
.
history_file
):
open
(
self
.
history_file
,
'a+'
)
.
close
()
with
open
(
self
.
history_file
,
'a+'
)
as
history
:
if
is_libedit
():
history
.
write
(
"_HiStOrY_V2_
\n\n
"
)
readline
.
read_history_file
(
self
.
history_file
)
readline
.
read_history_file
(
self
.
history_file
)
readline
.
set_history_length
(
self
.
history_length
)
readline
.
set_history_length
(
self
.
history_length
)
...
@@ -47,6 +48,9 @@ class BaseInterpreter(object):
...
@@ -47,6 +48,9 @@ class BaseInterpreter(object):
readline
.
set_completer
(
self
.
complete
)
readline
.
set_completer
(
self
.
complete
)
readline
.
set_completer_delims
(
'
\t\n
;'
)
readline
.
set_completer_delims
(
'
\t\n
;'
)
if
is_libedit
():
readline
.
parse_and_bind
(
"bind ^I rl_complete"
)
else
:
readline
.
parse_and_bind
(
"tab: complete"
)
readline
.
parse_and_bind
(
"tab: complete"
)
def
parse_line
(
self
,
line
):
def
parse_line
(
self
,
line
):
...
@@ -124,7 +128,9 @@ class BaseInterpreter(object):
...
@@ -124,7 +128,9 @@ class BaseInterpreter(object):
else
:
else
:
complete_function
=
self
.
raw_command_completer
complete_function
=
self
.
raw_command_completer
self
.
completion_matches
=
complete_function
(
text
,
line
,
start_index
,
end_index
)
self
.
completion_matches
=
complete_function
(
text
,
line
,
start_index
,
end_index
)
try
:
try
:
return
self
.
completion_matches
[
state
]
return
self
.
completion_matches
[
state
]
...
@@ -137,11 +143,17 @@ class BaseInterpreter(object):
...
@@ -137,11 +143,17 @@ class BaseInterpreter(object):
:param ignored:
:param ignored:
:return: full list of interpreter commands
:return: full list of interpreter commands
"""
"""
return
[
command
.
rsplit
(
"_"
)
.
pop
()
for
command
in
dir
(
self
)
if
command
.
startswith
(
"command_"
)]
return
[
command
.
rsplit
(
"_"
)
.
pop
()
for
command
in
dir
(
self
)
if
command
.
startswith
(
"command_"
)
]
def
raw_command_completer
(
self
,
text
,
line
,
start_index
,
end_index
):
def
raw_command_completer
(
self
,
text
,
line
,
start_index
,
end_index
):
""" Complete command w/o any argument """
""" Complete command w/o any argument """
return
filter
(
lambda
entry
:
entry
.
startswith
(
text
),
self
.
suggested_commands
())
return
[
command
for
command
in
self
.
suggested_commands
()
if
command
.
startswith
(
text
)
]
def
default_completer
(
self
,
*
ignored
):
def
default_completer
(
self
,
*
ignored
):
return
[]
return
[]
...
...
tests/test_completer.py
View file @
88551596
...
@@ -12,21 +12,25 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -12,21 +12,25 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
cli_path
=
os
.
path
.
abspath
(
self
.
cli_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
os
.
pardir
,
os
.
pardir
,
'rsf.py'
)
os
.
path
.
join
(
__file__
,
os
.
pardir
,
os
.
pardir
,
'rsf.py'
)
)
)
self
.
raw_prompt
=
"
\033
[4mrsf
\033
[0m > "
self
.
raw_prompt
=
".+?rsf.+?
\
s>
\
s"
self
.
module_prompt
=
lambda
\
self
.
module_prompt
=
lambda
x
:
".+?rsf.+?
\
(.+?{}.+?
\
)
\
s>
\
s"
.
format
(
x
)
x
:
"
\033
[4mrsf
\033
[0m (
\033
[91m{}
\033
[0m) > "
.
format
(
x
)
def
setUp
(
self
):
def
setUp
(
self
):
self
.
rsf
=
pexpect
.
spawn
(
'python {}'
.
format
(
self
.
cli_path
))
self
.
rsf
=
pexpect
.
spawn
(
'python {}'
.
format
(
self
.
cli_path
))
self
.
rsf
.
send
(
'
\r\n
'
)
self
.
rsf
.
send
(
'
\r\n
'
)
self
.
rsf
.
expect
_exact
(
self
.
raw_prompt
,
timeout
=
3
)
self
.
rsf
.
expect
(
self
.
raw_prompt
,
timeout
=
3
)
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
rsf
.
terminate
(
force
=
True
)
self
.
rsf
.
terminate
(
force
=
True
)
def
assertPrompt
(
self
,
*
args
):
def
assertPrompt
(
self
,
*
args
):
value
=
''
.
join
(
args
)
""" Assert command prompt
self
.
rsf
.
expect_exact
(
value
,
timeout
=
1
)
:param elements:
:return:
"""
value
=
'
\
s*?'
.
join
(
args
)
self
.
rsf
.
expect
(
value
,
timeout
=
1
)
def
set_module
(
self
):
def
set_module
(
self
):
self
.
rsf
.
send
(
"use creds/ftp_bruteforce
\r\n
"
)
self
.
rsf
.
send
(
"use creds/ftp_bruteforce
\r\n
"
)
...
@@ -35,8 +39,9 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -35,8 +39,9 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
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
.
assertPrompt
(
'exec exit help search show use
\r\n
'
,
'exec'
,
'exit'
,
'help'
,
'search'
,
'show'
,
'use'
,
'
\r\n
'
,
self
.
raw_prompt
)
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
"
)
...
@@ -45,7 +50,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -45,7 +50,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def
test_complete_use
(
self
):
def
test_complete_use
(
self
):
self
.
rsf
.
send
(
"use
\t\t
"
)
self
.
rsf
.
send
(
"use
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'creds exploits payloads scanners
\r\n
'
,
"creds"
,
"exploits"
,
"payloads"
,
"scanners"
,
"
\r\n
"
,
self
.
raw_prompt
,
self
.
raw_prompt
,
'use '
'use '
)
)
...
@@ -73,7 +78,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -73,7 +78,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def
test_complete_use_exploits_2
(
self
):
def
test_complete_use_exploits_2
(
self
):
self
.
rsf
.
send
(
"use exploits/
\t\t
"
)
self
.
rsf
.
send
(
"use exploits/
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
"exploits/cameras/
exploits/misc/ exploits/routers/
\r\n
"
,
"exploits/cameras/
"
,
"exploits/misc/"
,
"exploits/routers/"
,
"
\r\n
"
,
self
.
raw_prompt
self
.
raw_prompt
)
)
...
@@ -94,8 +99,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -94,8 +99,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'back
exec help search setg use
\r\n
'
'back
'
,
'exec'
,
'help'
,
'search'
,
'setg'
,
'use'
,
'
\r\n
'
,
'check
exit run set show
\r\n
'
,
'check
'
,
'exit'
,
'run'
,
'set'
,
'show'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
self
.
module_prompt
(
'FTP Bruteforce'
)
)
)
...
@@ -103,47 +108,43 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -103,47 +108,43 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"b
\t\t
"
)
self
.
rsf
.
send
(
"b
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'back'
'back'
)
)
def
test_complete_check_raw
(
self
):
def
test_complete_check_raw
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"c
\t\t
"
)
self
.
rsf
.
send
(
"c
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'check'
'check'
)
)
def
test_complete_run_raw
(
self
):
def
test_complete_run_raw
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"r
\t\t
"
)
self
.
rsf
.
send
(
"r
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'run'
'run'
)
)
def
test_complete_search
(
self
):
def
test_complete_search
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"sea
\t
"
)
self
.
rsf
.
send
(
"sea
\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'search '
,
'search '
,
)
)
def
test_complete_set_raw
(
self
):
def
test_complete_set_raw
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"s
\t\t
"
)
self
.
rsf
.
send
(
"s
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'search
set setg show
\r\n
'
,
'search
'
,
'set'
,
'setg'
,
'show'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
self
.
module_prompt
(
'FTP Bruteforce'
)
,
's'
)
)
def
test_complete_set_raw_2
(
self
):
def
test_complete_set_raw_2
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"se
\t\t
"
)
self
.
rsf
.
send
(
"se
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'search
set setg
\r\n
'
,
'search
'
,
'set'
,
'setg'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
)
)
...
@@ -151,7 +152,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -151,7 +152,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"set
\t\t
"
)
self
.
rsf
.
send
(
"set
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'set
setg
\r\n
'
,
'set
'
,
'setg'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
)
)
...
@@ -159,36 +160,32 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -159,36 +160,32 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"set
\t\t
"
)
self
.
rsf
.
send
(
"set
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'passwords stop_on_success threads verbosity
\r\n
'
'passwords'
,
'stop_on_success'
,
'threads'
,
'verbosity'
,
'
\r\n
'
,
'port target usernames
\r\n
'
,
'port'
,
'target'
,
'usernames'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'set '
,
'set '
,
)
)
def
test_complete_set_2
(
self
):
def
test_complete_set_2
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"set u
\t\t
"
)
self
.
rsf
.
send
(
"set u
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'set usernames '
,
'set usernames '
,
)
)
def
test_complete_setg
(
self
):
def
test_complete_setg
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"setg
\t\t
"
)
self
.
rsf
.
send
(
"setg
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'passwords stop_on_success threads verbosity
\r\n
'
'passwords'
,
'stop_on_success'
,
'threads'
,
'verbosity'
,
'
\r\n
'
,
'port target usernames
\r\n
'
,
'port'
,
'target'
,
'usernames'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'setg '
,
'setg '
,
)
)
def
test_complete_setg_2
(
self
):
def
test_complete_setg_2
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"setg u
\t\t
"
)
self
.
rsf
.
send
(
"setg u
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'setg usernames '
,
'setg usernames '
,
)
)
def
test_complete_unsetg
(
self
):
def
test_complete_unsetg
(
self
):
...
@@ -198,8 +195,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -198,8 +195,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
"back exec help search setg use
\r\n
"
'back'
,
'exec'
,
'help'
,
'search'
,
'setg'
,
'use'
,
'
\r\n
'
,
"check exit run set show
\r\n
"
,
'check'
,
'exit'
,
'run'
,
'set'
,
'show'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
)
)
...
@@ -211,8 +208,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -211,8 +208,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
rsf
.
send
(
"setg target foo
\r\n
"
)
self
.
rsf
.
send
(
"setg target foo
\r\n
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'back
exec help search setg unsetg
\r\n
'
'back
'
,
'exec'
,
'help'
,
'search'
,
'setg'
,
'unsetg'
,
'
\r\n
'
,
'check
exit run set show use
\r\n
'
,
'check
'
,
'exit'
,
'run'
,
'set'
,
'show'
,
'use'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
)
)
...
@@ -225,7 +222,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -225,7 +222,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
rsf
.
send
(
"setg port bar
\r\n
"
)
self
.
rsf
.
send
(
"setg port bar
\r\n
"
)
self
.
rsf
.
send
(
"unsetg
\t\t
"
)
self
.
rsf
.
send
(
"unsetg
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
"port target
\r\n
"
,
'port'
,
'target'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
)
)
...
@@ -237,24 +234,22 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -237,24 +234,22 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
rsf
.
send
(
"setg target foo
\r\n
"
)
self
.
rsf
.
send
(
"setg target foo
\r\n
"
)
self
.
rsf
.
send
(
"unsetg t
\t\t
"
)
self
.
rsf
.
send
(
"unsetg t
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
"unsetg target"
"unsetg target"
)
)
def
test_complete_show_raw
(
self
):
def
test_complete_show_raw
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"sh
\t\t
"
)
self
.
rsf
.
send
(
"sh
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'show '
,
'show '
,
)
)
def
test_complete_show
(
self
):
def
test_complete_show
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"show
\t\t
"
)
self
.
rsf
.
send
(
"show
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
'all
creds devices exploits '
'all
'
,
'creds'
,
'devices'
,
'exploits'
,
'info options scanners
\r\n
'
,
r'info'
,
'options'
,
'scanners'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
self
.
module_prompt
(
'FTP Bruteforce'
)
)
)
...
@@ -262,16 +257,14 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
...
@@ -262,16 +257,14 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"show i
\t\t
"
)
self
.
rsf
.
send
(
"show i
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'show info'
'show info'
)
)
def
test_complete_show_options
(
self
):
def
test_complete_show_options
(
self
):
self
.
set_module
()
self
.
set_module
()
self
.
rsf
.
send
(
"show o
\t\t
"
)
self
.
rsf
.
send
(
"show o
\t\t
"
)
self
.
assertPrompt
(
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
self
.
module_prompt
(
'FTP Bruteforce'
),
'show options'
'show options'
)
)
...
...
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