PDF-in-HTML: a creative approach to credential harvesting

Researcher g3tsyst3m has published an analysis of a technique that embeds a PDF into an HTML page through iframe, avoiding the JavaScript execution restrictions imposed by modern PDF readers. The technique harvests credentials through a fake modal prompt, using WebSocket as the communication channel.
The core idea Modern browsers sandbox the PDF renderer in a separate process, preventing them from access to the DOM and cookies. Rather than trying to bypass this sandbox, the researcher suggests embedding the PDF in an iframe within a regular HTML page. All JavaScript runs in the context of the surrounding page, which is not subject to the PDF reader's execution restrictions.
How the chain works
  1. The HTML file is opened from an email attachment or via a link. It appears as a page displaying a PDF.
  2. The page opens a WebSocket connection to the attacker's server (wss:// on port 443). WebSockets are not subject to the same client-side CORS restrictions as fetch or XMLHttpRequest: the browser does not block connections to another origin. During the handshake, the server receives the Origin header and can reject the connection if the origin is not allowed. However, this is a server-side check: the browser itself does not block cross-origin WebSocket connections.
  3. Instead of displaying the document content immediately, the page shows a Windows 11–styled modal prompt with the message: «This PDF is encrypted. Enter your username and password to open it»
  4. The entered username and password are sent to the server in a JSON frame named doc_auth. Each frame includes clientId, allowing the server to associate the credentials with a specific session.
  5. Once the credentials are submitted, the PDF becomes visible. The server also push additional modal prompts or files to the user's browser through the same WebSocket connection.
Network architecture. The setup consists of three components: a local console (ws_server.py), a VPS running the intermediary WebSocket relay (ws_listener.py) and Cloudflare Tunnel. The relay forwards WebSocket frames between the console and connected clients. No component exposes an inbound port to the public internet: all connections are initiated outbound. The user's browser connects to a Cloudflare domain, and traffic is forwarded through the tunnel to ws_listener.py, which routes frames by clientId and adds the client's IP address from the CF-Connecting-IP header.
Vendors
Products