rapid7/metasploit-framework — pull request #2000 by kernelsmith (2013-06-21 07:27:44+00:00)
Title: Add capability to run multiple commands on one line, also fixes rm7705 msfconsole -x escaping issue

This is a resubmit of https://github.com/rapid7/metasploit-framework/pull/1336 after much discussion on the best way to implement run_multiple, specifically the parsing. The conclusion was to use the builtin ruby CSV parser but change the separator from ',' to ';'. Therefore, due to the escaping syntax of the CSV parser, you use a quote char to escape an entire field (ie command in this case). The default quote char is " (double quotes). To escape the quote char, you must double it up (so "" in this case). The methods added support calls which specify there own sep and quote char, but currently there's no way for the user to change them at run time. This could be solved by making those values advanced or basic options of msfconsole, but this has not been implemented in this PR.

This PR also fixes https://dev.metasploit.com/redmine/issues/7705. For test results and some example corner case oddities of the syntax, see https://gist.github.com/kernelsmith/5822064

Altho this PR changes 10 files, most of those are just refactors from run_single to run_multiple (tho not all calls to run_single had to be replaced).

To test this PR, apply it and just run various attempts to run multiple commands on a single line and via msfconsole -x. You can reference some of the stranger examples via the gist link above. If you run into cases where you don't think the escaping is working correctly, it's probably due to the strange way the CSV parser escapes things. Reference the commentary above as well as the gist and/or the ruby docs on the CSV parser.