Making disk imaging a little easier

Greetings everyone. I recently created a Linux bash script that will add a text based user interface to one of the oldest disk imaging tools out there. The idea behind this was I tend to fat finger a bit so instead of typing out all of the command I would rather have a script handle the command syntax for me and all I would have to do is enter a few bits of data. After that the script would handle the rest.

This script uses the dd command for imaging. First let’s start off with the normal way dd is used.

checking for mounted devices
Before I use the dd command I check on which location in the file system the drive I want to image is located.
image being taken
This is the way the dd command is used on the command line.

Here’s the breakdown of the command:

sudo = this command provides the user with temporary root privileges

dd= the invocation of the dd command

if= This is the location of the disk that is to be imaged. In this case it’s /dev/sdb

of= the name of the output file. In this cases it’s image.dd

bs= this is the block size. DD takes data in chunks called blocks. The smaller the block the less errors you may have during imaging but it will take longer. The block size for this image is 2048K

Here’s the script in action.

This is the invocation of the dd script
This is the invocation of the dd script
Entering the location
Next the script will display a list of what devices are mounted to the OS The blkls command is used in the script to show this data. From this data a location of a mounted drive can be entered in.
entering output file name
The script is then going to ask for a file name for the image
Selecting the block size
After the file name is entered the script is going to ask for a block size. All the user has to do is enter a number 1-4 and a corresponding block size is selected
imaging started
Next the script will show what options the user selected and the imaging will begin. The script is still a work in progress. This is evident with the blank output in the current location field. The image is always located in the current working directory.

I plan on making tweaks and changes to this script. Once everything is done I’ll put the completed script in another post. Thanks for reading!

Bash IF statements

In computer programs sometimes you need something to happen if a condition is fulfilled. Other times if the condition is not fulfilled the program has to do something. In programming IF statements is one of the ways that is used to have a computer do multiple tasks based on a variable outcome. Here’s an example using a small bash script I wrote.

This script shows the user three options and prompts the user for a response. Either 1, 2, or 3.

If 1 is chosen then the computer will display the word “Yes”

If 2 is chosen the the word “No” will display.

If 3 is chosen then the program will quit.

Here's the first part of the script.
Here’s the first part of the script.
Here's the second part of the script.
Here’s the second part of the script.

