Skip to content

Commit fc16d0a

Browse files
authored
Fix tradfri RCE: diyhue#105 (diyhue#888)
1 parent af6fdd2 commit fc16d0a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

BridgeEmulator/flaskUI/core/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def pairTradfri():
6767
try:
6868
data = request.get_json(force=True)
6969
pprint(data)
70-
registration = json.loads(check_output("./coap-client-linux -m post -u \"Client_identity\" -k \"" + data["tradfriCode"] + "\" -e '{\"9090\":\"" + data["identity"] + "\"}' \"coaps://" + data["tradfriGwIp"] + ":5684/15011/9063\"", shell=True).decode('utf-8').rstrip('\n').split("\n")[-1])
70+
cmd = ["./coap-client-linux", "-m", "post", "-u", "Client_identity", "-k", data["tradfriCode"], "-e", "{\"9090\":\"" + data["identity"] + "\"}", "coaps://" + data["tradfriGwIp"] + ":5684/15011/9063"]
71+
registration = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
7172
if "9091" in registration:
7273
bridgeConfig["config"]["tradfri"] = {"psk": registration["9091"], "tradfriGwIp": data["tradfriGwIp"], "identity": data["identity"]}
7374
return {"result": "success", "psk": registration["9091"]}

BridgeEmulator/lights/protocols/tradfri.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ def set_light(light, data):
5252

5353
if "5712" not in payload:
5454
payload["5712"] = 4 #If no transition add one, might also add check to prevent large transitiontimes
55-
check_output("./coap-client-linux -B 2 -m put -u \"" + light.protocol_cfg["identity"] + "\" -k \"" + light.protocol_cfg["psk"] + "\" -e '{ \"3311\": [" + json.dumps(payload) + "] }' \"" + url + "\"", shell=True)
55+
cmd = ["./coap-client-linux", "-B", "2", "-m", "put", "-u", light.protocol_cfg["identity"], "-k", light.protocol_cfg["psk"], "-e", "{ \"3311\": [" + json.dumps(payload) + "] }", url]
56+
check_output(cmd)
5657

5758
def get_light_state(light):
5859
state ={}
59-
light_data = json.loads(check_output("./coap-client-linux -B 5 -m get -u \"" + light.protocol_cfg["identity"] + "\" -k \"" + light.protocol_cfg["psk"] + "\" \"coaps://" + light.protocol_cfg["ip"] + ":5684/15001/" + str(light.protocol_cfg["id"]) +"\"", shell=True).decode('utf-8').rstrip('\n').split("\n")[-1])
60+
cmd = ["./coap-client-linux", "-B", "5", "-m", "get", "-u", light.protocol_cfg["identity"], "-k", light.protocol_cfg["psk"], "coaps://" + light.protocol_cfg["ip"] + ":5684/15001/" + str(light.protocol_cfg["id"])]
61+
light_data = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
6062
state["on"] = bool(light_data["3311"][0]["5850"])
6163
state["bri"] = light_data["3311"][0]["5851"]
6264
if "5706" in light_data["3311"][0]:
@@ -75,10 +77,12 @@ def discover(detectedLights, tradfriConfig):
7577
if "psk" in tradfriConfig:
7678
logging.debug("tradfri: <discover> invoked!")
7779
try:
78-
tradriDevices = json.loads(check_output("./coap-client-linux -B 5 -m get -u \"" + tradfriConfig["identity"] + "\" -k \"" + tradfriConfig["psk"] + "\" \"coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001\"", shell=True).decode('utf-8').rstrip('\n').split("\n")[-1])
80+
cmd = ["./coap-client-linux", "-B", "5", "-m", "get", "-u", tradfriConfig["identity"], "-k", tradfriConfig["psk"], "coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001"]
81+
tradriDevices = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
7982
logging.debug(tradriDevices)
8083
for device in tradriDevices:
81-
deviceParameters = json.loads(check_output("./coap-client-linux -B 5 -m get -u \"" + tradfriConfig["identity"] + "\" -k \"" + tradfriConfig["psk"] + "\" \"coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001/" + str(device) +"\"", shell=True).decode('utf-8').rstrip('\n').split("\n")[-1])
84+
cmd = ["./coap-client-linux", "-B", "5", "-m", "get", "-u", tradfriConfig["identity"], "-k", tradfriConfig["psk"], "coaps://" + tradfriConfig["tradfriGwIp"] + ":5684/15001/" + str(device)]
85+
deviceParameters = json.loads(check_output(cmd).decode('utf-8').rstrip('\n').split("\n")[-1])
8286
if "3311" in deviceParameters:
8387
logging.debug("found tradfi light " + deviceParameters["9001"])
8488
detectedLights.append({"protocol": "tradfri", "name": deviceParameters["9001"], "modelid": "LCT015", "protocol_cfg": {"ip": tradfriConfig["tradfriGwIp"], "id": device, "identity": tradfriConfig["identity"], "psk": tradfriConfig["psk"]}})

0 commit comments

Comments
 (0)