Author: xathrya

Home / Author: xathrya

Running Firmware on Qemu

August 4, 2017 | Article | 1 Comment

As a reverse engineer, especially if we deal with embedded system, facing various architecture and its typical system is expected. Sometimes we have no access to the device and got only the firmware. In this condition, our only option is static analysis of the firmware, or it is not?

Our goal is to observe and extract the knowledge from inner part of the device. From the abstract things we call software. Modern device implement logic on a software and most of them incorporate an operating system to manage the resources and to run the program. Linux is very popular for it’s existence and support in various processor. This software stack (from linux kernel to various user space program) are coupled and packaged as a firmware (or firmware stack).

In this article we will discuss about firmware stack and how we can possibly run it on Qemu. The steps described here should be treated as a generic steps. I hope it can be used for the different setup you use.

Obtain the Materials

You can install Qemu from source or download it via your package manager.

We are discussing about firmware so naturally to practicing we need a firmware for reference. Here we will use following firmware. This fimware is a firmware for Linksys EA4500 , a wifi router that is publicly available for download. You can also download and use arbitrary firmware you want, but make sure you read the next section and know the architecture of the devices. It can be either ARM, MIPS, x86, etc.

Firmware Stack and Basic Concept

Fundamentally, software stack for PC-compatible and embedded system have different arrangement. In PC we use HDD to store the operating system and any user space program we need. The booting process come from BIOS (which is firmware in motherboard), to bootloader, and then the kernel on the disk. It’s very modular and we can replace the components as we want. We can upgrade it individually. In embedded system we have no luxury on that level. In most case, every components are tightly coupled, as well as the firmware.

Most modern embedded system incorporate linux system. The firmware stack, be it for your typical wireless routers to smart devices, consists not only softwares. They are also packed with a whole partition, in this case in squashfs format. This filesystem, known as rootfs, is used in runtime in similar manner to our partition. You might ask why. Linux kernel always need a minimum filesystem. Even in booting proses it use initramfs or initrd which is minimal filesystem.

There might be many sections inside the firmware file, but for most firmware they have minimum three components: the bootloader (ex: U-boot), kernel, rootfs. Flashing process might rearrange them to different place, but our focus is on the firmware file itself, before flashing.

So here’s the basic concept.

The filesystem used in runtime is packed inside the firmware, mostly using squashfs format. Therefore, we need to extract that filesystem. One of the tool in our disposal is binwalk. Read the next section for detail. So if we have both kernel and filesystem we can boot the system? That’s a pitfall there. We have no guarantee that booting the firmware in “normal” flow will give success result. If we are successful, we can see the system running. If not, we might not able to enter the shell and stuck.

Why?

Remember that the operating system in embedded system is interfacing many things, including peripheral, sensors, actuators, etc. When linux kernel is booting, it spawn the first use space program called init to initialize all runtime configuration the embedded system need. If for some reason the initialization fail, and high chance it will, then the system might have no stable state. And, that’s why we might have our system stuck.

So here’s the trick. In the end we need working kernel with working filesystem. How do we make sure that booting is completed? No, we don’t. We are cheating a little here. We skip it. We are pretending that the booting is complete. From here on we can invoke various commands there, and investigate how system behave. We complete this by using chroot and use the Qemu as the shell. While observing foreign architecture, all of this operations are done in our lovely x86 machine.

Firmware Extraction

If the firmware layout is simple enough, then we might identifying something like this.

file FW_EA4500V3_3.1.7.181919_prod.img

 

We use binwalk to identify the firmware component and automatically extract the content.

binwalk -e FW_EA4500V3_3.1.7.181919_prod.img

Here, binwalk is generous enough. We see three sections there. The first section, blue rectangle, start from offset 0, is a bootloader. It will  boot a Linux kernel for MIPS architecture. The second is red rectangle, the linux kernel. The third one is the squashfs filesystem.

Binwalk will create a folder and extract the content to that folder. For example, we got this. The squashfs is automatically extracted as squashfs-root.

 

There we can see the familiar directory structure.

Running the System

After all preparation we have done, it’s time for the actual thing.

Note that the kernel in this case is the 40.7z however, when doing a chroot we are using our own kernel and sandboxing the environment of running embedded system so kernel is not really used here.

Because we will interact with MIPS

First we need to copy the qemu-mips-static to the root directory of our squashfs (squashfs-root). Then we will chroot to that environment.

cd squashfs-root
cp $(which qemu-mips-static) bin/qemu
chroot . qemu /bin/sh

Sure, we can then do anything as if this were the fully working embedded system shell.

I Passed eMAPT Certification

June 20, 2017 | Publication | No Comments

