sao: add encrtped response

This commit is contained in:
Hay1tsme 2023-11-09 20:56:03 -05:00
parent 8769c99f4a
commit 840db275fa

View File

@ -6,6 +6,7 @@ from logging.handlers import TimedRotatingFileHandler
from os import path from os import path
from Crypto.Cipher import Blowfish from Crypto.Cipher import Blowfish
from hashlib import md5 from hashlib import md5
import random
from core import CoreConfig, Utils from core import CoreConfig, Utils
from core.title import BaseServlet from core.title import BaseServlet
@ -87,10 +88,10 @@ class SaoServlet(BaseServlet):
return (True, "SAO1") return (True, "SAO1")
def render_POST(self, request: Request, game_code: str, matchers: Dict) -> bytes: def render_POST(self, request: Request, game_code: str, matchers: Dict) -> bytes:
endpoint = matchers.get('endpoint', '') endpoint = matchers.get('endpoint', '')
request.responseHeaders.addRawHeader(b"content-type", b"text/html; charset=utf-8") request.responseHeaders.addRawHeader(b"content-type", b"text/html; charset=utf-8")
iv = b""
req_raw = request.content.read() req_raw = request.content.read()
sao_request = req_raw.hex() sao_request = req_raw.hex()
@ -103,7 +104,6 @@ class SaoServlet(BaseServlet):
return b"" return b""
if self.game_cfg.crypt.enable: if self.game_cfg.crypt.enable:
iv = req_raw[40:48] iv = req_raw[40:48]
cipher = Blowfish.new(self.game_cfg.crypt.key, Blowfish.MODE_CBC, iv) cipher = Blowfish.new(self.game_cfg.crypt.key, Blowfish.MODE_CBC, iv)
crypt_data = req_raw[48:] crypt_data = req_raw[48:]
@ -125,4 +125,11 @@ class SaoServlet(BaseServlet):
self.logger.debug(f"Request: {request.content.getvalue().hex()}") self.logger.debug(f"Request: {request.content.getvalue().hex()}")
resp = handler(sao_request) resp = handler(sao_request)
self.logger.debug(f"Response: {resp.hex()}") self.logger.debug(f"Response: {resp.hex()}")
if self.game_cfg.crypt.enable:
iv = random.randbytes(8)
cipher = Blowfish.new(self.game_cfg.crypt.key, Blowfish.MODE_CBC, iv)
data_crypt = cipher.encrypt(resp[24:])
resp = resp[:24] + iv + data_crypt
return resp return resp