Телеграм: https://t.me/js_is_easy
Оригинальное видео
Как открыть приложения Telegram в браузере? / Безопасность браузера
window.Telegram.WebApp = {...window.Telegram.WebApp, platform: 'android'}
<script>
(function() {
function replaceTelegramPlatform() {
if (typeof window.Telegram !== 'undefined' && typeof window.Telegram.WebApp !== 'undefined') {
window.Telegram.WebApp = {...window.Telegram.WebApp, platform: 'android'}
} else {
requestAnimationFrame(replaceTelegramPlatform); // Планируем следующую проверку
}
}
requestAnimationFrame(replaceTelegramPlatform); // Запускаем первую проверку
})();
</script>
const DEFAULT_HEADERS = {
Connection: "keep-alive",
"User-Agent":
"Mozilla/5.0 (Linux; Android 13; Pixel 7a Build/TQ3A.230605.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Mobile Safari/537.36",
"Content-Type": "application/json",
accept: "application/json",
"X-Requested-With": "org.telegram.messenger.web",
"Sec-Fetch-Site": "same-site",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"accept-encoding": "gzip, deflate",
"accept-language": "en,en-US;q=0.9",
};
from mitmproxy import http
# Мобильные заголовки
ENFORCED_HEADERS = {
"Connection": "keep-alive",
"User-Agent": "Mozilla/5.0 (Linux; Android 13; Pixel 7a Build/TQ3A.230605.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.114 Mobile Safari/537.36",
"X-Requested-With": "org.telegram.messenger.web",
"Sec-Fetch-Site": "same-site",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty"
}
# X-Frame заголовки
SECURITY_HEADERS = [
"X-Frame-Options",
"Content-Security-Policy"
]
# Список домены, запросы которых нунжно модифицировать
WHITELIST_DOMAINS = ["hamsterkombat", "blum", 'muskempire']
# Домены аналитики. Запросы на эти домены будут отменены
ANALYTICS_DOMAINS = ["sentry", "posthog", 'google-analytics']
def is_whitelisted(url: str) -> bool:
return any(domain in url for domain in WHITELIST_DOMAINS)
def is_analytics_request(flow: http.HTTPFlow) -> bool:
return any(analytics_domain in flow.request.pretty_url for analytics_domain in ANALYTICS_DOMAINS)
def request(flow: http.HTTPFlow) -> None:
if is_whitelisted(flow.request.pretty_url):
flow.request.headers.update(ENFORCED_HEADERS)
if is_whitelisted(flow.request.headers.get("Origin", "")):
if is_analytics_request(flow):
flow.response = http.Response.make(403, b"Request blocked", {"Content-Type": "text/plain"})
return
def response(flow: http.HTTPFlow) -> None:
if is_whitelisted(flow.request.pretty_url):
for header in SECURITY_HEADERS:
flow.response.headers.pop(header, None)
# Модификация контента telegram-web-app.js скрипта
if "telegram-web-app.js" in flow.request.pretty_url:
try:
original_body = flow.response.content.decode('utf-8')
modified_body = original_body.replace('return webAppPlatform;', 'return "android";')
flow.response.content = modified_body.encode('utf-8')
except Exception as e:
print(f"Error modifying response: {e}")