Two days ago, I had completed my journey in eMAPT (eLearnSecurity Mobile Application Penetration Tester) certification. The certificate ID is eMAPT-117 which can be verified here. This is my second certification process and I am glad that I pass this.

So what’s the fun in eMAPT?

As eLS said, eMAPT certification is really practical. It uses no multiple-choice style of exam. In the certification process, I was tasked to create a program to exploiting the vulnerabilities in certain application. Worry not. In the MASPT (Mobile Application Security and Penetration Testing) course, the course provided for eMAPT certification, we can learn many things from the basic and fundamental concept. I can say that eLS had done a good job elaborate the course materials with lots of labs experience.

Oh, the course itself has two sections. One for Android and another one for iOS.

That’s for it. I won’t spoil the fun more than it is.

It’s been a while after my latest post about “building something”.

Lately I want to download some files from vulnhub site. Since some months ago I accidentally delete my collection (which are not touched often), I have to redownload most of them (16 pages). Manual download is not an option as I rarely stay at home with rather stable home connection. It is also not possible for me to use torrent when I am doing onsite pentesting. Therefore I decide to build a dedicated box for torrent activity.

The next section is about the requirements I need and the solution I have. If, for whatever reason, you want to know the steps of building then you can skip the next section.

Requirements

What I want is a small box with sufficient resource, supplied by stable connection. It would sits in my room, connected to internet and can be remotely controlled wherever I am. PC is overkill for this task, besides I don’t have working PC right now. The alternative is single board computer. From many options I have (Raspberry Pi, Beagleboard, ODROID, etc) I pick ODROID. It might be subjective but my ODROID XU4 has 2 slots of USB3, which some SBCs don’t have.

Storing downloaded files on a single SD card is not wise. I use one of my external HDD as storage, connected via USB3, should be fast enough.

There exists some implementation of bittorent client for linux. But I use Transmission. It works fine.

When I said “the box should be able to remotely controlled wherever I am”, I didn’t mean to give it a dedicated IP address. It’s obviously mandatory for us to keep our box behind the firewall. So for this goal, I need a rendezvous point, a tunnel, a middleman which will redirect all traffic between my box and me. It’s not port forwarding on router. I don’t have access to that. To solve this, I can use socat or ssh tunnel for creating two open end tunnel. However, I need simple and reliable solution so I use service for that. Either ngrok, PageKite, and Forward are suitable but I choose ngrok.

Setup

0. Minimal Setup

I use ODROID XU4 as BSC. You can read the user manual here.

The operating system I choose is Ubuntu minimal, which can be downloaded here. I only need linux as base system and no need fancy GUI so ubuntu minimal is perfectly fine.

Consult the user manual to burn the image to uSD card. Though some aspect is different you can use this article as guide.

1. Component Installation

Don’t forget to update the package list and confirm that we have working connection

apt-get update

Install transmission.

apt-get install transmission-cli transmission-common transmission-daemon

Like other service, transmission is composed of a daemon (transmission-daemon) that manage all bittorrent activities and clients. The transmission-cli is a client program, use CLI.

Check whether the service is working fine.

service transmission-daemon start
service transmission-daemon stop
service transmission-daemon reload

Don’t forget to enable it.

systemctl enable transmission-daemon

Next we need to install ntfs-3g package to mount NTFS partition. We also need unzip to unzip files and screen to create a background job elegantly.

apt-get install ntfs-3g unzip screen

2. Disk Configuration

In this article, I mount my disk on /mnt/disk0. I also create a directory on /mnt/disk0/transmission with following subdirectories for torrent operation.

mkdir /mnt/disk0
ntfs-3g /dev/sda1 /mnt/disk0
mkdir /mnt/disk0/transmission
cd /mnt/disk0/transmission
mkdir completed incomplete torrents

3. Configuration Script

Transmission daemon need a configuration script in /etc/transmission-daemon/settings.json to run properly. If the service is restarted or stopped then started, a new configuration file is created (overwriting the old one) so if we have customed the script then we need to reload the script. However accident might happen, thus we move the original file to safe location and link it.

mv /etc/transmission-daemon/settings.json /opt/transmission-settings.json
ln -s /opt/transmission-settings.json /etc/transmission-daemon/settings.json

Next we configure it. There are some settings I change so you should adjust it to your case (trunked)

"download-dir": "/mnt/disk0/transmission/completed",
...
"incomplete-dir": "/mnt/disk0/transmission/incomplete",
"incomplete-dir-enabled": true,
...
"rpc-authentication-required": true,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-password": "[email protected]",
"rpc-port": 9091,
"rpc-username": "ursa",
"rpc-whitelist": "127.0.0.1,*.*.*.*",
"rpc-whitelist-enabled": true,
...
"umask": 2,
...
"watch-dir": "/mnt/disk0/transmission/",
"watch-dir-enabled": true

