Skip to content
RCE Write-up Advanced

Method Confusion In Go SSTIs Lead To File Read And RCE.

The report shows that Go's html/template and text/template modules allow calling methods on the data object passed to the template, and that exported methods like Echo's File can be abused to read local files or execute commands. An attacker who controls the template string could read arbitrary files or run commands on the server.

onsecurity.io

Published on onsecurity.io

Although SSTI’s have been thoroughly researched in common web languages such as PHP and Python, I noticed a lack in research towards Go’s builtin html/template module (apart from this writeup, which explains how to achieve XSS).

The author, on onsecurity.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, the template engine allows calling any exported method on the data object passed to the template, and if the template string is user-controlled, this can be abused to invoke dangerous methods.

What the attacker needed

User-controlled template string; data object with exported dangerous method

How it was found

  1. Create a Go program that parses a template from user input and executes it with a data object that has an exported method performing a dangerous action.
  2. Pass a template string that calls that method with a parameter, such as a command to execute.
  3. Observe that the method is called and its output is included in the rendered template.
  4. For file read, use a web framework like Echo that has a File method, and call it with a file path.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A template engine lets a program mix fixed text with data to produce web pages. If an attacker can insert their own template code, they can call methods on the data object, and some of those methods can read files or run commands. This report shows that Go's template engines allow such method calls, which can lead to serious attacks.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.