Unbricking the Mini PTZ V2

pozzello

Known around here
Joined
Oct 7, 2015
Messages
2,270
Reaction score
1,117
same here in the /home/.config file:

#
# Ambarella Sensor Configuration
#
# CONFIG_SENSOR_MT9T002 is not set
# CONFIG_SENSOR_MT9T002_MIPI is not set
# CONFIG_SENSOR_MT9T002_PARALLEL is not set
# CONFIG_SENSOR_AR0130 is not set
# CONFIG_SENSOR_AR0141 is not set
# CONFIG_SENSOR_AR0230 is not set
# CONFIG_SENSOR_AR0230P is not set
# CONFIG_SENSOR_OV2710P is not set
CONFIG_SENSOR_OV4689_MIPI=y
# CONFIG_SENSOR_OV5653 is not set
# CONFIG_SENSOR_OV9710 is not set
...


still no lovin with the NFS mount:

# mount -t nfs -o nolock 192.168.0.1:/nfs/share_1 /home/nfs_local/
mount: 192.168.0.1:/nfs/share_1 failed, reason given by server: Permission denied
mount: mounting 192.168.0.1:/nfs/share_1 on /home/nfs_local/ failed: Bad file descriptor


edit:

hang on, i had changed the name of the share while farting around:

# mount -t nfs -o nolock 192.168.0.1:/nfs/share1 /home/nfs_local/
#

that's more like it. will grab mtdblock4...
 

Zeddy

Getting the hang of it
Joined
Jun 19, 2016
Messages
92
Reaction score
42
The screen print on your board doesn't label the pads - but the same pads are there.
Pretty easy to hook up the USB to serial TTL convertor and see what's going on.

Thanks for the info on the password attempt.
I don't think JtR is going to cough up the zip password in my lifetime.
Unlike the Huisun telnet root password which took very little time. I kicked it off, looked away, when I looked back it was done. The log showed 13s.
When I get back home from work I'll hook something up. I should have a USB -> TTL somewhere. I figured there might be serial port on one of those test points but wasn't sure which. I even tried desoldering the coin cell on the PCB to see if that would reset anything, but it didn't.

BTW how are you using JtR on the firmware zip? When I try and to a zip2john on the file I get "package.bin is using old encryption!"
 

klasipca

Banned
Joined
Mar 27, 2014
Messages
3,146
Reaction score
750
cool tried telnet access with port 3232, works as expected. Don't know what to do there, so hoping something good comes out of all this messing around. :)
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
BTW how are you using JtR on the firmware zip? When I try and to a zip2john on the file I get "package.bin is using old encryption!"
I'm using the jumbo version here:
/home/alastair/john-1.7.9-jumbo-7-Linux-x86-64/run/zip2john
With this resultant password file from zip2john
/home/alastair/cctv/Huisun/IPNC_S2l1.0.2_build201512161014.zip:$pkzip$1*2*3*0*4b7eae*4b7d67*384fc10a*0*45*8*3e*5221*/home/alastair/cctv/Huisun/IPNC_S2l1.0.2_build201512161014.zip*$/pkzip$
Giving this result:
0:00:00:00 Starting a new session
0:00:00:00 Loaded a total of 1 password hash
0:00:00:00 - Hash type: PKZIP (lengths up to 31)
0:00:00:00 - Algorithm: 32/64
0:00:00:00 - Candidate passwords will be buffered and tried in chunks of 64
0:00:00:00 - Configured to use otherwise idle processor cycles only
0:00:00:00 Proceeding with "single crack" mode
What firmware file version did you try?
 

Zeddy

Getting the hang of it
Joined
Jun 19, 2016
Messages
92
Reaction score
42
The firmware I'm using is IPNC_S2l2.0.1_build201603031830.zip. I'll try your version and see how I go.

I'm using the built in JtR from Kali Linux. I'll try the jumbo version if it's not installed. I gave fcrackzip a go, but it was getting false positives, I was testing with unzip option but it reduced performance to a crawl. I've got a beefy haswell 6 core to load test, this would be a good workload for it. I wouldn't mind finding something that can take advantage of CUDA in the graphics card.
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
I wouldn't mind finding something that can take advantage of CUDA in the graphics card.
I compiled the 1.8.0 jumbo version of JtR after having installed CUDA support for an Nvidia card, but I couldn't get the resultant program to recognise the CUDA libraries, despite them being where it complained they were not.
Does your installed JtR have the option to use all CPU cores? (fork=n)
 