To enable remote connection, we need RPC. It will listen on port 9091, ready for taking command. I don’t want the box is left without authentication so we need to supply one. On my In this example I need to supply “ursa” as username and “[email protected]” as the password.

4. Setting up Rendezvous Point

To use ngrok service we are obligated to have valid identity there. Sign up here to begin. You need to get an API key which will be used by ngrok.

Download the “agent” into our box. As the ODROID is an ARM board, we need the ARM version of ngrok. Extract and authenticate.

wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
unzip ngrok-stable-linux-arm.zip
mv ngrok /usr/local/bin/ngrok
ngrok authtoken <your auth token here>

Ngrok need tio remain running for functioning tunnel.In some case it is not possible therefore we need to run ngrok on detachable session. Screen is used for that.

screen

There we are on a screen session. Run the ngrok, create a tunnel for tcp port of 9091.

ngrok tcp 9091

Read the endpoint described there. It should be a domain of ngrok with some port.

To exit, first CTRL+A and then press D. We are out of screen session but the ngrok is still running on that session.

Testing

Download Transmission Remote GUI. Click on Torrent – Connect to Transmission – New connection. Fill the URL offered by ngrok earlier and don’t forget to enable authentication.

Hai,

Aku Satria Ady Pradana. Seorang reverse engineer dan konsultan yang biasa disebut sebagai xathrya.

Beberapa bulan yang lalu, tepatnya bulan Februari, kami mendirikan sebuah komunitas kecil bernama Reversing.ID. Reversing.ID adalah sebuah komunitas berbasis kesamaan minat yang berfokus pada pembahasan segala hal berkaitan dengan Reverse Engineering. Dengan kata lain, ini adalah wadah bagi peminat RE untuk berkreasi dan berdiskusi serta membongkar segala macam hal yang menarik.

Tujuan kami sederhana, memasyarakatkan Reverse Engineering dan mengumpulkan orang untuk dapat saling berbagi dan bertukar pikiran tentang Reverse Engineering.

Reverse Engineering kadang dianggap sebagai sesuatu hal yang tabu, ilmu hitam, dan dekat dengan dunia underground. Hal ini tidak sepenuhnya benar. Reverse Engineer dapat digunakan oleh seorang programmer untuk mempelajari program jadul dan melakukan porting ke platform yang baru. Reverse Engineer juga dapat digunakan untuk mempelajari alur program untuk menemukan bug terutama security. Pada akhirnya, semua ilmu bergantung kepada sang pengguna.

Apa yang kami lakukan?

  • Berbagi challenge dan pembahasannya
  • Berbagi materi dan bahan bacaan
  • Diskusi tentang suatu materi
  • Kulgram (kuliah telegram) yang membahas topik tertentu.

Bergabung bersama kami di

Last week I was invited to give a talk about reverse engineering basic. Frankly, this is the most excited talk for me. It is not very common theme for a seminar in university level so I think we need more. I had two days for my presentation. The first day is a seminar and the second day is the workshop.

The first day I talk about basic and common things and reverse engineering. To be honest, Reverse Engineering is a broad term so we had to focus our attention to software reverse engineering or reverse code engineering. I emphasize on three things in any Reverse Engineering process: Comprehension, Decomposition, and Reconstruction, as you can see in the slide. Though, I am not an expert in this field.

In the workshop we also had many hands on. It is difficult to teach assembly language in such time (2 hours) so I decided to bring CIL in. The “assembly” in .NET language is relatively easy for newcomers and the participant might have not hurt their head too much.

As always, you are free to read and spread it.

The slides for seminar can be obtained from here.

 

The slide for workshop is available here.

So there was a seminar and workshop, a week ago. Not a big one, limited to at least 30 people. DracOs is invited to give a workshop, and I was one of the speaker. The presentation I brought is about memory forensics. This is an introduction and we were discussing certain basic of memory forensic there. I got two slots, the seminar in the morning and the workshop in the afternoon.

For workshop we were talking about Volatility framework for analysis and some tools for dumping memory in Windows. We also had handson material. We were not analyzing some random sample of memory dump, but we were analyzing a memory dump of host which infected by malware.

As always, you are free to read and spread it.

For the Seminar, you can grab it here.

 

For the workshop, you can grab it here.

Some days ago I was invited to give a talk about security. The presentation I brought is just an insight about security. How do we start learn and what to learn. What I want to give is a fundamental concept of hacking / penetration testing, not an instant hacking.

