<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by HarishBabu Rengaraj on Medium]]></title>
        <description><![CDATA[Stories by HarishBabu Rengaraj on Medium]]></description>
        <link>https://medium.com/@reharish?source=rss-7b5248a945c6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cCD0bm0dEUx0__31RUc3Ug.png</url>
            <title>Stories by HarishBabu Rengaraj on Medium</title>
            <link>https://medium.com/@reharish?source=rss-7b5248a945c6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:11:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reharish/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Turning Boredom into Exploration: Unveiling Firmware’s Secret with Binwalk]]></title>
            <link>https://reharish.medium.com/turning-boredom-into-exploration-unveiling-firmwares-secret-with-binwalk-bc8106fb6c6a?source=rss-7b5248a945c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc8106fb6c6a</guid>
            <dc:creator><![CDATA[HarishBabu Rengaraj]]></dc:creator>
            <pubDate>Sun, 03 Sep 2023 17:37:56 GMT</pubDate>
            <atom:updated>2025-07-03T09:54:08.266Z</atom:updated>
            <content:encoded><![CDATA[<h3>Extracting Firmware form binaries using Binwalk</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*avQATwm-m8ovV_fC" /><figcaption>Photo by <a href="https://unsplash.com/@swimstaralex?utm_source=medium&amp;utm_medium=referral">Alexander Sinn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>My usual escapes from boredom are HackTheBox &amp; TryHackMe CTFs.</p><p>But, for some reasons that seems not interesting anymore. One of the reason, they are more favorable to premium/paid users in leaderboard.</p><p>Now, I need to find some other way to get rid of my boredom.</p><p>I am always curious about <strong>Reverse Engineering</strong>. Long back, I heard about binwalk while doing CTFs.</p><blockquote>Binwalk is a command-line tool in Linux that is used to analyze and extract the contents of binary files.</blockquote><p>Now, I wanna give binwalk a shot.</p><h3>What I Planned.</h3><ul><li>Download a firmware.</li><li>Extract Root file-system.</li><li>Try to Emulate in QEMU(if possible)</li></ul><h3>TASK 1: Download a Firmware.</h3><p>We have plenty of choices to choose from. I choose a random NVR’s Firmware which i already downloaded.</p><p>Task 1 completed. Ouf !, That was easy.</p><h3>TASK 2: Extract Root file-system.</h3><p>The downloaded zip file contains a dav file.</p><blockquote>A DAV file is a video created by a DVR365 or Dahua Technology digital video recorder (DVR) connected to a closed-circuit television (CCTV).</blockquote><p>But, When i run file command it shows like DOS executable.</p><pre>$ file digicap.dav <br>digicap.dav: DOS executable (COM)</pre><h4>Unleashing Binwalk</h4><p>Then, I ran binwalk on that dav file.</p><pre>$ binwalk digicap.dav <br><br>DECIMAL       HEXADECIMAL     DESCRIPTION<br>--------------------------------------------------------------------------------<br>1440          0x5A0           uImage header, header size: 64 bytes, header CRC: 0xC376C93, created: 2023-06-14 09:06:03, image size: 4435265 bytes, Data Address: 0x40008000, Entry Point: 0x40008000, data CRC: 0x9B8326E3, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: &quot;Linux-4.9.138&quot;<br>1504          0x5E0           Linux kernel ARM boot executable zImage (little-endian)<br>3968          0xF80           device tree image (dtb)<br>25780         0x64B4          xz compressed data<br>26148         0x6624          xz compressed data<br>4416416       0x4363A0        device tree image (dtb)<br>18924912      0x120C570       LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: -1 bytes</pre><p>Got a bunch of familiar files and Those files are uBoot Header, Linux Kernel, DTB, and some other compressed files. I thought, maybe the compressed files are the ones that have linux rootfs.</p><p>Now, I need to extract those archive files from the binary.</p><h4>Hmm, How could anyone extract a file from a file ?</h4><p>There are too many ways to do that.</p><ol><li>using binwalk extract option.</li><li>dd (disk destroyer) command.</li><li>Programmatic way.</li></ol><h4>1. using binwalk extract option.</h4><p>with -e flag, files are extracted into a folder by the address.</p><pre>$ digicap -e digicap.dav<br>$ ls _digicap.dav.extracted/<br>120C570  120C570.7z  64B4.xz  6624  6624.xz</pre><h4>2. using dd — command.</h4><p>I always used to google when it comes to dd.</p><pre>$ START=26148<br>$ COUNT=4390268<br>$ dd if=digicap.dav of=test.tar bs=1 skip=$START count=$COUNT<br>47141+1 records in<br>47141+1 records out<br>24136288 bytes (24 MB, 23 MiB) copied, 0.0890812 s, 271 MB/s</pre><h4>3. Programmatic way.</h4><p>At this point, all i know is simple python. So, Here it comes.</p><pre># START and END OF FILE<br>start = int(offset_byte)<br>end = int(eof_byte)<br>inputfile = &#39;digicap.dav&#39;<br><br># just the name of output<br>outputfile = f&quot;{start}-{end}_{inputfile.split(&#39;/&#39;)[-1]}&quot; <br><br># Read from input file<br>with open(inputfile, &#39;rb&#39;) as fp:<br>    fp.seek(start) # Go to offset<br>    # write to output file<br>    with open(outputfile, &#39;wb&#39;) as of:<br>        of.write(fp.read(end-start))</pre><h4>Extracted xz from dav</h4><p>All those three archives are extracted from the Firmware Binary.</p><p>Now, I extract them one by one.</p><p>The first file contains a font pack</p><p>file contains the data for UI.</p><p>Now, We have only one file. But, I couldn’t extract because it is corrupted, while extracting from the firmware. OUCH !!!…</p><pre>$ file 6624.tar.xz <br>6624.tar.xz: XZ compressed data<br><br>$ tar --xz -xvf 6624.tar.xz<br>tar: This does not look like a tar archive<br>tar: Skipping to next header<br>tar: Exiting with failure status due to previous errors</pre><p>Ah! We can run binwalk on the archive.</p><h4><strong>Pieces of a jigsaw puzzle finally coming together.</strong></h4><p>we got the sign of file system.</p><pre>$ binwalk -e 6624.tar.xz<br><br>DECIMAL       HEXADECIMAL     DESCRIPTION<br>--------------------------------------------------------------------------------<br>612           0x264           device tree image (dtb)<br>1815453       0x1BB39D        Certificate in DER format (x509 v3), header length: 4, sequence length: 1284<br>1822577       0x1BCF71        Certificate in DER format (x509 v3), header length: 4, sequence length: 774<br>4785085       0x4903BD        Certificate in DER format (x509 v3), header length: 4, sequence length: 1356<br>6867968       0x68CC00        CRC32 polynomial table, little endian<br>7133562       0x6CD97A        Unix path: /var/run/rpcbind.sock<br>7135794       0x6CE232        Unix path: /var/run/gssproxy.sock<br>7646260       0x74AC34        Unix path: /dev/vc/0<br>7725612       0x75E22C        xz compressed data<br>7776228       0x76A7E4        Unix path: /lib/firmware/updates/4.9.138<br>7791937       0x76E541        Neighborly text, &quot;neighbor_adv_enal_autocfg&quot;<br>7820895       0x77565F        Unix path: /sys/kernel/debug/sata<br>7958596       0x797044        Unix path: /sys/firmware/devicetree/base<br>7960172       0x79766C        Unix path: /sys/firmware/fdt&#39;: CRC check failed<br>7976629       0x79B6B5        Neighborly text, &quot;neighbor table overflow!is %x&quot;<br>8000840       0x7A1548        Neighborly text, &quot;NeighborSolicitsp6InMsgs&quot;<br>8000860       0x7A155C        Neighborly text, &quot;NeighborAdvertisementsrs&quot;<br>9646927       0x93334F        LZMA compressed data, properties: 0xC0, dictionary size: 0 bytes, uncompressed size: 64 bytes<br>9669092       0x9389E4        ASCII cpio archive (SVR4 with no CRC), file name: &quot;.&quot;, file name length: &quot;0x00000002&quot;, file size: &quot;0x00000000&quot;<br>9669204       0x938A54        ASCII cpio archive (SVR4 with no CRC), file name: &quot;dev&quot;, file name length: &quot;0x00000004&quot;, file size: &quot;0x00000000&quot;<br>9669320       0x938AC8        ASCII cpio archive (SVR4 with no CRC), file name: &quot;dev/console&quot;, file name length: &quot;0x0000000C&quot;, file size: &quot;0x00000000&quot;<br>.<br>.<br>.<br>13405656      0xCC8DD8        ASCII cpio archive (SVR4 with no CRC), file name: &quot;TRAILER!!!&quot;, file name length: &quot;0x0000000B&quot;, file size: &quot;0x00000000&quot;</pre><p>You can see the binaries, libraries and configs all are extracted into the folder. Looks like a pile of mess.</p><pre>$ ls _6624.extracted <br>&#39;[&#39;              do_update       ifconfig                libm-0.9.33.2.so             lzopcat       rmmod              sys<br>&#39;[[&#39;             du              ifdown                  libm.so.0                    mesg          root               tar<br> 01-udev.rules   echo            ifup                    libnsl-0.9.33.2.so           mkdir         route              test<br> 75E22C.xz       egrep           init                    libnsl.so.0                  mkdosfs       rules.d            timeout<br> 93334F          etc             init.d                  libpthread-0.9.33.2.so       mke2fs        run                tmp<br> 93334F.7z       false           initiatorname.iscsi     libpthread.so.0              mknod         S20hikbase         top<br> 9389E4.cpio     fatattr         inittab                 libresolv-0.9.33.2.so        mkpasswd      S30udev            true<br> app             fgrep           insmod                  libresolv.so.0               mnt           S31devs            truncate<br> arp             find            ipneigh                 librt-0.9.33.2.so            mount         S40distmnt         ubiattach<br> ash             format_ubifs    iscsi                   librt.so.0                   mount_ubifs   S70hostname        ubidetach<br> awk             free            iscsid.conf             libstdc++.so                 mpstat        S70ramoops         ubiformat<br> basename        fstab           jm575.bin               libstdc++.so.6               mv            S71ifconfig        ubimkvol<br> bin             fstrim          kill                    libstdc++.so.6.0.20          netstat       S80mem             ubinfo<br> blkdiscard      getty           killall                 libstdc++.so.6.0.20-gdb.py   null          S80net             ubirename<br> bsp             group           ld-uClibc-0.9.33.2.so   libthread_db-0.9.33.2.so     opt           S80update          ubirmvol<br> busybox         gzip            ld-uClibc.so.0          libthread_db.so.1            pidof         S81startbsp        udev<br> bzcat           halt            lib                     libuClibc-0.9.33.2.</pre><p>But, One file looks interesting which is 9389E4.cpio file. After a simple google search found it was an archive.</p><blockquote>A CPIO archive is created as a binary file that is not human-readable. It stores the collection of files and directories. The contents of a CPIO archive is identified with metadata information such as file names, permissions, ownership, and timestamps.</blockquote><p>By extracting the cpio ,</p><pre>$ mkdir rootfs; cd $_<br>$ cpio -id &lt; ../9389E4.cpio<br>$ ls<br>bin  dev  etc  home  init  lib  linuxrc  mnt  opt  proc  root  sbin  sys  tmp  usr  var</pre><blockquote>we got the Linux Root File system.</blockquote><figure><img alt="GIPHY.com" src="https://cdn-images-1.medium.com/max/480/1*rf6eMQAGiRwTeetwt5nwVQ.gif" /><figcaption>SOURCE: GIPHY.com</figcaption></figure><h3><strong>Task 3: From Extraction to Virtual Reality</strong></h3><p>Eager to push my exploration further, I decide to boot the extracted Linux file system using QEMU, a virtualization tool.</p><p>To do that we need mainly these things</p><ul><li>Root Filesystem</li><li>Kernel</li><li>DTB file</li><li>Machine type</li><li>Little tweak in the kernel Parameters</li></ul><pre>$ qemu-system-arm -m virt -kernel hikvision.zImage \<br>                -initrd rootfs.cpio.gz \<br>                -append &quot;root=/dev/ram&quot; \<br>                -serial mon:stdio -display none</pre><p>But I guess, I couldn’t find the right machine type for this kernel/rootfs/dtb file combination.</p><p>Anyway, atleast i can chroot into the rootfs using qemu-arm-static binary and do basic stuffs.</p><blockquote>The qemu-arm-static translates ARM machine instructions into your host cpu machine instructions.</blockquote><pre>$ ROOTFS=$PWD/rootfs<br>$ cp /usr/bin/qemu-system-arm $ROOTFS/bin/<br>$ sudo chroot $ROOTFS /bin/qemu-system-arm /bin/ash<br># id<br>uid=0(root) gid=0(root) groups=0(root)</pre><p><strong>From Boredom to Revelation</strong></p><p>What began as a remedy for boredom has evolved into an exciting journey. All thanks to Binwalk and QEMU. The once-mysterious firmware now stands before me, its enigma unraveled. Just ensure to use your newfound knowledge responsibly and ethically.</p><p>(Note: Always respect the rules and guidelines when sharing your discoveries with the world.)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc8106fb6c6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Flask using Gunicorn]]></title>
            <link>https://reharish.medium.com/deploying-flask-using-gunicorn-b0c0e8a58e07?source=rss-7b5248a945c6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0c0e8a58e07</guid>
            <dc:creator><![CDATA[HarishBabu Rengaraj]]></dc:creator>
            <pubDate>Sun, 23 Jul 2023 07:20:29 GMT</pubDate>
            <atom:updated>2023-09-03T17:46:12.320Z</atom:updated>
            <content:encoded><![CDATA[<p>I got recently introduced to the Web framework in python called <strong>Flask.</strong></p><p>What is Python-Flask,</p><blockquote>Flask is a micro web framework written in Python. It is classified as a micro-framework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.</blockquote><p>Moreover, the community is huge, you can find literally find related to everything related to Flask by a single search. Also, It is currently used by tech giants such as Netflix, Reddit and CRED.</p><p>I wrote an application, I tested the application locally by executing the script.</p><pre>python3 app.py</pre><p>github: <a href="https://github.com/reharish/meme-api">https://github.com/reharish/meme-api</a></p><p>Yes, Running Flask locally. You may probably recognize this line,</p><p>WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJO-NgziGPxfgmByzFw9CA.png" /><figcaption>app.py (stdout)</figcaption></figure><blockquote>The CLI output will tell you do not run like this as/for production. As as well in the Flask <a href="https://flask.palletsprojects.com/en/2.2.x/server/#:~:text=Flask%20provides%20a%20run%20command,reload%20when%20code%20is%20changed.&amp;text=Do%20not%20use%20the%20development,use%20only%20during%20local%20development">Deployment Documentation Page</a>.</blockquote><p>That doesn’t bother me. Anyway, I gonna deploy this as AWS EC2 instance.</p><p>To make it simpler, I wrote a Dockerfile to deployed to the server.</p><h3>Phew.. It works.</h3><p>Link: <a href="https://meme.whitedot.tk/">https://meme.whitedot.tk</a> [link broken now 😅]</p><h3>Then, My OCD kicks in..</h3><p>Is it really a bad thing ? Deploying a dev server into production with a debugger. ?</p><p>To find out I want to try compromising my own server.</p><p>Tried out this awesome guide by <a href="https://github.com/wdahlenburg/werkzeug-debug-console-bypass">wdahlenburg</a></p><p>I could able to get into the console,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*hSfyiGCF7Tgip9rRy_wGFA.png" /></figure><h3><strong>Hardening Flask’s.</strong></h3><p>Now, I decided to implement Flask properly. After a bit of search, I found that we can use a <strong>Gunicorn.</strong></p><p>We can install using pip.</p><pre>python3 -m pip install flask gunicorn</pre><p>After going through the documentation, Here are the think we need to do</p><p>Create a python file inside the project root. Like this one below.</p><pre>from app import app<br><br>bind = &quot;127.0.0.1:8080&quot;<br>workers = 2<br><br>if __name__ == &quot;__main__&quot;:<br> app.run()</pre><p>Here the bind means the socket you want to host the app. For now i’m using 127.0.0.1 to run local, you can change this to 0.0.0.0 and the workers represents something similar to threads which gonna handle the requests. (Increase the workers as per your requirements)</p><p>Then run this command to test our app. As long this script runs on the terminal the app will be online.</p><pre>/path/to/gunicorn app:app -c &lt;config.py&gt;</pre><p>To make this app more persist. We can create a systemd service which can handle the application.</p><p>create a file: <em>/etc/systemd/system/gunicorn.service</em></p><pre>[Unit]<br>Description=Gunicorn instance to serve flask application<br>After=network.target<br><br>[Service]<br>User=www-data<br>Group=www-data<br>WorkingDirectory=/var/www/meme-api/<br>Environment=&quot;PATH=$PATH:/var/www/meme-api/meme-api-env/bin&quot;<br>ExecStart=gunicorn app:app -c gunicorn_config.py<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Then we need to activate that service with these commands below.</p><pre>sudo systemctl enable gunicorn.service<br>sudo systemctl start gunicorn.service</pre><p>Thats pretty much it.</p><p>More: <a href="https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-22-04">https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-22-04</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0c0e8a58e07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>