{"id":489,"date":"2010-04-30T16:04:11","date_gmt":"2010-04-30T08:04:11","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=489"},"modified":"2013-01-04T22:50:18","modified_gmt":"2013-01-04T14:50:18","slug":"ip-cam-hacking-pt5","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2010\/04\/ip-cam-hacking-pt5\/","title":{"rendered":"IP Cam Hacking \u2013 pt#5"},"content":{"rendered":"<p>So far in this series, we&#8217;ve learnt a few things.<br \/>\nFirst, is that this hardware is quite nice for hacking purposes, as they&#8217;ve left the uBoot in a nice state, and have easily accessible debug ports.<br \/>\nSecond is that doing this kind of thing isn&#8217;t really that complicated, and can be quite fun.<\/p>\n<p>We&#8217;re pretty much ready to start doing our own coding, as we know how the images are packed, and we can use the uBoot to either flash onl the romfs on or own, or alternately roll a complete linux + romfs binary image.<\/p>\n<p>For that, we&#8217;ll need to be ready to roll up our sleeves, and actually do some development (finally!).<\/p>\n<p>Getting a development environment setup is our next step, as we&#8217;re ready to test out adding binaries.<\/p>\n<p>I&#8217;m using Debian, but most Linux environments should be similar.  OSX is BSD based, and more of a pain due to Apple not putting everything needed in the normal places, so I&#8217;m doing this in a VM on my Macbook under Debian.<\/p>\n<p>Go grab a copy of &#8220;NUC700 Series MCU uCLinux BSP.zip&#8221; from here <a href=\"http:\/\/www.metavert.com\/public\/NO-SUPPORT\/\">http:\/\/www.metavert.com\/public\/NO-SUPPORT\/<\/a><\/p>\n<p>Setup a VM for Debian (not going to cover that) or install Debian or similar.<\/p>\n<p>Copy the zip file to \/home in the OS you use.<\/p>\n<p><code>cd \/home<br \/>\nmkdir N745<br \/>\ncd N745<br \/>\nunzip ..\/NUC700\\ Series\\ MCU\\ uCLinux\\ BSP.zip<\/code><\/p>\n<p>You should now see something like this:<\/p>\n<p><code>:\/home\/N745\/NUC700 Series MCU uCLinux BSP# ls -al<br \/>\ntotal 68<br \/>\ndrwxr-xr-x 6 root root  4096 2009-05-15 20:02 .<br \/>\ndrwxr-xr-x 3 root root  4096 2010-04-30 02:23 ..<br \/>\ndrwxr-xr-x 3 root root  4096 2009-05-15 20:06 bootloader<br \/>\ndrwxr-xr-x 2 root root  4096 2009-05-15 20:03 bsp<br \/>\ndrwxr-xr-x 2 root root  4096 2009-05-15 20:02 doc<br \/>\ndrwxr-xr-x 4 root root  4096 2009-05-15 20:02 mkrom<br \/>\n-r--r--r-- 1 root root 44632 2009-03-27 11:49 NUC700 uClinux BSP Release Note.pdf<br \/>\ndebian:\/home\/N745\/NUC700 Series MCU uCLinux BSP# <\/code><\/p>\n<p>Unfortunately the build *really* doesn&#8217;t like long filenames, so lets move all this to the N745 folder, and get rid of the annoyingly named folder.<\/p>\n<p><code><br \/>\n\/home\/N745\/NUC700 Series MCU uCLinux BSP# mv * ..<br \/>\n\/home\/N745\/# cd ..<br \/>\n\/home\/N745\/# rm -r NUC700\\ Series\\ MCU\\ uCLinux\\ BSP\/<br \/>\n<\/code><\/p>\n<p>We still need to unzip the BSP, as its compressed, so go into bsp<\/p>\n<p><code><br \/>\n\/home\/N745\/# cd bsp<br \/>\n\/home\/N745\/bsp# tar -xzvf NUC700BSP.tar.gz<br \/>\nNUC700BSP\/<br \/>\nNUC700BSP\/arm_tools.tar.gz<br \/>\nNUC700BSP\/install.sh<br \/>\nNUC700BSP\/arm_tools_3.3.tar.gz<br \/>\nNUC700BSP\/build.tar.gz<br \/>\nNUC700BSP\/applications.tar.gz<br \/>\nNUC700BSP\/uClinux-dist.tar.gz<br \/>\n<\/code><\/p>\n<p>Yay, yet another bloody subdirectory.  Sigh.<\/p>\n<p><code><br \/>\n\/home\/N745\/bsp# cd NUC700BSP<br \/>\ndebian:\/home\/N745\/bsp\/NUC700BSP# ls -al<br \/>\ntotal 183300<br \/>\ndrwxr-xr-x 2 shanghaiguide shanghaiguide     4096 2009-03-26 22:38 .<br \/>\ndrwxr-xr-x 3 root          root              4096 2010-04-30 02:29 ..<br \/>\n-rw-r--r-- 1 shanghaiguide shanghaiguide 29521418 2009-03-26 21:55 applications.tar.gz<br \/>\n-rw-r--r-- 1 shanghaiguide shanghaiguide 43742203 2009-03-26 21:22 arm_tools_3.3.tar.gz<br \/>\n-rw-r--r-- 1 shanghaiguide shanghaiguide 36108739 2009-03-26 21:11 arm_tools.tar.gz<br \/>\n-rw-r--r-- 1 shanghaiguide shanghaiguide  5643452 2009-03-26 21:24 build.tar.gz<br \/>\n-rwxr--r-- 1 shanghaiguide shanghaiguide     4370 2009-03-26 22:31 install.sh<br \/>\n-rw-r--r-- 1 shanghaiguide shanghaiguide 72439431 2009-03-26 20:53 uClinux-dist.tar.gz<br \/>\ndebian:\/home\/N745\/bsp\/NUC700BSP#<br \/>\n<\/code><\/p>\n<p>Run the install &#8211; I&#8217;ve decided to install the whole shebang to \/home\/N745<\/p>\n<blockquote><p>Note &#8211; The observant amongst you will notice I&#8217;m running this as root.<br \/>\nThis is <strong>NOT<\/strong> recommended.  I&#8217;m running under a VM solely created to play with this, so I don&#8217;t really care if I break it (as I can roll back to the initial install image fairly easy in vmware).  Don&#8217;t do this yourselves (unless you want to break things). <\/p><\/blockquote>\n<p><code><br \/>\ndebian:\/home\/N745\/bsp\/NUC700BSP# .\/install.sh<br \/>\nfirstly install arm_tools.tar.gz -->\/usr\/local\/<br \/>\nwait for a while<br \/>\nsuccessfully finished installing arm_tools.tar.gz<br \/>\nnow begin to install build.tar.gz,applications.tar.gz and uClinux-dist.tar.gz<br \/>\nPlease enter your absolute path for installing build.tar.gz, applications.tar.gz and uClinux-dist.tar.gz:<br \/>\n\/home\/N745<br \/>\n\/home\/N745 has existed<br \/>\nplease wait for a while, it will take some time<br \/>\nwhole installation finished successfully!<br \/>\ndebian:\/home\/N745\/bsp\/NUC700BSP#<br \/>\n<\/code><\/p>\n<p>We finally have our build environment unzipped, and its sitting in nuc700-uClinux.<\/p>\n<p><code>debian:\/home\/N745# cd nuc700-uClinux\/<br \/>\ndebian:\/home\/N745\/nuc700-uClinux# ls -al<br \/>\ntotal 24<br \/>\ndrwxr-xr-x  6 root root 4096 2010-04-30 02:31 .<br \/>\ndrwxr-xr-x  7 root root 4096 2010-04-30 02:31 ..<br \/>\ndrwxr-xr-x  7 root root 4096 2009-03-25 00:44 applications<br \/>\ndrwxr-xr-x  2 root root 4096 2009-03-26 21:23 image<br \/>\ndrwxr-xr-x 12 root root 4096 2009-03-26 04:54 romdisk<br \/>\ndrwxr-xr-x 10 root root 4096 2009-03-26 06:50 uClinux-dist<br \/>\ndebian:\/home\/N745\/nuc700-uClinux# <\/code><\/p>\n<p>uClinux-dist has the default binaries we want, plus we need to configure the kernel, so lets visit there first (the more adventurous can look at the other folders)<\/p>\n<p><code><br \/>\ndebian:\/home\/N745\/nuc700-uClinux# cd uClinux-dist\/<br \/>\ndebian:\/home\/N745\/nuc700-uClinux\/uClinux-dist# ls -al<br \/>\ntotal 84<br \/>\ndrwxr-xr-x  10 root root  4096 2009-03-26 06:50 .<br \/>\ndrwxr-xr-x   6 root root  4096 2010-04-30 02:31 ..<br \/>\ndrwxr-xr-x   2 root root  4096 2009-01-22 23:27 bin<br \/>\ndrwxr-xr-x   3 root root  4096 2009-03-26 06:50 config<br \/>\n-rw-r--r--   1 root root 18007 2009-01-22 23:29 COPYING<br \/>\ndrwxr-xr-x   3 root root  4096 2009-01-22 23:27 Documentation<br \/>\ndrwxr-xr-x  11 root root  4096 2009-01-22 23:29 freeswan<br \/>\ndrwxr-xr-x   5 root root  4096 2009-01-22 23:29 lib<br \/>\ndrwxr-xr-x  15 root root  4096 2009-03-26 06:50 linux-2.4.x<br \/>\n-rw-r--r--   1 root root  3228 2009-01-22 23:28 MAINTAINERS<br \/>\n-rw-r--r--   1 root root  7977 2009-01-22 23:27 Makefile<br \/>\n-rw-r--r--   1 root root  4935 2009-01-22 23:29 README<br \/>\n-rw-r--r--   1 root root  1654 2009-01-22 23:29 SOURCE<br \/>\ndrwxr-xr-x 158 root root  4096 2009-01-22 23:28 user<br \/>\ndrwxr-xr-x   4 root root  4096 2009-03-12 03:54 vendors<br \/>\ndebian:\/home\/N745\/nuc700-uClinux\/uClinux-dist#<br \/>\n<\/code><\/p>\n<p>Looks like it should be fairly easy, right?<br \/>\nWrong.<\/p>\n<p>The default build doesn&#8217;t work.   Why would it be that easy.<\/p>\n<p>You&#8217;ll end up with issues like:<\/p>\n<blockquote><p>entry-armv.S:782: Error: Internal_relocation (type 210) not fixed up<br \/>\n(OFFSET_IMM)<br \/>\nentry-armv.S:784: Error: Internal_relocation (type 208) not fixed up<br \/>\n(IMMEDIATE)\n<\/p><\/blockquote>\n<p>So, we need to make sure we start off fresh.<br \/>\nAlso, note that we&#8217;re building for an N745 cpu, so we&#8217;ll need to configure that at the make config stage.<br \/>\nLastly, and <strong>EXTREMELY<\/strong> important, is that we&#8217;ll need to put our required tools in the path.<\/p>\n<p><strong>DO NOT FORGET TO DO THIS<\/strong><br \/>\nsample PATH below:<\/p>\n<p>PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/local\/arm_tools\/bin<\/p>\n<p><code><br \/>\ndebian:\/home\/N745\/nuc700-uClinux\/uClinux-dist# PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/local\/arm_tools\/bin<\/p>\n<p>debian:\/home\/N745\/nuc700-uClinux\/uClinux-dist#make clean<\/p>\n<blockquote><p>Now we have a choice - Recommend use make xconfig if possible.<br \/>\nYou need to  have a GUI, and have tk installed.  (apt-get install tk)<br \/>\nOtherwise run make config, and run through the tediously large amount of questions<\/p><\/blockquote>\n<p><strong>OPTION#preferred<\/strong><\/p>\n<p>debian:\/home\/N745\/nuc700-uClinux\/uClinux-dist#make xconfig     <\/p>\n<p><strong>OPTION#not recommended<\/strong><\/p>\n<p>debian:\/home\/N745\/nuc700-uClinux\/uClinux-dist# make config<br \/>\nconfig\/mkconfig > config.in<br \/>\n#<br \/>\n# No defaults found<br \/>\n#<br \/>\n*<br \/>\n* Target Platform Selection<br \/>\n*<br \/>\n*<br \/>\n* Choose a Vendor\/Product combination.<br \/>\n*<br \/>\nVendor\/Product (nuvoton\/nuc710, nuvoton\/nuc740, nuvoton\/nuc745) [nuvoton\/nuc710] (NEW) nuvoton\/nuc745<\/p>\n<p>[For the rest, I used the defaults (except for the Network Tools questions, which I said Y to all)]<\/p>\n<blockquote><p>Continue here from whatever menu (x)config you used.<\/p><\/blockquote>\n<p>debian:\/home\/N745\/nuc700-uClinux\/uClinux-dist#make oldconfig<\/p>\n<p>[Needed, or compile doesn't work]<\/p>\n<p>debian:\/home\/N745\/nuc700-uClinux\/uClinux-dist#make dep<\/p>\n<p>[A gazillion pages of info later, we have a build environment!]<br \/>\n<\/code><\/p>\n<p>We&#8217;re finally ready to use our weapon of mass destruction.<\/p>\n<p><code><br \/>\ndebian:\/home\/N745\/nuc700-uClinux\/uClinux-dist#make<br \/>\n...<\/p>\n<p><\/code><\/p>\n<p>It should compile without issue.  <\/p>\n<p>Next step is to mount our created rom image, and copy the binaries off, or just go to the compiled folders, and get the binaries.<\/p>\n<p>I&#8217;ve done this step already, and have a zip file of a few useful files ready.<\/p>\n<p>-rwxr-xr-x  1 root root  110888 2010-04-30 03:50 ftpd<br \/>\n-rwxr-xr-x  1 root root   55164 2010-04-30 03:52 ping<br \/>\n-rwxr-xr-x  1 root root 1201904 2010-04-30 03:51 ssh<br \/>\n-rwxr-xr-x  1 root root 1219864 2010-04-30 03:51 sshd<br \/>\n-rwxr-xr-x  1 root root  118004 2010-04-30 03:45 telnet<br \/>\n-rwxr-xr-x  1 root root   45460 2010-04-30 03:45 telnetd<\/p>\n<p> file *<br \/>\nftpd:    BFLT executable &#8211; version 4 ram<br \/>\nping:    BFLT executable &#8211; version 4 ram<br \/>\nssh:     BFLT executable &#8211; version 4 ram<br \/>\nsshd:    BFLT executable &#8211; version 4 ram<br \/>\ntelnet:  BFLT executable &#8211; version 4 ram<br \/>\ntelnetd: BFLT executable &#8211; version 4 ram<\/p>\n<p>Download that here &#8211; <a href='http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/04\/arm7-nettools.zip'>arm7-nettools<\/a><\/p>\n<p>All we need to do now is mount our romfs image, unzip the arm7-nettools.zip, copy the arm7 bFLT binaries over to bin, add telnetd, sshd, and  ftpd to our \/bin\/init, and rebuild by running genromfs on our filesystem.<\/p>\n<p>We can then finally flash our new romfs, and test it out.<\/p>\n<blockquote><p>\nDon&#8217;t forget that romfs is a read only file system, so we can&#8217;t modify it by mounting it.  We need to mount, copying everything to elsewhere, do our required bits and pieces, then rebuild.<\/p>\n<p>eg<\/p>\n<p>mount -o loop -t romfs still_unsure.img \/mnt\/test -r<\/p>\n<p>mkdir \/mnt\/new<br \/>\ncd \/mnt<br \/>\nrsync -arv \/mnt\/test\/ new<br \/>\ncd new\/bin<br \/>\nwget http:\/\/www.computersolutions.cn\/blog\/wp-content\/uploads\/2010\/04\/arm7-nettools.zip<br \/>\nunzip arm7-nettools.zip<br \/>\nrm arm7-nettools.zip<\/p>\n<p>[We need to also edit init]<br \/>\npico init<\/p>\n<p>Add <\/p>\n<p>sshd&#038;<br \/>\ntelnetd&#038;<br \/>\nftpd&#038;<\/p>\n<p>eg &#8211;<br \/>\ncat init<br \/>\nmount -t proc none \/proc<br \/>\nmount -t ramfs none \/usr<br \/>\nmount -t ramfs none \/swap<br \/>\nmount -t ramfs none \/var\/run<br \/>\nmount -t ramfs none \/etc<br \/>\nmount -t ramfs none \/flash<br \/>\nmount -t ramfs none \/home<br \/>\ncamera&#038;<br \/>\nsshd&#038;<br \/>\ntelnetd&#038;<br \/>\nftpd&#038;<br \/>\nsh<\/p>\n<p>Change to the next directory up, and lets run genromfs<\/p>\n<p> genromfs -d new -f testrom.img<br \/>\ndebian:\/mnt# ls testrom.img<br \/>\ntestrom.img<br \/>\ndebian:\/mnt# ls -al testrom.img<br \/>\n-rw-r&#8211;r&#8211; 1 root root 3329024 2010-04-30 04:18 testrom.img<\/p>\n<p>In theory, this should be usable (famous last words!).\n<\/p><\/blockquote>\n<p>Unfortunately, I can&#8217;t try testing on that at home, as all the equipment is at the office, but that should be fairly easy.<\/p>\n<p>Probably also some small config issues to sort out, as ftpd, telnetd and sshd will probably choke without their related \/etc\/whatever config files needed, but we can sort that out via serial on the debug ports.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So far in this series, we&#8217;ve learnt a few things. First, is that this hardware is quite nice for hacking purposes, as they&#8217;ve left the uBoot in a nice state, and have easily accessible debug ports. Second is that doing this kind of thing isn&#8217;t really that complicated, and can be quite fun. We&#8217;re pretty [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[252,1],"tags":[248,258,245,118,240,250,249,247],"class_list":["post-489","post","type-post","status-publish","format-standard","hentry","category-ip-cam","category-uncategorized","tag-arm7","tag-debian","tag-foscam","tag-howto","tag-ipcam","tag-nc745","tag-nuvoton","tag-uclinux"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=489"}],"version-history":[{"count":13,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/489\/revisions"}],"predecessor-version":[{"id":918,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/489\/revisions\/918"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}