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/apache_j_p.rb
Views: 11655
1
# -*- coding: binary -*-
2
3
require 'bindata'
4
5
# @see: https://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html
6
module Rex::Proto::ApacheJP
7
class ApacheJPBoolean < BinData::Primitive
8
endian :big
9
10
uint8 :data
11
12
def get
13
self.data != 0
14
end
15
16
def set(v)
17
self.data = v ? 1 : 0
18
end
19
end
20
21
class ApacheJPString < BinData::Primitive
22
endian :big
23
24
uint16 :len, value: -> { data.length }
25
stringz :data
26
27
def get
28
self.data
29
end
30
31
def set(v)
32
self.data = v
33
end
34
end
35
36
class ApacheJPHeaderName < BinData::Primitive
37
COMMON_HEADERS = []
38
39
endian :big
40
41
uint16 :len_or_code
42
stringz :data, onlyif: -> { len_or_code < 0xa000 }
43
44
def get
45
if len_or_code >= 0xa000
46
self.class::COMMON_HEADERS[(len_or_code.to_i & 0xff) - 1]
47
else
48
self.data
49
end
50
end
51
52
def set(v)
53
if (idx = self.class::COMMON_HEADERS.index(v))
54
self.len_or_code = 0xa000 | (idx + 1)
55
else
56
raise RuntimeError if v.length >= 0xa000
57
58
self.len_or_code = v.length
59
self.data = v
60
end
61
end
62
end
63
64
class ApacheJPReqHeaderName < ApacheJPHeaderName
65
COMMON_HEADERS = %w{ accept accept-charset accept-encoding accept-language authorization connection content-type content-length cookie cookie2 host pragma referer user-agent }
66
end
67
68
class ApacheJPResHeaderName < ApacheJPHeaderName
69
COMMON_HEADERS = %w{ Content-Type Content-Language Content-Length Date Last-Modified Location Set-Cookie Set-Cookie2 Servlet-Engine Status WWW-Authentication }
70
end
71
72
class ApacheJPRequestHeader < BinData::Record
73
endian :big
74
75
apache_jp_req_header_name :header_name
76
apache_jp_string :header_value
77
end
78
79
class ApacheJPResponseHeader < BinData::Record
80
endian :big
81
82
apache_jp_res_header_name :header_name
83
apache_jp_string :header_value
84
end
85
86
class ApacheJPRequestAttribute < BinData::Record
87
CODE_CONTEXT = 1
88
CODE_SERVLET_PATH = 2
89
CODE_REMOTE_USER = 3
90
CODE_AUTH_TYPE = 4
91
CODE_QUERY_STRING = 5
92
CODE_JVM_ROUTE = 6
93
CODE_SSL_CERT = 7
94
CODE_SSL_CIPHER = 8
95
CODE_SSL_SESSION = 9
96
CODE_REQ_ATTRIBUTE = 10
97
CODE_TERMINATOR = 0xff
98
99
endian :big
100
101
uint8 :code
102
apache_jp_string :attribute_name, onlyif: -> { code == CODE_REQ_ATTRIBUTE }
103
apache_jp_string :attribute_value, onlyif: -> { code != CODE_TERMINATOR }
104
end
105
106
class ApacheJPForwardRequest < BinData::Record
107
HTTP_METHOD_OPTIONS = 1
108
HTTP_METHOD_GET = 2
109
HTTP_METHOD_HEAD = 3
110
HTTP_METHOD_POST = 4
111
HTTP_METHOD_PUT = 5
112
HTTP_METHOD_DELETE = 6
113
HTTP_METHOD_TRACE = 7
114
HTTP_METHOD_PROPFIND = 8
115
HTTP_METHOD_PROPPATCH = 9
116
HTTP_METHOD_MKCOL = 10
117
HTTP_METHOD_COPY = 11
118
HTTP_METHOD_MOVE = 12
119
HTTP_METHOD_LOCK = 13
120
HTTP_METHOD_UNLOCK = 14
121
HTTP_METHOD_ACL = 15
122
HTTP_METHOD_REPORT = 16
123
HTTP_METHOD_VERSION_CONTROL = 17
124
HTTP_METHOD_CHECKIN = 18
125
HTTP_METHOD_CHECKOUT = 19
126
HTTP_METHOD_UNCHECKOUT = 20
127
HTTP_METHOD_SEARCH = 21
128
PREFIX_CODE = 2
129
130
endian :big
131
132
uint8 :prefix_code, value: PREFIX_CODE
133
uint8 :http_method
134
apache_jp_string :protocol, initial_value: 'HTTP/1.1'
135
apache_jp_string :req_uri
136
apache_jp_string :remote_addr
137
apache_jp_string :remote_host
138
apache_jp_string :server_name
139
uint16 :server_port, initial_value: -> { is_ssl ? 80 : 443 }
140
apache_jp_boolean :is_ssl, initial_value: false
141
uint16 :num_headers, initial_value: -> { headers.length }
142
array :headers, type: :apache_jp_request_header, initial_length: :num_headers
143
array :attributes, type: :apache_jp_request_attribute, read_until: -> { element.code == ApacheJPRequestAttribute::TERMINATOR }
144
end
145
146
class ApacheJPSendBodyChunk < BinData::Record
147
PREFIX_CODE = 3
148
149
endian :big
150
151
uint8 :prefix_code, value: PREFIX_CODE
152
uint16 :body_chunk_length, initial_value: -> { body_chunk.length }
153
string :body_chunk, read_length: :body_chunk_length
154
end
155
156
class ApacheJPSendHeaders < BinData::Record
157
PREFIX_CODE = 4
158
159
endian :big
160
161
uint8 :prefix_code, value: PREFIX_CODE
162
uint16 :http_status_code
163
apache_jp_string :http_status_msg
164
uint16 :num_headers, initial_value: -> { header.length }
165
array :headers, type: :apache_jp_response_header, initial_length: :num_headers
166
end
167
168
class ApacheJPEndResponse < BinData::Record
169
PREFIX_CODE = 5
170
171
endian :big
172
173
uint8 :prefix_code, value: PREFIX_CODE
174
apache_jp_boolean :reuse
175
end
176
177
class ApacheJPGetBodyChunk < BinData::Record
178
PREFIX_CODE = 6
179
180
endian :big
181
182
uint8 :prefix_code, value: PREFIX_CODE
183
uint16 :requested_length
184
end
185
end
186
187