/* Sitio EternalBlue — scroll-scrubbed film page.
   The scroll chrome comes from scroll-world-film.js (adapted from
   oso95/scroll-world); the film itself is the composition stage from
   lab-scene.jsx, seeked by scroll instead of by its own clock. */
(function () {
  const MONO = "'IBM Plex Mono', ui-monospace, monospace";
  const DISP = "'Bricolage Grotesque', system-ui, sans-serif";
  const ACID = '#e6ff2e';
  const INK = '#e9edf1';
  const DIM = '#79828d';
  const FAINT = '#4b535c';
  const PDF = 'informe-eternalblue-itse.pdf';

  const SECTIONS = [
    { id: 'apertura', label: 'Inicio', dur: 7, accent: ACID,
      eyebrow: 'Proyecto final · Análisis de Vulnerabilidades',
      title: 'MS17-010, de la teoría al control total',
      body: 'Recorrido completo del análisis: reconocimiento, detección, explotación y los controles que cierran la ruta.',
    },
    { id: 'entorno', label: 'Entorno', dur: 10, accent: ACID,
      eyebrow: 'Etapas 1 y 2',
      title: 'Dos máquinas en una red aislada',
      body: 'El atacante corre Kali Linux en 192.168.0.17. El objetivo es un Windows 7 Ultimate SP1 de 64 bits en 192.168.0.16, dentro de la misma subred. Ningún tráfico sale del laboratorio.',
      tags: ['Kali Linux', 'Windows 7 SP1', '192.168.0.0/24'] },
    { id: 'reconocimiento', label: 'Reconocimiento', dur: 13, accent: ACID,
      eyebrow: 'Etapa 3',
      title: 'Nmap responde qué hay del otro lado',
      body: 'El barrido descubre 13 hosts activos y, en el objetivo, los puertos 135, 139 y 445 abiertos sobre un sistema Windows. El 445 es SMB: la puerta.',
      tags: ['nmap -sS -sV -O', '445/tcp abierto', 'AUDITOR-PC'] },
    { id: 'deteccion', label: 'Detección', dur: 12, accent: ACID,
      eyebrow: 'Etapas 4 a 6',
      title: 'El escáner confirma la sospecha',
      body: 'El módulo auxiliary/scanner/smb/smb_ms17_010 de Metasploit reporta que el host es probablemente vulnerable a MS17-010 y devuelve la huella exacta del sistema.',
      tags: ['Metasploit', 'smb_ms17_010', 'VULNERABLE'] },
    { id: 'amenaza', label: 'La amenaza', dur: 10, accent: ACID,
      eyebrow: 'Clasificación y CVE',
      title: 'La misma falla que movió a WannaCry',
      body: 'El boletín MS17-010 agrupa seis CVE. Aquí se explota CVE-2017-0144: ejecución remota de código sin autenticación sobre SMBv1, el vector que propagó WannaCry y NotPetya en 2017.',
      tags: ['CVE-2017-0144', 'SMBv1', 'RCE sin autenticación'] },
    { id: 'armado', label: 'Armado', dur: 11, accent: '#ff4d3d',
      eyebrow: 'Etapas 8 a 12',
      title: 'El primer intento no entra',
      body: 'Con ms17_010_psexec y un payload reverse_http el módulo no encuentra un named pipe accesible y no se crea la sesión. Un mismo fallo puede exigir otra técnica.',
      tags: ['ms17_010_psexec', 'reverse_http', 'sin sesión'] },
    { id: 'explotacion', label: 'Explotación', dur: 15, accent: ACID,
      eyebrow: 'Etapas 13 y 14',
      title: 'EternalBlue sí entra',
      body: 'El exploit trabaja el pool no paginado del kernel con 12 groom allocations, lo sobrescribe y entrega el payload. Sesión Meterpreter abierta contra 192.168.0.17:4444.',
      tags: ['ms17_010_eternalblue', 'x64/meterpreter', 'sesión 1'] },
    { id: 'post', label: 'Post-explotación', dur: 13, accent: ACID,
      eyebrow: 'Etapas 15 y 16',
      title: 'Una carpeta como prueba de concepto',
      body: 'Desde Meterpreter se llega al escritorio del usuario auditor y se crea la carpeta PITA con mkdir. La evidencia aparece en la pantalla de la víctima.',
      tags: ['meterpreter', 'mkdir PITA', 'C:\\Users\\auditor'] },
    { id: 'tunel', label: 'El túnel', dur: 9, accent: ACID,
      eyebrow: 'Etapa 17',
      title: 'La conexión queda a la vista',
      body: 'netstat -an en el equipo comprometido muestra 192.168.0.16:49225 hacia 192.168.0.17:4444 en estado ESTABLISHED. El túnel es observable desde la propia víctima.',
      tags: ['netstat', '4444/tcp', 'ESTABLISHED'] },
    { id: 'controles', label: 'Controles', dur: 14, accent: ACID,
      eyebrow: 'NIST CSF 2.0',
      title: 'Del hallazgo al control',
      body: 'Seis controles repartidos en Gobernar, Identificar, Proteger, Detectar, Responder y Recuperar. Tres quedan comprobados con la evidencia del propio laboratorio.',
      tags: ['Identificar', 'Proteger', 'Detectar'] },
    { id: 'cierre', label: 'Cierre', dur: 8, accent: ACID,
      eyebrow: 'Conclusión',
      title: 'Un parche de 2017 sigue siendo la diferencia',
      body: 'Aplicar MS17-010, deshabilitar SMBv1 y segmentar la red cierra la ruta completa que acabas de recorrer.' },
  ];

  const REFS = [
    ['Microsoft (2017)', 'Security bulletin MS17-010 (KB4013389)', 'https://learn.microsoft.com/security-updates/securitybulletins/2017/ms17-010'],
    ['NVD (2017)', 'CVE-2017-0144 detail', 'https://nvd.nist.gov/vuln/detail/CVE-2017-0144'],
    ['NIST (2024)', 'Cybersecurity Framework (CSF) 2.0', 'https://doi.org/10.6028/NIST.CSWP.29'],
    ['MITRE', 'Exploitation of remote services (T1210)', 'https://attack.mitre.org/techniques/T1210/'],
    ['Rapid7', 'MS17-010 EternalBlue — módulo de Metasploit', 'https://www.rapid7.com/db/modules/exploit/windows/smb/ms17_010_eternalblue/'],
    ['Nmap Project', 'Nmap: the network mapper', 'https://nmap.org/'],
    ['Offensive Security', 'Kali Linux', 'https://www.kali.org/'],
  ];

  function LabSite() {
    const worldRef = React.useRef(null);
    const [t, setT] = React.useState(0);
    const [mobile, setMobile] = React.useState(() => window.matchMedia('(max-width: 860px)').matches);

    React.useEffect(() => {
      const mq = window.matchMedia('(max-width: 860px)');
      const on = () => setMobile(mq.matches);
      mq.addEventListener ? mq.addEventListener('change', on) : mq.addListener(on);
      return () => { mq.removeEventListener ? mq.removeEventListener('change', on) : mq.removeListener(on); };
    }, []);

    React.useEffect(() => {
      if (!worldRef.current || !window.mountScrollWorldFilm) return;
      let last = -1;
      const seek = (v) => { if (Math.abs(v - last) < 0.008) return; last = v; setT(v); };
      mountScrollWorldFilm(worldRef.current, {
        brand: { logo: 'logo-itse-white.svg', href: '#apertura' },
        nav: false,
        meta: { label: 'Integrantes',
                names: 'Carlos Araúz · Gloria Pita · Carolina Osorio · Milkia Rodríguez',
                group: 'D-CS-4-1 · Técnico Superior en Ciberseguridad' },
        hint: 'desplázate para recorrer el ataque',
        vhPerSecond: 0.17,
        sections: SECTIONS,
        onScrub: seek,
      });
    }, []);

    const filmStyle = mobile
      ? { position: 'fixed', zIndex: 10, left: 0, right: 0, top: 78, height: '52vh', pointerEvents: 'none' }
      : { position: 'fixed', zIndex: 10, left: 'min(37vw, 540px)', right: 0, top: 'clamp(56px,6vh,86px)', bottom: 0, pointerEvents: 'none' };

    return (
      <div style={{ position: 'relative', background: '#07080a', minHeight: '100vh' }}>
        <div className="sw-film" style={filmStyle}>
          <WorldPanel t={t} />
        </div>

        <div ref={worldRef} style={{ position: 'relative' }} />

        <footer data-sw-credits="true" style={{
          position: 'relative', zIndex: 30, background: '#0a0c0f', borderTop: '1px solid rgba(255,255,255,0.09)',
          minHeight: '100vh', display: 'flex', alignItems: 'center',
          padding: 'clamp(56px,8vh,110px) clamp(18px,4vw,56px)',
        }}>
          <div style={{ display: 'grid', gridTemplateColumns: mobile ? '1fr' : '1.1fr 1fr 1fr', gap: 'clamp(32px,4vw,64px)', maxWidth: 1600, margin: '0 auto', width: '100%' }}>
            <div>
              <img src="logo-itse-white.svg" alt="ITSE" style={{ height: 'clamp(44px,4vw,64px)', display: 'block' }} />
              <div style={{ font: `400 clamp(15px,1.15vw,19px)/1.7 ${DISP}`, color: DIM, marginTop: 28, maxWidth: '40ch', textWrap: 'pretty' }}>
                Explotación de la vulnerabilidad MS17-010 (EternalBlue). Asignatura de Análisis de Vulnerabilidades, docente Jorge Macías.
              </div>
              <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, marginTop: 26 }}>
                <a href={PDF} download="Informe-EternalBlue-MS17-010-ITSE.pdf" style={{ font: `500 12px ${MONO}`, letterSpacing: '.1em', textTransform: 'uppercase', color: '#07080a', background: ACID, padding: '12px 20px', borderRadius: 999, textDecoration: 'none' }}>Informe completo</a>
              </div>
            </div>

            <div>
              <div style={{ font: `500 12px ${MONO}`, letterSpacing: '.2em', textTransform: 'uppercase', color: FAINT }}>Equipo</div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 'clamp(12px,1.4vh,20px)', marginTop: 26 }}>
                {['Carlos Araúz', 'Gloria Pita', 'Carolina Osorio', 'Milkia Rodríguez'].map((n) => (
                  <div key={n} style={{ font: `500 clamp(19px,1.6vw,28px) ${DISP}`, color: INK }}>{n}</div>
                ))}
              </div>
            </div>

            <div>
              <div style={{ font: `500 12px ${MONO}`, letterSpacing: '.2em', textTransform: 'uppercase', color: FAINT }}>Referencias</div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 14, marginTop: 22 }}>
                {REFS.map(([who, what, href]) => (
                  <a key={what} href={href} target="_blank" rel="noreferrer"
                     style={{ textDecoration: 'none', display: 'block' }}>
                    <span style={{ font: `400 12px ${MONO}`, letterSpacing: '.08em', color: FAINT, display: 'block' }}>{who}</span>
                    <span style={{ font: `400 15px/1.4 ${DISP}`, color: DIM }}>{what}</span>
                  </a>
                ))}
              </div>
            </div>
          </div>
        </footer>
      </div>
    );
  }

  window.LabSite = LabSite;
})();
