text
stringlengths
0
1.99k
Control over LAN can be achieved by exploiting an old network service that
opens a pathway through HTTP requests. By targeting a vulnerability
in the service request's parsing of parameters, a patient attacker can
force the execution of unauthorized commands as in a command line. This
flow allows bypassing the built-in rulesets that would otherwise block such
exploits, making it possible to gain deeper access. By carefully crafting
unexpected HTTP requests while manipulating specific SOAP payloads, we can
reach what we desire the most, the takeover of the network.
---------------------------------------------------------------------------
--[ 2. Introduction
Universal Plug and Play (UPnP) has long been a subject of concern due to
its widespread use in simplifying network configurations, often at the
expense of security. Originally designed to allow devices to automatically
discover and configure themselves on a network, UPnP relies on the Internet
Gateway Device (IGD), typically a router, to manage inbound and outbound
traffic. However, the very features that make it convenient, such as
automatic port forwarding and NAT traversal, also open doors to exploit.
Over time, Linux IGD implementations, which allow Linux-based systems to
perform similar functions, have become increasingly relevant in the threat
landscape. Despite being an old service, UPnP and its related components
still present a range of vulnerabilities that attackers can exploit.
The next section will explore how a modified version of linuxigd
(linux-igd)[1] can be exploited.
---------------------------------------------------------------------------
--[ 3. White-box audit
The focus of this analysis is on the implementation of linuxigd (linux-igd)
and its derivatives, such as the reuse of its codebase within SDKs. The
original code can be found on SourceForge[2]. The service was written in
C++ at first, but the developers switched to C starting with version 0.95.
+----------------------+----------+
| Version | Language |
+----------------------+----------+
| gateway-0.71.tgz | C++ |
| gateway-0.75.tgz | C++ |
| gateway-0.90.tgz | C++ |
| gateway-0.91.tgz | C++ |
| linuxigd-0.92.tgz | C++ |
| linuxigd-0.95.tar.gz | C |
| linuxigd-1.0.tar.gz | C |
+----------------------+----------+
While each version and its changes have been analyzed, the vendor seems to
have modified version 1.0 for its SDK. The code examples below are based on
the vendor's modified source code of the latest version of linuxigd (1.0).
It is up to the reader through firmware analysis to identify examples where
this service codebase is reused in SDKs.
By reading the file pmlist.c source code, several command injections can be
identified in the pmlist_AddPortMapping() and pmlist_DeletePortMapping()
functions.
int pmlist_AddPortMapping(int enabled, char *protocol, char *externalPort,
char *internalClient, char *internalPort)
{
if (enabled)
{
...
char command[COMMAND_LEN];
int status;
{
...
snprintf(command, COMMAND_LEN, "%s -t nat -I %s -i %s -p %s"
" --dport %s -j DNAT --to %s:%s", g_vars.iptables,
g_vars.preroutingChainName, g_vars.extInterfaceName,
protocol, externalPort, internalClient, internalPort);
trace(3, "%s", command);
system(command);
...
}
if (g_vars.forwardRules)
{
snprintf(command, COMMAND_LEN, "%s -A %s -p %s"
" -d %s --dport %s -j ACCEPT", g_vars.iptables,
g_vars.forwardChainName, protocol, internalClient,
internalPort);
trace(3, "%s", command);
system(command);
...
}
...
}
return 1;
}
int pmlist_DeletePortMapping(int enabled, char *protocol,
char *externalPort, char *internalClient,
char *internalPort)
{
if (enabled)
{