Zeddy

Getting the hang of it
Joined
Jun 19, 2016
Messages
92
Reaction score
42
I'm using the jumbo version here:

With this resultant password file from zip2john

Giving this result:


What firmware file version did you try?
I installed the "Bleeding Jumbo" based on 1.8.0 https://github.com/magnumripper/JohnTheRipper
I was having trouble compiling the jumbo one from the openwall site. Failing on MD5 hashes or something. It was recommended to use this patched version.

The zip2john worked fine, but the hashed output file is over 10MB in size. JtR seems to be processing it, all 12 cores of the virtual machines host are flat out at 100% :eek:nthego:

It's been running for 12 hours now and no hits. I've tried the dictionary file that is included and the one from Kali but no hits there. Perhaps a rainbow table is next? I did do some more reading and the encryption it's using isn't suited for CUDA use, so I can't use the graphics card for it.

This is the firmware file I'm using.
IPNC_S2l2.0.1-build20160303
 

klasipca

Banned
Joined
Mar 27, 2014
Messages
3,146
Reaction score
750
I installed the "Bleeding Jumbo" based on 1.8.0 https://github.com/magnumripper/JohnTheRipper
I was having trouble compiling the jumbo one from the openwall site. Failing on MD5 hashes or something. It was recommended to use this patched version.

The zip2john worked fine, but the hashed output file is over 10MB in size. JtR seems to be processing it, all 12 cores of the virtual machines host are flat out at 100% :eek:nthego:

It's been running for 12 hours now and no hits. I've tried the dictionary file that is included and the one from Kali but no hits there. Perhaps a rainbow table is next? I did do some more reading and the encryption it's using isn't suited for CUDA use, so I can't use the graphics card for it.

This is the firmware file I'm using.
IPNC_S2l2.0.1-build20160303
There is one user that got in somehow https://www.ipcamtalk.com/showthread.php/6978-Mini-PTZ-v1-Firmware-Discussion?p=96689#post96689
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
cool tried telnet access with port 3232, works as expected. Don't know what to do there, so hoping something good comes out of all this messing around. :)
Well, if you forget your web GUI password, you can use the fixed telnet root password to look it up, it's held in plain text ... not good.
At least in Hikvision's NVRs the passwords in the exported device configuration file are hidden by the file encryption. But hang on - it's the same cipher and key they use all over the NVR, so they can be extracted too. Oh well.
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
I spent (quite) a while last night exploring how to unbrick this Mini PTZ V2 camera and eventually succeeded.
And I'd promised @pozzello I'd write it up for this forum in response to the challenge that he'd set me.
So - how to cut a long story short? That's not going to happen - as it did take me longer than I thought it would!
Including dealing with a Catch-22 situation where you can have working hardware but no root command access, or root access but only partly working hardware.
It's actually not going to be that short - but hopefully will still be of interest, and maybe even useful, to the techies amongst us.

To recap slightly - the camera was bricked after it accepted a mismatching firmware version. It appeared dead.
But finding and using the serial console connections showed that there was actually a lot of activity.
The kernel was booting OK, but the firmware was falling over in the final stages when starting up the application.
Amboot, the Ambarella bootloader, was fully functional.
Transcripts of initial findings are in the first post of this thread.

In any forensic examination it's good practice to gather as much info as possible before changing anything.
So I was able to use the Amboot 'spinor dump <memory address range>' command to extract in hex form the entire flash storage via a PuTTY logfile.
This was converted into binary and split into the segments corresponding to the 5 flash partitions, the mtdblocks.
mtdblock4 at 16MB, labelled 'lnx', was a jffs2 file system image.
With a bit of trickery this can be mounted on a Linux box after a pseudo mtd device has been created. It yielded a file system that had much of the Linux components present, but none of the application components.
So how to apply the full firmware when there is no web GUI update, and the firmware file is ZIPped with a strong password?
Amboot suggests an upgrade path via a USB device - but that would need special firmware from Huisun.
Mtdblock4 could be cloned from a working copy, given a functional enough root shell access to the kernel.
So I extracted the kernel root hash from my reconstituted mtdblock4 and cracked it very easily. @pozzello agreed to try, and succeeded, a telnet access to his working Mini PTZ and pulled out a copy of mtdblock4.
That was pretty well done, as he had to set up an NFS share and configure the mount point in the camera.

