Skip to content
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 a second chance on cmd_use for bug #4549 #4615

Merged
merged 3 commits into from
Jan 21, 2015

Conversation

todb-r7
Copy link

@todb-r7 todb-r7 commented Jan 20, 2015

This is a weak attempt to solve a race condition between modules loading and cmd_use being fired. Upon startup, saved configurations, running resource scripts, and running commands will sometimes jump ahead of the module loading procedure.

I have not discovered where the race actually is and how to cause the race to happen. However, the timing seems to be fairly close to a second; by waiting three seconds after trying use again, we seem to be in the clear, at least according to testing.

Fixes #4549, but better solutions are welcome.

Verification

  • The following bash script may be sufficient to catch the failing condition. Run it.

for i in {1..20}; do echo Attempt $i; time ./msfconsole -Lqx "use auxiliary/scanner/http/http_version;exit"; echo Sleeping...; sleep 5; done

In the usual case, where the modules load before you try to use the one, you should see something like this:

todb@mazikeen:~/git/rapid7/metasploit-framework$ for i in {1..20}; do echo Attempt $i; time ./msfconsole -Lqx "use auxiliary/scanner/http/http_version;exit"; echo Sleeping...; sleep 5; done
Attempt 1

real    0m4.805s
user    0m4.407s
sys 0m0.297s
Sleeping...

[etc for 20 more times]

If you're currently unlucky, or enter a period of unluckiness, you will see see a result like this:

Attempt 2

real    0m7.825s
user    0m4.611s
sys 0m0.332s
Sleeping...

Note the three second difference between Attempt 1 and Attempt 2.

Yes, this is a test that relies on luck. Totally scientific, I know.

I don't know what causes the initial fail, but it is resolved after a three second delay. This delayed cmd_use functionality will only last as long as the conditions are that the cmd_use would otherwise normally fail.

  • In order to show that nonexistent modules will continue to fail to load normally, run: time ./msfconsole -Lqx "use auxiliary/fake/module/here;exit"

Note that the time taken should be three seconds longer than normal, just as in the caught failure case.

@limhoff-r7 or @jlee-r7 will likely have a better solution for this some time, but please don't let that block you landing this. I'm not thrilled with the fix but it's better than having automated jobs fail out. It's also better than asking users to remember to drop in sleep commands in their rc scripts.

This is a weak attempt to solve a race condition between modules loading
and cmd_use being fired. Upon startup, saved configurations, running
resource scripts, and running commands will sometimes jump ahead of the
module loading procedure.

I have not discovered where the race actually is and how to cause the
race to happen. However, the timing seems to be fairly close to a second;
by waiting three seconds after trying use again, we seem to be in the
clear, at least according to testing.

Fixes rapid7#4549, but better solutions are welcome!
@todb-r7
Copy link
Author

todb-r7 commented Jan 20, 2015

Marking this as msfcli because without this fix, the migration to msfconsole for prior msfcli usages is pretty well blocked.

Tod Beardsley added 2 commits January 20, 2015 16:21
Because it reads nicer, though `mod` will never be `FalseClass`
@wvu wvu self-assigned this Jan 21, 2015
wvu added a commit to wvu/metasploit-framework that referenced this pull request Jan 21, 2015
@wvu wvu merged commit 9017aa0 into rapid7:master Jan 21, 2015
@wvu
Copy link
Contributor

wvu commented Jan 21, 2015

I couldn't use Timeout nicely, so this will have to do for now...

todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Mar 17, 2015
This reverts commit a52f491, reversing
changes made to 2f4ad97.

[See rapid7#4340]
todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Mar 17, 2015
Replaces the strategy in rapid7#4615.
[See rapid7#4340]
todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Mar 17, 2015
In order to avoid wasting too much time sleeping between attempts, just
sleep 0.1 seconds and retry 300 times.

Also fixed a style bug on line 2565, use `return false unless mod`
instead of `return false if mod.nil?`

[See rapid7#4340] [See rapid7#4615]
todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Mar 24, 2015
This reverts commit a52f491, reversing
changes made to 2f4ad97.

[See rapid7#4340]
todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Mar 24, 2015
Replaces the strategy in rapid7#4615.
[See rapid7#4340]
todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Mar 24, 2015
In order to avoid wasting too much time sleeping between attempts, just
sleep 0.1 seconds and retry 300 times.

Also fixed a style bug on line 2565, use `return false unless mod`
instead of `return false if mod.nil?`

[See rapid7#4340] [See rapid7#4615]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSFCONSOLE -X Multiple Instance Failure
2 participants