479 points · by wilsonfiifi · 6y ago · 89 comments
I was trying to reverse-engineer my parent's network CCTV DVR so I could hopefully integrate it with Home Assistant - as far as I'm aware the sluggish smartphone apps are still the only way to access those boxes. I wasn't ever able to get as far as George did with his IP cameras; I hit a snag on trying to correctly reassemble the H264 streams, so all I ever got out of it was mostly corrupt still frames.
If you're reading this George, well done! :D
Well done!
I don't really have any use for C today, but it definitely taught me a lot. It was intimidating at first, but when the concept of pointers finally clicked I felt like I had a sense of control in the language, and things were relatively deterministic and predictable.
I did most of my projects in C for a few years, but eventually got sucked into the JS ecosystem like pretty much everyone else at the time. These days I mostly work in .NET - C# is constantly evolving, and with .NET Core it's seemed to strike a good balance between powerful tooling, cross-platform support, performance, and just fun language features. I'm pretty content for now :)
Also very impressive code OP!
[1] https://www.thirtythreeforty.net/posts/2019/08/mastering-emb...
1. Were the requirements just vague? e.g. PRD just says "Encrypt the payload somehow, lol" and junior engineer Charlie, not being a crypto expert, just made something up? If so, that should have been caught and corrected by a code review. More eyes than Charlie would have at least looked at it and should have raised an alarm.
2. Did the requirements actually say "The payload shall be XOR'ed with the string 'Charlie is the designer of P2P!!' and then the bytes shuffled around as such: [...]" and everyone agreed this would be great? Where is engineering/security leadership push-back during the design phase, in that case?
3. Did the requirements call for proper encryption, and Charlie just ran out of time and cobbled this together? Again--code review, maybe insufficient project planning?
I mean, bugs slip in to code all the time, but this seems like something deliberately done this way and deliberately ignored through the entire design, development, test, and deploy process!
That is some excellent Google-Fu!
I had never thought about Googling the reversed-endian versions of hexadecimal constants -- until you wrote about doing this; I think it's a brilliant idea, so I'm adding it to my search engine technique toolbox.
In summation, it's a great idea!
It's both simple and elegant!
I have written a lot of ONVIF stuff, and have done pretty similar stuff with WireShark and Cocoa Packet Analyzer.
Video is still surprisingly proprietary, even after all this time.
I got the ONVIF stuff sorted, but the challenges I deal with, these days, is providing the video in a realtime streaming format that can be interpreted by as many clients as possible (especially Apple). RT[S]P doesn’t really cut it.
There is even a nice sample application that you can try out without having to write any code.
https://github.com/Kurento/kurento-tutorial-java/tree/master...
As you probably know, Apple is not just badly supported in the surveillance industry, it is actively hated.
As I was working on the ONVIF stuff, I encountered this quite often. As soon as people found out I was working on Apple stuff, the relationship would go belly-up.
I ended up not bothering to renew my ONVIF membership, because it didn’t really buy me anything.
I created a “breadboard” streaming server for ffmpeg[0], but I’ve put my ONVIF stuff aside for a while, as I work on Bluetooth projects.
I ended up reverse engineering a bunch of the hikvision protocol for the bits that I could not do with ONVIF.
I think that one of the reasons that its uptake has been slow, is because manufacturers like to keep everything "in-house," and aren't too happy to allow devices they don't make to access their equipment.
I understand that. I really do. I worked for a manufacturer like that for ages. All kinds of hell can break loose, when you move from proprietary to open. It's not a simple transition.
The people that do like it, though, are the integrators. They are the ones that buy cameras in lots of a thousand, so there is definitely a case to be made in its favor.
(I developed pyGridware, which was based on SOAP and WSDL. It took hundreds of lines of code just to build Echo Hello World.
I had used Wowza to take multiple rtsp streams (from cctv cameras) and properly stream to multiple clients (Flash h.264 player and iOS streaming).
That's not-so-simple. The VLAN folks have written some excellent SDKs for their VLCKit engine, but it is quite "heavy." I've also messed around with ffmpeg, but that's not much lighter, and doesn't easily work on iOS.
Another consideration for iOS is battery use. Video tends to be a bit "piggy," when it comes to power usage.
I am sort of waiting to see who comes out of the scrum. Video is just too damn important to be allowed to remain the rather chaotic mess it's in now.
Now its someone elses problem transcoding the data into millions of formats for every device under the sun...
The camera industry is shady AF with everything listed as call-for-price. I hate trying to source anything for it.
One other approach that could have been taken: to add the desired protocols into the camera directly. I assume you're just adding a control channel and the video stream encapsulation would be minimal.
Don't underestimate the licensing cost of the software. Afaik most camera vendors use http://www.live555.com/mediaServer/ for the RTSP server software. There's a licensing cost for commercial use.
btw I wouldnt be surprised if they didnt even pay HEVC royalties.
― William Wordsworth
I was thrilled to see a rigorous reverse engineering article. It's exactly the sort of thing I always hope to find when I browse HN. But I have to admit, it was a special delight to get to the end and find that the author was a fellow MSU alum. :)
This is working for me with an Amcrest camera, but I also got a Reolink E1 thinking it supported RTSP and felt cheated when I learned it didn't. I'll be playing with Neolink the rest of the day. Thanks.
Great job and realy well written post.
Nextwave Piranha CNC protocol -- easy, about three days of work Virtucache for VMWare ESXi -- easy-ish, about five days of work to completey take apart SONY camera firmware -- quite hard, about two weeks of work Loc8tor tracking tags - easy once I understood how active RFID works
It may not always get you to the finish line, but without any documentation, persistence and some tools is all you have anyway. Knowledge is acquired during the process.
I found myself wondering while reading the article what the guys notes look like. Does he screenshot everything and bullet point as he goes along? Or does he hit a logical stopping point and write up what worked from A-B, B-C etc.?
It's massively inspiring though.
If you don't mind a different style (clam shell), you can get them for significantly less: https://www.aliexpress.com/item/33025755888.html
I suspect both AliExpress listings are an order of magnitude more expensive than they can be purchased on Taobao, but then you have to A) find it on Taobao, and B) use a shipping agent in China to export it.
Found a US-based seller who has them for $3/each (min quantity 10): http://siliconkit.com/ocart/index.php?route=product/product&...
Ah, the model number is listed on the flashrom wiki: https://www.flashrom.org/Technology#SO8.2FSOIC8:_Small-Outli...
Edit: Here's the Taobao link: https://item.taobao.com/item.htm?id=576521466919
https://item.taobao.com/item.htm?id=529625834683
and looks like others have pointed out various resellers.
I bombed digital systems classes (I didn't actually fail, but I really suck at it) and I want to get better. I give out this info just to relay my feeble grasp at what is happening here.
Seeing the layout of the flash in a straight forward image like this is pretty inspirational honestly. Definitely will be checking out more of his work.