-
Notifications
You must be signed in to change notification settings - Fork 612
/
Copy pathcontroller.rb
93 lines (74 loc) · 1.7 KB
/
controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
##
# controller.rb
# Created April, 2014
# By Ron Bowes
#
# See: LICENSE.md
#
# This keeps track of all sessions.
##
require 'controller/controller_commands'
require 'controller/packet'
require 'controller/session'
require 'libs/commander'
require 'libs/dnscat_exception'
require 'trollop'
class Controller
include ControllerCommands
attr_accessor :window
def initialize()
@commander = Commander.new()
@sessions = {}
_register_commands()
WINDOW.on_input() do |data|
data = Settings::GLOBAL.do_replace(data)
begin
@commander.feed(data)
rescue ArgumentError => e
WINDOW.puts("Error: #{e}")
WINDOW.puts()
@commander.educate(data, WINDOW)
end
end
end
def _get_or_create_session(id)
if(@sessions[id])
return @sessions[id]
end
return (@sessions[id] = Session.new(id, WINDOW))
end
def session_exists?(id)
return !@sessions[id].nil?
end
def find_session(id)
return @sessions[id]
end
def find_session_by_window(id)
id = id.to_s()
@sessions.each_value do |session|
if(session.window.id.to_s() == id)
return session
end
end
return nil
end
def kill_session(id)
session = find(id)
if(!session.nil?)
session.kill()
end
end
def list()
return @sessions
end
def feed(data, max_length)
# If it's a ping packet, handle it up here
if(Packet.peek_type(data) == Packet::MESSAGE_TYPE_PING)
WINDOW.puts("Responding to ping packet: #{Packet.parse(data).body}")
return data
end
session_id = Packet.peek_session_id(data)
session = _get_or_create_session(session_id)
return session.feed(data, max_length)
end
end