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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
62 deletions
+67
-62
interpreter.py
routersploit/interpreter.py
+23
-11
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
itertools
import
os
...
...
@@ -13,10 +11,11 @@ from routersploit.exploits import Exploit, GLOBAL_OPTS
from
routersploit.payloads
import
BasePayload
from
routersploit.printer
import
PrinterThread
,
printer_queue
if
sys
.
platform
==
"darwin"
:
import
gnureadline
as
readline
else
:
import
readline
import
readline
def
is_libedit
():
return
"libedit"
in
readline
.
__doc__
class
BaseInterpreter
(
object
):
...
...
@@ -37,7 +36,9 @@ class BaseInterpreter(object):
:return:
"""
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
.
set_history_length
(
self
.
history_length
)
...
...
@@ -47,7 +48,10 @@ class BaseInterpreter(object):
readline
.
set_completer
(
self
.
complete
)
readline
.
set_completer_delims
(
'
\t\n
;'
)
readline
.
parse_and_bind
(
"tab: complete"
)
if
is_libedit
():
readline
.
parse_and_bind
(
"bind ^I rl_complete"
)
else
:
readline
.
parse_and_bind
(
"tab: complete"
)
def
parse_line
(
self
,
line
):
""" Split line into command and argument.
...
...
@@ -124,7 +128,9 @@ class BaseInterpreter(object):
else
:
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
:
return
self
.
completion_matches
[
state
]
...
...
@@ -137,11 +143,17 @@ class BaseInterpreter(object):
:param ignored:
: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
):
""" 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
):
return
[]
...
...
tests/test_completer.py
View file @
88551596
...
...
@@ -12,21 +12,25 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
cli_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
__file__
,
os
.
pardir
,
os
.
pardir
,
'rsf.py'
)
)
self
.
raw_prompt
=
"
\033
[4mrsf
\033
[0m > "
self
.
module_prompt
=
lambda
\
x
:
"
\033
[4mrsf
\033
[0m (
\033
[91m{}
\033
[0m) > "
.
format
(
x
)
self
.
raw_prompt
=
".+?rsf.+?
\
s>
\
s"
self
.
module_prompt
=
lambda
x
:
".+?rsf.+?
\
(.+?{}.+?
\
)
\
s>
\
s"
.
format
(
x
)
def
setUp
(
self
):
self
.
rsf
=
pexpect
.
spawn
(
'python {}'
.
format
(
self
.
cli_path
))
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
):
self
.
rsf
.
terminate
(
force
=
True
)
def
assertPrompt
(
self
,
*
args
):
value
=
''
.
join
(
args
)
self
.
rsf
.
expect_exact
(
value
,
timeout
=
1
)
""" Assert command prompt
:param elements:
:return:
"""
value
=
'
\
s*?'
.
join
(
args
)
self
.
rsf
.
expect
(
value
,
timeout
=
1
)
def
set_module
(
self
):
self
.
rsf
.
send
(
"use creds/ftp_bruteforce
\r\n
"
)
...
...
@@ -35,8 +39,9 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def
test_raw_commands_no_module
(
self
):
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
'exec exit help search show use
\r\n
'
,
self
.
raw_prompt
)
'exec'
,
'exit'
,
'help'
,
'search'
,
'show'
,
'use'
,
'
\r\n
'
,
self
.
raw_prompt
)
def
test_complete_use_raw
(
self
):
self
.
rsf
.
send
(
"u
\t\t
"
)
...
...
@@ -45,7 +50,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def
test_complete_use
(
self
):
self
.
rsf
.
send
(
"use
\t\t
"
)
self
.
assertPrompt
(
'creds exploits payloads scanners
\r\n
'
,
"creds"
,
"exploits"
,
"payloads"
,
"scanners"
,
"
\r\n
"
,
self
.
raw_prompt
,
'use '
)
...
...
@@ -73,7 +78,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
def
test_complete_use_exploits_2
(
self
):
self
.
rsf
.
send
(
"use exploits/
\t\t
"
)
self
.
assertPrompt
(
"exploits/cameras/
exploits/misc/ exploits/routers/
\r\n
"
,
"exploits/cameras/
"
,
"exploits/misc/"
,
"exploits/routers/"
,
"
\r\n
"
,
self
.
raw_prompt
)
...
...
@@ -94,8 +99,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
'back
exec help search setg use
\r\n
'
'check
exit run set show
\r\n
'
,
'back
'
,
'exec'
,
'help'
,
'search'
,
'setg'
,
'use'
,
'
\r\n
'
,
'check
'
,
'exit'
,
'run'
,
'set'
,
'show'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
)
...
...
@@ -103,47 +108,43 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
rsf
.
send
(
"b
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'back'
self
.
module_prompt
(
'FTP Bruteforce'
),
'back'
)
def
test_complete_check_raw
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"c
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'check'
self
.
module_prompt
(
'FTP Bruteforce'
),
'check'
)
def
test_complete_run_raw
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"r
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'run'
self
.
module_prompt
(
'FTP Bruteforce'
),
'run'
)
def
test_complete_search
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"sea
\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'search '
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'search '
,
)
def
test_complete_set_raw
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"s
\t\t
"
)
self
.
assertPrompt
(
'search
set setg show
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
'search
'
,
'set'
,
'setg'
,
'show'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
,
's'
)
def
test_complete_set_raw_2
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"se
\t\t
"
)
self
.
assertPrompt
(
'search
set setg
\r\n
'
,
'search
'
,
'set'
,
'setg'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
)
...
...
@@ -151,7 +152,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
rsf
.
send
(
"set
\t\t
"
)
self
.
assertPrompt
(
'set
setg
\r\n
'
,
'set
'
,
'setg'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
)
...
...
@@ -159,36 +160,32 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
rsf
.
send
(
"set
\t\t
"
)
self
.
assertPrompt
(
'passwords stop_on_success threads verbosity
\r\n
'
'port target usernames
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'set '
,
'passwords'
,
'stop_on_success'
,
'threads'
,
'verbosity'
,
'
\r\n
'
,
'port'
,
'target'
,
'usernames'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'set '
,
)
def
test_complete_set_2
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"set u
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'set usernames '
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'set usernames '
,
)
def
test_complete_setg
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"setg
\t\t
"
)
self
.
assertPrompt
(
'passwords stop_on_success threads verbosity
\r\n
'
'port target usernames
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'setg '
,
'passwords'
,
'stop_on_success'
,
'threads'
,
'verbosity'
,
'
\r\n
'
,
'port'
,
'target'
,
'usernames'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'setg '
,
)
def
test_complete_setg_2
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"setg u
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'setg usernames '
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'setg usernames '
,
)
def
test_complete_unsetg
(
self
):
...
...
@@ -198,8 +195,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
"back exec help search setg use
\r\n
"
"check exit run set show
\r\n
"
,
'back'
,
'exec'
,
'help'
,
'search'
,
'setg'
,
'use'
,
'
\r\n
'
,
'check'
,
'exit'
,
'run'
,
'set'
,
'show'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
)
...
...
@@ -211,8 +208,8 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
rsf
.
send
(
"setg target foo
\r\n
"
)
self
.
rsf
.
send
(
"
\t\t
"
)
self
.
assertPrompt
(
'back
exec help search setg unsetg
\r\n
'
'check
exit run set show use
\r\n
'
,
'back
'
,
'exec'
,
'help'
,
'search'
,
'setg'
,
'unsetg'
,
'
\r\n
'
,
'check
'
,
'exit'
,
'run'
,
'set'
,
'show'
,
'use'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
)
...
...
@@ -225,7 +222,7 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
rsf
.
send
(
"setg port bar
\r\n
"
)
self
.
rsf
.
send
(
"unsetg
\t\t
"
)
self
.
assertPrompt
(
"port target
\r\n
"
,
'port'
,
'target'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
),
)
...
...
@@ -237,24 +234,22 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
rsf
.
send
(
"setg target foo
\r\n
"
)
self
.
rsf
.
send
(
"unsetg t
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
"unsetg target"
self
.
module_prompt
(
'FTP Bruteforce'
),
"unsetg target"
)
def
test_complete_show_raw
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"sh
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'show '
,
self
.
module_prompt
(
'FTP Bruteforce'
),
'show '
,
)
def
test_complete_show
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"show
\t\t
"
)
self
.
assertPrompt
(
'all
creds devices exploits '
'info options scanners
\r\n
'
,
'all
'
,
'creds'
,
'devices'
,
'exploits'
,
r'info'
,
'options'
,
'scanners'
,
'
\r\n
'
,
self
.
module_prompt
(
'FTP Bruteforce'
)
)
...
...
@@ -262,16 +257,14 @@ class RoutersploitCompleterTest(RoutersploitTestCase):
self
.
set_module
()
self
.
rsf
.
send
(
"show i
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'show info'
self
.
module_prompt
(
'FTP Bruteforce'
),
'show info'
)
def
test_complete_show_options
(
self
):
self
.
set_module
()
self
.
rsf
.
send
(
"show o
\t\t
"
)
self
.
assertPrompt
(
self
.
module_prompt
(
'FTP Bruteforce'
),
'show options'
self
.
module_prompt
(
'FTP Bruteforce'
),
'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