text
stringlengths
0
1.99k
|__ linuxigd/
| |__ dummy.xml
| |__ gateconnSCPD.xml
| |__ gatedesc.xml
| |__ gateicfgSCPD.xml
|__ upnpd.conf
To have a functional service that simulates a real network device, our
virtual machine needs two interfaces:
- WAN interface (created as a dummy interface)
- LAN interface (the one we are connected to via SSH).
$ sudo ip link add name dummy0 type dummy
$ sudo ip link set dummy0 up
$ sudo ip addr add 192.168.13.37/24 dev dummy0
To verify that the interface has been correctly created and configured, use
the following command.
$ ip addr show dummy0
Once the tests are complete, it can be deleted using the following command.
$ sudo ip link delete dummy0
To set up debugging, use GDB to place a breakpoint on the system() function
call but first, set the debug_mode value in the file /etc/upnpd.conf as
follows (to improve debugging).
# Daemon debug level. Messages are logged via syslog to debug.
# 0 - no debug messages
# 1 - log errors
# 2 - log errors and basic info
# 3 - log errors and verbose info
# default = 0
debug_mode = 3
The service can then be started using the following command.
$ sudo LD_LIBRARY_PATH=/usr/local/lib upnpd -f <WAN_IFACE> <LAN_IFACE>
To debug with GDB, simply retrieve the PID of the process associated with
the service.
$ ps auxf|grep upnpd
$ gdb -p <PID>
$ (gdb) break system
$ (gdb) c
Now that the service is up and running and the debugging setup is complete,
the next step is to interact with it. To do this, we need to review the
contents of the gatedesc.xml and gateconnSCPD.xml files which are located
in /etc/linuxigd/. Although we were not always fans of AI, we have come to
realize that, as the saying goes, "Only fools do not change their minds!'
With that in mind, it might be worthwhile to use a Large Language Model
(LLM) based on the GPT-4 architecture to parse the XML files and generate
the necessary HTTP requests for interacting with the service. This approach
is especially useful when working with a service that has been enhanced
with new features (but still based on linux-igd within the SDK). For
instance, ChatGPT was able to provide the HTTP requests to reach the
vulnerable function pmlist_AddPortMapping().
POST /upnp/control/WANIPConn1 HTTP/1.1
Host: 127.0.0.1:49152
Content-Type: text/xml; charset="utf-8"
SOAPAction: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
Content-Length: 704
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:schemas-upnp-org:service:WANIPConnection:1">
<soapenv:Header/>
<soapenv:Body>
<urn:AddPortMapping>
<NewRemoteHost></NewRemoteHost>
<NewEnabled>1</NewEnabled>
<NewLeaseDuration>1</NewLeaseDuration>
<NewPortMappingDescription>POC</NewPortMappingDescription>
<NewProtocol>AAA</NewProtocol>
<NewExternalPort>BBBBB</NewExternalPort>
<NewInternalClient>CCCCCCCCCCCCCCC</NewInternalClient>
<NewInternalPort>DDDDD</NewInternalPort>
</urn:AddPortMapping>
</soapenv:Body>
</soapenv:Envelope>
Once the request is sent using curl, the following behavior can be
monitored.
$ curl -v \
-d @body.soap \
-H 'Content-Type: text/xml; charset="utf-8"' \
-H 'SOAPAction: "...IPConnection:1#AddPortMapping"' \
'http://127.0.0.1:49152/upnp/control/WANIPConn1'
$ sudo LD_LIBRARY_PATH=/usr/local/lib upnpd -f dummy0 ens3
upnpd[1878]: Initializing UPnP SDK ...
upnpd[1878]: UPnP SDK Successfully Initialized.
upnpd[1878]: Setting the Web Server Root Directory to /etc/linuxigd