{"id":663,"date":"2020-08-16T21:50:56","date_gmt":"2020-08-16T20:50:56","guid":{"rendered":"https:\/\/cybercop-training.ch\/?p=663"},"modified":"2020-09-07T21:26:16","modified_gmt":"2020-09-07T20:26:16","slug":"analyzing-router-firmware-p1","status":"publish","type":"post","link":"https:\/\/cybercop-training.ch\/?p=663","title":{"rendered":"Analyzing Router Firmware P1"},"content":{"rendered":"<p><strong>Challenge 1 &#8211; find network backdoor<br \/>\n<\/strong><\/p>\n<blockquote>\n<p style=\"text-align: justify;\">You have received a firmware image for forensic analysis. The network administrator uncovered this backdoor while monitoring the network. The Wi-Fi router only had port 22 and 80 open when they had installed it. However, the firewall seems to be picking up traffic on port 4763 as well. They did some preliminary analysis but to no avail. The attacker seems to have hidden the firmware well.<\/p>\n<\/blockquote>\n<p>Firmware analysis is the process of recovering, extracting, and analyzing the contents of a firmware. A firmware here refers to a software (or operating system) running on an embedded device like a router, camera, refrigerator etc.<\/p>\n<p style=\"text-align: justify;\">For this challenge I&#8217;ll use binwalk. binwalk is a solid and popular tool for working with firmware for devices which run some kind of OS. It is written in python. At a high-level, by default, binwalk iterates through all the bytes in a binary, looking for <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_file_signatures\" target=\"_blank\" rel=\"noopener noreferrer\">magic bytes<\/a>. If finds one, it will report it on a table it prints to stdout.<\/p>\n<p style=\"text-align: justify;\">It can also \u201ccarve\u201d out (\/extract) each segment it finds, so you can look at it in isolation. Use the <strong>-e flag<\/strong> to specify that it should <strong>extract files<\/strong> rather than print everything it finds to stdout. Extracted files all go into <strong>a directory called _filename.extracted<\/strong> (or _filename-[int].extracted, if that folder already exists), based on the filename of the file you\u2019ve run binwalk against.<\/p>\n<p><a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk1-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-673\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk1-2-1024x125.png\" alt=\"\" width=\"1024\" height=\"125\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk1-2-1024x125.png 1024w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk1-2-300x37.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk1-2-768x94.png 768w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk1-2.png 1304w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Let&#8217;s check the extracted content and browse in the squashfs root directory:<\/p>\n<p><a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-675\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk2.png\" alt=\"\" width=\"609\" height=\"83\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk2.png 609w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk2-300x41.png 300w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/a><\/p>\n<p>In the \/etc directory I&#8217;ll have a closer look for the rc.local file which is a well-known file used to start processes or perform a task on boot up.<\/p>\n<p><a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-677\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk3.png\" alt=\"\" width=\"602\" height=\"212\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk3.png 602w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk3-300x106.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<p>We can observe that FIREWALL_INIT is point to another file, probably a shell script. Let&#8217;s open that and see what it does<\/p>\n<p><a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-679\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk4.png\" alt=\"\" width=\"661\" height=\"553\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk4.png 661w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk4-300x251.png 300w\" sizes=\"auto, (max-width: 661px) 100vw, 661px\" \/><\/a><\/p>\n<p>The script is running a suspicious command. The command is encoded as base64 and is decoding during execution.<\/p>\n<p>I use the following command to decode, which reveals a netcat listener on port 4763<\/p>\n<blockquote><p><strong>echo \u201cbmMgLWwgNDc2Mw==\u201d | base64 -d<\/strong><\/p><\/blockquote>\n<p><a href=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-680\" src=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk5.png\" alt=\"\" width=\"795\" height=\"51\" srcset=\"https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk5.png 795w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk5-300x19.png 300w, https:\/\/cybercop-training.ch\/wp-content\/uploads\/2020\/08\/binwalk5-768x49.png 768w\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Challenge 1 &#8211; find network backdoor You have received a firmware image for forensic analysis. The network administrator uncovered this backdoor while monitoring the network. <a class=\"mh-excerpt-more\" href=\"https:\/\/cybercop-training.ch\/?p=663\" title=\"Analyzing Router Firmware P1\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":2,"featured_media":664,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4,17,16],"tags":[],"class_list":["post-663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-forensic","category-hacking","category-iot-stuff","category-linux"],"_links":{"self":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=663"}],"version-history":[{"count":12,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts\/663\/revisions"}],"predecessor-version":[{"id":695,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/posts\/663\/revisions\/695"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=\/wp\/v2\/media\/664"}],"wp:attachment":[{"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cybercop-training.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}