As always, you are free to read and spread it.

It was quite old. On March I deliver a workshop about web security in Depok, Indonesia. The main theme is of course about web security. The presentation slides is avalable on my slideshare. Mostly we were talking about web security with OWASP as our references. The slides is always free and you may spread it as you like. If you have a question you can direct your question to me.

Best regards,

Satria Ady Pradana.

There is a misconception in some community that Windows doesn’t support hard link and symbolic link as in Unix world. Most of us think that Windows OS only support link (with .lnk extension) and I’ve seen that there are also several articles point out that symbolic linking in Unix world is closely resemble to Windows .lnk file.

Though the concept is not very similar, we can say that Windows has three type of linking: hard link, junction, and symbolic link. Before we go through them, let’s give the concept of hard link and symbolic link (soft link).

Links in Unix

In Unix world, symbolic link (also termed as soft link) is a special kind of file that points to another file. Well, hard link too is a special kind of file that points to another file. The difference between two is symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system. The difference gives symbolic link certain qualities that hard links does not offer, such as the ability to link to directories, or to files on remote computers network through NFS. When we delete a target file, symbolic links to the file become unusable. Whereas the hard links preserve the contents of the file. So we can say that hard link is essentially a label or another name assigned to a file. Operation executed upon any of these “different names” will be operated upon the original file. When the original file is deleted, the hard link will still persist. You can think it as a reference count.

In Unix, these commands create symbolic link and hard link respectively.

# Symbolic Link
ln -s target link

# Hard Link
ln target link

Concept of Links in Windows

Now let’s go to the Windows world. The definition of hard link and symbolic link is nearly similar.

A hard link is the file system representation of a file by which more than one path references a single file in the same volume.MSDN states that any changes to the file are instantly visible to applications that access it through the hard links that reference it. Changes in the original file will be reflected in every hard link made to that file. Thus, if there are multiple hard link point to a READ-ONLY file and we want to delete a particular hard link, then after delete it we need to reset the READONLY attribute to any of remaining hard link (or original file).

A symbolic link is a file-system object that points to another file system object. The object being pointed to is called the target. They are transparent to users; the links appear as normal file or directories and can be acted upon by the user or application in exactly the same manner.

Then, what is junction?

Junction (Microsoft refer it as soft link) is similar to hard link. Indeed it is a hard link. It differs from a hard link in that the storage object it references are separate directories and a junction can link directories located on different local volumes on the same computer. Otherwise it is identical to hard link.

The Command (Utility)

Hard Link

mklink /H link target

Symbolic Link

# File Symbolic Link
mklink link target

# Directory Symbolic Link
mklink /D link target

Junction

mklink /J link target

Create Link Programmatically

Hard Link: CreateHardLink

Symbolic Link: CreateSymbolicLink

Misc

So what’s the different of these links with .lnk file?

Well we need to see the representation. Links are file system object while the .lnk file is a file. The .lnk file is a file describe the redirection and any extra operation need to perform when it is executed. The links are only redirection to the file.

To feed our brain, NTFS has many advanced options that is unknown to us as end-user.

List of Alternative Android Emulator

March 25, 2017 | Article | No Comments

Android is a popular operating system for handheld and now dominating the market share. Though the there are already exists various cheap devices running android, many of us want want to run android on our PC. I myself has two reasons for this: first to play some games without open my device, and second is to test my application.

Fortunately, there are plenty of them available, from free to paid one. This article is not an exhaust list of android emulator, but serve as a purpose as a documentation of emulator I had known and taste (some of them).

The Basic Concept

Many years ago the only processor supported by android is ARM architecture. The only way to start an android in our PC is through official Android emulator, bundled with the SDK. It is so slow due to many things. We name it emulator, as we are emulating the android environment (in ARM) to run in our PC environment (in x86/x86-64). Then some projects exists to port Android to x86 architecture. This unofficial build is known as Android x86. Later, Android officially support x86 processor which is not very different to PC one. However, we still need this piece of software, emulator. Why?

Android is an operating system for mobile device such as mobile phone, tablet, smart TV, etc. Android device has many different hardware variation as each manufacture can ship any hardware they like but android ensure that the platform is viewed as one uniform. Android abstract the complicated and give it as a single platform. As a platform, android has different component those are different to PC (typically a Windows PC). For example the interface and the application format, they are different. So to make android application running on top our Windows PC, there should be something that can bridge this two platform, and that would be an emulator.

Simply, an emulator is a hardware or software that enables one platform (called host) to behave like another platform (called guest). These android emulator can run the application simply by providing environment that looks like the real device. We are not seeing Android from the point of processor is run on, but the Android platform as a whole.

