text stringlengths 0 1.99k |
|---|
... |
char command[COMMAND_LEN]; |
int status; |
{ |
... |
snprintf(command, COMMAND_LEN, "%s -t nat -D %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 -D %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; |
} |
The creation of the string command, with elements controlled by an attacker |
supplied as a parameter to the system() function, raises a security issue. |
The pmlist_AddPortMapping() function is called by the pmlist_PushBack() |
function within the pmlist.c file. |
int pmlist_PushBack(struct portMap* item) |
{ |
int action_succeeded = 0; |
... |
if (action_succeeded == 1) |
{ |
pmlist_AddPortMapping(item->m_PortMappingEnabled, |
item->m_PortMappingProtocol, |
item->m_ExternalPort, item->m_InternalClient, |
item->m_InternalPort); |
return 1; |
} |
else |
return 0; |
} |
By analyzing the code above, it appears that the values supplied to the |
pmlist_AddPortMapping() function are not sanitized. This happens earlier |
in the call stack, specifically when the portMap structure is created and |
supplied to the pmlist_PushBack() function. This can be observed in the |
gatedevice.c file, where the AddPortMapping() function is defined. This |
function is called by the SOAP action handler HandleActionRequest(), which |
is registered by EventHandler() to process the associated HTTP request. |
int AddPortMapping(struct Upnp_Action_Request *ca_event) |
{ |
char *remote_host = NULL; |
char *ext_port = NULL; |
char *proto = NULL; |
char *int_port = NULL; |
char *int_ip = NULL; |
char *int_duration = NULL; |
char *bool_enabled = NULL; |
char *desc = NULL; |
struct portMap *ret, *new; |
int result; |
char num[5]; // Maximum number of port mapping entries 9999 |
IXML_Document *propSet = NULL; |
int action_succeeded = 0; |
char resultStr[RESULT_LEN]; |
if ( |
(ext_port = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewExternalPort")) && |
(proto = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewProtocol")) && |
(int_port = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewInternalPort")) && |
(int_ip = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewInternalClient")) && |
(int_duration = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewLeaseDuration")) && |
(bool_enabled = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewEnabled")) && |
(desc = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewPortMappingDescription"))) |
{ |
remote_host = GetFirstDocumentItem(ca_event->ActionRequest, |
"NewRemoteHost"); |
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.