2024-06-24 12:43:02 +03:00
|
|
|
from mitmproxy.tools.dump import DumpMaster
|
|
|
|
from mitmproxy import options,http
|
2024-06-18 08:17:48 +03:00
|
|
|
import os
|
2024-06-18 09:33:54 +03:00
|
|
|
|
2024-06-24 12:43:02 +03:00
|
|
|
#https://upgrade.mikrotik.com/routeros/NEWESTa7.stable
|
|
|
|
#https://upgrade.mikrotik.com/routeros/7.15.1/CHANGELOG
|
|
|
|
|
|
|
|
|
2024-06-18 09:33:54 +03:00
|
|
|
class UpgradeAddon:
|
2024-06-24 12:43:02 +03:00
|
|
|
def __init__(self, upstream_server):
|
|
|
|
self.upstream_server = upstream_server
|
2024-06-18 08:17:48 +03:00
|
|
|
def request(self,flow: http.HTTPFlow) -> None:
|
2024-06-24 12:43:02 +03:00
|
|
|
flow.request.host = self.upstream_server
|
|
|
|
flow.request.scheme = "https"
|
|
|
|
flow.request.port = 443
|
|
|
|
print(flow.request.url)
|
2024-06-18 08:17:48 +03:00
|
|
|
if len(flow.request.path_components)==3 and flow.request.path_components[0] == 'routeros':
|
|
|
|
version = flow.request.path_components[1]
|
|
|
|
file = os.path.join(version,flow.request.path_components[2])
|
|
|
|
if flow.request.method == 'HEAD':
|
|
|
|
if os.path.exists(version) and os.path.isfile(file):
|
|
|
|
flow.response = http.Response.make(
|
|
|
|
status_code=200,
|
|
|
|
headers={
|
|
|
|
'Content-Type': 'application/octet-stream',
|
|
|
|
'Accept-Ranges':'bytes',
|
|
|
|
'Content-Length': str(os.stat(file).st_size),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
flow.response = http.Response.make(status_code=404)
|
|
|
|
elif flow.request.method == 'GET' and flow.request.path_components[2].endswith('.npk'):
|
|
|
|
if os.path.exists(version) and os.path.isfile(file):
|
|
|
|
flow.response = http.Response.make(
|
|
|
|
status_code=200,
|
|
|
|
content=open(file,'rb').read(),
|
|
|
|
headers={'Content-Type': 'application/octet-stream',},
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
flow.response = http.Response.make(status_code=404)
|
2024-06-18 09:33:54 +03:00
|
|
|
|
2024-06-18 08:17:48 +03:00
|
|
|
async def start_listen(port):
|
2024-06-24 12:43:02 +03:00
|
|
|
opts = options.Options(listen_host='0.0.0.0',listen_port=port)
|
|
|
|
upstream_server = "upgrade.mikrotik.com"
|
2024-06-18 08:17:48 +03:00
|
|
|
master = DumpMaster(opts)
|
2024-06-24 12:43:02 +03:00
|
|
|
master.addons.add(UpgradeAddon(upstream_server))
|
2024-06-18 08:17:48 +03:00
|
|
|
try:
|
|
|
|
await master.run()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
master.shutdown()
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import asyncio
|
|
|
|
from package import check_install_package
|
|
|
|
check_install_package(['mitmproxy'])
|
|
|
|
print(f'ip dns static add name=upgrade.mikrotik.com address=<your ip address>')
|
|
|
|
print(f'ip dns cache flush')
|
2024-06-24 12:43:02 +03:00
|
|
|
asyncio.run(start_listen(80))
|
|
|
|
|
|
|
|
|