modified: README.md

modified:   README_CN.md
	modified:   netinstall.py
	deleted:    upgrade.py
This commit is contained in:
zyb 2024-07-14 22:16:10 +08:00
parent f993d41a7a
commit 96515d2333
4 changed files with 6 additions and 68 deletions

View File

@ -30,9 +30,8 @@
### patch.py
Patch public key and sign NPK files
### netinstall.py
Modify netinstallexe to enable network installation of NPK files that have been resigned in ISO
### upgrade.py
By adding static domain name resolution in RouterOS, the NPK file that has been resigned in ISO can be installed during the upgrade process.
Patch netinstall to enable network installation of NPK files that have been resigned in ISO
## all patches are applied automatically with [Github Action](https://github.com/elseif/MikroTikPatch/blob/main/.github/workflows/mikrotik_patch.yml).

View File

@ -31,9 +31,8 @@
### patch.py
替换公钥并签名
### netinstall.py
替换 netinstallexe 中的bootloader的公钥使通过网络安装时可以安装ISO文件内的npk文件
### upgrade.py
在RouterOS内增加静态域名解析使升级时可以安装ISO文件内的npk文件
替换 netinstall 中的 bootloader 的公钥使通过网络安装时可以安装ISO文件内的npk文件
## 所有的修补操作都自动运行在[Github Action](https://github.com/elseif/MikroTikPatch/blob/main/.github/workflows/mikrotik_patch.yml)。

View File

@ -132,7 +132,6 @@ def patch_netinstall(key_dict: dict,input_file,output_file=None):
STRING_TABLE_INDEX = struct.unpack_from(b'<H',netinstall[0x32:])[0]
section_name_offset = SECTION_HEADER_OFFSET_IN_FILE + STRING_TABLE_INDEX * SECTION_HEADER_ENTRY_SIZE + 16
SECTION_NAME_BLOCK = struct.unpack_from(b'<I',netinstall[section_name_offset:])[0]
for i in range(NUMBER_OF_SECTION_HEADER_ENTRIES):
section_offset = SECTION_HEADER_OFFSET_IN_FILE + i * SECTION_HEADER_ENTRY_SIZE
name_offset,_,_,addr,offset = struct.unpack_from('<IIIII',netinstall[section_offset:])
@ -145,9 +144,9 @@ def patch_netinstall(key_dict: dict,input_file,output_file=None):
offset = re.search(rb'\x83\x00\x00\x00.{12}\x8A\x00\x00\x00.{12}\x81\x00\x00\x00.{12}',netinstall).start()
print(f'found bootloaders offset {hex(offset)}')
for i in range(10):
id,name_ptr,boot_ptr,boot_size = struct.unpack_from('<IIII',netinstall[offset+i*16:offset+i*16+16])
id,name_ptr,data_ptr,data_size = struct.unpack_from('<IIII',netinstall[offset+i*16:offset+i*16+16])
name = netinstall[text_section_offset+name_ptr-text_section_addr:].split(b'\0')[0]
data = netinstall[text_section_offset+boot_ptr-text_section_addr:text_section_offset+boot_ptr-text_section_addr+boot_size]
data = netinstall[text_section_offset+data_ptr-text_section_addr:text_section_offset+data_ptr-text_section_addr+data_size]
print(f'found {name.decode()}({id}) bootloader')
try:
if data[:2] == b'MZ':

View File

@ -1,59 +0,0 @@
from mitmproxy.tools.dump import DumpMaster
from mitmproxy import options,http
import os
#https://upgrade.mikrotik.com/routeros/NEWESTa7.stable
#https://upgrade.mikrotik.com/routeros/7.15.1/CHANGELOG
class UpgradeAddon:
def __init__(self, upstream_server):
self.upstream_server = upstream_server
def request(self,flow: http.HTTPFlow) -> None:
flow.request.host = self.upstream_server
flow.request.scheme = "https"
flow.request.port = 443
print(flow.request.url)
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)
async def start_listen(port):
opts = options.Options(listen_host='0.0.0.0',listen_port=port)
upstream_server = "upgrade.mikrotik.com"
master = DumpMaster(opts)
master.addons.add(UpgradeAddon(upstream_server))
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')
asyncio.run(start_listen(80))