CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/nuuo/client_request.rb
Views: 11704
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Nuuo
6
7
class ClientRequest
8
9
DefaultConfig = {
10
#
11
# Nuuo stuff
12
#
13
'method' => 'USERLOGIN',
14
'server_version' => nil,
15
'data' => nil,
16
'headers' => nil,
17
'proto' => 'NUCM',
18
'version' => '1.0',
19
'file_name' => nil,
20
'file_type' => nil,
21
'user_session' => nil,
22
}
23
24
attr_reader :opts
25
26
def initialize(opts={})
27
@opts = DefaultConfig.merge(opts)
28
@opts['headers'] ||= {}
29
end
30
31
def to_s
32
# Set default header: <method> <proto/version>
33
req = ''
34
req << set_method
35
req << ' '
36
req << set_proto_version
37
38
# Set headers
39
req << set_header('server_version', 'Version')
40
req << set_header('user_session', 'User-Session-No')
41
42
# Add any additional headers
43
req << set_extra_headers
44
45
# Set data
46
req << set_body
47
end
48
49
def set_method
50
"#{opts['method']}"
51
end
52
53
def set_proto_version
54
"#{opts['proto']}/#{opts['version']}\r\n"
55
end
56
57
#
58
# Return <name> header
59
#
60
def set_header(key, name)
61
unless opts['headers'] && opts['headers'].keys.map(&:downcase).include?(name.downcase)
62
return opts[key] ? set_formatted_header(name, opts[key]) : ''
63
end
64
''
65
end
66
67
# Return additional headers
68
#
69
def set_extra_headers
70
buf = ''
71
opts['headers'].each_pair do |var,val|
72
buf << set_formatted_header(var,val)
73
end
74
75
buf
76
end
77
78
def set_body
79
return "\r\n#{opts['data']}"
80
end
81
82
def set_formatted_header(var, val)
83
"#{var}: #{val}\r\n"
84
end
85
86
end
87
end
88
end
89
end
90
91