Having decided on the method, now to finally attempt some changes to implement it.
As it stands, there is no shell access on bootup, the console finally just pops up the same handful of odd characters every few seconds, and no shell prompt is available.
Bootloaders such as U-boot and Amboot pass command-line startup parameters to the Linux kernels they boot.
These are configurable.
The camera was using a standard
"[ 0.000000] Kernel command line: console=ttyS0 root=/dev/mtdblock4 rw rootfstype=jffs2 init=/linuxrc"
which uses the init function of Busybox to process the contents of /etc/inittab to start the system up.
Well - that looks easy!
Just replace "init=/linuxrc" with "init=/bin/sh" and I'll have root shell access so I can re-write mtdblock4.
Sure enough - the device boots eventually to a full root shell.
But - the console shows quite a few differences in getting there.
No network interface - unable to be initiallised. That's a bummer - how to get files in and out?
Problems with the memory manager.
No /proc interface, or a few of the other standard kernel facilities.
In summary, no real facility to be able to bring the mtdblock4 copy in and apply it.
I did at this point insert a Micro-SD card, but trying to access it just gave garbage, and I did not know how to attempt formatting it from the shell.

At this point, what had seemed like it would be straightforward had just receded into the distance.
I tried manually executing the commands in /etc/inittab, and lots of others, but it seemed like the kernel was not functioning properly. No way to configure the network when the hardware apparently does not exist.
Experiments showed that ANY parameters given to the Amboot 'boot' command resulted in only partially working hardware.
I'd speculate that this is an Amboot bug - that a modified boot command is not resetting and initiallising the hardware properly.
I tried all sorts of things and got nowhere.
Definitely a form of Catch-22 situation.

Until -
Finally, I decided to try customising the scripts that /etc/init.d/rcS processes as part of /etc/inittab processing.
I renamed the existing ones out of the way. Anything named S??* gets processed.
Here is what i created, to attempt to get it executed as part of a normal startup, a bit like a trojan horse.
Code:
#!/bin/sh
echo "Just about done"
/sbin/ifconfig
/sbin/ifconfig eth0 192.168.1.131 up
/sbin/route add -net 192.168.1.0 netmask 255.255.255.0 eth0
/sbin/ifconfig
/usr/sbin/telnetd
/bin/mount -t nfs -o nolock 192.168.1.12:/home/alastair/tftp_root /tmp
/bin/cp /etc/inittab /tmp
/bin/ls -al /tmp
#
date >> /etc/init.d/status.log
/sbin/ifconfig >> /etc/init.d/status.log
mount >> /etc/init.d/status.log
ping -c 5 192.168.1.12 >> /etc/init.d/status.log
ls -al /dev/mmc* >> /etc/init.d/status.log
df >> /etc/init.d/status.log
How did I transfer the file?
Just a small amount of trickery - copy the text to the PC clipboard, then at the camera use the echo command pasting the text in:
echo "pasted text from the PC" > S01udev.sh
and the new small text file is created.
chmod +x S01*
and it's ready to use.


And it worked! Mostly.
On bootup, the console still showed the bunches of odd characters every few seconds.
But I could ping the camera.
But there was nothing showing in my tftp_root folder.
Rebooting to to the shell prompt showed that the nfs mount command wasn't working, some bogus error about no known route to host.
But when I rebooted normally again, I did a port scan and saw that telnet was running!
And I could log in via telnet to a root shell, with the cracked root password.
Wow! Home straight here we come.

OK, so manually trying the nfs mount still didn't work.
But with no app running, there is loads of free memory available, so plenty of space to copy in the 16MB mtdblock4 file with tftp.
Last hurdle in sight!
I issued the oh-so-familiar (from Hikvision) command
cat mtdblock4 > /dev/mtdblock4
"Permission denied - read-only device". Shades of Hikvision NVRs.
OK, so lets try flashcp from the full-fat Busybox that Huisun are using, unlike those skinny Hikvision versions.
flashcp -v mtdblock4 /dev/mtdblock4
"Not an mtdblock flash device"
Hmm... OK, try
flashcp -v mtdblock4 /dev/mtd4
"Erasing flash ....
Writing flash ....."
So it appeared to do what I had so wanted it to do. Dare I reboot? What's it going to do?
Well, I rebooted, and watched with amazement as the camera sitting on the floor with wires sticking out started it's calibration dance. And the console showed so much more activity, apps starting up, video status message etc etc.
It was working!

