[util] implement 'decrypt_xor()'

This commit is contained in:
Mike Fährmann
2025-03-04 16:32:27 +01:00
parent b5c1bf3f59
commit 5486a9c429
3 changed files with 19 additions and 27 deletions

View File

@@ -11,7 +11,6 @@
from .common import Extractor
from .lolisafe import LolisafeAlbumExtractor
from .. import text, util, config, exception
import binascii
import random
if config.get(("extractor", "bunkr"), "tlds"):
@@ -175,7 +174,8 @@ class BunkrAlbumExtractor(LolisafeAlbumExtractor):
url, method="POST", headers=headers, json={"id": data_id}).json()
if data.get("encrypted"):
file_url = self._decrypt_url(data["url"], data["timestamp"])
key = "SECRET_KEY_{}".format(data["timestamp"] // 3600)
file_url = util.decrypt_xor(data["url"], key.encode())
else:
file_url = data["url"]
@@ -192,16 +192,6 @@ class BunkrAlbumExtractor(LolisafeAlbumExtractor):
"_http_validate": self._validate,
}
def _decrypt_url(self, encrypted_b64, timestamp):
encrypted_bytes = binascii.a2b_base64(encrypted_b64)
key = "SECRET_KEY_{}".format(timestamp // 3600).encode()
div = len(key)
return bytes([
encrypted_bytes[i] ^ key[i % div]
for i in range(len(encrypted_bytes))
]).decode()
def _validate(self, response):
if response.history and response.url.endswith("/maintenance-vid.mp4"):
self.log.warning("File server in maintenance mode")

View File

@@ -9,8 +9,7 @@
"""Extractors for Chevereto galleries"""
from .common import BaseExtractor, Message
from .. import text
import binascii
from .. import text, util
class CheveretoExtractor(BaseExtractor):
@@ -33,18 +32,6 @@ class CheveretoExtractor(BaseExtractor):
url = text.extr(page, '<a data-pagination="next" href="', '" ><')
def _decrypt_url(self, encrypted_b64):
encrypted_hex = binascii.a2b_base64(encrypted_b64)
encrypted_bytes = bytes.fromhex(encrypted_hex.decode())
key = b"seltilovessimpcity@simpcityhatesscrapers"
div = len(key)
return bytes([
encrypted_bytes[i] ^ key[i % div]
for i in range(len(encrypted_bytes))
]).decode()
BASE_PATTERN = CheveretoExtractor.update({
"jpgfish": {
@@ -75,7 +62,9 @@ class CheveretoImageExtractor(CheveretoExtractor):
pos = page.find(" download=")
url = text.rextract(page, 'href="', '"', pos)[0]
if not url.startswith("https://"):
url = self._decrypt_url(url)
url = util.decrypt_xor(
url, b"seltilovessimpcity@simpcityhatesscrapers",
fromhex=True)
image = {
"id" : self.path.rpartition(".")[2],

View File

@@ -48,6 +48,19 @@ def bdecode(data, alphabet="0123456789"):
return num
def decrypt_xor(encrypted, key, base64=True, fromhex=False):
if base64:
encrypted = binascii.a2b_base64(encrypted)
if fromhex:
encrypted = bytes.fromhex(encrypted.decode())
div = len(key)
return bytes([
encrypted[i] ^ key[i % div]
for i in range(len(encrypted))
]).decode()
def advance(iterable, num):
""""Advance 'iterable' by 'num' steps"""
iterator = iter(iterable)