Skip to content
RCE Write-up Intermediate

Bypassing dnsmasq dhcp-script limitations for command execution in config injection attacks

The text describes a class of vulnerability where devices fail to encode user input before generating dnsmasq configuration files, allowing newline injection of arbitrary options. An attacker who can set configuration options could inject directives that lead to command execution via dnsmasq's dhcp-script feature.

blog.nns.ee

Published on blog.nns.ee

When researching networking devices, I frequently encounter a particular vulnerability: the ability to inject arbitrary options into dnsmasq's config files. These devices often delegate functionality to dnsmasq, and when they allow users to set configuration options, they might perform basic templating to generate…

The author, on blog.nns.ee

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 device builds dnsmasq configuration files by templating user-supplied option values without encoding newline characters, so injected lines become new configuration directives.

What the attacker needed

Ability to set dnsmasq config options

The fix

User-supplied option values should be strictly validated and newline characters encoded or rejected before they are written into dnsmasq configuration files.

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.

Some devices let you type settings that they pass into a configuration file for a networking program called dnsmasq. If the device does not clean up special characters like line breaks, you can sneak in extra settings the device did not intend. One of those settings can tell dnsmasq to run a command, which means your text input could end up executing code on the device.

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.