But I couldn't ping it, or access the web GUI. SADP (amazing how Hikvision-like this camera is) showed it on a foreign IP address - presumably due to something I'd not considered - it was @pozzello 's configuration in the mtdblock4 he'd sent me.
I changed the PC IP address and was able to get a web GUI logon page. But the default logon credentials didn't work.
I was part way through penning a PM to @pozzello to ask for his password, and hope it wasn't embarrassing or too rude when I thought it might be worth looking in the config files to see if it was available.
And it was, in plain text! And it worked.

I think that's much more than enough for now.
Thanks for reading.

Footnote : With the cracked linux root password, and the web GUI passwords held in plain text, these cameras are wide open.
 
Last edited by a moderator:

klasipca

Banned
Joined
Mar 27, 2014
Messages
3,146
Reaction score
750
This looks like far more complex unbricking process then with Longse cam which was also bricked with wrong firmware.
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
This looks like far more complex unbricking process then with Longse cam which was also bricked with wrong firmware.
Yes, I agree, but the method was the same - directly update the flash mtdblocks with the correct versions via a shell access.
At the end of the day - the method was simple enough - but my long explanation of how I got there makes it sound more complex.

Your VF camera was working OK apart from no VF - web GUI OK, telnet access OK.
This Huisun PTZ would have been simple too but for the fact that activating the shell access using the changed bootparams broke the standard shell ways to do the updates.
I'm pretty sure it's got to be a little bug in the specific version of Amboot installed, not something deliberate.
 

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
@LeeH - I'm wondering if your bricked Mini PTZ V2 is a firmware issue and not a hardware fault?
You reported the same symptoms as @pozzello s - no network traffic, no movement on power up.
Do you still have the camera?
 
Last edited by a moderator:

vasycara

Getting the hang of it
Joined
Jun 22, 2015
Messages
227
Reaction score
48
with new firmware-IPNC_S2l2.0.1_build201607221508.JPGFrom my experience with this min PTZ :
I tried it IPNC_S2l2.0.1_build201602010919 update firmw, in me Mini ptz v2.Another time was fine with this firmw, so this firmw is good. I had several times put this file in me Mini ptz. Mini PTZ .BEGINNING UPDATING AND ON THE 88% FAILED.Mini PTZ was still visible brauser, and I tried to firmw IPNC_S2l2.0.1_build201603031830, all the same ON THE 88% FAILED.
Another time was fine with this firmw, so this firmw is good. I knew that if I reboot and mini PTZ will be dead. I did not reboot, I accessed the telnet, seemed to have an error in sd card.
I removed the mini sd card from mini PTZ and I put everything in telnet mtdblock4 tab, reboot, and everything is ok.
Then after reboot, everything was ok and I tried updating to the same tab in brauser and did update ok. But with sd card out.
I suspect failed due to firmware bug sd card.
I then tried the update with firmw IPNC_S2l2.0.1_build201607221508 in brauser updated ok with this firmw. (sd card is removed) .I'm mentioning ,that ,with this firmw I brycuited
first time ,mini PTZ and now she goes perfectly ,with sd memory card out of the mini PTZ.
I will make updates firmw just outside sd card.
I mention that without help from Mr. Alastairstevenson .. me mini PTZ was now dead.
This is my experience with this min PTZ maybe help someone.
 
Last edited by a moderator:

alastairstevenson

Staff member
Joined
Oct 28, 2014
Messages
15,973
Reaction score
6,797
Location
Scotland
I am impressed that you have done these experiments.
The results look quite interesting.
You appear to have found a flaw in the Huisun firmware update routine.
I wonder how many other people can say if they had an sd card in when they had a firmware update failure?
It will be interesting to see what comments your post gets.
Well done!
 

klasipca

Banned
Joined
Mar 27, 2014
Messages
3,146
Reaction score
750
None of mine had SD card but early builds for v2 did not have fully implemented SD card slots requiring you soldier something as reported by Techbill
 

pozzello

Known around here
Joined
Oct 7, 2015
Messages
2,270
Reaction score
1,117
FWIW, the V2 I bricked going from 201603031830 to 201606201315 did have an SD-card in it at the time.
pretty sure I took it out while trying to recover it and before sending it to greener pastures...
 
Top