{"article":{"slug":"taking-another-shot-at-the-cheap-ip-camera-part-2","title":"Taking another shot at the cheap IP camera, part 2","subtitle":null,"summary":"Eric Park revisits a cheap Tuya-based IP camera he had given up on and works through getting a local video stream out of it without the vendor's cloud, documenting the reverse-engineering process and his verdict on the class of device.","content_type":"blog_post","language":"en","canonical_url":"https://ericswpark.com/blog/2026/2026-11-09-ip-camera-pt2/","author":{"name":"Eric Park","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Eric Park's Blog","url":"https://ericswpark.com/","listing_slug":null,"listing":null},"topics":[{"name":"hardware","slug":"hardware","url":"https://listedarticles.com/topics/hardware"},{"name":"security","slug":"security","url":"https://listedarticles.com/topics/security"},{"name":"reverse-engineering","slug":"reverse-engineering","url":"https://listedarticles.com/topics/reverse-engineering"},{"name":"iot","slug":"iot","url":"https://listedarticles.com/topics/iot"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":6821,"reading_minutes":30,"published_at":"2026-11-09T00:00:00.000Z","added_at":"2026-11-10T17:12:33.906Z","updated_at":"2026-11-10T17:12:33.906Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/taking-another-shot-at-the-cheap-ip-camera-part-2","markdown_url":"https://listedarticles.com/articles/taking-another-shot-at-the-cheap-ip-camera-part-2.md","example":false,"citation":"Eric Park, Eric Park's Blog. \"Taking another shot at the cheap IP camera, part 2.\" 9 Nov 2026. https://ericswpark.com/blog/2026/2026-11-09-ip-camera-pt2/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://ericswpark.com/blog/2026/2026-11-09-ip-camera-pt2/"},"body_markdown":"# Taking another shot at the cheap IP camera, part 2\n\n### November 9, 2026\n\n[About a year ago](https://ericswpark.com/blog/2025/2025-04-18-a-rant-about-cheap-proprietary-ip-cameras-featuring-hej-home/), I ranted about this particular cheap IP camera that was\nbased on some proprietary Chinese IoT platform named Tuya. After trying and\nfailing to get a local video stream from it without going through their servers,\nI concluded that my time would be better served by using cameras that actually\nexposed their streaming capabilities, and set it aside.\n\nWell, I recently dug the camera out while moving to my new job in New Jersey,\nand thought it might be worthwhile to give it another shot. I had plenty of\nspare time, and if I couldn’t figure it out, LLMs are recently all the rage for\nbeing really great at reverse-engineering things. But my initial goal was,\nI’d attempt it myself first, and then hand it off to an LLM if I failed and try\nand learn something from what it had figured out.\n\nSo what’s our goal, exactly? We know from last time that the camera has some\nsort of ONVIF server built in. That’s basically a standardized interface for\nIP cameras, defined by the Open Network Vision Interface Forum (or ONVIF!)\nAnd most ONVIF cameras expose their video streams using RTSP, or the\nReal-Time Streaming Protocol. You may have come across this protocol if you’ve\never streamed to a live-streaming platform like YouTube or Twitch.\n\nThe problem is that these servers are disabled on the firmware side, and their\nports are closed off. Last time, we tried to enable them using the configuration\noptions, but that didn’t work. Now, it’s time to figure out why that failed, and\nif there’s truly a way to enable those streams.\n\nSo with that in mind, let’s first extract the firmware image with `binwalk -Me`:\n\n| Decimal | Hexadecimal | Description |\n| --- | --- | --- |\n| 113992 | 0x1BD48 | CRC32 polynomial table, little endian |\n| 458752 | 0x70000 | uImage firmware image, header size: 64 bytes, data size: 2803328 bytes, compression: none, CPU: ARM, OS: Linux, image type: OS, Kernel Image, load address: 0x81C08000, entry point: 0x81C08040, creation time: 2021-06-21 03:03:42, image name: “Linux-3.4.35” |\n| 3604480 | 0x370000 | CramFS filesystem, little endian, 3 files, total size: 3248128 bytes |\n| 7736524 | 0x760CCC | JFFS2 filesystem, little endian, nodes: 256, total size: 648000 bytes |\n\nOK, so it runs Linux 3.4.35. When was that released again? March 2013.\nA 13-year old kernel! (I guess it was only 8-years old when they compiled it.)\n\nLast time, we found the Tuya configuration file with the ONVIF config at\n`./extractions/cctv.bin.extracted/760CCC/jffs2-root/tuya_config.json`. I think\nthe reason it might not have worked is because we edited the firmware image\nitself with a hex editor, and doing so probably corrupted some checksum.\n\nBut, we have the image extraction, so why not trace where the config option\nis being used? Perhaps the binary doesn’t even use that option at all.\n\nSo what binary is launched? We should look at the initialization script of the\ncamera at `.\\extractions\\cctv.bin.extracted\\370000\\initrun.sh`. That script\nextracts some app tarball, then runs the script at `home/init.d/initS`, which\nin turn runs the other init scripts inside `home/init.d`.\n\nMost of the scripts are like, setting up the kernel parameters regarding memory\nand networking and DHCP and what not, so we’ll skip past all that. The important\nbit is the last script, which is `S60ppsapp`, which runs `ppsapp` in `/home/app`.\n\nOne `find` command and we find\n`extractions\\cctv.bin.extracted\\370000\\app.tar.gz.extracted\\0\\decompressed.bin.extracted\\0\\home\\app\\ppsapp`.\nAnd `strings` tells us it has ONVIF stuff in it:\n\n```\n$ strings ppsapp | grep -C 2 \"onvif_enable\"\nmotion_area_switch\nmotion_area\nonvif_enable\nonvif_pwd\n```\n\nOK, but is there some reference to the ONVIF streaming within the binary itself?\n\n```\n$ strings ppsapp | grep \"Starting onvif\"\nStarting onvif server on port %s\n$ strings ppsapp | grep \"rtsp://\"\nrtsp://\nrtsp://%s:%d/Streaming/Channels/101\nrtsp://%s:%d/Streaming/Channels/102\n```\n\nOK, that’s good! We now know the ONVIF streaming URL format, though we still\nneed to know what port it runs on.\n\nSo let’s throw the binary itself into Ghidra and run the analyzer. Looking\nthrough the strings, a lot of the hardcoded paths reference\n`/var/lib/jenkins/workspace/`, so whoever built this image probably did so with\na Jenkins pipeline. Does it really matter for what we’re doing? No, but I\nthought it was interesting. They probably have a Jenkins workflow for each\ncamera SKU they push out the door, although I’m sure they use it only once,\nconsidering that support is an afterthought.\n\nThe binary itself is 2.4 MB, and I’m not that familiar\nwith reading ARM assembly, but we don’t have to, just yet! We just need to look around\nfor the onvif part since we know the config string there.\n\nOn Ghidra, strings can be found by going to “Search -> For Strings…”. After\nyou select the options the string search window shows up. Luckily for me,\nfiltering for `onvif_enable` shows only two places where they are used:\n\nPlace 1 (warning: long)\n\n```\nundefined4 FUN_0000f3c0(void)\n{\n  bool bVar1;\n  FILE *__stream;\n  byte *__s;\n  size_t sVar2;\n  undefined4 *puVar3;\n  undefined4 *puVar4;\n  undefined4 uVar5;\n  void *__src;\n  \n  __stream = fopen64(\"/home/cfg/tuya_config.json\",\"r+\");\n  if (__stream == (FILE *)0x0) {\n    uVar5 = 0xffffffff;\n  }\n  else {\n    __s = malloc(0x800);\n    if (__s == (byte *)0x0) {\n      fclose(__stream);\n      uVar5 = 0xffffffff;\n    }\n    else {\n      memset(__s,0,0x800);\n      sVar2 = fread(__s,1,0x800,__stream);\n      if (sVar2 == 0) {\n        fclose(__stream);\n        free(__s);\n        uVar5 = 0xffffffff;\n      }\n      else {\n        fclose(__stream);\n        puVar3 = FUN_001f5cfc(__s);\n        if (puVar3 == (undefined4 *)0x0) {\n          uVar5 = 0xffffffff;\n        }\n        else {\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"version\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d58 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"sleep_mode\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d5c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"light_onoff\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d60 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"flip_onoff\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d64 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"watermark_onoff\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d68 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"night_mode\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d6c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"alarm_fun_onoff\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d70 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"alarm_fun_sensitivity\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d74 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"alarm_fun_mode_switch\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d78 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"alarm_fun_time_start\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d7c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"alarm_fun_time_end\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d80 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"loudspeaker_vol_pct\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279efc = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"sound_detect_onoff\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d84 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"sound_detect_sensitivity\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d88 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"event_record_time\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d90 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"enable_event_record\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d8c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"record_enable\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d94 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"motion_trace\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279f44 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"motion_tracking\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279ec0 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"cry_detection_switch\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279ec4 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"humanoid_filter\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279ec8 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          bVar1 = FUN_00192cf8();\n          if (bVar1) {\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)\"jingle_mode\");\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279da0 = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)\"jingle_sound\");\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279d9c = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)\"jingle_volume\");\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279d98 = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)\"jingle_exist\");\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279da4 = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"motion_area_switch\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279da8 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"motion_area\");\n          if (puVar4 != (undefined4 *)0x0) {\n            memset(&DAT_00279dac,0,0x100);\n            __src = (void *)puVar4[4];\n            sVar2 = strlen((char *)puVar4[4]);\n            memcpy(&DAT_00279dac,__src,sVar2);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"onvif_enable\");\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279f00 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)\"onvif_pwd\");\n          if (puVar4 != (undefined4 *)0x0) {\n            memset(&DAT_00279f04,0,0x40);\n            strcpy((char *)&DAT_00279f04,(char *)puVar4[4]);\n            sVar2 = strlen((char *)&DAT_00279f04);\n            FUN_00041ba0(&DAT_00279f04,sVar2);\n          }\n          if (puVar3 != (undefined4 *)0x0) {\n            FUN_001f4480(puVar3);\n          }\n          free(__s);\n          uVar5 = 0;\n        }\n      }\n    }\n  }\n  return uVar5;\n}\n```\n\nAnd\n\nPlace 2 (warning: also somewhat long)\n\n```\nundefined4 FUN_0000fd5c(void)\n{\n  bool bVar1;\n  undefined4 *puVar2;\n  void *pvVar3;\n  char *__s;\n  FILE *__stream;\n  undefined4 uVar4;\n  ulonglong uVar5;\n  \n  puVar2 = FUN_001f8384();\n  if (puVar2 == (undefined4 *)0x0) {\n    uVar4 = 0xffffffff;\n  }\n  else {\n    uVar5 = FUN_00225410(DAT_00279d58);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"version\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d5c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"sleep_mode\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d70);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"alarm_fun_onoff\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d74);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"alarm_fun_sensitivity\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d78);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"alarm_fun_mode_switch\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d7c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"alarm_fun_time_start\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d80);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"alarm_fun_time_end\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d64);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"flip_onoff\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d60);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"light_onoff\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d6c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"night_mode\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d84);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"sound_detect_onoff\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d88);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"sound_detect_sensitivity\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d68);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"watermark_onoff\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d90);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"event_record_time\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d8c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"enable_event_record\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d94);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"record_enable\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279f44);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"motion_trace\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279da8);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"motion_area_switch\",(int)pvVar3);\n    pvVar3 = FUN_001f82f4(&DAT_00279dac);\n    FUN_001f7b54((int)puVar2,\"motion_area\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279ec0);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"motion_tracking\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279ec4);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"cry_detection_switch\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279ec8);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"humanoid_filter\",(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279efc);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"loudspeaker_vol_pct\",(int)pvVar3);\n    bVar1 = FUN_00192cf8();\n    if (bVar1) {\n      uVar5 = FUN_00225410(DAT_00279da0);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n      FUN_001f7b54((int)puVar2,\"jingle_mode\",(int)pvVar3);\n      uVar5 = FUN_00225410(DAT_00279d9c);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n      FUN_001f7b54((int)puVar2,\"jingle_sound\",(int)pvVar3);\n      uVar5 = FUN_00225410(DAT_00279d98);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n      FUN_001f7b54((int)puVar2,\"jingle_volume\",(int)pvVar3);\n      uVar5 = FUN_00225410(DAT_00279da4);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n      FUN_001f7b54((int)puVar2,\"jingle_exist\",(int)pvVar3);\n    }\n    uVar5 = FUN_00225410(DAT_00279f00);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 >> 0x20));\n    FUN_001f7b54((int)puVar2,\"onvif_enable\",(int)pvVar3);\n    pvVar3 = FUN_001f82f4((char *)&DAT_00279f04);\n    FUN_001f7b54((int)puVar2,\"onvif_pwd\",(int)pvVar3);\n    __s = FUN_001f5d2c((int)puVar2);\n    if (__s != (char *)0x0) {\n      __stream = fopen64(\"/home/cfg/tuya_config.json\",\"w+\");\n      if (__stream == (FILE *)0x0) {\n        free(__s);\n        return 0xffffffff;\n      }\n      fputs(__s,__stream);\n      fclose(__stream);\n      free(__s);\n    }\n    FUN_001f4480(puVar2);\n    uVar4 = 0;\n  }\n  return uVar4;\n}\n```\n\n…yeah, that’s not very fun to read. But we can figure out several things just\nfrom reasoning it out.\n\nFor starters, when we open the configuration file `tuya_config.json`, notice the\nfirst function’s call is with `fopen()`, and the second parameter being `r+`.\nWhereas with the second function, the same `fopen()` call is at the end of the\nfunction with `w+`. This tells us that the first function is a config reader\nand the second function is a config writer!\n\nOK, and there’s a bunch of calls to a function named `FUN_001f7978`. What is\nthat?\n\n```\nundefined4 * FUN_001f7978(int param_1,byte *param_2)\n{\n  uint uVar1;\n  undefined4 *local_c;\n  \n  if (param_1 == 0) {\n    local_c = (undefined4 *)0x0;\n  }\n  else {\n    local_c = *(undefined4 **)(param_1 + 8);\n    while ((local_c != (undefined4 *)0x0 &&\n           (uVar1 = FUN_001f4230((byte *)local_c[8],param_2), uVar1 != 0))) {\n      local_c = (undefined4 *)*local_c;\n    }\n  }\n  return local_c;\n}\n```\n\nOK, what is `FUN_001f4230` then?\n\n```\nuint FUN_001f4230(byte *param_1,byte *param_2)\n{\n  int iVar1;\n  int iVar2;\n  uint uVar3;\n  byte *local_18;\n  byte *local_14;\n  \n  if (param_1 == (byte *)0x0) {\n    uVar3 = (uint)(param_2 != (byte *)0x0);\n  }\n  else {\n    local_18 = param_2;\n    local_14 = param_1;\n    if (param_2 == (byte *)0x0) {\n      uVar3 = 1;\n    }\n    else {\n      while( true ) {\n        iVar1 = tolower((uint)*local_14);\n        iVar2 = tolower((uint)*local_18);\n        if (iVar1 != iVar2) break;\n        if (*local_14 == 0) {\n          return 0;\n        }\n        local_14 = local_14 + 1;\n        local_18 = local_18 + 1;\n      }\n      iVar1 = tolower((uint)*local_14);\n      iVar2 = tolower((uint)*local_18);\n      uVar3 = iVar1 - iVar2;\n    }\n  }\n  return uVar3;\n}\n```\n\nHm, a bit of renaming later, and:\n\n```\nuint FUN_001f4230(byte *s1,byte *s2)\n{\n  int c1;\n  int c2;\n  uint retVal;\n  byte *local_18;\n  byte *local_14;\n  \n  if (s1 == (byte *)NULL) {\n    retVal = (uint)(s2 != (byte *)NULL);\n  }\n  else {\n    local_18 = s2;\n    local_14 = s1;\n    if (s2 == (byte *)NULL) {\n      retVal = 1;\n    }\n    else {\n      while( true ) {\n        c1 = tolower((uint)*local_14);\n        c2 = tolower((uint)*local_18);\n        if (c1 != c2) break;\n        if (*local_14 == 0) {\n          return 0;\n        }\n        local_14 = local_14 + 1;\n        local_18 = local_18 + 1;\n      }\n      c1 = tolower((uint)*local_14);\n      c2 = tolower((uint)*local_18);\n      retVal = c1 - c2;\n    }\n  }\n  return retVal;\n}\n```\n\nOh, this is just `strcasecmp`! I’m going to call it `strcasecmp_nc` because it\ndoes null checks unlike the `glibc` one. Back up a layer, a bit of renaming, and\nwe get:\n\n```\nundefined4 * FUN_001f7978(int config_data,byte *config_key)\n{\n  uint uVar1;\n  undefined4 *retVal;\n  \n  if (config_data == 0) {\n    retVal = (undefined4 *)NULL;\n  }\n  else {\n    retVal = *(undefined4 **)(config_data + 8);\n    while ((retVal != (undefined4 *)NULL &&\n           (uVar1 = strcasecmp_nc((byte *)retVal[8],config_key), uVar1 != 0))) {\n      retVal = (undefined4 *)*retVal;\n    }\n  }\n  return retVal;\n}\n```\n\nOK, so this function is just looking for the specific configuration key-value\npair from the given configuration data, and it does this by iterating through\nsome array/linked-list structure. Since we have the overall idea on how this\nfunction works we just rename it to `find_config` and go up a layer.\n\nWhat is `FUN_00225a88`, then?\n\n```\nuint FUN_00225a88(uint param_1,uint param_2)\n{\n  uint retVal;\n  int iVar1;\n  uint uVar2;\n  \n  iVar1 = param_2 * 2 + 0x200000;\n  if (param_2 * 2 < 0xffe00000) {\n    if (-1 < iVar1) {\n      return 0;\n    }\n    retVal = iVar1 >> 0x15;\n    uVar2 = -retVal - 0x3e1;\n    if (retVal < 0xfffffc20 && uVar2 != 0) {\n      retVal = (param_2 << 0xb | 0x80000000 | param_1 >> 0x15) >> (uVar2 & 0xff);\n      if ((param_2 & 0x80000000) != 0) {\n        retVal = -retVal;\n      }\n      return retVal;\n    }\n  }\n  else if (param_1 != 0 || (param_2 & 0xfffff) != 0) {\n    return 0;\n  }\n  retVal = param_2 & 0x80000000;\n  if (retVal == 0) {\n    retVal = 0x7fffffff;\n  }\n  return retVal;\n}\n```\n\nYeesh. I have no idea what those constants and magic numbers are. But maybe an\nLLM will. And it does!\n\nThis function converts an IEEE 754 double-precision floating-point number\ninto a signed 32-bit integer.\n\nOh, okay, so it’s literally `f64` to `i32` but in decompiled C. That was\nhelpful.\n\nSo now we look at the calls again:\n\n```\nraw_config_value = find_config((int)config_data,(byte *)\"onvif_enable\");\nif (raw_config_value != (undefined4 *)NULL) {\n  DAT_00279f00 = f64_to_i32(raw_config_value[6],raw_config_value[7]);\n}\nraw_config_value = find_config((int)config_data,(byte *)\"onvif_pwd\");\nif (raw_config_value != (undefined4 *)NULL) {\n  memset(&DAT_00279f04,0,0x40);\n  strcpy((char *)&DAT_00279f04,(char *)raw_config_value[4]);\n  config_file_size = strlen((char *)&DAT_00279f04);\n  FUN_00041ba0(&DAT_00279f04,config_file_size);\n}\n```\n\nThat is much better to look at! So all that was just reading the ONVIF key-value\npairs from the configuration file. Now we need to check where `DAT_00279f00` is\nused, but I’m going to rename that as `ONVIF_ENABLE`.\n\nSearching for references to `ONVIF_ENABLE` brings up 10 locations:\n\n![Locations where ONVIF_ENABLE is referenced](https://ericswpark.com/_astro/onvif-enable-reference-locations.BllTNQRp_1FbAYi.webp)\n\nBut, we can focus on the `READ` context only since that is probably where the\nbinary checks the config before enabling ONVIF functionality. Filter out the\nreference in the `write_configuration()` function earlier, and we’re left with\ntwo callsites:\n\n```\nint FUN_00010a98(void)\n{\n  int iVar1;\n  \n  FUN_00041304(ONVIF_ENABLE);\n  FUN_000788f8(ONVIF_ENABLE);\n  iVar1 = FUN_0001118c(0xff,ONVIF_ENABLE);\n  return iVar1;\n}\n\nint FUN_00013480(int param_1)\n{\n  int iVar1;\n  \n  if (param_1 == 0) {\n    iVar1 = 0;\n  }\n  else {\n    ONVIF_ENABLE = *(int *)(param_1 + 4);\n    FUN_00041304(ONVIF_ENABLE);\n    FUN_000788f8(ONVIF_ENABLE);\n    write_configuration();\n    iVar1 = FUN_0001118c(0xff,ONVIF_ENABLE);\n  }\n  return iVar1;\n}\n```\n\nRight off the bat, because of the call to `write_configuration()` in function\n`FUN_00013480()`, we know that this is the function that is called when the\nONVIF functionality is changed while the camera is running. The first function,\n`FUN_00010a98()`, is a bit more interesting. Let’s look at what it’s calling:\n\n```\nint FUN_00041304(int onvif_enable)\n{\n  int iVar1;\n  \n  pthread_mutex_lock((pthread_mutex_t *)&DAT_0027b238);\n  DAT_0027b1f4 = (uint)(onvif_enable != 0);\n  iVar1 = pthread_mutex_unlock((pthread_mutex_t *)&DAT_0027b238);\n  return iVar1;\n}\n\nint FUN_000788f8(int onvif_enable)\n{\n  DAT_0030c4cc = (uint)(onvif_enable != 0);\n  return onvif_enable;\n}\n```\n\nStrangely, there are two data locations where the ONVIF flag is set, so we’ll\nmap it to:\n\n- `DAT_0030c4cc` -> `ONVIF_ENABLED_1`\n- `DAT_0027b1f4` -> `ONVIF_ENABLED_2`\n\nUnfortunately, I hit a wall here, because both of those variables got passed\naround a bunch of functions that kept updating different variables.\n\nI also want to check out the string “Starting onvif server on port %s” since my\n(rather uneducated) guess is that’s where the ONVIF server is started.\n(God my brain actually works sometimes)\n\n```\nvoid FUN_00040794(void)\n{\n  pthread_t __th;\n  int iVar1;\n  undefined4 auStack_28 [6];\n  int *local_10;\n  char *onvif_server_port_num_s;\n  \n  __th = pthread_self();\n  pthread_detach(__th);\n  FUN_001fae18(0x2293c8);\n  onvif_server_port_num_s = \"8000\";\n  while( true ) {\n    while (iVar1 = FUN_00041358(), iVar1 != 1) {\n      sleep(1);\n    }\n    printf(\"Starting onvif server on port %s\\n\",onvif_server_port_num_s);\n    FUN_0020f62c(auStack_28,0);\n    local_10 = FUN_002106bc(auStack_28,onvif_server_port_num_s,FUN_0007893c);\n    if (local_10 == (int *)0x0) break;\n    FUN_002157e0((int)local_10);\n    do {\n      FUN_00212158(auStack_28,500);\n      iVar1 = FUN_00041358();\n    } while (iVar1 != 0);\n    FUN_0020f6e8(auStack_28);\n  }\n  FUN_0020f6e8(auStack_28);\n  return;\n}\n```\n\nOh great, so it runs on port `8000`! And by referencing the `ONVIF_ENABLE_*`\nvariables from earlier, we can guesstimate that there aren’t any additional\nchecks to enable ONVIF. Here’s the final disassembly I got to:\n\n```\nvoid check_and_enable_onvif_server(void)\n{\n  pthread_t __th;\n  int is_onvif_enabled;\n  undefined4 auStack_28 [6];\n  int *local_10;\n  char *onvif_server_port_num_s;\n  \n  __th = pthread_self();\n  pthread_detach(__th);\n  FUN_001fae18(0x2293c8);\n  onvif_server_port_num_s = \"8000\";\n  while( true ) {\n    while (is_onvif_enabled = get_onvif_enabled_2(), is_onvif_enabled != 1) {\n      sleep(1);\n    }\n    printf(\"Starting onvif server on port %s\\n\",onvif_server_port_num_s);\n    FUN_0020f62c(auStack_28,0);\n    local_10 = start_onvif_server(auStack_28,onvif_server_port_num_s,FUN_0007893c);\n    if (local_10 == (int *)NULL) break;\n    FUN_002157e0((int)local_10);\n    do {\n      FUN_00212158(auStack_28,500);\n      is_onvif_enabled = get_onvif_enabled_2();\n    } while (is_onvif_enabled != 0);\n    FUN_0020f6e8(auStack_28);\n  }\n  FUN_0020f6e8(auStack_28);\n  return;\n}\n```\n\nOK, cool. So how do we actually edit the configuration file, then repack it in a\nway that the camera will actually accept it?\n\nWell, we know that the configuration file `tuya_config.json` is at\n`./extractions/cctv.bin.extracted/760CCC/jffs2-root/tuya_config.json`, so instead\nof doing the dumb thing from last time where we tried to hex-edit the raw\nfirmware image, maybe we can edit the file and re-pack a JFFS2 partition image.\n\nBut why didn’t the hex-edit work? Well, [JFFS2 is a special filesystem](https://en.wikipedia.org/wiki/JFFS2) that\nis log-structured, and it’s designed for flash memory devices. I guess it’s\nsorta like F2FS, which is another filesystem designed for flash memory devices,\nbut unlike its usage on Android devices JFFS2 is designed for flash memory that\ndoesn’t have a wear-leveling mechanism on the hardware side.\n\n**What is wear-leveling?** TL;DR: Flash chips and SSDs have flash cells. Flash\ncells have a limited lifespan and don’t like it when you write to them\nrepeatedly. Wear-leveling mechanisms thus try and make sure writes are evenly\ndistributed across flash cells to prolong their lifespan.\n\nBecause flash memory can only be addressed in terms of blocks, and because JFFS2\nhas to handle the wear-leveling mechanism in software, you can’t just overwrite\nthe old block when you change one byte in it (in this case the config option),\nbecause you’re then writing to that same spot in memory. JFFS2 thus writes\nanother block to the flash memory with a higher version number.\n\nAnd like all good filesystems, [JFFS2 utilizes checksums for error detection](http://linux-mtd.infradead.org/~dwmw2/jffs2),\nand from what I can gather, uses a 32-bit CRC. Which means editing just the data\nportion corrupts that entire block.\n\nNow, I don’t remember if I changed all of the occurrences of `onvif_enable` last\ntime or not, but it doesn’t really matter. If a given block is bad, JFFS2 will\ngo back to the older block with a lower version number. And if I did change\nall the blocks and corrupted them, I’m assuming the `ppsapp` binary then fell\nback to sane system defaults, which was probably why I got the chime during\nboot.\n\nWe can actually grep for the block occurrences in the image:\n\n```\n$ grep -b -a -n \"onvif_enable\" extractions/cctv.bin\n22803:7849741:  \"onvif_enable\": 0,\n22857:7971273:  \"onvif_enable\": 0,\n22932:7997857:  \"onvif_enable\": 0,\n23041:8064473:  \"onvif_enable\": 0,\n23169:8197025:  \"onvif_enable\": 0,\n23195:8197893:  \"onvif_enable\": 0,\n23227:8205921:  \"onvif_enable\": 0,\n23315:8219209:  \"onvif_enable\": 0,\n```\n\nOK, OK, all that failure analysis is fun and good, but I need a working camera\nby the end of this blog post. Back to making our own JFFS2 image.\n\n```\ncp -r extractions/cctv.bin.extracted/760CCC/jffs2-root jffs2-root_modified\n```\n\nThen we edit `onvif_enable` to `1` in `jffs2-root_modified/tuya_config.json`.\n\nFinally, repack the JFFS2 image. When we issue the `mkfs.jffs2` call, we need to\nkeep in mind that the file should be in little-endian (because of the Anyka\nAK3918), and the erase block size is 4 KB (0x1000), and the image size is 640 KB\n(0xA0000), since the entire `cctv.bin` firmware image is 0x800000 and the JFFS2\nimage starts at 0x760000. Since the original image was `grep`-able, we also do\nnot want any compression.\n\n```\nmkfs.jffs2 -d jffs2-root_modified -m none -e 0x1000 -p 0xA0000 -l --pad=0xA0000 -o new_jffs2.bin\n```\n\nUnfortunately, this causes the following warning to be printed:\n\n```\nErase size 0x1000 too small. Increasing to 8KiB minimum\n```\n\nThat’s a problem for us, because the original image used an erase block size of\n4 KB. Looking through the Linux mailing lists, I came across [this thread](https://narkive.com/M1vYX9Je)\nwhere someone already tried to patch `mkfs.jffs2` to get rid of the size check,\nand it worked fine.\n\nBut that’s really strange, because I got curious as to when the check was added,\nand found that it was there since the utility was first created. Going through\nthe [Git history and blame for `mtd-utils`](https://git.infradead.org/mtd-utils.git), it seems like the check was\nthere ever since the [initial commit](https://git.infradead.org/?p=mtd-utils.git;a=commit;h=72212c137c574b564723327af751c4054c7cfca6), which was made in April of 2006.\n\nIt seemed strange that Tuya would go out of their way to change this value down\nto `0x1000` by themselves, but after researching it a bit more\n[I came across a patch in the official OpenWrt repository](https://github.com/openwrt/openwrt/blob/main/tools/mtd-utils/patches/130-lzma_jffs2.patch). They also patch\nthe size check down to `0x1000`, so I guess it is common for embedded systems!\n\nAt any rate, we can do the same thing ourselves:\n\n```\ngit clone git://git.infradead.org/mtd-utils.git\ncd mtd-utils\ngit checkout v2.3.1\n```\n\nThen download this patch and apply it:\n\n```\nindex da07b69..9a60129 100644\n--- a/jffsX-utils/mkfs.jffs2.c\n+++ b/jffsX-utils/mkfs.jffs2.c\n@@ -1668,11 +1668,11 @@ int main(int argc, char **argv)\n                                                  }\n                                                  erase_block_size *= units;\n\n-                                                 /* If it's less than 8KiB, they're not allowed */\n-                                                 if (erase_block_size < 0x2000) {\n-                                                         fprintf(stderr, \"Erase size 0x%x too small. Increasing to 8KiB minimum\\n\",\n+                                                 /* If it's less than 4KiB, they're not allowed */\n+                                                 if (erase_block_size < 0x1000) {\n+                                                         fprintf(stderr, \"Erase size 0x%x too small. Increasing to 4KiB minimum\\n\",\n                                                                          erase_block_size);\n-                                                         erase_block_size = 0x2000;\n+                                                         erase_block_size = 0x1000;\n                                                  }\n                                                  break;\n                                          }\n```\n\nNow we can build `mkfs.jffs2`:\n\n```\n./autogen.sh\n./configure --without-ubifs\nmake -j$(nproc) mkfs.jffs2\n```\n\nNow we can go back out and use the new `mkfs.jffs2` binary to create the image:\n\n```\ncd ..\n./mtd-utils/mkfs.jffs2 -d jffs2-root_modified -m none -e 0x1000 -p 0xA0000 -l --pad=0xA0000 -o new_jffs2.bin\n```\n\nAnd inject it back into the original firmware image:\n\n```\ncp extractions/cctv.bin cctv_modified.bin\ndd if=new_jffs2.bin of=cctv_modified.bin bs=1 seek=$((0x760000)) conv=notrunc\n```\n\nYay, so we just need to flash this new image. Grab the CH341A, flash it with\n`flashrom`, connect it to the Wi-Fi, and…\n\nIt doesn’t work.\n\nOK, that’s annoying. Turns out, the function that enables the ONVIF server\nisn’t referenced anywhere, according to Ghidra anyway. Nor is the function that\nsets up the RTSP streams.\n\nPerhaps I was reversing code that never gets called.\n\nBut hey, we can flash whatever we want to this device, right? Let’s try running\n`telnetd` by editing the initialization step.\n\n`./extractions/cctv.bin.extracted/370000/initrun.sh`:\n\n```\n#!/bin/sh\n\nBASE_DIR=/opt/pps\nif [ -e /tmp/PPStrong.runpath ]; then\n        BASE_DIR=`cat /tmp/PPStrong.runpath`\nfi\n\nif [ ! -e ${BASE_DIR} ]; then\n        exit\nfi\n\ntar xzf ${BASE_DIR}/app.tar.gz -C /\numount ${BASE_DIR}\n\n# Run telnet\ntelnetd -l /bin/sh &\n\nhome/init.d/initS &\n```\n\nRepack the image:\n\n```\ncd ./extractions/cctv.bin.extracted/370000/\nmkdir tmp\ncp initrun.sh tmp\ncp app.tar.gz tmp\nmkfs.cramfs tmp cramfs_new.bin\n```\n\nAnd inject it back into the firmware image:\n\n```\ndd if=cramfs_new.bin of=cctv.bin bs=1 seek=$((0x370000)) conv=notrunc\n```\n\nAnd flash. Does it work?\n\n```\n> nmap -p 23 192.168.8.11\nStarting Nmap 7.98 ( https://nmap.org ) at 2026-09-13 16:24 -0400\nNmap scan report for 192.168.8.11\nHost is up (0.038s latency).\n\nPORT     STATE  SERVICE\n23/tcp   closed telnet\nMAC Address: B4:FB:E3:C2:11:BC (AltoBeam (China))\n\nNmap done: 1 IP address (1 host up) scanned in 2.26 seconds\n```\n\nWhy?!\n\nTurns out, the `busybox` binary built into the camera doesn’t have `telnetd`.\n\nAt this point, I decided to search online if *anybody else* had ever come\nacross this camera. Surely, Tuya was a massive ecosystem of products and there\nmust’ve been *someone* who did this before I did.\n\nAnd there is:\n\n- <https://github.com/guino/ppsapp-rtsp>\n- <https://github.com/guino/Merkury1080P>\n\nSo if you are reading this, thanks @guino.\n\nGoing back to the `ppsapp` binary, I decided to do exactly what he did and just\npatch all the calls that have to do with `onvif_enable` to `1`. But I also\ndecided, just for fun, to just patch out all the checks for the `onvif_enable`\nvariable and make sure it would always unconditionally launch the ONVIF server.\nIt really is satisfying when all the instructions get turned away into `nop`s.\n\nNow, packaging this back into the original firmware is even more annoying than\nit already is, because `ppsapp` is within `app.tar.gz`, which is again within\nthe CramFS partition, which is then within the original `cctv.bin` firmware.\nSo I guess I have to package it three times now.\n\n(We’ll assume I’ve already copied the modified binary to the directory listed\nbelow…)\n\n```\ncd ./extractions/new_wifi_mod.bin.extracted/370000/app.tar.gz.extracted/0/decompressed.bin.extracted.modified/0\ntar -czf ../../../../new_app.tar.gz bin etc home\ncd ../../../../\nmkdir tmp\ncp new_app.tar.gz tmp/app.tar.gz\ncp initrun.sh tmp\nmkfs.cramfs tmp new_cramfs.bin\ncd ../../../\ncp new_wifi_mod.bin third_try.bin\ndd if=new_cramfs.bin of=third_try.bin bs=1 seek=$((0x370000)) conv=notrunc\n```\n\nUnfortunately, after flashing this image, the camera became unhappy and wouldn’t\nconnect to the Wi-Fi anymore, and the blue LED would continuously blink,\na change from the usual solid indicator.\n\nI spent several weeks (yes, weeks!) banging my head against the wall, doing all\nkinds of detours. I found a bunch of UART pads on the board itself and decided\nit might be worthwhile to hook up a serial monitor to it. I grabbed an Arduino\nI had lying around and hooked it up, but nothing got printed to the console.\n\nOn a hunch, I pulled out my multimeter and my heart dropped when I read 3.3V on\nthe pads. The Arduino Uno ran at 5V. **Oops.**\n\nThankfully, I hadn’t fried the board, because I got a USB logic analyzer to\ndetermine whether the pads were UART pads at all. And yes, they were UART pads,\nas evidenced by PulseView:\n\n![Pulseview dump screenshot](https://ericswpark.com/_astro/pulseview-dump.D6zcg_LT_Z1OuEzf.webp)\n\nSo I bought a proper USB-to-TTL adapter that could do multiple voltage levels.\nMy hope was that something in the boot output would tell me why the\ninitialization was failing.\n\n![Cables soldered to the UART pads](https://ericswpark.com/_astro/uart-pads.w8hbCrGM_ZzjOm.webp)\n\n…yeah, that’s me using the screw and pad as a ground because the last pad\nthat is ground refused to wick up solder. Thank god it was that pad and not the\nTX/RX ones.\n\nHowever, when I booted up the camera, my hopes were dashed. After the following\nprintout, it just… stopped.\n\n```\nU-Boot 2013.10.0-AK_V3.0.07 (Jan 22 2021 - 14:16:01)\n\nDRAM:  64 MiB\n8 MiB\nANYKA SDHC/MMC4.0: 0\nPPS:Jan 22 2021 14:16:03   anyka_c3:  3 \b\b\b 2 \b\b\b 1 \b\b\b 0 \nmagic err\nmagic err\ncommand:setenv bootargs mem=64M console=ttySAK0,115200n8 loglevel=10   mtdparts=spi0.0:256k(bld),64k(env),64k(enc),64k(sysflg),3m(sys),4032k(app),640k(cfg) ppsAppParts=5 ip=192.168.1.99:::255.255.255.0 eth=00:55:7b:b5:7d:f7\n## Booting kernel from Legacy Image at 81c08000 ...\n   Image Name:   Linux-3.4.35\n   Image Type:   ARM Linux Kernel Image (uncompressed)\n   Data Size:    2803328 Bytes = 2.7 MiB\n   Load Address: 81c08000\n   Entry Point:  81c08040\n   Verifying Checksum ... OK\n   XIP Kernel Image ... OK\n\nStarting kernel ...\n\nUncompressing Linux... done, booting the kernel.\nAnyka Linux Kernel Version: 1.1.12\n```\n\nI tried power-cycling the camera and pressing Enter, to be greeted with a\npassword prompt:\n\n```\nANYKA SDHC/MMC4.0: 0\nPPS:Jan 22 2021 14:16:03   anyka_c3:  3 \b\b\b 2 \b\b\b 0 \n\nplease input password::\n```\n\nHm. What can I do here, really?\n\nI tried a couple of password guesses, but they were all wrong, and each time,\nthe board would reset and start over.\n\nI thought about going through the U-Boot region on the firmware extraction and\ntrying to piece together how the password was compared and where it was stored\non memory. But I realized that part wasn’t that interesting to me, so I decided\nto try giving it to an LLM.\n\nClaude immediately refused:\n\n![Claude refuses](https://ericswpark.com/_astro/im-sorry-dave.DapRuk8o_Z1wY70c.webp)\n\nIt’d be really funny if the AI bubble popped because the companies are being\n*too* responsible, puritan, and hoity-toity about how you use their models.\n\nFine. If the US won’t help me, China will. I filed a refund request for the\nClaude subscription which had lasted all but 40 seconds, then went on OpenRouter,\ncreated an account, loaded up some credits, then made an API key. I then\nconnected it to OpenCode, selected Deepseek V4.1 Flash 1017, and then told it\nwhere I had the firmware binary file, and the specific password string that\nU-Boot spat out.\n\nAfter about 3 minutes of searching, it didn’t disappoint:\n\nYes — it’s in the firmware dump.\n\n**U-Boot password: `pps_password`**\n\nI tried it, and it worked. I was in the U-Boot environment!\n\nOK, but this feels like cheating. I’ll admit, it kinda is. I was curious as to\nwhat learning opportunity I missed out by giving this task to the LLM, so I\nexpanded the “thinking” portion to see what it had done to get to that output:\n\nThe auth routine is at `0x80E07000`; it prints `please input password::` and compares your input with a string at `0x80E244A8` (file offset `0x246A8`).\n\nThat string isn’t stored as plaintext — it’s obfuscated with a bitwise NOT. Raw bytes: `8f 8f 8c a0 8f 9e 8c 8c 88 90 8d 9b ff`\n\nInverted gives: `pps_password\\0`\n\nOK, maybe I could’ve gotten this, but maybe not? I don’t know if I would’ve\ngotten the obfuscation part without a lot more head-meet-table sessions. But\npersonally, that part is not that interesting to me. What is interesting is\ngetting this damn camera to talk to me.\n\nAfter another LLM prompt, Deepseek told me to append\n`ignore_loglevel printk.time=1 ppsdebug=onshow` to the kernel boot arguments,\nso that the `ppsapp` binary would give me more log output. OK, sure!\n\n```\nloadk\nprintenv bootargs\nsetenv bootargs `mem=64M console=ttySAK0,115200n8 ignore_loglevel printk.time=1 ppsdebug=onshow`\nbootm 0x81C08000\n```\n\n(Keep in mind that `loadk` appends a bunch more parameters after the\n`console=ttySAK0,115200n8` line, like the partition layout of the flash memory.\nYou need to copy those and append them to after `ppsdebug=onshow`. I actually\nhad to remove the `log_level` parameter entirely, because U-Boot complained\nabout the command being too long.)\n\nAnd now we got a lot more log output. I looked at the lines where it was doing\nthe Wi-Fi authentication:\n\n```\nwpa_supplicant service ... [stop] ok\nwpa_supplicant service ... [start]\n[   21.676261] [atbm_log]:br0_netdev_open()-1116: dev_get_by_name(br0) failed2!wpa_supplicant: can't load library 'libnl-3.so.200'\nwpa_supplicant service ... [start] ok\nosd set init ok--------------->ak_isp_set_user_params_do 1458, set main osd mem attr\n\n[   22.730306] ak_isp_set_user_params_do 1473 chn:0, paddr:80dbd2a0 size:50400 \n[01-01 18:12:17:845 TUYA Err][gw_intf.c:598] wf_station_connect error:-1\n[01-01 18:12:17:845 TUYA Notice][gw_intf.c:466] stop smt cfg mthd:0\nchan:0  set rect ok x:60,y:60,w:[   22.757244] ak_isp_set_user_params_do 1509 paddr:80dca280 size:5600 \n840,h:60,_,w:1920,h:1080\n[   22.774108] [atbm_log]:ieee80211_netdev_ioctrl:cmd err\n[   22.779634] [atbm_log]:ieee80211_netdev_ioctrl:cmd err\n```\n\nHm. Missing library?\n\nRemember when I issued the following command to repack the last image?\n\n```\ntar -czf ../../../../new_app.tar.gz bin etc home\n```\n\nGuess what folders there are when I do an `ls`?\n\n```\n[ericswpark@stanley 0]$ ls\nbin  etc  home  lib\n```\n\nYeah… oops. Let’s pretend that never happened and try again.\n\nAfter flashing the new firmware image, we finally got somewhere! The camera\nshowed back up on the WiFi network, and a network scan showed port `8000` was\nopen, for the ONVIF server. I tried the `admin:admin` credentials as @guino\ndocumented, but I got no response back from the server.\n\nSearching online, I found that Tuya cameras basically stop working if you\nblock access to their SDK servers. And indeed, I’d blocked them from ever\ncontacting the outside world.\n\nI decided to ask Deepseek once more to see if it could figure out where in the\n`ppsapp` binary it was doing the online connectivity check. It found the\nfollowing offsets:\n\n| Offset | Before | Before instruction | After | After instruction |\n| --- | --- | --- | --- | --- |\n| 0x78980 | 00 00 00 0A | `beq 0x78988` | 00 00 00 EA | `b 0x78988` |\n| 0x40E0C | 00 48 2D E9 | `stmdb sp!,{r11,lr}` | 00 00 A0 E3 | `mov r0,#0x0` |\n| 0x40E10 | 04 B0 8D E2 | `add r11,sp,#0x4` | 1E FF 2F E1 | `bx lr` |\n\nI tried to make sense of why these patches were important by looking at the\ndisassembly on Ghidra. The first one was for the ONVIF server, and the decompile\nin Ghidra showed that it was the function body of function `FUN_0007893c`.\nWith the patch, it removed the `else` block in the decompiled code, which I\nguess was the part that ran whenever it couldn’t reach the Tuya servers.\n\nThe other two patches were interesting. It basically turned the entire body\nof function `FUN_00040E0C` into:\n\n```\nundefined4 FUN_00040E0C(void)\n{\n    return 0;\n}\n```\n\nI guess if I learned anything from this, it’s that ARM’s equivalent to x86\\_64’s\n`ret` is `bx lr`.\n\nIf you’re interested in what the LLM had to say about how the connectivity check\nworked, you could click below to open up the transcript:\n\nClick here to read the LLM transcript\n\nThe ONVIF HTTP handler is `FUN_0007893c` (vaddr `0x7893c`). Before it parses or answers any request, it does this:\n\n```\nif (*ONVIF_ENABLED_1 != 0) {\n   if (FUN_00019f50c() != 0) {\n       return;              // <-- silently drops the request\n   }\n   if (event != 0x64) return;\n   ... handle HTTP / ONVIF ...\n}\n```\n\n`FUN_00019f50c` reads a global network/cloud state at `0x344230` and returns nonzero for states **1, 2, and 4**:\n\n- `0` → proceed\n- `1` → blocked\n- `2` → blocked\n- `3` → proceed\n- `4` → blocked\n- `5` → proceed\n\nThat state is maintained by a Tuya SDK network-monitor task (`FUN_00019fbcc` → `FUN_00019fa4c`) driven by the Wi-Fi and cloud-status callbacks. With internet blocked, the camera can get an IP and listen on 8000, but it never transitions to a “ready” state — so the handler returns before sending a single byte.\n\nAfter repackaging and building the modified firmware image again, I flashed it,\nand got promising results from `nmap`:\n\n```\n> nmap -p 8000,8554 192.168.8.11\nStarting Nmap 7.993 ( https://nmap.org ) at 2026-11-05 21:24 -0500\nNmap scan report for 101846353.lan (192.168.8.11)\nHost is up (0.085s latency).\n\nPORT     STATE  SERVICE\n8000/tcp open   http-alt\n8554/tcp open   rtsp-alt\n\nNmap done: 1 IP address (1 host up) scanned in 0.21 seconds\n```\n\nAnd when I checked the RTSP stream…\n\n![RTSP stream from the camera!](https://ericswpark.com/_astro/rtsp-stream.BCKaEsqs_8VkIv.webp)\n\n# Conclusion\n\nI learned a **lot** attempting this. But at the same time, the ending might not\nbe quite so satisfying.\n\nOn one hand, it feels like I used LLMs as a crutch, because I’m not yet skilled\nat reading ARM assembly and actually going through the motions of reverse\nengineering binaries by hand through Ghidra.\n\nOn the other hand, I still learned a lot by actually going through the motions\nof decompressing, searching, soldering, packaging, compressing, flashing, and\nthe large amount of research and time that went into this. I actually started\nthis blog post in the second week of September! Even though I was quite busy\nwith work at the same time, the roughly two months of work didn’t seem wasteful.\n\nI also think that it’s cool that LLMs are making this more accessible, and even\nthough it brings the temptation where you just offload everything to it and have\nit do all the patching and re-compressing for you to have a perfect working\nbinary firmware image at the end (because yes, I’m sure it could definitely do\nthat now), making sure that you **don’t** do that and go through the\nintermediary steps that you know how to do yourself really helps.\n\nAlso, for those that are curious: the total cost of running the Deepseek model\non OpenRouter was 22 cents. Yes, **$0.22**. You don’t need an expensive\nsubscription or sell your soul to Altman or Amodei.\n\nWould I try this again? Not for this particular class of camera. As I said in\nthe previous post, this was basically an e-waste camera that a relative of mine\ngave me for free, and we all know by now to not buy any crap from Tuya. And\nagain, good cameras that don’t pull this bullshit are cheap! I did this just\nbecause I wanted to see if I could.\n\n---\n","body_html":"<h1 id=\"taking-another-shot-at-the-cheap-ip-camera-part-2\">Taking another shot at the cheap IP camera, part 2</h1>\n<h3 id=\"november-9-2026\">November 9, 2026</h3>\n<p><a href=\"https://ericswpark.com/blog/2025/2025-04-18-a-rant-about-cheap-proprietary-ip-cameras-featuring-hej-home/\" rel=\"nofollow ugc noopener\">About a year ago</a>, I ranted about this particular cheap IP camera that was\nbased on some proprietary Chinese IoT platform named Tuya. After trying and\nfailing to get a local video stream from it without going through their servers,\nI concluded that my time would be better served by using cameras that actually\nexposed their streaming capabilities, and set it aside.</p>\n<p>Well, I recently dug the camera out while moving to my new job in New Jersey,\nand thought it might be worthwhile to give it another shot. I had plenty of\nspare time, and if I couldn’t figure it out, LLMs are recently all the rage for\nbeing really great at reverse-engineering things. But my initial goal was,\nI’d attempt it myself first, and then hand it off to an LLM if I failed and try\nand learn something from what it had figured out.</p>\n<p>So what’s our goal, exactly? We know from last time that the camera has some\nsort of ONVIF server built in. That’s basically a standardized interface for\nIP cameras, defined by the Open Network Vision Interface Forum (or ONVIF!)\nAnd most ONVIF cameras expose their video streams using RTSP, or the\nReal-Time Streaming Protocol. You may have come across this protocol if you’ve\never streamed to a live-streaming platform like YouTube or Twitch.</p>\n<p>The problem is that these servers are disabled on the firmware side, and their\nports are closed off. Last time, we tried to enable them using the configuration\noptions, but that didn’t work. Now, it’s time to figure out why that failed, and\nif there’s truly a way to enable those streams.</p>\n<p>So with that in mind, let’s first extract the firmware image with <code>binwalk -Me</code>:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Decimal</th><th>Hexadecimal</th><th>Description</th></tr></thead><tbody><tr><td>113992</td><td>0x1BD48</td><td>CRC32 polynomial table, little endian</td></tr><tr><td>458752</td><td>0x70000</td><td>uImage firmware image, header size: 64 bytes, data size: 2803328 bytes, compression: none, CPU: ARM, OS: Linux, image type: OS, Kernel Image, load address: 0x81C08000, entry point: 0x81C08040, creation time: 2021-06-21 03:03:42, image name: “Linux-3.4.35”</td></tr><tr><td>3604480</td><td>0x370000</td><td>CramFS filesystem, little endian, 3 files, total size: 3248128 bytes</td></tr><tr><td>7736524</td><td>0x760CCC</td><td>JFFS2 filesystem, little endian, nodes: 256, total size: 648000 bytes</td></tr></tbody></table></div>\n<p>OK, so it runs Linux 3.4.35. When was that released again? March 2013.\nA 13-year old kernel! (I guess it was only 8-years old when they compiled it.)</p>\n<p>Last time, we found the Tuya configuration file with the ONVIF config at\n<code>./extractions/cctv.bin.extracted/760CCC/jffs2-root/tuya_config.json</code>. I think\nthe reason it might not have worked is because we edited the firmware image\nitself with a hex editor, and doing so probably corrupted some checksum.</p>\n<p>But, we have the image extraction, so why not trace where the config option\nis being used? Perhaps the binary doesn’t even use that option at all.</p>\n<p>So what binary is launched? We should look at the initialization script of the\ncamera at <code>.\\extractions\\cctv.bin.extracted\\370000\\initrun.sh</code>. That script\nextracts some app tarball, then runs the script at <code>home/init.d/initS</code>, which\nin turn runs the other init scripts inside <code>home/init.d</code>.</p>\n<p>Most of the scripts are like, setting up the kernel parameters regarding memory\nand networking and DHCP and what not, so we’ll skip past all that. The important\nbit is the last script, which is <code>S60ppsapp</code>, which runs <code>ppsapp</code> in <code>/home/app</code>.</p>\n<p>One <code>find</code> command and we find\n<code>extractions\\cctv.bin.extracted\\370000\\app.tar.gz.extracted\\0\\decompressed.bin.extracted\\0\\home\\app\\ppsapp</code>.\nAnd <code>strings</code> tells us it has ONVIF stuff in it:</p>\n<pre><code>$ strings ppsapp | grep -C 2 &quot;onvif_enable&quot;\nmotion_area_switch\nmotion_area\nonvif_enable\nonvif_pwd</code></pre>\n<p>OK, but is there some reference to the ONVIF streaming within the binary itself?</p>\n<pre><code>$ strings ppsapp | grep &quot;Starting onvif&quot;\nStarting onvif server on port %s\n$ strings ppsapp | grep &quot;rtsp://&quot;\nrtsp://\nrtsp://%s:%d/Streaming/Channels/101\nrtsp://%s:%d/Streaming/Channels/102</code></pre>\n<p>OK, that’s good! We now know the ONVIF streaming URL format, though we still\nneed to know what port it runs on.</p>\n<p>So let’s throw the binary itself into Ghidra and run the analyzer. Looking\nthrough the strings, a lot of the hardcoded paths reference\n<code>/var/lib/jenkins/workspace/</code>, so whoever built this image probably did so with\na Jenkins pipeline. Does it really matter for what we’re doing? No, but I\nthought it was interesting. They probably have a Jenkins workflow for each\ncamera SKU they push out the door, although I’m sure they use it only once,\nconsidering that support is an afterthought.</p>\n<p>The binary itself is 2.4 MB, and I’m not that familiar\nwith reading ARM assembly, but we don’t have to, just yet! We just need to look around\nfor the onvif part since we know the config string there.</p>\n<p>On Ghidra, strings can be found by going to “Search -&gt; For Strings…”. After\nyou select the options the string search window shows up. Luckily for me,\nfiltering for <code>onvif_enable</code> shows only two places where they are used:</p>\n<p>Place 1 (warning: long)</p>\n<pre><code>undefined4 FUN_0000f3c0(void)\n{\n  bool bVar1;\n  FILE *__stream;\n  byte *__s;\n  size_t sVar2;\n  undefined4 *puVar3;\n  undefined4 *puVar4;\n  undefined4 uVar5;\n  void *__src;\n  \n  __stream = fopen64(&quot;/home/cfg/tuya_config.json&quot;,&quot;r+&quot;);\n  if (__stream == (FILE *)0x0) {\n    uVar5 = 0xffffffff;\n  }\n  else {\n    __s = malloc(0x800);\n    if (__s == (byte *)0x0) {\n      fclose(__stream);\n      uVar5 = 0xffffffff;\n    }\n    else {\n      memset(__s,0,0x800);\n      sVar2 = fread(__s,1,0x800,__stream);\n      if (sVar2 == 0) {\n        fclose(__stream);\n        free(__s);\n        uVar5 = 0xffffffff;\n      }\n      else {\n        fclose(__stream);\n        puVar3 = FUN_001f5cfc(__s);\n        if (puVar3 == (undefined4 *)0x0) {\n          uVar5 = 0xffffffff;\n        }\n        else {\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;version&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d58 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;sleep_mode&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d5c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;light_onoff&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d60 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;flip_onoff&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d64 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;watermark_onoff&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d68 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;night_mode&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d6c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;alarm_fun_onoff&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d70 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;alarm_fun_sensitivity&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d74 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;alarm_fun_mode_switch&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d78 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;alarm_fun_time_start&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d7c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;alarm_fun_time_end&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d80 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;loudspeaker_vol_pct&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279efc = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;sound_detect_onoff&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d84 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;sound_detect_sensitivity&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d88 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;event_record_time&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d90 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;enable_event_record&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d8c = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;record_enable&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279d94 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;motion_trace&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279f44 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;motion_tracking&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279ec0 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;cry_detection_switch&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279ec4 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;humanoid_filter&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279ec8 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          bVar1 = FUN_00192cf8();\n          if (bVar1) {\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;jingle_mode&quot;);\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279da0 = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;jingle_sound&quot;);\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279d9c = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;jingle_volume&quot;);\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279d98 = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n            puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;jingle_exist&quot;);\n            if (puVar4 != (undefined4 *)0x0) {\n              DAT_00279da4 = FUN_00225a88(puVar4[6],puVar4[7]);\n            }\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;motion_area_switch&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279da8 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;motion_area&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            memset(&amp;DAT_00279dac,0,0x100);\n            __src = (void *)puVar4[4];\n            sVar2 = strlen((char *)puVar4[4]);\n            memcpy(&amp;DAT_00279dac,__src,sVar2);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;onvif_enable&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            DAT_00279f00 = FUN_00225a88(puVar4[6],puVar4[7]);\n          }\n          puVar4 = FUN_001f7978((int)puVar3,(byte *)&quot;onvif_pwd&quot;);\n          if (puVar4 != (undefined4 *)0x0) {\n            memset(&amp;DAT_00279f04,0,0x40);\n            strcpy((char *)&amp;DAT_00279f04,(char *)puVar4[4]);\n            sVar2 = strlen((char *)&amp;DAT_00279f04);\n            FUN_00041ba0(&amp;DAT_00279f04,sVar2);\n          }\n          if (puVar3 != (undefined4 *)0x0) {\n            FUN_001f4480(puVar3);\n          }\n          free(__s);\n          uVar5 = 0;\n        }\n      }\n    }\n  }\n  return uVar5;\n}</code></pre>\n<p>And</p>\n<p>Place 2 (warning: also somewhat long)</p>\n<pre><code>undefined4 FUN_0000fd5c(void)\n{\n  bool bVar1;\n  undefined4 *puVar2;\n  void *pvVar3;\n  char *__s;\n  FILE *__stream;\n  undefined4 uVar4;\n  ulonglong uVar5;\n  \n  puVar2 = FUN_001f8384();\n  if (puVar2 == (undefined4 *)0x0) {\n    uVar4 = 0xffffffff;\n  }\n  else {\n    uVar5 = FUN_00225410(DAT_00279d58);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;version&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d5c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;sleep_mode&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d70);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;alarm_fun_onoff&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d74);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;alarm_fun_sensitivity&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d78);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;alarm_fun_mode_switch&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d7c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;alarm_fun_time_start&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d80);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;alarm_fun_time_end&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d64);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;flip_onoff&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d60);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;light_onoff&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d6c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;night_mode&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d84);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;sound_detect_onoff&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d88);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;sound_detect_sensitivity&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d68);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;watermark_onoff&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d90);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;event_record_time&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d8c);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;enable_event_record&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279d94);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;record_enable&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279f44);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;motion_trace&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279da8);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;motion_area_switch&quot;,(int)pvVar3);\n    pvVar3 = FUN_001f82f4(&amp;DAT_00279dac);\n    FUN_001f7b54((int)puVar2,&quot;motion_area&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279ec0);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;motion_tracking&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279ec4);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;cry_detection_switch&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279ec8);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;humanoid_filter&quot;,(int)pvVar3);\n    uVar5 = FUN_00225410(DAT_00279efc);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;loudspeaker_vol_pct&quot;,(int)pvVar3);\n    bVar1 = FUN_00192cf8();\n    if (bVar1) {\n      uVar5 = FUN_00225410(DAT_00279da0);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n      FUN_001f7b54((int)puVar2,&quot;jingle_mode&quot;,(int)pvVar3);\n      uVar5 = FUN_00225410(DAT_00279d9c);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n      FUN_001f7b54((int)puVar2,&quot;jingle_sound&quot;,(int)pvVar3);\n      uVar5 = FUN_00225410(DAT_00279d98);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n      FUN_001f7b54((int)puVar2,&quot;jingle_volume&quot;,(int)pvVar3);\n      uVar5 = FUN_00225410(DAT_00279da4);\n      pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n      FUN_001f7b54((int)puVar2,&quot;jingle_exist&quot;,(int)pvVar3);\n    }\n    uVar5 = FUN_00225410(DAT_00279f00);\n    pvVar3 = FUN_001f8294((uint)uVar5,(uint)(uVar5 &gt;&gt; 0x20));\n    FUN_001f7b54((int)puVar2,&quot;onvif_enable&quot;,(int)pvVar3);\n    pvVar3 = FUN_001f82f4((char *)&amp;DAT_00279f04);\n    FUN_001f7b54((int)puVar2,&quot;onvif_pwd&quot;,(int)pvVar3);\n    __s = FUN_001f5d2c((int)puVar2);\n    if (__s != (char *)0x0) {\n      __stream = fopen64(&quot;/home/cfg/tuya_config.json&quot;,&quot;w+&quot;);\n      if (__stream == (FILE *)0x0) {\n        free(__s);\n        return 0xffffffff;\n      }\n      fputs(__s,__stream);\n      fclose(__stream);\n      free(__s);\n    }\n    FUN_001f4480(puVar2);\n    uVar4 = 0;\n  }\n  return uVar4;\n}</code></pre>\n<p>…yeah, that’s not very fun to read. But we can figure out several things just\nfrom reasoning it out.</p>\n<p>For starters, when we open the configuration file <code>tuya_config.json</code>, notice the\nfirst function’s call is with <code>fopen()</code>, and the second parameter being <code>r+</code>.\nWhereas with the second function, the same <code>fopen()</code> call is at the end of the\nfunction with <code>w+</code>. This tells us that the first function is a config reader\nand the second function is a config writer!</p>\n<p>OK, and there’s a bunch of calls to a function named <code>FUN_001f7978</code>. What is\nthat?</p>\n<pre><code>undefined4 * FUN_001f7978(int param_1,byte *param_2)\n{\n  uint uVar1;\n  undefined4 *local_c;\n  \n  if (param_1 == 0) {\n    local_c = (undefined4 *)0x0;\n  }\n  else {\n    local_c = *(undefined4 **)(param_1 + 8);\n    while ((local_c != (undefined4 *)0x0 &amp;&amp;\n           (uVar1 = FUN_001f4230((byte *)local_c[8],param_2), uVar1 != 0))) {\n      local_c = (undefined4 *)*local_c;\n    }\n  }\n  return local_c;\n}</code></pre>\n<p>OK, what is <code>FUN_001f4230</code> then?</p>\n<pre><code>uint FUN_001f4230(byte *param_1,byte *param_2)\n{\n  int iVar1;\n  int iVar2;\n  uint uVar3;\n  byte *local_18;\n  byte *local_14;\n  \n  if (param_1 == (byte *)0x0) {\n    uVar3 = (uint)(param_2 != (byte *)0x0);\n  }\n  else {\n    local_18 = param_2;\n    local_14 = param_1;\n    if (param_2 == (byte *)0x0) {\n      uVar3 = 1;\n    }\n    else {\n      while( true ) {\n        iVar1 = tolower((uint)*local_14);\n        iVar2 = tolower((uint)*local_18);\n        if (iVar1 != iVar2) break;\n        if (*local_14 == 0) {\n          return 0;\n        }\n        local_14 = local_14 + 1;\n        local_18 = local_18 + 1;\n      }\n      iVar1 = tolower((uint)*local_14);\n      iVar2 = tolower((uint)*local_18);\n      uVar3 = iVar1 - iVar2;\n    }\n  }\n  return uVar3;\n}</code></pre>\n<p>Hm, a bit of renaming later, and:</p>\n<pre><code>uint FUN_001f4230(byte *s1,byte *s2)\n{\n  int c1;\n  int c2;\n  uint retVal;\n  byte *local_18;\n  byte *local_14;\n  \n  if (s1 == (byte *)NULL) {\n    retVal = (uint)(s2 != (byte *)NULL);\n  }\n  else {\n    local_18 = s2;\n    local_14 = s1;\n    if (s2 == (byte *)NULL) {\n      retVal = 1;\n    }\n    else {\n      while( true ) {\n        c1 = tolower((uint)*local_14);\n        c2 = tolower((uint)*local_18);\n        if (c1 != c2) break;\n        if (*local_14 == 0) {\n          return 0;\n        }\n        local_14 = local_14 + 1;\n        local_18 = local_18 + 1;\n      }\n      c1 = tolower((uint)*local_14);\n      c2 = tolower((uint)*local_18);\n      retVal = c1 - c2;\n    }\n  }\n  return retVal;\n}</code></pre>\n<p>Oh, this is just <code>strcasecmp</code>! I’m going to call it <code>strcasecmp_nc</code> because it\ndoes null checks unlike the <code>glibc</code> one. Back up a layer, a bit of renaming, and\nwe get:</p>\n<pre><code>undefined4 * FUN_001f7978(int config_data,byte *config_key)\n{\n  uint uVar1;\n  undefined4 *retVal;\n  \n  if (config_data == 0) {\n    retVal = (undefined4 *)NULL;\n  }\n  else {\n    retVal = *(undefined4 **)(config_data + 8);\n    while ((retVal != (undefined4 *)NULL &amp;&amp;\n           (uVar1 = strcasecmp_nc((byte *)retVal[8],config_key), uVar1 != 0))) {\n      retVal = (undefined4 *)*retVal;\n    }\n  }\n  return retVal;\n}</code></pre>\n<p>OK, so this function is just looking for the specific configuration key-value\npair from the given configuration data, and it does this by iterating through\nsome array/linked-list structure. Since we have the overall idea on how this\nfunction works we just rename it to <code>find_config</code> and go up a layer.</p>\n<p>What is <code>FUN_00225a88</code>, then?</p>\n<pre><code>uint FUN_00225a88(uint param_1,uint param_2)\n{\n  uint retVal;\n  int iVar1;\n  uint uVar2;\n  \n  iVar1 = param_2 * 2 + 0x200000;\n  if (param_2 * 2 &lt; 0xffe00000) {\n    if (-1 &lt; iVar1) {\n      return 0;\n    }\n    retVal = iVar1 &gt;&gt; 0x15;\n    uVar2 = -retVal - 0x3e1;\n    if (retVal &lt; 0xfffffc20 &amp;&amp; uVar2 != 0) {\n      retVal = (param_2 &lt;&lt; 0xb | 0x80000000 | param_1 &gt;&gt; 0x15) &gt;&gt; (uVar2 &amp; 0xff);\n      if ((param_2 &amp; 0x80000000) != 0) {\n        retVal = -retVal;\n      }\n      return retVal;\n    }\n  }\n  else if (param_1 != 0 || (param_2 &amp; 0xfffff) != 0) {\n    return 0;\n  }\n  retVal = param_2 &amp; 0x80000000;\n  if (retVal == 0) {\n    retVal = 0x7fffffff;\n  }\n  return retVal;\n}</code></pre>\n<p>Yeesh. I have no idea what those constants and magic numbers are. But maybe an\nLLM will. And it does!</p>\n<p>This function converts an IEEE 754 double-precision floating-point number\ninto a signed 32-bit integer.</p>\n<p>Oh, okay, so it’s literally <code>f64</code> to <code>i32</code> but in decompiled C. That was\nhelpful.</p>\n<p>So now we look at the calls again:</p>\n<pre><code>raw_config_value = find_config((int)config_data,(byte *)&quot;onvif_enable&quot;);\nif (raw_config_value != (undefined4 *)NULL) {\n  DAT_00279f00 = f64_to_i32(raw_config_value[6],raw_config_value[7]);\n}\nraw_config_value = find_config((int)config_data,(byte *)&quot;onvif_pwd&quot;);\nif (raw_config_value != (undefined4 *)NULL) {\n  memset(&amp;DAT_00279f04,0,0x40);\n  strcpy((char *)&amp;DAT_00279f04,(char *)raw_config_value[4]);\n  config_file_size = strlen((char *)&amp;DAT_00279f04);\n  FUN_00041ba0(&amp;DAT_00279f04,config_file_size);\n}</code></pre>\n<p>That is much better to look at! So all that was just reading the ONVIF key-value\npairs from the configuration file. Now we need to check where <code>DAT_00279f00</code> is\nused, but I’m going to rename that as <code>ONVIF_ENABLE</code>.</p>\n<p>Searching for references to <code>ONVIF_ENABLE</code> brings up 10 locations:</p>\n<figure><img src=\"https://ericswpark.com/_astro/onvif-enable-reference-locations.BllTNQRp_1FbAYi.webp\" alt=\"Locations where ONVIF_ENABLE is referenced\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></figure>\n<p>But, we can focus on the <code>READ</code> context only since that is probably where the\nbinary checks the config before enabling ONVIF functionality. Filter out the\nreference in the <code>write_configuration()</code> function earlier, and we’re left with\ntwo callsites:</p>\n<pre><code>int FUN_00010a98(void)\n{\n  int iVar1;\n  \n  FUN_00041304(ONVIF_ENABLE);\n  FUN_000788f8(ONVIF_ENABLE);\n  iVar1 = FUN_0001118c(0xff,ONVIF_ENABLE);\n  return iVar1;\n}\n\nint FUN_00013480(int param_1)\n{\n  int iVar1;\n  \n  if (param_1 == 0) {\n    iVar1 = 0;\n  }\n  else {\n    ONVIF_ENABLE = *(int *)(param_1 + 4);\n    FUN_00041304(ONVIF_ENABLE);\n    FUN_000788f8(ONVIF_ENABLE);\n    write_configuration();\n    iVar1 = FUN_0001118c(0xff,ONVIF_ENABLE);\n  }\n  return iVar1;\n}</code></pre>\n<p>Right off the bat, because of the call to <code>write_configuration()</code> in function\n<code>FUN_00013480()</code>, we know that this is the function that is called when the\nONVIF functionality is changed while the camera is running. The first function,\n<code>FUN_00010a98()</code>, is a bit more interesting. Let’s look at what it’s calling:</p>\n<pre><code>int FUN_00041304(int onvif_enable)\n{\n  int iVar1;\n  \n  pthread_mutex_lock((pthread_mutex_t *)&amp;DAT_0027b238);\n  DAT_0027b1f4 = (uint)(onvif_enable != 0);\n  iVar1 = pthread_mutex_unlock((pthread_mutex_t *)&amp;DAT_0027b238);\n  return iVar1;\n}\n\nint FUN_000788f8(int onvif_enable)\n{\n  DAT_0030c4cc = (uint)(onvif_enable != 0);\n  return onvif_enable;\n}</code></pre>\n<p>Strangely, there are two data locations where the ONVIF flag is set, so we’ll\nmap it to:</p>\n<ul><li><code>DAT_0030c4cc</code> -&gt; <code>ONVIF_ENABLED_1</code></li><li><code>DAT_0027b1f4</code> -&gt; <code>ONVIF_ENABLED_2</code></li></ul>\n<p>Unfortunately, I hit a wall here, because both of those variables got passed\naround a bunch of functions that kept updating different variables.</p>\n<p>I also want to check out the string “Starting onvif server on port %s” since my\n(rather uneducated) guess is that’s where the ONVIF server is started.\n(God my brain actually works sometimes)</p>\n<pre><code>void FUN_00040794(void)\n{\n  pthread_t __th;\n  int iVar1;\n  undefined4 auStack_28 [6];\n  int *local_10;\n  char *onvif_server_port_num_s;\n  \n  __th = pthread_self();\n  pthread_detach(__th);\n  FUN_001fae18(0x2293c8);\n  onvif_server_port_num_s = &quot;8000&quot;;\n  while( true ) {\n    while (iVar1 = FUN_00041358(), iVar1 != 1) {\n      sleep(1);\n    }\n    printf(&quot;Starting onvif server on port %s\\n&quot;,onvif_server_port_num_s);\n    FUN_0020f62c(auStack_28,0);\n    local_10 = FUN_002106bc(auStack_28,onvif_server_port_num_s,FUN_0007893c);\n    if (local_10 == (int *)0x0) break;\n    FUN_002157e0((int)local_10);\n    do {\n      FUN_00212158(auStack_28,500);\n      iVar1 = FUN_00041358();\n    } while (iVar1 != 0);\n    FUN_0020f6e8(auStack_28);\n  }\n  FUN_0020f6e8(auStack_28);\n  return;\n}</code></pre>\n<p>Oh great, so it runs on port <code>8000</code>! And by referencing the <code>ONVIF_ENABLE_*</code>\nvariables from earlier, we can guesstimate that there aren’t any additional\nchecks to enable ONVIF. Here’s the final disassembly I got to:</p>\n<pre><code>void check_and_enable_onvif_server(void)\n{\n  pthread_t __th;\n  int is_onvif_enabled;\n  undefined4 auStack_28 [6];\n  int *local_10;\n  char *onvif_server_port_num_s;\n  \n  __th = pthread_self();\n  pthread_detach(__th);\n  FUN_001fae18(0x2293c8);\n  onvif_server_port_num_s = &quot;8000&quot;;\n  while( true ) {\n    while (is_onvif_enabled = get_onvif_enabled_2(), is_onvif_enabled != 1) {\n      sleep(1);\n    }\n    printf(&quot;Starting onvif server on port %s\\n&quot;,onvif_server_port_num_s);\n    FUN_0020f62c(auStack_28,0);\n    local_10 = start_onvif_server(auStack_28,onvif_server_port_num_s,FUN_0007893c);\n    if (local_10 == (int *)NULL) break;\n    FUN_002157e0((int)local_10);\n    do {\n      FUN_00212158(auStack_28,500);\n      is_onvif_enabled = get_onvif_enabled_2();\n    } while (is_onvif_enabled != 0);\n    FUN_0020f6e8(auStack_28);\n  }\n  FUN_0020f6e8(auStack_28);\n  return;\n}</code></pre>\n<p>OK, cool. So how do we actually edit the configuration file, then repack it in a\nway that the camera will actually accept it?</p>\n<p>Well, we know that the configuration file <code>tuya_config.json</code> is at\n<code>./extractions/cctv.bin.extracted/760CCC/jffs2-root/tuya_config.json</code>, so instead\nof doing the dumb thing from last time where we tried to hex-edit the raw\nfirmware image, maybe we can edit the file and re-pack a JFFS2 partition image.</p>\n<p>But why didn’t the hex-edit work? Well, <a href=\"https://en.wikipedia.org/wiki/JFFS2\" rel=\"nofollow ugc noopener\">JFFS2 is a special filesystem</a> that\nis log-structured, and it’s designed for flash memory devices. I guess it’s\nsorta like F2FS, which is another filesystem designed for flash memory devices,\nbut unlike its usage on Android devices JFFS2 is designed for flash memory that\ndoesn’t have a wear-leveling mechanism on the hardware side.</p>\n<p><strong>What is wear-leveling?</strong> TL;DR: Flash chips and SSDs have flash cells. Flash\ncells have a limited lifespan and don’t like it when you write to them\nrepeatedly. Wear-leveling mechanisms thus try and make sure writes are evenly\ndistributed across flash cells to prolong their lifespan.</p>\n<p>Because flash memory can only be addressed in terms of blocks, and because JFFS2\nhas to handle the wear-leveling mechanism in software, you can’t just overwrite\nthe old block when you change one byte in it (in this case the config option),\nbecause you’re then writing to that same spot in memory. JFFS2 thus writes\nanother block to the flash memory with a higher version number.</p>\n<p>And like all good filesystems, <a href=\"http://linux-mtd.infradead.org/~dwmw2/jffs2\" rel=\"nofollow ugc noopener\">JFFS2 utilizes checksums for error detection</a>,\nand from what I can gather, uses a 32-bit CRC. Which means editing just the data\nportion corrupts that entire block.</p>\n<p>Now, I don’t remember if I changed all of the occurrences of <code>onvif_enable</code> last\ntime or not, but it doesn’t really matter. If a given block is bad, JFFS2 will\ngo back to the older block with a lower version number. And if I did change\nall the blocks and corrupted them, I’m assuming the <code>ppsapp</code> binary then fell\nback to sane system defaults, which was probably why I got the chime during\nboot.</p>\n<p>We can actually grep for the block occurrences in the image:</p>\n<pre><code>$ grep -b -a -n &quot;onvif_enable&quot; extractions/cctv.bin\n22803:7849741:  &quot;onvif_enable&quot;: 0,\n22857:7971273:  &quot;onvif_enable&quot;: 0,\n22932:7997857:  &quot;onvif_enable&quot;: 0,\n23041:8064473:  &quot;onvif_enable&quot;: 0,\n23169:8197025:  &quot;onvif_enable&quot;: 0,\n23195:8197893:  &quot;onvif_enable&quot;: 0,\n23227:8205921:  &quot;onvif_enable&quot;: 0,\n23315:8219209:  &quot;onvif_enable&quot;: 0,</code></pre>\n<p>OK, OK, all that failure analysis is fun and good, but I need a working camera\nby the end of this blog post. Back to making our own JFFS2 image.</p>\n<pre><code>cp -r extractions/cctv.bin.extracted/760CCC/jffs2-root jffs2-root_modified</code></pre>\n<p>Then we edit <code>onvif_enable</code> to <code>1</code> in <code>jffs2-root_modified/tuya_config.json</code>.</p>\n<p>Finally, repack the JFFS2 image. When we issue the <code>mkfs.jffs2</code> call, we need to\nkeep in mind that the file should be in little-endian (because of the Anyka\nAK3918), and the erase block size is 4 KB (0x1000), and the image size is 640 KB\n(0xA0000), since the entire <code>cctv.bin</code> firmware image is 0x800000 and the JFFS2\nimage starts at 0x760000. Since the original image was <code>grep</code>-able, we also do\nnot want any compression.</p>\n<pre><code>mkfs.jffs2 -d jffs2-root_modified -m none -e 0x1000 -p 0xA0000 -l --pad=0xA0000 -o new_jffs2.bin</code></pre>\n<p>Unfortunately, this causes the following warning to be printed:</p>\n<pre><code>Erase size 0x1000 too small. Increasing to 8KiB minimum</code></pre>\n<p>That’s a problem for us, because the original image used an erase block size of\n4 KB. Looking through the Linux mailing lists, I came across <a href=\"https://narkive.com/M1vYX9Je\" rel=\"nofollow ugc noopener\">this thread</a>\nwhere someone already tried to patch <code>mkfs.jffs2</code> to get rid of the size check,\nand it worked fine.</p>\n<p>But that’s really strange, because I got curious as to when the check was added,\nand found that it was there since the utility was first created. Going through\nthe <a href=\"https://git.infradead.org/mtd-utils.git\" rel=\"nofollow ugc noopener\">Git history and blame for <code>mtd-utils</code></a>, it seems like the check was\nthere ever since the <a href=\"https://git.infradead.org/?p=mtd-utils.git;a=commit;h=72212c137c574b564723327af751c4054c7cfca6\" rel=\"nofollow ugc noopener\">initial commit</a>, which was made in April of 2006.</p>\n<p>It seemed strange that Tuya would go out of their way to change this value down\nto <code>0x1000</code> by themselves, but after researching it a bit more\n<a href=\"https://github.com/openwrt/openwrt/blob/main/tools/mtd-utils/patches/130-lzma_jffs2.patch\" rel=\"nofollow ugc noopener\">I came across a patch in the official OpenWrt repository</a>. They also patch\nthe size check down to <code>0x1000</code>, so I guess it is common for embedded systems!</p>\n<p>At any rate, we can do the same thing ourselves:</p>\n<pre><code>git clone git://git.infradead.org/mtd-utils.git\ncd mtd-utils\ngit checkout v2.3.1</code></pre>\n<p>Then download this patch and apply it:</p>\n<pre><code>index da07b69..9a60129 100644\n--- a/jffsX-utils/mkfs.jffs2.c\n+++ b/jffsX-utils/mkfs.jffs2.c\n@@ -1668,11 +1668,11 @@ int main(int argc, char **argv)\n                                                  }\n                                                  erase_block_size *= units;\n\n-                                                 /* If it&#39;s less than 8KiB, they&#39;re not allowed */\n-                                                 if (erase_block_size &lt; 0x2000) {\n-                                                         fprintf(stderr, &quot;Erase size 0x%x too small. Increasing to 8KiB minimum\\n&quot;,\n+                                                 /* If it&#39;s less than 4KiB, they&#39;re not allowed */\n+                                                 if (erase_block_size &lt; 0x1000) {\n+                                                         fprintf(stderr, &quot;Erase size 0x%x too small. Increasing to 4KiB minimum\\n&quot;,\n                                                                          erase_block_size);\n-                                                         erase_block_size = 0x2000;\n+                                                         erase_block_size = 0x1000;\n                                                  }\n                                                  break;\n                                          }</code></pre>\n<p>Now we can build <code>mkfs.jffs2</code>:</p>\n<pre><code>./autogen.sh\n./configure --without-ubifs\nmake -j$(nproc) mkfs.jffs2</code></pre>\n<p>Now we can go back out and use the new <code>mkfs.jffs2</code> binary to create the image:</p>\n<pre><code>cd ..\n./mtd-utils/mkfs.jffs2 -d jffs2-root_modified -m none -e 0x1000 -p 0xA0000 -l --pad=0xA0000 -o new_jffs2.bin</code></pre>\n<p>And inject it back into the original firmware image:</p>\n<pre><code>cp extractions/cctv.bin cctv_modified.bin\ndd if=new_jffs2.bin of=cctv_modified.bin bs=1 seek=$((0x760000)) conv=notrunc</code></pre>\n<p>Yay, so we just need to flash this new image. Grab the CH341A, flash it with\n<code>flashrom</code>, connect it to the Wi-Fi, and…</p>\n<p>It doesn’t work.</p>\n<p>OK, that’s annoying. Turns out, the function that enables the ONVIF server\nisn’t referenced anywhere, according to Ghidra anyway. Nor is the function that\nsets up the RTSP streams.</p>\n<p>Perhaps I was reversing code that never gets called.</p>\n<p>But hey, we can flash whatever we want to this device, right? Let’s try running\n<code>telnetd</code> by editing the initialization step.</p>\n<p><code>./extractions/cctv.bin.extracted/370000/initrun.sh</code>:</p>\n<pre><code>#!/bin/sh\n\nBASE_DIR=/opt/pps\nif [ -e /tmp/PPStrong.runpath ]; then\n        BASE_DIR=`cat /tmp/PPStrong.runpath`\nfi\n\nif [ ! -e ${BASE_DIR} ]; then\n        exit\nfi\n\ntar xzf ${BASE_DIR}/app.tar.gz -C /\numount ${BASE_DIR}\n\n# Run telnet\ntelnetd -l /bin/sh &amp;\n\nhome/init.d/initS &amp;</code></pre>\n<p>Repack the image:</p>\n<pre><code>cd ./extractions/cctv.bin.extracted/370000/\nmkdir tmp\ncp initrun.sh tmp\ncp app.tar.gz tmp\nmkfs.cramfs tmp cramfs_new.bin</code></pre>\n<p>And inject it back into the firmware image:</p>\n<pre><code>dd if=cramfs_new.bin of=cctv.bin bs=1 seek=$((0x370000)) conv=notrunc</code></pre>\n<p>And flash. Does it work?</p>\n<pre><code>&gt; nmap -p 23 192.168.8.11\nStarting Nmap 7.98 ( https://nmap.org ) at 2026-09-13 16:24 -0400\nNmap scan report for 192.168.8.11\nHost is up (0.038s latency).\n\nPORT     STATE  SERVICE\n23/tcp   closed telnet\nMAC Address: B4:FB:E3:C2:11:BC (AltoBeam (China))\n\nNmap done: 1 IP address (1 host up) scanned in 2.26 seconds</code></pre>\n<p>Why?!</p>\n<p>Turns out, the <code>busybox</code> binary built into the camera doesn’t have <code>telnetd</code>.</p>\n<p>At this point, I decided to search online if <em>anybody else</em> had ever come\nacross this camera. Surely, Tuya was a massive ecosystem of products and there\nmust’ve been <em>someone</em> who did this before I did.</p>\n<p>And there is:</p>\n<ul><li><a href=\"https://github.com/guino/ppsapp-rtsp\" rel=\"nofollow ugc noopener\">https://github.com/guino/ppsapp-rtsp</a></li><li><a href=\"https://github.com/guino/Merkury1080P\" rel=\"nofollow ugc noopener\">https://github.com/guino/Merkury1080P</a></li></ul>\n<p>So if you are reading this, thanks @guino.</p>\n<p>Going back to the <code>ppsapp</code> binary, I decided to do exactly what he did and just\npatch all the calls that have to do with <code>onvif_enable</code> to <code>1</code>. But I also\ndecided, just for fun, to just patch out all the checks for the <code>onvif_enable</code>\nvariable and make sure it would always unconditionally launch the ONVIF server.\nIt really is satisfying when all the instructions get turned away into <code>nop</code>s.</p>\n<p>Now, packaging this back into the original firmware is even more annoying than\nit already is, because <code>ppsapp</code> is within <code>app.tar.gz</code>, which is again within\nthe CramFS partition, which is then within the original <code>cctv.bin</code> firmware.\nSo I guess I have to package it three times now.</p>\n<p>(We’ll assume I’ve already copied the modified binary to the directory listed\nbelow…)</p>\n<pre><code>cd ./extractions/new_wifi_mod.bin.extracted/370000/app.tar.gz.extracted/0/decompressed.bin.extracted.modified/0\ntar -czf ../../../../new_app.tar.gz bin etc home\ncd ../../../../\nmkdir tmp\ncp new_app.tar.gz tmp/app.tar.gz\ncp initrun.sh tmp\nmkfs.cramfs tmp new_cramfs.bin\ncd ../../../\ncp new_wifi_mod.bin third_try.bin\ndd if=new_cramfs.bin of=third_try.bin bs=1 seek=$((0x370000)) conv=notrunc</code></pre>\n<p>Unfortunately, after flashing this image, the camera became unhappy and wouldn’t\nconnect to the Wi-Fi anymore, and the blue LED would continuously blink,\na change from the usual solid indicator.</p>\n<p>I spent several weeks (yes, weeks!) banging my head against the wall, doing all\nkinds of detours. I found a bunch of UART pads on the board itself and decided\nit might be worthwhile to hook up a serial monitor to it. I grabbed an Arduino\nI had lying around and hooked it up, but nothing got printed to the console.</p>\n<p>On a hunch, I pulled out my multimeter and my heart dropped when I read 3.3V on\nthe pads. The Arduino Uno ran at 5V. <strong>Oops.</strong></p>\n<p>Thankfully, I hadn’t fried the board, because I got a USB logic analyzer to\ndetermine whether the pads were UART pads at all. And yes, they were UART pads,\nas evidenced by PulseView:</p>\n<figure><img src=\"https://ericswpark.com/_astro/pulseview-dump.D6zcg_LT_Z1OuEzf.webp\" alt=\"Pulseview dump screenshot\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></figure>\n<p>So I bought a proper USB-to-TTL adapter that could do multiple voltage levels.\nMy hope was that something in the boot output would tell me why the\ninitialization was failing.</p>\n<figure><img src=\"https://ericswpark.com/_astro/uart-pads.w8hbCrGM_ZzjOm.webp\" alt=\"Cables soldered to the UART pads\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></figure>\n<p>…yeah, that’s me using the screw and pad as a ground because the last pad\nthat is ground refused to wick up solder. Thank god it was that pad and not the\nTX/RX ones.</p>\n<p>However, when I booted up the camera, my hopes were dashed. After the following\nprintout, it just… stopped.</p>\n<pre><code>U-Boot 2013.10.0-AK_V3.0.07 (Jan 22 2021 - 14:16:01)\n\nDRAM:  64 MiB\n8 MiB\nANYKA SDHC/MMC4.0: 0\nPPS:Jan 22 2021 14:16:03   anyka_c3:  3 \b\b\b 2 \b\b\b 1 \b\b\b 0 \nmagic err\nmagic err\ncommand:setenv bootargs mem=64M console=ttySAK0,115200n8 loglevel=10   mtdparts=spi0.0:256k(bld),64k(env),64k(enc),64k(sysflg),3m(sys),4032k(app),640k(cfg) ppsAppParts=5 ip=192.168.1.99:::255.255.255.0 eth=00:55:7b:b5:7d:f7\n## Booting kernel from Legacy Image at 81c08000 ...\n   Image Name:   Linux-3.4.35\n   Image Type:   ARM Linux Kernel Image (uncompressed)\n   Data Size:    2803328 Bytes = 2.7 MiB\n   Load Address: 81c08000\n   Entry Point:  81c08040\n   Verifying Checksum ... OK\n   XIP Kernel Image ... OK\n\nStarting kernel ...\n\nUncompressing Linux... done, booting the kernel.\nAnyka Linux Kernel Version: 1.1.12</code></pre>\n<p>I tried power-cycling the camera and pressing Enter, to be greeted with a\npassword prompt:</p>\n<pre><code>ANYKA SDHC/MMC4.0: 0\nPPS:Jan 22 2021 14:16:03   anyka_c3:  3 \b\b\b 2 \b\b\b 0 \n\nplease input password::</code></pre>\n<p>Hm. What can I do here, really?</p>\n<p>I tried a couple of password guesses, but they were all wrong, and each time,\nthe board would reset and start over.</p>\n<p>I thought about going through the U-Boot region on the firmware extraction and\ntrying to piece together how the password was compared and where it was stored\non memory. But I realized that part wasn’t that interesting to me, so I decided\nto try giving it to an LLM.</p>\n<p>Claude immediately refused:</p>\n<figure><img src=\"https://ericswpark.com/_astro/im-sorry-dave.DapRuk8o_Z1wY70c.webp\" alt=\"Claude refuses\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></figure>\n<p>It’d be really funny if the AI bubble popped because the companies are being\n<em>too</em> responsible, puritan, and hoity-toity about how you use their models.</p>\n<p>Fine. If the US won’t help me, China will. I filed a refund request for the\nClaude subscription which had lasted all but 40 seconds, then went on OpenRouter,\ncreated an account, loaded up some credits, then made an API key. I then\nconnected it to OpenCode, selected Deepseek V4.1 Flash 1017, and then told it\nwhere I had the firmware binary file, and the specific password string that\nU-Boot spat out.</p>\n<p>After about 3 minutes of searching, it didn’t disappoint:</p>\n<p>Yes — it’s in the firmware dump.</p>\n<p><strong>U-Boot password: <code>pps_password</code></strong></p>\n<p>I tried it, and it worked. I was in the U-Boot environment!</p>\n<p>OK, but this feels like cheating. I’ll admit, it kinda is. I was curious as to\nwhat learning opportunity I missed out by giving this task to the LLM, so I\nexpanded the “thinking” portion to see what it had done to get to that output:</p>\n<p>The auth routine is at <code>0x80E07000</code>; it prints <code>please input password::</code> and compares your input with a string at <code>0x80E244A8</code> (file offset <code>0x246A8</code>).</p>\n<p>That string isn’t stored as plaintext — it’s obfuscated with a bitwise NOT. Raw bytes: <code>8f 8f 8c a0 8f 9e 8c 8c 88 90 8d 9b ff</code></p>\n<p>Inverted gives: <code>pps_password\\0</code></p>\n<p>OK, maybe I could’ve gotten this, but maybe not? I don’t know if I would’ve\ngotten the obfuscation part without a lot more head-meet-table sessions. But\npersonally, that part is not that interesting to me. What is interesting is\ngetting this damn camera to talk to me.</p>\n<p>After another LLM prompt, Deepseek told me to append\n<code>ignore_loglevel printk.time=1 ppsdebug=onshow</code> to the kernel boot arguments,\nso that the <code>ppsapp</code> binary would give me more log output. OK, sure!</p>\n<pre><code>loadk\nprintenv bootargs\nsetenv bootargs `mem=64M console=ttySAK0,115200n8 ignore_loglevel printk.time=1 ppsdebug=onshow`\nbootm 0x81C08000</code></pre>\n<p>(Keep in mind that <code>loadk</code> appends a bunch more parameters after the\n<code>console=ttySAK0,115200n8</code> line, like the partition layout of the flash memory.\nYou need to copy those and append them to after <code>ppsdebug=onshow</code>. I actually\nhad to remove the <code>log_level</code> parameter entirely, because U-Boot complained\nabout the command being too long.)</p>\n<p>And now we got a lot more log output. I looked at the lines where it was doing\nthe Wi-Fi authentication:</p>\n<pre><code>wpa_supplicant service ... [stop] ok\nwpa_supplicant service ... [start]\n[   21.676261] [atbm_log]:br0_netdev_open()-1116: dev_get_by_name(br0) failed2!wpa_supplicant: can&#39;t load library &#39;libnl-3.so.200&#39;\nwpa_supplicant service ... [start] ok\nosd set init ok---------------&gt;ak_isp_set_user_params_do 1458, set main osd mem attr\n\n[   22.730306] ak_isp_set_user_params_do 1473 chn:0, paddr:80dbd2a0 size:50400 \n[01-01 18:12:17:845 TUYA Err][gw_intf.c:598] wf_station_connect error:-1\n[01-01 18:12:17:845 TUYA Notice][gw_intf.c:466] stop smt cfg mthd:0\nchan:0  set rect ok x:60,y:60,w:[   22.757244] ak_isp_set_user_params_do 1509 paddr:80dca280 size:5600 \n840,h:60,_,w:1920,h:1080\n[   22.774108] [atbm_log]:ieee80211_netdev_ioctrl:cmd err\n[   22.779634] [atbm_log]:ieee80211_netdev_ioctrl:cmd err</code></pre>\n<p>Hm. Missing library?</p>\n<p>Remember when I issued the following command to repack the last image?</p>\n<pre><code>tar -czf ../../../../new_app.tar.gz bin etc home</code></pre>\n<p>Guess what folders there are when I do an <code>ls</code>?</p>\n<pre><code>[ericswpark@stanley 0]$ ls\nbin  etc  home  lib</code></pre>\n<p>Yeah… oops. Let’s pretend that never happened and try again.</p>\n<p>After flashing the new firmware image, we finally got somewhere! The camera\nshowed back up on the WiFi network, and a network scan showed port <code>8000</code> was\nopen, for the ONVIF server. I tried the <code>admin:admin</code> credentials as @guino\ndocumented, but I got no response back from the server.</p>\n<p>Searching online, I found that Tuya cameras basically stop working if you\nblock access to their SDK servers. And indeed, I’d blocked them from ever\ncontacting the outside world.</p>\n<p>I decided to ask Deepseek once more to see if it could figure out where in the\n<code>ppsapp</code> binary it was doing the online connectivity check. It found the\nfollowing offsets:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Offset</th><th>Before</th><th>Before instruction</th><th>After</th><th>After instruction</th></tr></thead><tbody><tr><td>0x78980</td><td>00 00 00 0A</td><td><code>beq 0x78988</code></td><td>00 00 00 EA</td><td><code>b 0x78988</code></td></tr><tr><td>0x40E0C</td><td>00 48 2D E9</td><td><code>stmdb sp!,{r11,lr}</code></td><td>00 00 A0 E3</td><td><code>mov r0,#0x0</code></td></tr><tr><td>0x40E10</td><td>04 B0 8D E2</td><td><code>add r11,sp,#0x4</code></td><td>1E FF 2F E1</td><td><code>bx lr</code></td></tr></tbody></table></div>\n<p>I tried to make sense of why these patches were important by looking at the\ndisassembly on Ghidra. The first one was for the ONVIF server, and the decompile\nin Ghidra showed that it was the function body of function <code>FUN_0007893c</code>.\nWith the patch, it removed the <code>else</code> block in the decompiled code, which I\nguess was the part that ran whenever it couldn’t reach the Tuya servers.</p>\n<p>The other two patches were interesting. It basically turned the entire body\nof function <code>FUN_00040E0C</code> into:</p>\n<pre><code>undefined4 FUN_00040E0C(void)\n{\n    return 0;\n}</code></pre>\n<p>I guess if I learned anything from this, it’s that ARM’s equivalent to x86_64’s\n<code>ret</code> is <code>bx lr</code>.</p>\n<p>If you’re interested in what the LLM had to say about how the connectivity check\nworked, you could click below to open up the transcript:</p>\n<p>Click here to read the LLM transcript</p>\n<p>The ONVIF HTTP handler is <code>FUN_0007893c</code> (vaddr <code>0x7893c</code>). Before it parses or answers any request, it does this:</p>\n<pre><code>if (*ONVIF_ENABLED_1 != 0) {\n   if (FUN_00019f50c() != 0) {\n       return;              // &lt;-- silently drops the request\n   }\n   if (event != 0x64) return;\n   ... handle HTTP / ONVIF ...\n}</code></pre>\n<p><code>FUN_00019f50c</code> reads a global network/cloud state at <code>0x344230</code> and returns nonzero for states <strong>1, 2, and 4</strong>:</p>\n<ul><li><code>0</code> → proceed</li><li><code>1</code> → blocked</li><li><code>2</code> → blocked</li><li><code>3</code> → proceed</li><li><code>4</code> → blocked</li><li><code>5</code> → proceed</li></ul>\n<p>That state is maintained by a Tuya SDK network-monitor task (<code>FUN_00019fbcc</code> → <code>FUN_00019fa4c</code>) driven by the Wi-Fi and cloud-status callbacks. With internet blocked, the camera can get an IP and listen on 8000, but it never transitions to a “ready” state — so the handler returns before sending a single byte.</p>\n<p>After repackaging and building the modified firmware image again, I flashed it,\nand got promising results from <code>nmap</code>:</p>\n<pre><code>&gt; nmap -p 8000,8554 192.168.8.11\nStarting Nmap 7.993 ( https://nmap.org ) at 2026-11-05 21:24 -0500\nNmap scan report for 101846353.lan (192.168.8.11)\nHost is up (0.085s latency).\n\nPORT     STATE  SERVICE\n8000/tcp open   http-alt\n8554/tcp open   rtsp-alt\n\nNmap done: 1 IP address (1 host up) scanned in 0.21 seconds</code></pre>\n<p>And when I checked the RTSP stream…</p>\n<figure><img src=\"https://ericswpark.com/_astro/rtsp-stream.BCKaEsqs_8VkIv.webp\" alt=\"RTSP stream from the camera!\" loading=\"lazy\" decoding=\"async\" referrerpolicy=\"no-referrer\" /></figure>\n<h1 id=\"conclusion\">Conclusion</h1>\n<p>I learned a <strong>lot</strong> attempting this. But at the same time, the ending might not\nbe quite so satisfying.</p>\n<p>On one hand, it feels like I used LLMs as a crutch, because I’m not yet skilled\nat reading ARM assembly and actually going through the motions of reverse\nengineering binaries by hand through Ghidra.</p>\n<p>On the other hand, I still learned a lot by actually going through the motions\nof decompressing, searching, soldering, packaging, compressing, flashing, and\nthe large amount of research and time that went into this. I actually started\nthis blog post in the second week of September! Even though I was quite busy\nwith work at the same time, the roughly two months of work didn’t seem wasteful.</p>\n<p>I also think that it’s cool that LLMs are making this more accessible, and even\nthough it brings the temptation where you just offload everything to it and have\nit do all the patching and re-compressing for you to have a perfect working\nbinary firmware image at the end (because yes, I’m sure it could definitely do\nthat now), making sure that you <strong>don’t</strong> do that and go through the\nintermediary steps that you know how to do yourself really helps.</p>\n<p>Also, for those that are curious: the total cost of running the Deepseek model\non OpenRouter was 22 cents. Yes, <strong>$0.22</strong>. You don’t need an expensive\nsubscription or sell your soul to Altman or Amodei.</p>\n<p>Would I try this again? Not for this particular class of camera. As I said in\nthe previous post, this was basically an e-waste camera that a relative of mine\ngave me for free, and we all know by now to not buy any crap from Tuya. And\nagain, good cameras that don’t pull this bullshit are cheap! I did this just\nbecause I wanted to see if I could.</p>\n<hr />","headings":[{"level":1,"text":"Taking another shot at the cheap IP camera, part 2","id":"taking-another-shot-at-the-cheap-ip-camera-part-2"},{"level":3,"text":"November 9, 2026","id":"november-9-2026"},{"level":1,"text":"Conclusion","id":"conclusion"}]}}