Skip to content

Instantly share code, notes, and snippets.

@yutopio
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutopio/e3ef210f94124a009022 to your computer and use it in GitHub Desktop.
Save yutopio/e3ef210f94124a009022 to your computer and use it in GitHub Desktop.
Shell injection test. DO NOT DEPLOY outside the testing environment.
<h1>Exec</h1>
<%= form_tag(command_exec_url) do %>
<div class="actions">
<%= text_area_tag(:stdin, "", size: "50x20") %>
</div>
<%= submit_tag("Execute") %>
<% end %>
Rails.application.routes.draw do
root 'command#home'
post 'e' => 'command#exec', as: :command_exec
end
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