Android, in Android SDK, has ship an official emulator for testing. But this emulator is proven to be slow and need much time for startup. So there are many people starts to create some lightweight android emulators that can boot android faster and consume less resource, compared to official one. Unless you tweak the emulator, like enabling Intel HAXM (Hardware Accelerated Execution Manager), these alternative emulators are preferable.

You can also see other article about Inside the Android Emulator series to discuss something deeper than this.

The List

  1. Nox App Player
  2. BlueStacks
  3. GenyMotion
  4. Andyroid
  5. YouWave
  6. Visual Studio Android Emulator
  7. MEmu
  8. Jar of Beans
  9. Manymo
  10. Xamarin Android Player
  11. MEmu

Nox App Player

Site: http://en.bignox.com/

Definitely my favorite. Minimalist yet provide many things.

It is one of the best options available to emulate android on PC. It also supports wide range of Android Gaming controls. And the best part of this, Nox App Player support most of the top android games. This full-fledged android emulator will need us to set some things, such as google accounts. Apart from the standard mouse and keyboard support, Nox also support several input/output devices such as gamepads and controllers. Nox also support multiple emulator instances, or profile you might say. This way we can have more than one emulator each with different configuration.

Technically, Nox App Player use (at this time) an Android 4.4.2 kernel, or preferably called Android KitKat. It mimics UI operations on a tablet or smartphone so the learning curve is not steep. Also Nox comes with the Google Play Store integrated into the install package. In my experience, Nox App Player is also easy to use for penetration testing purpose.

BlueStacks

Site: http://www.bluestacks.com/

A big player in this emulation world. BlueStacks is mature enough and support almost all of android games and apps that play store is offering. Some sites recommends it as the first option to emulate android. No wonder, BlueStack supports about 96% of the games and apps available on Play Store (in their claim).

GenyMotion

Site: https://www.genymotion.com/

What’s interesting for me is their GenyMotion on demand, aside of their android emulator on our local PC. It is an Android AMs on Amazon EC2 infrastructure. While the local emulator is proven fast, it also offer graphic acceleration and use x86 as its base, which is not different to our PC.

Some sites recommends it as the first alternative for BlueStack or now might be the first opinion for Android emulator.

Andyroid

Site: http://www.andyroid.net/

Also known as Andy OS. One of the feature is one can use their phone as remote control while playing a game through the emulator. It even supports seamless, wireless transition of apps from computer to android device.

YouWave

Site: https://youwave.com/

There are two version available at this time. The free version use Android 4.0 (Ice Cream Sandwich) and the premium version use Android 5.1 Lollipop.

Visual Studio Android Emulator

Site: https://www.visualstudio.com/vs/msft-android-emulator/

One of project / component in Visual Studio that can be installed on demand. Similar to Windows Mobile emulator, this product need Hyper-V installed. And when running, Hyper-V (as well as Visual Studio Android Emulator) will locks the virtualization support exclusively and not sharing it with other software like VirtualBox or VMware. One of the feature that highlighted is the Work-From-Home, which makes it works over remote desktop.

MEMU

Site: http://www.memuplay.com/

A new but promising emulator.

Technically, it uses Android 4.4 as default image for any instance. Optionally, you can also download the Android 5.1 as base system if you like.

Jar of Beans

Site: http://forum.xda-developers.com/showthread.php?t=1975675

Sadly, it has been discontinued.

From XDA forum, home of android hackers. It is an android jelly beans emulator and allows us to do easy installation and configuration. It supports multi user in the form of profile and enables us to customize our own settings. We can also create Virtual SD card. It requires no setup as it is completely portable.

Manymo

Site: https://www.manymo.com/

Sadly, it has been discontinued.

They said Manymo is a better emulator. Unlike other emulator, Manymo is an in-browser emulator and support multiple android versions. It means, you need no installation, you only launch the emulator you need. Their target audience is developer, which wants to eliminates the tedious task by providing a facility to test apps on different android version without having those devices. They say it’s lightweight as the actual computation is held on their end but you need stable internet connection to use it.

Xamarin Android Player

Site: https://www.xamarin.com/

Sadly, it has been discontinued.

Xamarin specialize itself in mobile application development. They create SDK which makes us able to deliver an application in native Android, iOS, and Windows platform. One of their suite is their emulator.

While the development itself had been ceased, you can still download the Xamarin Android Player for free.

Xamarin provides various version of Android, from 4.1.1 (Jelly Bean) to 5.1.0 (Lollipop). Most of them are preconfigured as Nexus device.

 

 

Other

There are other alternative way to run android on PC.

Social media & sharing icons powered by UltimatelySocial