{"action":"created","issue":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5927","labels_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5927/labels{/name}","comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5927/comments","events_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5927/events","html_url":"https://github.com/rapid7/metasploit-framework/pull/5927","id":104591523,"number":5927,"title":"This PR cleans up sys.rb for idiomatic problems","user":{"login":"kernelsmith","id":620129,"avatar_url":"https://avatars.githubusercontent.com/u/620129?v=3","gravatar_id":"","url":"https://api.github.com/users/kernelsmith","html_url":"https://github.com/kernelsmith","followers_url":"https://api.github.com/users/kernelsmith/followers","following_url":"https://api.github.com/users/kernelsmith/following{/other_user}","gists_url":"https://api.github.com/users/kernelsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/kernelsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kernelsmith/subscriptions","organizations_url":"https://api.github.com/users/kernelsmith/orgs","repos_url":"https://api.github.com/users/kernelsmith/repos","events_url":"https://api.github.com/users/kernelsmith/events{/privacy}","received_events_url":"https://api.github.com/users/kernelsmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-02T23:25:06Z","updated_at":"2015-09-03T01:32:21Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/5927","html_url":"https://github.com/rapid7/metasploit-framework/pull/5927","diff_url":"https://github.com/rapid7/metasploit-framework/pull/5927.diff","patch_url":"https://github.com/rapid7/metasploit-framework/pull/5927.patch"},"body":"When attempting to normalize the behavior and return values (tho they are mostly meaningless for the cmd_ methods), I decided to add two constants to dispatcher_shell, namely COMMAND_SUCCESS and COMMAND_FAILURE.  Tho the return values on these are rarely checked, this gives a) an easy place to update them should they ever become important, b) a much clearer picture of the intent of the code and c) the start of the ability to use the return values for something.  This may help w/those folks who want to know when a command has finished etc.  \r\n\r\nthis code still needs more YARD, but I ran out of steam on that front.\r\n\r\nTo confirm, just run through the various sys commands at your leisure.\r\n\r\n```\r\nmeterpreter > execute -f calc.exe\r\nProcess 4324 created.\r\nmeterpreter > kill 4324\r\nKilling: 4324\r\nmeterpreter > getenv\r\n[-] You must provide env vars to lookup, or -h\r\n\r\nUsage: getenv varname [varname2] ...\r\nmeterpreter > getenv %COMSPEC%\r\n\r\nEnvironment Variables\r\n=====================\r\n\r\nVariable  Value\r\n--------  -----\r\nCOMSPEC   C:\\Windows\\system32\\cmd.exe\r\n\r\nmeterpreter > getenv %COMSPEC% %COMPUTERNAME%\r\n\r\nEnvironment Variables\r\n=====================\r\n\r\nVariable      Value\r\n--------      -----\r\nCOMPUTERNAME  VICTIM\r\nCOMSPEC       C:\\Windows\\system32\\cmd.exe\r\n\r\nmeterpreter > getpid\r\nCurrent pid: 2512\r\nmeterpreter > getsid\r\nServer SID: S-1-5-21-1720418662-3660741266-2307421305-1004\r\nmeterpreter > getuid\r\nServer username: victim\\victim\r\nmeterpreter > ps\r\n\r\nProcess List\r\n============\r\n\r\n PID   PPID  Name                      Arch  Session  User              Path\r\n ---   ----  ----                      ----  -------  ----              ----\r\n 0     0     [System Process]\r\n 4     0     System\r\n 296   4     smss.exe\r\n 368   356   csrss.exe\r\n 448   440   csrss.exe\r\n 456   356   wininit.exe\r\n 504   440   winlogon.exe\r\n 552   456   services.exe\r\n 560   456   lsass.exe\r\n 572   456   lsm.exe\r\n 660   552   svchost.exe\r\n 724   552   vmacthlp.exe\r\n 768   552   svchost.exe\r\n...snip...\r\n\r\nmeterpreter > ps -h\r\n\r\nUsage: ps [options]\r\n\r\nUse the command with no arguments to see all running processes.\r\nThe following options can be used to filter those results:\r\n\r\nOPTIONS:\r\n\r\n    -A <opt>  Filters processes on architecture (x86 or x86_64)\r\n    -S <opt>  String to search for (converts to regex)\r\n    -U <opt>  Filters processes on the user using the supplied RegEx\r\n    -h        Help menu.\r\n    -s        Show only SYSTEM processes\r\n\r\nmeterpreter > ps -S cmd\r\n\r\nProcess List\r\n============\r\n\r\n PID   PPID  Name                      Arch  Session  User              Path\r\n ---   ----  ----                      ----  -------  ----              ----\r\n 4928  3528  cmd.exe                   x86   1        victim\\victim  C:\\Windows\\system32\\cmd.exe\r\n\r\nmeterpreter > reg\r\n\r\nUsage: reg [command] [options]\r\n\r\nInteract with the target machine's registry.\r\n\r\nOPTIONS:\r\n\r\n    -d <opt>  The data to store in the registry value.\r\n    -h        Help menu.\r\n    -k <opt>  The registry key path (E.g. HKLM\\Software\\Foo).\r\n    -r <opt>  The remote machine name to connect to (with current process credentials\r\n    -t <opt>  The registry value type (E.g. REG_SZ).\r\n    -v <opt>  The registry value name (E.g. Stuff).\r\n    -w        Set KEY_WOW64 flag, valid values [32|64].\r\n\r\nCOMMANDS:\r\n\r\n    enumkey  Enumerate the supplied registry key [-k <key>]\r\n    createkey  Create the supplied registry key  [-k <key>]\r\n    deletekey  Delete the supplied registry key  [-k <key>]\r\n    queryclass Queries the class of the supplied key [-k <key>]\r\n    setval  Set a registry value [-k <key> -v <val> -d <data>]\r\n    deleteval  Delete the supplied registry value [-k <key> -v <val>]\r\n    queryval  Queries the data contents of a value [-k <key> -v <val>]\r\n\r\nmeterpreter > execute -f calc.exe\r\nProcess 2232 created.\r\nmeterpreter > suspend 2232\r\n[*] Suspending: 2232\r\n[*] Targeting process with PID 2232...\r\nmeterpreter > suspend -h\r\n\r\nUsage: suspend [options] pid1 pid2 pid3 ...\r\n\r\nSuspend one or more processes.\r\n\r\nOPTIONS:\r\n\r\n    -c        Continues suspending or resuming even if an error occurs\r\n    -h        Help menu.\r\n    -r        Resumes the target processes instead of suspending\r\n\r\nmeterpreter > suspend -r 2232\r\n[*] Resuming: 2232\r\n[*] Targeting process with PID 2232...\r\nmeterpreter > sysinfo\r\nComputer        : VICTIM\r\nOS              : Windows 7 (Build 7601, Service Pack 1).\r\nArchitecture    : x86\r\nSystem Language : en_US\r\nDomain          : WORKGROUP\r\nLogged On Users : 2\r\nMeterpreter     : x86/win32\r\nmeterpreter >\r\n```"},"comment":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/comments/137296618","html_url":"https://github.com/rapid7/metasploit-framework/pull/5927#issuecomment-137296618","issue_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/5927","id":137296618,"user":{"login":"hmoore-r7","id":1171392,"avatar_url":"https://avatars.githubusercontent.com/u/1171392?v=3","gravatar_id":"","url":"https://api.github.com/users/hmoore-r7","html_url":"https://github.com/hmoore-r7","followers_url":"https://api.github.com/users/hmoore-r7/followers","following_url":"https://api.github.com/users/hmoore-r7/following{/other_user}","gists_url":"https://api.github.com/users/hmoore-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/hmoore-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmoore-r7/subscriptions","organizations_url":"https://api.github.com/users/hmoore-r7/orgs","repos_url":"https://api.github.com/users/hmoore-r7/repos","events_url":"https://api.github.com/users/hmoore-r7/events{/privacy}","received_events_url":"https://api.github.com/users/hmoore-r7/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T01:32:21Z","updated_at":"2015-09-03T01:32:21Z","body":"Embedded newlines aren't handled properly in various third-party GUIs, which is why we use print_line() instead of just embedding a \"\\n\". As for the other changes, its not clear if the changes are an improvement in any way, and given the amount of review required to land this, they may not be worth the overhead."}}