{"action":"closed","number":6864,"pull_request":{"url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/6864","id":69474587,"html_url":"https://github.com/rapid7/metasploit-framework/pull/6864","diff_url":"https://github.com/rapid7/metasploit-framework/pull/6864.diff","patch_url":"https://github.com/rapid7/metasploit-framework/pull/6864.patch","issue_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/6864","number":6864,"state":"closed","locked":false,"title":"fix  suspending shells from meterpreter","user":{"login":"bcook-r7","id":10031469,"avatar_url":"https://avatars.githubusercontent.com/u/10031469?v=3","gravatar_id":"","url":"https://api.github.com/users/bcook-r7","html_url":"https://github.com/bcook-r7","followers_url":"https://api.github.com/users/bcook-r7/followers","following_url":"https://api.github.com/users/bcook-r7/following{/other_user}","gists_url":"https://api.github.com/users/bcook-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/bcook-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcook-r7/subscriptions","organizations_url":"https://api.github.com/users/bcook-r7/orgs","repos_url":"https://api.github.com/users/bcook-r7/repos","events_url":"https://api.github.com/users/bcook-r7/events{/privacy}","received_events_url":"https://api.github.com/users/bcook-r7/received_events","type":"User","site_admin":false},"body":"This PR fixes an error that happens when suspending a shell in a Meterpreter session. The problem is that you can only do a limited subset of things from a signal handler (e.g. you can't do anything that is not async-signal safe). So, we spawn a thread to do the things, but still join the thread from the signal context to avoid doing anything more thread-unsafe (as to not surprise the existing set of signal handlers)\r\n\r\nThis also partially addresses #4555\r\n\r\nPrior to this patch, this happens when you background a shell\r\n```\r\n./msfconsole -qx 'use exploit/multi/handler; set payload python/meterpreter/reverse_tcp; set lhost 192.168.56.1; run'\r\npayload => python/meterpreter/reverse_tcp\r\nlhost => 192.168.56.1\r\n[*] Started reverse TCP handler on 192.168.56.1:4444 \r\n[*] Starting the payload handler...\r\n[*] Sending stage (38526 bytes) to 192.168.56.1\r\n[*] Meterpreter session 1 opened (192.168.56.1:4444 -> 192.168.56.1:50194) at 2016-05-10 03:57:14 -0500\r\n\r\nmeterpreter > shell \r\nProcess 17558 created.\r\nChannel 1 created.\r\n/bin/sh: 0: can't access tty; job control turned off\r\n\\[\\033[00;32m\\]\\u@\\h:\\w$ \\[\\033[00m\\]^Z\r\nBackground channel 1? [y/N]  y\r\n[-] Error running command shell: ThreadError can't be called from trap context\r\nmeterpreter >\r\nBackground channel 1? [y/N]  [-] Session manipulation failed: can't be called from trap context [\"/home/bcook/projects/metasploit-framework/lib/rex/post/meterpreter/packet_dispatcher.rb:170:in `synchronize'\", \"/home/bcook/projects/metasploit-framework/lib/rex/post/meterpreter/packet_dispatcher.rb:170:in `send_packet'\", \"/home/bcook/projects/metasploit-framew\r\n```\r\n\r\n## Verification\r\n\r\nList the steps needed to make sure this thing works\r\n\r\n- [ ] Start a meterpreter session (any meterpreter will do)\r\n```\r\n./msfconsole -qx 'use exploit/multi/handler; set payload python/meterpreter/reverse_tcp; set lhost 192.168.56.1; run'\r\n```\r\n- [ ] run the `shell` command\r\n- [ ] hit Ctrl-Z to background the shell, hit 'y' to accept at the prompt\r\n- [ ] Verify that the shell backgrounds without an error\r\n- [ ] run `channel -i 1` to interact with the shell command again\r\n- [ ] verify that you can still interact with the channel\r\n\r\n```\r\n[*] Started reverse TCP handler on 192.168.56.1:4444 \r\n[*] Starting the payload handler...\r\n[*] Sending stage (38526 bytes) to 192.168.56.1\r\n[*] Meterpreter session 1 opened (192.168.56.1:4444 -> 192.168.56.1:50356) at 2016-05-10 04:04:48 -0500\r\n\r\nmeterpreter > shell \r\nProcess 18036 created.\r\nChannel 1 created.\r\n/bin/sh: 0: can't access tty; job control turned off\r\n\\[\\033[00;32m\\]\\u@\\h:\\w$ \\[\\033[00m\\]^Z\r\nBackground channel 1? [y/N]  y\r\n\r\nmeterpreter > channel -i 1\r\nInteracting with channel 1...\r\n\r\n\r\n\\[\\033[00;32m\\]\\u@\\h:\\w$ \\[\\033[00m\\]ls\r\nand.sh\t\t       HACKING\t\t\t     payloads.json\r\napp\t\t       lib\t\t\t     plugins\r\nbin\t\t       LICENSE\t\t\t     railgun-calls.txt\r\nbuild_rev.txt.2        local\t\t\t     Rakefile\r\ncallgrind.out.25815    log\t\t\t     README.md\r\ncheatsheet\t       metasploit-framework.gemspec  script\r\nCODE_OF_CONDUCT.md     modules\t\t\t     scripts\r\nconfig\t\t       msfbinscan\t\t     spec\r\nCONTRIBUTING.md        msfconsole\t\t     test\r\nCOPYING\t\t       msfd\t\t\t     test.db\r\ncoverage\t       msfelfscan\t\t     test.elf\r\ncp_meterp_dlls\t       msfinstall\t\t     test.exe\r\ndata\t\t       msfmachscan\t\t     test.exectig\r\ndb\t\t       msfpescan\t\t     test.jar\r\ndocumentation\t       msfrop\t\t\t     test.php\r\nexternal\t       msfrpc\t\t\t     test.py\r\nfeatures\t       msfrpcd\t\t\t     test.rc\r\nGemfile\t\t       msfupdate\t\t     test-scripts\r\nGemfile.local.example  msfvenom\t\t\t     test.xml\r\nGemfile.lock\t       mytest\t\t\t     tmp\r\ngen_payloads\t       notes.txt\t\t     tools\r\n\\[\\033[00;32m\\]\\u@\\h:\\w$ \\[\\033[00m\\]^Z\r\nBackground channel 1? [y/N]  y\r\nmeterpreter > exit\r\n[*] Shutting down Meterpreter...\r\n\r\n[*] 192.168.56.1 - Meterpreter session 1 closed.  Reason: User exit\r\n```\r\n\r\n\r\n","created_at":"2016-05-10T09:28:59Z","updated_at":"2016-05-16T16:16:28Z","closed_at":"2016-05-16T16:16:28Z","merged_at":"2016-05-16T16:16:28Z","merge_commit_sha":"af84e85174bb1d30f08ded103048092a06ed61b9","assignee":{"login":"dmaloney-r7","id":1146440,"avatar_url":"https://avatars.githubusercontent.com/u/1146440?v=3","gravatar_id":"","url":"https://api.github.com/users/dmaloney-r7","html_url":"https://github.com/dmaloney-r7","followers_url":"https://api.github.com/users/dmaloney-r7/followers","following_url":"https://api.github.com/users/dmaloney-r7/following{/other_user}","gists_url":"https://api.github.com/users/dmaloney-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/dmaloney-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmaloney-r7/subscriptions","organizations_url":"https://api.github.com/users/dmaloney-r7/orgs","repos_url":"https://api.github.com/users/dmaloney-r7/repos","events_url":"https://api.github.com/users/dmaloney-r7/events{/privacy}","received_events_url":"https://api.github.com/users/dmaloney-r7/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/6864/commits","review_comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/6864/comments","review_comment_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/6864/comments","statuses_url":"https://api.github.com/repos/rapid7/metasploit-framework/statuses/af84e85174bb1d30f08ded103048092a06ed61b9","head":{"label":"bcook-r7:fix-suspend-shell","ref":"fix-suspend-shell","sha":"af84e85174bb1d30f08ded103048092a06ed61b9","user":{"login":"bcook-r7","id":10031469,"avatar_url":"https://avatars.githubusercontent.com/u/10031469?v=3","gravatar_id":"","url":"https://api.github.com/users/bcook-r7","html_url":"https://github.com/bcook-r7","followers_url":"https://api.github.com/users/bcook-r7/followers","following_url":"https://api.github.com/users/bcook-r7/following{/other_user}","gists_url":"https://api.github.com/users/bcook-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/bcook-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcook-r7/subscriptions","organizations_url":"https://api.github.com/users/bcook-r7/orgs","repos_url":"https://api.github.com/users/bcook-r7/repos","events_url":"https://api.github.com/users/bcook-r7/events{/privacy}","received_events_url":"https://api.github.com/users/bcook-r7/received_events","type":"User","site_admin":false},"repo":{"id":27561397,"name":"metasploit-framework","full_name":"bcook-r7/metasploit-framework","owner":{"login":"bcook-r7","id":10031469,"avatar_url":"https://avatars.githubusercontent.com/u/10031469?v=3","gravatar_id":"","url":"https://api.github.com/users/bcook-r7","html_url":"https://github.com/bcook-r7","followers_url":"https://api.github.com/users/bcook-r7/followers","following_url":"https://api.github.com/users/bcook-r7/following{/other_user}","gists_url":"https://api.github.com/users/bcook-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/bcook-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcook-r7/subscriptions","organizations_url":"https://api.github.com/users/bcook-r7/orgs","repos_url":"https://api.github.com/users/bcook-r7/repos","events_url":"https://api.github.com/users/bcook-r7/events{/privacy}","received_events_url":"https://api.github.com/users/bcook-r7/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bcook-r7/metasploit-framework","description":"Metasploit Framework","fork":true,"url":"https://api.github.com/repos/bcook-r7/metasploit-framework","forks_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/forks","keys_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/teams","hooks_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/hooks","issue_events_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/issues/events{/number}","events_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/events","assignees_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/assignees{/user}","branches_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/branches{/branch}","tags_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/tags","blobs_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/languages","stargazers_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/stargazers","contributors_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/contributors","subscribers_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/subscribers","subscription_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/subscription","commits_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/contents/{+path}","compare_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/merges","archive_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/downloads","issues_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/issues{/number}","pulls_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/labels{/name}","releases_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/releases{/id}","deployments_url":"https://api.github.com/repos/bcook-r7/metasploit-framework/deployments","created_at":"2014-12-04T21:42:14Z","updated_at":"2016-01-23T07:29:42Z","pushed_at":"2016-05-14T03:58:39Z","git_url":"git://github.com/bcook-r7/metasploit-framework.git","ssh_url":"git@github.com:bcook-r7/metasploit-framework.git","clone_url":"https://github.com/bcook-r7/metasploit-framework.git","svn_url":"https://github.com/bcook-r7/metasploit-framework","homepage":"http://www.metasploit.com/","size":273592,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rapid7:master","ref":"master","sha":"3db72e9b4b23ebbc35401e30edf3b611c3ba51de","user":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"repo":{"id":2293158,"name":"metasploit-framework","full_name":"rapid7/metasploit-framework","owner":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rapid7/metasploit-framework","description":"Metasploit Framework","fork":false,"url":"https://api.github.com/repos/rapid7/metasploit-framework","forks_url":"https://api.github.com/repos/rapid7/metasploit-framework/forks","keys_url":"https://api.github.com/repos/rapid7/metasploit-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rapid7/metasploit-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rapid7/metasploit-framework/teams","hooks_url":"https://api.github.com/repos/rapid7/metasploit-framework/hooks","issue_events_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/events{/number}","events_url":"https://api.github.com/repos/rapid7/metasploit-framework/events","assignees_url":"https://api.github.com/repos/rapid7/metasploit-framework/assignees{/user}","branches_url":"https://api.github.com/repos/rapid7/metasploit-framework/branches{/branch}","tags_url":"https://api.github.com/repos/rapid7/metasploit-framework/tags","blobs_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rapid7/metasploit-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/rapid7/metasploit-framework/languages","stargazers_url":"https://api.github.com/repos/rapid7/metasploit-framework/stargazers","contributors_url":"https://api.github.com/repos/rapid7/metasploit-framework/contributors","subscribers_url":"https://api.github.com/repos/rapid7/metasploit-framework/subscribers","subscription_url":"https://api.github.com/repos/rapid7/metasploit-framework/subscription","commits_url":"https://api.github.com/repos/rapid7/metasploit-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/rapid7/metasploit-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/rapid7/metasploit-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/rapid7/metasploit-framework/contents/{+path}","compare_url":"https://api.github.com/repos/rapid7/metasploit-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rapid7/metasploit-framework/merges","archive_url":"https://api.github.com/repos/rapid7/metasploit-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rapid7/metasploit-framework/downloads","issues_url":"https://api.github.com/repos/rapid7/metasploit-framework/issues{/number}","pulls_url":"https://api.github.com/repos/rapid7/metasploit-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/rapid7/metasploit-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/rapid7/metasploit-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rapid7/metasploit-framework/labels{/name}","releases_url":"https://api.github.com/repos/rapid7/metasploit-framework/releases{/id}","deployments_url":"https://api.github.com/repos/rapid7/metasploit-framework/deployments","created_at":"2011-08-30T06:13:20Z","updated_at":"2016-05-16T13:27:34Z","pushed_at":"2016-05-16T16:16:24Z","git_url":"git://github.com/rapid7/metasploit-framework.git","ssh_url":"git@github.com:rapid7/metasploit-framework.git","clone_url":"https://github.com/rapid7/metasploit-framework.git","svn_url":"https://github.com/rapid7/metasploit-framework","homepage":"http://www.metasploit.com/","size":1305224,"stargazers_count":5805,"watchers_count":5805,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3980,"mirror_url":null,"open_issues_count":270,"forks":3980,"open_issues":270,"watchers":5805,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/6864"},"html":{"href":"https://github.com/rapid7/metasploit-framework/pull/6864"},"issue":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/issues/6864"},"comments":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/issues/6864/comments"},"review_comments":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/6864/comments"},"review_comment":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/pulls/6864/commits"},"statuses":{"href":"https://api.github.com/repos/rapid7/metasploit-framework/statuses/af84e85174bb1d30f08ded103048092a06ed61b9"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"dmaloney-r7","id":1146440,"avatar_url":"https://avatars.githubusercontent.com/u/1146440?v=3","gravatar_id":"","url":"https://api.github.com/users/dmaloney-r7","html_url":"https://github.com/dmaloney-r7","followers_url":"https://api.github.com/users/dmaloney-r7/followers","following_url":"https://api.github.com/users/dmaloney-r7/following{/other_user}","gists_url":"https://api.github.com/users/dmaloney-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/dmaloney-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmaloney-r7/subscriptions","organizations_url":"https://api.github.com/users/dmaloney-r7/orgs","repos_url":"https://api.github.com/users/dmaloney-r7/repos","events_url":"https://api.github.com/users/dmaloney-r7/events{/privacy}","received_events_url":"https://api.github.com/users/dmaloney-r7/received_events","type":"User","site_admin":false},"comments":3,"review_comments":0,"commits":1,"additions":5,"deletions":5,"changed_files":1}}