Showing posts with label Information Security. Show all posts
Showing posts with label Information Security. Show all posts

Sunday, July 9, 2017

Working with various Base Numeric Systems



Nowadays people are more interested in programming languages like assembly language, shell scripting etc for pentesting or maybe automation processes. But unfortunately the people haven't mastered binary language consisting of 0's and 1's in which computer communicates.


In this post we will be talking about conversion of one base to another base numeric system which can be used in shell scripting for various purposes(pentesting, administration, etc.) to achieve their task.


We will be using a utility called 'bc' which is already available in linux for various conversion examples which consists of Decimal,Binary,Octal, Hexadecimal and various base numeric system.


- Decimal also called base 10 number system.

- Binary also called base 2 number system.
- Octal also called base 8 number system.
- Hex or Hexadecimal also called base 16 number system.

Throughout the post I will select only one number '23' which we will use to find out it's respective binary,Octal, Hexadecimal and various other base numeric representation.



Case 01 : Decimal to Binary



As you all know '23' is a decimal. So first let's convert decimal '23' to binary representation.
echo "obase=2;23" | bc

Figure 01 - Conversion from Decimal to Binary

Now let me explain the command to make it simplier for you inorder to understand without memorising.

echo prints the statement on the screen.

obase stands for output base. This is a special variable required by bc command which defines the output base value for a given number.
2 represents the base number system for binary
23 is the decimal number which I want to convert
| is the pipe (form of redirection used in linux)
bc is the utility which converts. (bc - An arbitrary precision calculator language)


Case 02 : Binary to Decimal


In this case we will convert the result obtained from previous case.

echo "ibase=2;10111"|bc

Figure 02 - Conversion from Binary to Decimal

The syntax is almost same for every case. The only difference is the keywords.
Here ibase stands for input base. This is a special variable required by bc command which defines the input base value provided for a given number.


Case 03 : Hexadecimal to Octal


In this case we will be converting the Hexadecimal representation for decimal '23' to octal.

echo "obase=8;ibase=16;17"|bc

Figure 03 - Conversion from Hexadecimal to Octal

Here I want my output in octal representation hence used obase with value '8'. The input value '17' is the hexadecimal (base 16) representation numeric system for the decimal number '23'.

I hope this post helps you out in making things easier to understand and work in a smarter way!


Extra's:


* Decimal - Hexadecimal : 

echo "obase=16;23"|bc


Figure 04 - Conversion from Decimal to Hexadecimal

* Hexadecimal - Decimal : 
echo "ibase=16;17"|bc


Figure 05 - Conversion from Hexadecimal to Decimal


* Binary - Octal
echo "obase=8;ibase=2;10111"|bc


Figure 06 - Conversion from Binary to Octal

* Octal - Binary : 
echo "obase=2;ibase=8;27"|bc

Figure 07 - Conversion from Octal to Binary

For your reference you can also use ascii manual page
man ascii

Figure 08 - Ascii Manual Page


Friday, May 13, 2016

Setting up database in Metasploit- Part 1



Introduction


Metasploit is one important framework which is used by many penetration testers for exploiting vulnerabilities found during a security testing project. Most of the times it becomes difficult for a penetration tester to maintain asset information, the services running and various vulnerabilities associated with them. Also, most organisations require you to provide logs during the assignment, for instance the commands that were executed for finding vulnerabilities and how those vulnerabilities were exploited by the tester. In order to help my fellow penetration testers with such daunting tasks, I am writing this article on Metasploit. Hoping to ease some of your work.
Let’s start.

Section1: Setting Up the Database in Metasploit


Since we are working with database along with Metasploit it becomes important to setup some kind of database.  PostgreSQL is the default database supported by the Metasploit framework. So before starting Metasploit it is important to initiate the PostgreSQL database where our all data will be stored while using Metasploit.
Let’s start the PostgreSQL database service:
This command initiates service for PostgreSQL database. 

Command: service postgresql start

 
Figure 1: Starting the POSTGRESQL Database

Next command checks whether the service is running.

PostgreSQL is a Relational Database Management System (RDBMS). So now we need to create a database named msfdbwhich will, by default, be associated with the Metasploit framework.

Command: msfdb init

 
Figure 2: Create msfdb Database

We can now check for the database files (database.yml and database.yml.example) by visiting the path (/usr/share/metasploit-framework/config/).

 
Figure 3: Database Files

Now let us check whether the database ‘msfdb’ is associated with Metasploit or not. We can perform this activity by opening Metasploit terminal and checking the status of the database.

Command: db_status
 
Figure 4: Checking the Status of Database

As you will notice in Figure 4, postgresql is now connected to Metasploit-framework (msf).
Note: In case the database is not getting associated with Metasploit for any technical reasons, you will get a ‘no-connection’ error as shown in the figure below. 

Figure 5: Error in association of 'msfdb' with the Metasploit-framework

In such cases you need to recheck the steps performed as per the commands mentioned until now in this documentation.

Section 2: Database Commands


Now that we are connected to the database, let me show you some commands that we will be using in this article.

Command: help database

 
Figure 6: Database Commands

Section 3: Using Workspace Commands


Workspaces are normally used by pen-testers to save scans from the different locations/networks/subnets. This helps keeping information separate and avoids confusion.
Command: workspace – h
 
Figure 7: Workspace Help File
Note: By default, Metasploit creates ‘default’ workspace. ‘*’ denotes current selected workspace we are working with.

Command: workspace
 
Figure 8: ‘Default’ Workspace



Command: For workspace

 
Figure 9: Various Workspace Commands


 Refer to further Parts for more information!