Here’s the breakdown of the script:

  • shebang (#!/bin/bash)
    • This is telling the OS which programming language I’m using. In this case it’s the built in bash scripting language.
  • The text in blue is just comments for the programmers reference
  • I have the program echo or display the options to choose from to the user
  • The read command take user’s input and puts it into a variable. In this case the variable name is option1
  • Next are my IF statements. These statements use the option1 variable as a condition to check and see what code to execute. For example if the user selects 1 then the first IF statement will execute because option1 (which is the user’s choice) equals 1.
    • The IF statements require several things in order to work right:
      • The condition
      • Brackets to encase the condition [[ ]]
      • Spaces between the brackets and the conditional
      • A semicolon at the end of the brackets
      • A then statement
      • Code to execute if the condition is met
      • A fi statement to end the IF statement

You will notice that all of the IF statements in this script have all of these.

Here’s the script in action using all of the options available to choose from.

option 3 part 1

option 3 part 2

option1 part 1

option1 part 2

option2 part 1

option2 part 2

Depending on what option I give the program it will either display Yes, No, or quit the program with a termination message. This is the power of IF statements. A programmer can have the computer test a large amount of possible options all within one program. Great stuff!

Another option is to use ELIFs and the ELSE statement with the IF statement. With ELIF (Else If) I can combine multiple conditionals into one statement rather then using multiple IF statements. The ELSE  statement will execute if the conditional for the IF statement is not met. To show this I’m going to modify the top script with ELIFs and an ELSE statement.

mod script part 1
Not only did I modify the script but I’m also using a different text editor. The editor is called vim which stands for vi improved. Vi is included in every distro of Linux.
mod script part 2
Instead of having multiple separate IF statements I now only have one huge statement that houses all of the conditions I want the program to evaluate. If any text other the the numbers 1, 2, and 3 are chosen the program will quit with a termination message. I also modified the user prompt using the -p (prompt) option with the read command. 

invaild input part 1

invalid input part 2

For more information on bash IF statements see: http://codewiki.wikidot.com/shell-script:if-else

Thanks for reading!

What is Linux scripting?

Linux scripting or bash (bourne again shell) scripting is the technique of taking one or more commands in the Linux command line and placing them into a single text file to be executed. This technique can be used to automate command line functions and can also be used to run multiple commands using just a single typed command on the Linux command line. Linux scripts are just a series of Linux commands.

Here’s an example: say I want to display a multiple line welcome message while I’m in the command line. There are two ways (that I know of) to do this:

1- use the echo command to display the each line one at a time

You could use two lines to display a welcome message
You could use two lines to display a welcome message

2 – write a script that will display the entire message all at once

I used the nano text editor to write the script
I used the nano text editor to write the script .The “#!/bin/bash is called a shebang. It is used to tell Linux what “interpreter” to use when going through the lines written in the script. In this case I’m using the built in bash scripting language so I have to tell Linux via the shebang that I’m using the bash scripting language otherwise the OS will not understand what I’m writing.

After I finished writing the script in order to use it I have to make it an executable program. I do this using the chmod command.

making the script executable
First is the command invocation”chmod” then “u” which stands for user the “+x” means that I’m giving executable permissions to the user. Then the last part is the file I’m changing permissions on which is “welcome”

After I set the permissions I run the script.

running the welcome script
Instead of having to type two lines to display a welcome message I just had to type a single word and the script did everything else for me.

This is just a small taste of what scripting in Linux can do. Scripting can do mundane things like display text and also advanced OS commands like process management. Thanks for reading!

A taste of memory forensics

As hacking techniques evolve more and more, hacks are being done without the malicious programs touching the hard drive. All of these processes reside inside the memory of the victim computer. When this happens memory forensics becomes necessary. In this post I’m going to show a few of the volatility modules that can be used to find running processes, unknown network connections, and the DLLs associated with each process that are found inside of computer memory.

First I’m going to make sure I’m in the directory that has my memory images

I navigated to the directory where I have my memory images and I used the ls command to list them.
I navigated to the directory where I have my memory images and I used the ls command to list them.

Once I know I have the right images to analyze I use the volatility framework to analyze the memory files. Volatility is a free open source suite of software that is used for advanced memory forensics. It is supported by the Volatility Foundation. The website for the volatility foundation can be found at: http://www.volatilityfoundation.org/

First I’m going to check for open network connections.

This is the command that is used to see the open network connections at the time the memory image was taken
This is the command that is used to see the open network connections at the time the memory image was taken. The timeliner module is going to be used
I used the grep command to narrow down the results to just network connections that are active or "established".
I used the grep command to narrow down the results to just network connections that are active or “established”.

This is odd because this computer should not have any active network connections at all. So this is the first indication that something is wrong.

Next I dig a little deeper and I use volatility to display a list of all the running processes. The pslist module is used to do this.

The command for viewing the running processes
The command for viewing the running processes
Notice that you see an FTKimager.exe process. This is the imaging software that I used to capture the memory image
Notice that you see an FTKimager.exe process. This is the imaging software that I used to capture the memory image

In windows each executable (.exe) has dynamic link libraries (DLLs) associated with it. These are located inside of the .exe file. Volatility can be used to see each DLL that is inside of an executable. The dlllist module is used for this task.

The command to get the DLLs from the executables.
The command to get the DLLs from the executables.
The dlllidt module lists all of the DLLs associated with the EXEs. The modle also lists the command line syntax that is used to run each executable. The process ID for each EXE is also listed.
The dlllist module lists all of the DLLs associated with the EXEs. The module also lists the command line syntax that is used to run each executable. The process ID for each EXE is also listed.

I found an interest DLL in one of the executables. I decided to Google it to see if it was something odd.

After searching Google for this I found out that this DLL is the Microsoft Visual C Run Time Library. It is a normal process that runs in Windows.
After searching Google for this I found out that this DLL is the Microsoft Visual C Run Time Library. It is a normal process that runs in Windows.

This is a small taste of what memory forensics is. It is a growing field and the more complex hacking attacks get the more rouge processes may be located in memory. Thanks for reading!

A few ways to find out if you’re compromised

With computing many programs and processes run in the background. Unless you’re a savvy computer user you may not be aware of these processes. Hackers sometimes use these processes to hide themselves inside victim computers.

In this post I’ll be using two of my virtual machines to demonstrate how a hack happens, one way a hacker can hide in a system, and how it can be found on the victim.

NOTE: These two machines are both under a host only network. Meaning that the hacking attempts shown in this demo cannot get out into the open internet. Even though this demo involves hacking I do not in any way support the illegal hacking of any computing device.

First I start off with setting my two virtual machines in a host only network sand boxed within my host system.

I had to make sure on both machine that they were set on VMNet1. This Virtual network is configured as host only so any communications that happen between these two machine will not get out into the open internet. Therefore I can safely hack the victim.
I had to make sure on both machine that they were set on VMnet1. This Virtual network is configured as host only so any communications that happen between these two machines will not get out into the open internet. Therefore I can safely hack the victim.

After confirming that the two VMs are configured correctly I boot them and disabled any firewalls, AV software, and other programs that would detect the hack on the victim. The purpose of this test is not to bypass all of these programs but to get a piece of malicious software on the machine and to show some ways that it can be found.

After the two computers are connected I had the VMs ping each other to make sure they can communicate. After that I used zenmap on my hacking platform to scan for open ports on the victim VM.

This program sends network packets to ports on the target computer and returns data based on if the ports are open or not. "Open" ports are gateways into other computer. These ports are listening for a connection from another computer.
This program sends network packets to ports on the target computer and returns data based on if the ports are open or not. “Open” ports are gateways into other computer. These ports are listening for a connection from another computer.

I already know which attack vector I want to use on the victim. It requires port 445 to be open. After checking the Zenmap report I found that port 445 is open. From there I start Metasploit and configure it to attack the victim.

Before hacking the victim I start a calculator on the victim and ran the tasklist command in the command line. What this command does is it shows all of the currently running processes on the computer and how much memory each process is using.

normal runnning calc.exe process
Notice how much memory the calc.exe (the calculator) is using: 9,752 KB

After the configuring of Metasploit is finished I ran the exploit with the meterpreter payload. What this does is it gives me a shell (a text user interface) to interact with the victim computer. Using this shell I can gather information on the victim computer. Examples are password hashes, OS version, user account names, and processes that are running on the victim.

This shows that Metaspolit was successful in exploiting or hacking the target.
This shows that Metaspolit was successful in exploiting or hacking the target.

Right know the rouge program should be sitting in memory. This can be found pretty easily by a savvy system administrator. Next I take the rouge process and hide it in a process that is running on the victim.

On the hacking platform I used Meterpreter to hide the rouge program inside of the calculator that is currently running on the victim. After the migration I ran tasklist on the victim to see hos much memory the calc.exe process was using. It shot up by 3,816K. This was because extra memory was need to accommodate the malicious code.
On the hacking platform I used Meterpreter to hide the rouge program inside of the calculator that is currently running on the victim. After the migration I ran tasklist on the victim to see how much memory the calc.exe process was using. It shot up by 3,816K. This was because extra memory was need to accommodate the malicious code.

If the system admin knows roughly how much memory each process is taking when they run then this should raise a red flag. This is one way that can be used to see if a computer has been compromised. But more evidence is needed in order to make a clear determination if the computer was hacked.

Now that I know something is amiss I check which connections are currently open or “Established”. I used the netstat command on the command line to do this.

I used the -n, -a, and -o options with netstat. The -n option displays active TCP connections. The -a option shows all active TCP and UDP connections and  the -o option displays active connections and show the process ID for each connection.  From here I found one connection that is strange. I should not have a connection with a computer with this IP address. Again this requires further investigation.
I used the -n, -a, and -o options with netstat.
The -n option displays active TCP connections.
The -a option shows all active TCP and UDP connections.
The -o option displays active connections and show the process ID for each connection.
I filtered netstat’s output through the find command. I was only looking for “EST” or established connections. From here I found one connection that is strange. I should not have a connection with a computer with this IP address. Again this requires further investigation. Know thy system. The only way to know if you’re compromised is to know what processes and network connections that are supposed to be running on your system.

After I found the strange connection I decided to check the event logs. First I checked the security logs.

I found a special login in the logs. (Event # 4672) This should not have happened. So far it's shaping up that this computer has been compromised. Note the time it happened. This is the exact time when the hack hit the victim computer.
I found a special logon in the logs. (Event # 4672). This should not have happened. So far it’s shaping up that this computer has been compromised. Note the time it happened. This is the exact time when the hack hit the victim computer. This time is in system time by the way. Unless you’re viewing the logs on another computer across time zones, then the times would adjust to your local time. This event happened on 2/3/15 5:17:06 PM system time.

After finding that event in the security logs I check the system logs to see if anything was installed on the computer. I use the time of the first event to search the system logs.

I made a discovery that a service was installed on the system 2/3/15 at 5:17:07 PM only one second after the unauthorized log on. Upon futhur examination of the log entry I found that the name of the service is a random character string. This is very odd. From this point I would say that this computer is compromised and step would have to be taken to isolate this machine and eliminate the infection.
I made a discovery that a service was installed on the system 2/3/15 at 5:17:07 PM only one second after the unauthorized log on. Upon futhur examination of the log entry I found that the name of the service is a random character string. This is very odd. From this point I would say that this computer is compromised and steps would have to be taken to isolate this machine and eliminate the infection.

In this demo I have used the netstat command on the command line, memory usage of running processes, and the security and system event logs to discover that something odd was happening on this system. These are just a few of the ways that can be used to find out if a computer was compromised. The most important fact to note is that you have to know what is running on your system. If you don’t then you not have a reference to find out if something is wrong. I hope you enjoyed this post. For the next post I’ll be running memory analysis to show what processes are running on a computer. Thanks for reading!

How do two computers communicate?

Back in the late 1960s the US department of defense was designing the predecessor of what we now know as the internet. This network was called ARPANET (Advanced Research Project Agency Network). This network was one of the first that was designed to use packet switching, one of the concepts that is the backbone of how the modern internet works. But how does all of the network stuff work? One of the ways that the communication between computers can be explained and shown is through networking models. There are several examples of networking models: the OSI model and the TCP/IP model are two examples.

The main purpose of networking models is to standardize communication methods between two or more computer systems and to show what happens to data as it is transmitted from one computer to another. For the purposes of this blog post I’ll be focusing on showing the OSI networking model.

The OSI model was created by the International Organization of Standardization and the International Telegraph and Telephone Consultative Committee. These two organizations started working on their own separate projects involving networking back in the late 1970s. Eventually they combined their efforts and created the OSI networking model.

For more information on the history of the OSI model visit:

http://en.wikipedia.org/wiki/OSI_model#History

The OSI model contains 7 layers, these 7 layers split up the communication and protocols that are used between one or more network devices. Protocols are a set of rules that govern how computers exchange information. Certain protocols only operate on certain layers of the OSI model. I will discuss the functions of specific protocols in a future post. What’s important here is to know where protocols stand in relation to the OSI model. The protocols that are listed in each layer may not be the only protocols that operate at that layer.

The seven layers are as follows:

Layer 7 – Application

  • This layer is at the top of the OSI model
  • The application layer is the layer that is the closest to the end user
  • The application layer generates data that is to be sent across the network
  • Protocols that operate in this layer: HTTP, FTP, and SSH

Layer 6 – Presentation

  • The presentation layer is responsible for formatting, encoding, and decoding the data that is received on the network
  • Protocols that operate at this layer: MIME and ASE
  • Character encoding also takes place at this layer. For example UTF-8 encoding

Layer 5 – Session

  • This layer creates and terminates application sessions or connections
  • Protocols that operate at this layer: NetBIOS, L2TP, and PPTP

Layer 4 – Transport

  • The transport layer is responsible for reliable delivery of information
  • Protocols that operate at this layer: TCP, UDP, and SCTP

Layer 3 – Network

  • The network layer sends packets (chunks of data) between computer networks
  • Protocols that operate at this layer: IP, ICMP, and IPX

Layer 2 – Data Link

  • This layer sends packets across a single network hop (a single network segment), computer to computer, or from computer to a router.
  • Protocols that operate at this layer: ARP, SLIP, and ATM

Layer 1 – Physical

  • This is the bottom of the OSI model
  • The physical layer is comprised of the physical devices that send the data (wires, radio transmitters, etc)
  • Protocols that operate at this layer: Ethernet and WiFi

When data is sent from from one computer to another it travels along the layers of the OSI model. For example say there are two computers that want to exchange data: computer A and computer B. When computer A sends a message to computer B the message starts at the application layer then travels down the OSI model. When the message travels between layers it is encapsulated. I like to think of encapsulation like the message is being placed inside of an envelop. When the data from computer A reaches the transport layer it is encapsulated into a network packet. Technically a piece of information called a header is attached to the data sent from computer A. This header contains the sending IP address and the destination IP address for the message. When the packet reaches layer two another header is added to the message. This header contains the physical address or MAC (Media Access Control) address of the destination computer. Further more the message is encapsulated or wrapped into a frame. When the message reaches layer 1 it is broken down into bits (1s and 0s) then sent across the physical wires or wireless signals.

After the data is sent across the wire or wireless it is reconstructed into the original layer 2 frame. Then as it travels up the OSI model it is encapsulated again but in reverse order. As the data is encapsulated the headers are read and stripped off until only the data that is to be sent to the destination remains. These headers that were added by the sending computer tell the routers and switches where the message is going. Without these headers the message would not get to its intended destination.

This explanation is an overview of the OSI model and how two computers communicate with each other.

For more information on the OSI model and other computing concepts please visit:

https://tutorials.cyberaces.org/tutorials

Thanks for reading!

What is a Host Protected Area?

Today computers come with large hard drives. Some can be 1 terabyte and other can be up to 4 terabytes (a terabyte is 1000 Gigabytes.) If a computer is purchased and the specs say that it has a 30 GB hard drive chances are that that actual useable space is smaller than that. Say around 27 GB, but when the user checks how much space is on the hard drive the OS will also say that it has 27 GB. This computer most likely has either a host protected area or a disk configuration overlay.

When a hard drive is made the vendor will set aside space at the end of the drive to be used as either a DCO (Disk configuration overlay) or HPA (Host protected area). This section of the hard drive is used to store data like system restoration files, or security software.

The concept of a disk configuration overlay was first seen in the ATA-4 standard and the host protected area was first seen in the ATA-6 standard. These concepts allow vendors to purchase hard drives of different sizes and essentially make them the same exact size so they can be used in their products.

The HPA and DCO cannot be accessed using normal commands or the operating system (the operating system does not see the HPA or DCO.) Some ATA commands are used to access these hidden areas. Examples of ATA commands are:

  • IDENTIFY DEVICE
    • Operating systems use this command to see what space on a hard drive can be used to store data.
  • SET MAX ADDRESS
    • This command can be used to create an HPA or DCO. As an example let’s say the maximum size of a hard drive is 1000GB. I use the SET MAX ADDRESS command to set the max address at 950GB. I just created an HPA; the last 50GB of the disk will not be seen by the OS since the max address according to the OS is 950GB.
  • READ NATIVE MAX ADDRESS
    • Certain pieces of hardware and firmware (i.e. the BIOS) use the READ NATIVE ADDRESS ATA command to see the true size of the hard drive. These devices are known as “HPA aware”

HPAs and DCOs have many uses some examples are:

  • Using an HPA to set a large hard drive to a smaller size so that older BIOS and boot loader programs can run.
  • The HPA can contain recovery programs or a preloaded OS set by the vendor
  • The HPA can also contain either root kits that are hiding or malicious code that can avoid detection by residing in the HPA.

For more information on HPAs and DCOs check the Wikipedia article at:

So the next time you check the size of your hard drive it may not be what the OS is showing you. Thanks for reading!

Teaching the computing world how to protect themselves against hackers.