Last active
August 29, 2015 14:19
-
-
Save yutopio/e3ef210f94124a009022 to your computer and use it in GitHub Desktop.
Shell injection test. DO NOT DEPLOY outside the testing environment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Exec</h1> | |
<%= form_tag(command_exec_url) do %> | |
<div class="actions"> | |
<%= text_area_tag(:stdin, "", size: "50x20") %> | |
</div> | |
<%= submit_tag("Execute") %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
root 'command#home' | |
post 'e' => 'command#exec', as: :command_exec | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open3' | |
class CommandController < ApplicationController | |
def home | |
end | |
def exec | |
input = params[:stdin] if params | |
input = request.body.string unless input | |
ret = '' | |
value = Open3.popen2("/bin/bash") { |i,o,t| | |
i.print input | |
i.close | |
exitCode = t.value | |
ret = o.read | |
exitCode | |
} | |
render plain: ret | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment