-
Notifications
You must be signed in to change notification settings - Fork 231
/
server.rb
243 lines (197 loc) · 5 KB
/
server.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# encoding: ASCII-8BIT
require 'rubygems'
require 'sinatra'
require 'json'
require 'fileutils'
require 'optparse'
require 'json'
require 'sequel'
require 'yaml'
require './lib/util'
require './lib/lib'
if not File.file?('./db/master.db')
puts "|+| Database does not exist, initializing a blank one."
out_file = File.new("./db/master.db", "w")
out_file.puts("")
out_file.close
DB = Sequel.sqlite("#{Dir.pwd}/db/master.db")
DB.create_table :oxfiles do
primary_key :id
String :filename
String :location
String :desc
String :type
DateTime :created_at
DateTime :updated_at
end
end
require './lib/model'
# TODO apply to all xml in docx
# TODO explain each menu item in help
# TODO soft link content types
set :public_folder, File.dirname(__FILE__) + '/public'
set :protocols, ["http","https","ftp","jar","file","netdoc","mailto","gopher","none"]
set :types, ["docx","pptx","xlsx","svg","odt","xml","odg","odp","ods"]
set :poc_types, ["pdf","jpg","gif"]
# Keep the payloads organized
set :payloads, read_payloads()
get '/' do
redirect to("/build")
end
get '/build' do
@types = settings.types
@payloads = settings.payloads
@protos = settings.protocols
slim :build
end
post '/build' do
fn = build_file(params)
# write entry to database
x = Oxfile.new
x.filename = fn.split('/').last
x.location = fn
x.desc = clean_html(params["desc"])
x.type = params["file_type"]
x.save
send_file(fn, :filename => "#{fn.split('/').last}")
end
get '/replace' do
@types = settings.types
@payloads = settings.payloads
@protos = settings.protocols
slim :replace
end
post '/replace' do
fn = replace_file(params)
# write entry to database
x = Oxfile.new
x.filename = fn.split('/').last
x.location = fn
x.desc = clean_html(params["desc"])
x.type = fn.split('.').last
x.save
send_file(fn, :filename => "#{fn.split('/').last}")
end
get '/xss' do
slim :xss
end
post '/xss' do
if params[:file] == nil
raise StandardError, "Error: no file included"
end
input_file = params[:file][:tempfile].read
nname = "temp_#{Time.now.to_i}_"
ext = params[:file][:filename].split('.').last
rand_file = "./output/#{nname}_z.#{ext}"
File.open(rand_file, 'wb') {|f| f.write(input_file) }
# TODO add an option to add an xss wherever
# TODO logic check if svg or xml
# TODO modify uri
# TODO add a supported types box
# TODO add a non-entity replacement option
xss = "<!DOCTYPE root [<!ENTITY xxe \"#{params[:xss]}\">]>"
xss = "<!DOCTYPE root [<!ENTITY xxe \"<![CDATA[#{params[:xss]}]>\">]>" if params[:cdata]
fn = string_replace(xss,rand_file,"","")
if fn == "|-|"
error = "|-| Could not find § in document, please verify."
puts error
slim :error
else
# write entry to database
file = Oxfile.new
file.filename = fn.split('/').last
file.location = fn
file.desc = clean_html(params["desc"])
file.type = fn.split('.').last
file.save
send_file(fn, :filename => "#{fn.split('/').last}")
end
end
get '/poc' do
@types = settings.poc_types
@protos = settings.protocols
slim :poc
end
post '/poc' do
if params["proto"] == "none"
ip = params["hostname"]
else
# TODO is this correct for all protocols?
ip = params["proto"]+"://"+params["hostname"]
end
if params["file_type"] == "pdf"
fn = pdf_poc(ip)
elsif params["file_type"] == "gif"
fn = gif_poc(ip)
elsif params["file_type"] == "jpg"
fn = jpg_poc(ip)
end
# write entry to database
file = Oxfile.new
file.filename = fn.split('/').last
file.location = fn
file.desc = clean_html(params["desc"])
file.type = params["file_type"]
file.save
send_file fn, :type => params["file_type"], :filename => "#{fn.split('/').last}"
end
get '/list' do
@files = Oxfile.all
slim :list
end
get '/download' do
# check if params is set
file = Oxfile.first(:id => params["id"])
send_file file.location, :filename => file.filename
end
get '/display' do
slim :display
end
post '/display_file' do
if params[:file] == nil
raise StandardError, "Error: no file included"
end
input_file = params[:file][:tempfile].read
nname = "temp_#{Time.now.to_i}_"
ext = params[:file][:filename].split('.').last
rand_file = "./output/#{nname}_z.#{ext}"
File.open(rand_file, 'wb') {|f| f.write(input_file) }
@files = display_file(rand_file)
slim :display_file
end
get '/view_file' do
if params[:id] == nil
raise StandardError, "Error: no file included"
end
file = Oxfile.first(:id => params["id"])
rand_file = file.location
@files = display_file(rand_file)
slim :display_file
end
get '/delete' do
file = Oxfile.first(:id => params["id"])
if file == nil
redirect '/list'
end
file.destroy if file
File.delete(file.location) if file.location
redirect '/list'
end
get '/help' do
@payloads = read_payloads()
slim :help
end
get '/overwrite' do
slim :overwrite
end
post '/overwrite' do
fn = overwrite_xml(params)
# write entry to database
file = Oxfile.new
file.filename = fn.split('/').last
file.location = fn
file.desc = clean_html(params["desc"])
file.type = fn.split('.').last
file.save
send_file(fn, :filename => "#{fn.split('/').last}")
end