I am working on the Web Application of openwrt system based on lua language and am…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
I am working on the Web Application of openwrt system based on lua language and am trying to find a type of bug called remote command execution. I need your help to analyze functions. A function may introduce illegal remote command injection. I will give you some function, and please tell me if the function initializes will introduce illegal remote command injection.
Here are some rules you can learn from:
-
The key to verifying whether a function's arguments will cause illegal command injection is whether the function has an entry in the entry function, for example entry({"admin", "status", "iptables_dump"}, call("dump_iptables")).leaf = true This is the entry to the dump_iptables function, only with such an entry, external users can control the implementation of the parameters of the function injection, to determine whether the function has an entry, if I did not provide you can ask me.
-
The functions verified include but are not limited to the following false positives, that is, they do not cause illegal injection. In the following example, the argument family can only be equal to "ip6" or "ip", and then passed to prefix to be executed by , which you can analyze with the idea of data flow, which is a false positive. while the argument “table” will be cause illegal command inject without parameter check, which is a false positive. So the multiple arguments of a function are something you need to consider separately. function dump_iptables(family, table) local prefix = (family == "6") and "ip6" or "ip" local ok, lines = pcall(io.lines, "/proc/net/%s_tables_names" % prefix) if ok and lines then local s for s in lines do if s == table then luci.http.prepare_content("text/plain") luci.sys.process.exec({ "/usr/sbin/%stables" % prefix, "-w", "-t", table, "--line-numbers", "-nxvL" }, luci.http.write) return end end end
luci.http.status(404, "No such table") luci.http.prepare_content("text/plain") end
In the following example, the statement fork_exec("sleep 1; killall dropbear uhttpd; sleep 1; /sbin/sysupgrade %s %q" %{keep, image_tmp}) cannot be entered by any external value, and image_tmp is a constant value, so it is also a false positive. function fork_exec(command) local pid = nixio.fork() if pid > 0 then return elseif pid == 0 then -- change to root dir nixio.chdir("/")
code-- patch stdin, out, err to /dev/null local null = nixio.open("/dev/null", "w+") if null then nixio.dup(null, nixio.stderr) nixio.dup(null, nixio.stdout) nixio.dup(null, nixio.stdin) if null:fileno() > 2 then null:close() end end -- replace with target command nixio.exec("/bin/sh", "-c", command) end -
- Assistant
I understand the task. You'll provide me with some functions from a Web Application based on the OpenWRT system written in , and my role is to analyze these functions to determine if they could potentially introduce illegal remote command injection vulnerabilities. Please go ahead and share the functions you'd like me to analyze.
- User
", "nlbw", "change_roll"}, call("action_change_roll"))
function action_change_roll() local set = luci.http.formvalue("set") os.execute("/usr/lib/bwmon/rollover.sh " .. set)
end
- Assistant
- User
entry({"api", "xqnetwork", "dmz_reload"}, call("reloadDMZ"), (""), 252) function reloadDMZ() local = require("xiaoqiang.module.") local result = { ["code"] = 0 } local mode = tonumber(LuciHttp.formvalue("mode")) or 0 XQDMZModule.dmzReload(mode) LuciHttp.write_json(result) end
- Assistant