-
Notifications
You must be signed in to change notification settings - Fork 13.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add repeat
command for repeating other commands
#10625
Conversation
Use Shellwords to join words that have been shellsplit and will be shellsplit again, and correctly reference a missing command name.
Interesting idea. If you didn't tell me it was heartbleed driven originally, I'd only be able to point to that module as one that would have a strong use case. However who knows what the future may hold! To me, having a command list, a ;, then sleep, then understanding the sleep runs between each iteration doesn't seem intuitive. What about adding a |
Ideally I would have made this behave more like a bourne-style shell, since there are lots of great one-liners and tutorials available and other reasons for learning, but that's not really feasible in the current code base. |
Great use case picking Heartbleed. I think this will be a superior approach for simple cases where writing a resource script is overkill. Thank you! |
lib/rex/ui/text/dispatcher_shell.rb
Outdated
@@ -432,7 +432,7 @@ def tab_complete_helper(dispatcher, str, words) | |||
# | |||
# Run a single command line. | |||
# | |||
def run_single(line) | |||
def run_single(line, propogate_errors: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you mean "propagate."
@@ -109,7 +109,10 @@ def initialize | |||
STARTTLS may also be vulnerable. | |||
|
|||
The module supports several actions, allowing for scanning, dumping of | |||
memory contents, and private key recovery. | |||
memory contents, and private key recovery. The `repeat` command can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I should have added a dump count to this module years ago. I will probably do this when I update Shellshock. In the absence of a true pipeline, I think we should keep this note regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering an advanced option for all modules for number of times to loop, but this felt more flexible and possibly less obscure. I think the MS15-034 scanner could also benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm a fan of this command over another top-level option. A pipeline would be a fantastic next evolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, I had found it annoying to use the Heartbleed module because you had to check the loot file(s) manually for anything interesting. I would have liked a way to tee
in a sense, but that was well outside design parameters.
@@ -109,7 +109,10 @@ def initialize | |||
STARTTLS may also be vulnerable. | |||
|
|||
The module supports several actions, allowing for scanning, dumping of | |||
memory contents, and private key recovery. | |||
memory contents, and private key recovery. The `repeat` command can be | |||
used to make running the `DUMP` many times more convient. As in: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean "convenient" here.
opts.separator '' | ||
|
||
opts.on '-t SECONDS', '--time SECONDS', 'Number of seconds to repeat COMMAND...', Integer do |n| | ||
looper = ->(&block) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the shorter lambda syntax with a block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a block that takes a block in a block for a block!
Typos fixed, @wvu-r7. Also, it now prints help when run without any commands instead of going into a loop with now output (similar to the |
|
Release NotesThis adds a |
Recently watching an assessment I came across a need to dump lots of memory from a heartbleed-vulnerable host (manually running the module lots of times was technically an option, but there wasn't a lot of time). I hacked something up with
irb
anddriver.run_single
, but it didn't feel very satisfying or user-friendly. I imagine there are other classes of auxiliary module that could use this, so instead of adding module specific options for repetition I added a new command that can be used with any module/command.The
repeat
command will continue starting commands until a certain amount of time elapses with-t
, for a fixed number of iterations with-n
, or indefinitely (the default). It supports running a list of commands separated by;
, since thesleep
command (and probably others) might come in handy. Any exception running a command will cause the loop to stop.Verification
msfconsole
Happy path
repeat grep grep grep; sleep 1
should print two lines every second until youCTRL-C
repeat -n 5 grep grep grep; sleep 1
should print the same 5 timesrepeat -t 6 grep grep grep; sleep 1
should do the samerepeat -h
andhelp repeat
should be identical and informativerepeat
should tab-completeSad path
repeat -t 5 grep -A
should print an error and not looprepeat -t asdf grep grep grep
should print an error and not looprepeat -n asdf grep grep grep
should print an error and not looprepeat
(with and without options) should print help when run with no commands