Files
metasploit-gs/documentation/api/v1/loot_api_doc.rb
T

249 lines
8.6 KiB
Ruby
Raw Normal View History

2018-04-26 11:24:05 -05:00
require 'swagger/blocks'
module LootApiDoc
include Swagger::Blocks
2018-05-22 14:57:21 -05:00
HOST_ID_DESC = 'The ID of the host record this loot is associated with.'
2018-05-08 15:41:17 -05:00
HOST_DESC = 'The IP address of the host from where the loot was obtained.'
2018-05-22 14:57:21 -05:00
SERVICE_ID_DESC = 'The ID of the service record this loot is associated with.'
2018-05-08 15:41:17 -05:00
LTYPE_DESC = 'The type of loot.'
LTYPE_EXAMPLE = "'file', 'image', 'config_file', etc."
PATH_DESC = 'The on-disk path to the loot file.'
PATH_EXAMPLE = '/path/to/file.txt'
DATA_DESC = "Base64 encoded copy of the file's contents."
DATA_EXAMPLE = 'dGhpcyBpcyB0aGUgZmlsZSdzIGNvbnRlbnRz'
2018-05-08 15:41:17 -05:00
CONTENT_TYPE_DESC = 'The mime/content type of the file at {#path}. Used to server the file correctly so browsers understand whether to render or download the file.'
CONTENT_TYPE_EXAMPLE = 'text/plain'
NAME_DESC = 'The name of the loot.'
NAME_EXAMPLE = 'password_file.txt'
INFO_DESC = 'Information about the loot.'
2018-05-22 14:57:21 -05:00
MODULE_RUN_ID_DESC = 'The ID of the module run record this loot is associated with.'
2018-05-08 15:41:17 -05:00
2019-01-10 12:45:28 -06:00
# Some of the attributes expect different data when doing a create.
CREATE_PATH_DESC = 'The name to give the file on the server. All files are stored in a server configured path, so a full path is not needed. If there is a corresponding file on disk, the given value will be prepended with a unique string to prevent accidental overwrites of other files.'
2019-01-10 12:45:28 -06:00
CREATE_PATH_EXAMPLE = 'password_file.txt'
2018-05-08 15:41:17 -05:00
2018-04-26 11:24:05 -05:00
# Swagger documentation for loot model
swagger_schema :Loot do
2018-05-17 16:56:22 -05:00
key :required, [:name, :ltype, :path]
2018-05-22 14:57:21 -05:00
property :id, type: :integer, format: :int32, description: RootApiDoc::ID_DESC
property :workspace_id, type: :integer, format: :int32, description: RootApiDoc::WORKSPACE_ID_DESC
property :host_id, type: :integer, format: :int32, description: HOST_ID_DESC
property :service_id, type: :integer, format: :int32, description: SERVICE_ID_DESC
2018-05-08 15:41:17 -05:00
property :ltype, type: :string, description: LTYPE_DESC, example: LTYPE_EXAMPLE
property :path, type: :string, description: PATH_DESC, example: PATH_EXAMPLE
property :data, type: :string, description: DATA_DESC, example: DATA_EXAMPLE
2018-05-08 15:41:17 -05:00
property :content_type, type: :string, description: CONTENT_TYPE_DESC, example: CONTENT_TYPE_EXAMPLE
property :name, type: :string, description: NAME_DESC, example: NAME_EXAMPLE
property :info, type: :string, description: INFO_DESC
2018-05-22 14:57:21 -05:00
property :module_run_id, type: :integer, format: :int32, description: MODULE_RUN_ID_DESC
property :created_at, type: :string, format: :date_time, description: RootApiDoc::CREATED_AT_DESC
property :updated_at, type: :string, format: :date_time, description: RootApiDoc::UPDATED_AT_DESC
2018-04-26 11:24:05 -05:00
end
2018-05-08 15:41:17 -05:00
swagger_path '/api/v1/loots' do
# Swagger documentation for /api/v1/loots GET
2018-04-26 11:24:05 -05:00
operation :get do
2018-05-17 16:56:22 -05:00
key :description, 'Return loot entries that are stored in the database.'
2018-04-30 16:40:07 -05:00
key :tags, [ 'loot' ]
2018-04-26 11:24:05 -05:00
parameter :workspace
response 200 do
2018-05-17 16:56:22 -05:00
key :description, 'Returns loot data.'
2018-04-26 11:24:05 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :type, :array
items do
key :'$ref', :Loot
end
2018-04-26 11:24:05 -05:00
end
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref', :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref', :ErrorModel
end
end
2018-04-26 11:24:05 -05:00
end
2018-05-08 15:41:17 -05:00
# Swagger documentation for /api/v1/loots POST
2018-04-26 11:24:05 -05:00
operation :post do
key :description, 'Create a loot entry.'
2018-04-30 16:40:07 -05:00
key :tags, [ 'loot' ]
2018-04-26 11:24:05 -05:00
parameter do
key :in, :body
key :name, :body
2018-05-17 16:56:22 -05:00
key :description, 'The attributes to assign to the loot.'
2018-04-26 11:24:05 -05:00
key :required, true
schema do
2018-05-22 14:57:21 -05:00
property :workspace, type: :string, required: true, description: RootApiDoc::WORKSPACE_POST_DESC, example: RootApiDoc::WORKSPACE_POST_EXAMPLE
property :host, type: :string, format: :ipv4, description: HOST_DESC, example: RootApiDoc::HOST_EXAMPLE
property :service, '$ref': :Service
2018-05-08 15:41:17 -05:00
property :ltype, type: :string, description: LTYPE_DESC, example: LTYPE_EXAMPLE, required: true
2019-01-10 12:45:28 -06:00
property :path, type: :string, description: CREATE_PATH_DESC, example: CREATE_PATH_EXAMPLE, required: true
property :data, type: :string, description: DATA_DESC, example: DATA_EXAMPLE
2018-05-08 15:41:17 -05:00
property :ctype, type: :string, description: CONTENT_TYPE_DESC, example: CONTENT_TYPE_EXAMPLE
property :name, type: :string, description: NAME_DESC, example: NAME_EXAMPLE, required: true
property :info, type: :string, description: INFO_DESC
2018-04-26 11:24:05 -05:00
end
end
response 200 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_200
2018-04-26 11:24:05 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :'$ref', :Loot
end
2018-04-26 11:24:05 -05:00
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref', :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref', :ErrorModel
end
end
2018-04-26 11:24:05 -05:00
end
# Swagger documentation for /api/v1/loot/ DELETE
operation :delete do
key :description, 'Delete the specified loot.'
2018-04-30 16:40:07 -05:00
key :tags, [ 'loot' ]
2018-04-26 11:24:05 -05:00
parameter :delete_opts
response 200 do
2018-07-26 08:43:05 -05:00
key :description, 'Returns an array containing the successfully deleted loot.'
2018-04-26 11:24:05 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :type, :array
items do
key :'$ref', :Loot
end
2018-04-26 11:24:05 -05:00
end
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref', :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref', :ErrorModel
end
end
2018-04-26 11:24:05 -05:00
end
end
2018-07-18 16:01:12 -05:00
swagger_path '/api/v1/loots/{id}' do
# Swagger documentation for api/v1/loots/:id GET
operation :get do
key :description, 'Return specific loot entry that is stored in the database.'
key :tags, [ 'loot' ]
parameter do
key :name, :id
key :in, :path
key :description, 'ID of loot to retrieve.'
key :required, true
key :type, :integer
key :format, :int32
end
response 200 do
key :description, 'Returns loot data.'
schema do
2018-07-25 18:01:05 -05:00
property :data do
2018-07-31 15:43:57 -05:00
key :'$ref', :Loot
2018-07-18 16:01:12 -05:00
end
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref', :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref', :ErrorModel
end
end
2018-07-18 16:01:12 -05:00
end
# Swagger documentation for /api/v1/loots/{id} PUT
2018-04-26 11:24:05 -05:00
operation :put do
2019-01-11 13:20:32 -05:00
key :description, 'Update the attributes on an existing loot.'
2018-04-30 16:40:07 -05:00
key :tags, [ 'loot' ]
2018-04-26 11:24:05 -05:00
parameter :update_id
parameter do
key :in, :body
key :name, :body
2018-05-17 16:56:22 -05:00
key :description, 'The updated attributes to overwrite to the loot.'
2018-04-26 11:24:05 -05:00
key :required, true
schema do
2019-01-16 10:42:00 -06:00
property :workspace, type: :string, required: true, description: RootApiDoc::WORKSPACE_POST_DESC, example: RootApiDoc::WORKSPACE_POST_EXAMPLE
property :host_id, type: :integer, format: :int32, description: HOST_ID_DESC
property :service_id, type: :integer, format: :int32, description: SERVICE_ID_DESC
property :ltype, type: :string, description: LTYPE_DESC, example: LTYPE_EXAMPLE, required: true
property :path, type: :string, description: CREATE_PATH_DESC, example: CREATE_PATH_EXAMPLE, required: true
property :ctype, type: :string, description: CONTENT_TYPE_DESC, example: CONTENT_TYPE_EXAMPLE
property :name, type: :string, description: NAME_DESC, example: NAME_EXAMPLE, required: true
property :info, type: :string, description: INFO_DESC
2018-04-26 11:24:05 -05:00
end
end
response 200 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_200
2018-04-26 11:24:05 -05:00
schema do
2018-07-25 18:01:05 -05:00
property :data do
key :'$ref', :Loot
end
2018-04-26 11:24:05 -05:00
end
end
2018-07-25 21:46:33 -05:00
2018-08-14 13:35:59 -05:00
response 401 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_401
2018-08-14 13:35:59 -05:00
schema do
key :'$ref', :AuthErrorModel
end
end
2018-07-25 21:46:33 -05:00
response 500 do
2018-08-15 15:26:35 -05:00
key :description, RootApiDoc::DEFAULT_RESPONSE_500
2018-07-25 21:46:33 -05:00
schema do
key :'$ref', :ErrorModel
end
end
2018-04-26 11:24:05 -05:00
end
end
2018-08-14 13:35:59 -05:00
end