{"id":18746689,"url":"https://github.com/matrixeditor/hiktools","last_synced_at":"2025-04-12T22:15:15.567Z","repository":{"id":214740631,"uuid":"729837797","full_name":"MatrixEditor/hiktools","owner":"MatrixEditor","description":"Python \u0026 C++ library for working with hikvision firmware/ SADP packets/ SADP Tool functionalities","archived":false,"fork":false,"pushed_at":"2023-12-11T15:44:12.000Z","size":596,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T16:21:25.730Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatrixEditor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-10T14:12:12.000Z","updated_at":"2025-03-26T01:24:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"6edb2622-b59e-403c-ba28-881d366e308d","html_url":"https://github.com/MatrixEditor/hiktools","commit_stats":null,"previous_names":["matrixeditor/hiktools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixEditor%2Fhiktools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixEditor%2Fhiktools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixEditor%2Fhiktools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatrixEditor%2Fhiktools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatrixEditor","download_url":"https://codeload.github.com/MatrixEditor/hiktools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637795,"owners_count":21137538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T16:26:32.294Z","updated_at":"2025-04-12T22:15:15.561Z","avatar_url":"https://github.com/MatrixEditor.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hiktools\n\n![Module](https://img.shields.io:/static/v1?label=Module\u0026message=hiktools\u0026color=9cf)\n![Build](https://img.shields.io:/static/v1?label=Python\u0026message=\u003e=3.5\u0026color=green)\n![Platform](https://img.shields.io:/static/v1?label=Platforms\u0026message=Linux|Windows\u0026color=yellowgreen)\n![PyPi](https://img.shields.io:/static/v1?label=PyPi\u0026message=1.2.2\u0026color=green)\n\n\nThis respository was former known as `hikvision-sdk-cam`, but has changed since the old content of this repository was deleted. This is now a small project with four main functionalities:\n* A Wireshark dissector for the Search Active Devices Protocol,\n* Decrypt and extract hikvision firmware,\n* Send raw SADP packets (only Linux) and\n* Send commands via UDP Broadcast.\n\nTo get familiar with the API provided in this repository, take a quick look at the python documentation available **[here »](https://hiktools.readthedocs.io/)** or the\nC++ documentation available at Github-Pages **[here »](https://matrixeditor.github.io/hiktools/docs/html/d3/dcc/md__r_e_a_d_m_e.html)**.\n\n### Installation\n\nYou can now install the `hiktools` module with pip:\n\n```bash\n$ python3 -m pip install hiktools\n```\n\n### Overview\n---\n**Update:** Since feature version `1.1.0` the native packet creation and communication works! It is still only usable on UNIX systems that support sending raw ethernet frames. The checksum algorithm was disassebled and decompiled correctly, just the input parameters were interpreted wrong. The algorithm is implemented in [C/C++](/cpp/checksum.h) and [python3](/hiktools/csadp/checksum.py).\n\nCommunication on UDP works fine at the moment - this API is just a small wrapper which can be used for a more general API.\n\nFirmware decryption and extraction will only work on newer `digicap.dav` files with at least  `1` file entry (otherwise there will be no files to inspect) in the header. All firmware files and updates can be downloaded from the following endpoint (EU):\n\n* https://www.hikvisioneurope.com/uk/portal\n\nThere is also a full list of files available at this enpoint stored in a JSON file named [firmwarelist.json](/gists/firmwarelist.json).\n\n\u003e Info: There is an interesting file located in the extracted files of a firmware image: /hroot.img/initrd/etc/passwd. A password is set to the root user:\n\n    Name: passwd\n    Folder: -\n    Size: 44\n    Packed Size: 1 024\n    Mode: -rwxrwxr-x\n    Last change: 2016-12-23 08:27:46\n    Last modification: 2016-12-23 08:27:46\n    -------------------------------------------\n\n    root:ToCOv8qxP13qs:0:0:root:/root/:/bin/psh\n\nThe plain password is `hiklinux`, kudos to [Don Bowman](https://blog.donbowman.ca/2018/01/18/hacking-the-hikvision-part-1/).\n\n\u003e Old exploit with authkey := YWRtaW46MTEK\n\n### Basic Usage\n---\n\n- Firmware inspection and extraction\n\n```python\nfrom hiktools import fmod\n\n# Open the resource at the specified path (loading is done automatically)\n# or manually decrypt the firmware file (see documentation for actual code).\nwith fmod.DigiCap('filename.dav') as dcap:\n  # Iterate over all files stored in the DigiCap object\n  for file_info in dcap:\n      print('\u003e File name=\"%s\", size=%d, pos=%d, checksum=%d' % file_info)\n\n  # get file amount and current language\n  print(\"Files: %d, Language: %d\" % (dcap.head.files, dcap.head.language))\n\n  # save all files stored in \u003cfilename.dav\u003e\n  fmod.export(dcap, \"outdir/\")\n```\n\nOr you can use the module main script to extract the files via the CLI:\n```console\npython3 -m hiktools.fmod input.dav outputDir\n```\n\n- Native interface on sending raw packets (only LINUX)\n```python\nfrom hiktools import csadp\n\n# Because the following module requires root priviledges it\n# has to be imported directly.\nfrom hiktools.csadp import CService\n\nsock = CService.l2socket('wlan0')\ncounter = 0x115e\n\n# To build an Inquiry packet, we need the following information:\n# - our mac, ipv4 and ipv6 address (and the counter of course)\npacket = csadp.inquiry('\u003cMAC\u003e', '\u003cIPv4\u003e', '\u003cIPv6\u003e', counter)\n\n# before we can send the message, a checksum has to be calculated\npacket.insert_checksum()\n\nsock.send(bytes(packet))\nresponse = csadp.SADPPacket(sock.recv(1024))\n\n# to view the contents just print the str() version\nprint(str(response))\n```\n\n- Interact with the device through UDP broadcast\n```python\nfrom hiktools import sadp\nfrom uuid import uuid4\n\n# create a packet from a simple dict object\ninquiry = sadp.fromdict({\n  'Uuid': str(uuid4()).upper(),\n  'MAC': 'ff-ff-ff-ff-ff-ff',\n  'Types': 'inquiry'\n})\n\n# Open up a client to communicate over broadcast\nwith sadp.SADPClient() as client:\n  # send the inquiry packet\n  client.write(inquiry)\n\n  # iterate over all received packets (None is returned on error)\n  for response in client:\n    if response is None: break\n    # initiate the response\n    message = sadp.unmarshal(response.toxml())\n\n    # message objects contain a dict-like implementation\n    for property_name in message:\n      print(message[property_name])\n\n    # e.g.\n    print('Device at', message['IPv4Address'])\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixeditor%2Fhiktools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatrixeditor%2Fhiktools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatrixeditor%2Fhiktools/lists"}