Skip to content

Commit

Permalink
add data/payloads dir (mitre#776)
Browse files Browse the repository at this point in the history
* add data/payloads dir

* small changes to exfil handler to make upload logic more usable by plugins
  • Loading branch information
unkempthenry authored and david committed Nov 18, 2019
1 parent f8c4f3a commit 77ad3f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ conf/*.yml
!conf/default.yml
data/object_store
data/results/*
!data/results/.gitkeep
!data/results/.gitkeep
data/payloads/*
!data/payloads/.gitkeep
11 changes: 7 additions & 4 deletions app/service/file_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ async def download(self, request):
except Exception as e:
return web.HTTPNotFound(body=e)

async def upload(self, request):
async def upload_exfil(self, request):
exfil_dir = await self._create_exfil_sub_directory(request.headers)
return await self.save_multipart_file_upload(request, exfil_dir)

async def save_multipart_file_upload(self, request, target_dir):
"""
Accept a multipart file via HTTP and save it to the server
:param request:
:return: None
:param target_dir: The path of the directory to save the uploaded file to.
"""
try:
reader = await request.multipart()
exfil_dir = await self._create_exfil_sub_directory(request.headers)
while True:
field = await reader.next()
if not field:
break
filename = field.filename
with open(os.path.join(exfil_dir, filename), 'wb') as f:
with open(os.path.join(target_dir, filename), 'wb') as f:
while True:
chunk = await field.read_chunk()
if not chunk:
Expand Down
Empty file added data/payloads/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def init(address, port, services, users):
app.on_startup.append(background_tasks)

app.router.add_route('*', '/file/download', services.get('file_svc').download)
app.router.add_route('POST', '/file/upload', services.get('file_svc').upload)
app.router.add_route('POST', '/file/upload', services.get('file_svc').upload_exfil)

await attach_plugins(app, services)
runner = web.AppRunner(app)
Expand Down

0 comments on commit 77ad3f7

Please sign in to comment.