Friday, February 19, 2016

How to open Shell on web server using PHP

Web servers are the most vulnerable for attacks. Because they directly connected with internet and also what are they meant to be. So for a hacker web server is a good start. Spidering web site, directory traversal, catching the x site scripts and finding holes in a web site is lead to a good hack. So here i'm going to explain a good trick to hack a web site using php script. But there should be some vulnerables in the particular web site in order to make this hack.

<?php
$output 
= shell_exec('ls -lart');
echo 
"<pre>$output</pre>";?>


Friday, January 22, 2016

How to install Ubuntu Core and work with it

Ubuntu is the most popular Linux distro which handled by canonicals. It offers several installations which is customized such as gnome-ubuntu, ubuntu-core. Ubuntu core is a light version of ubuntu which is not a installation iso but its a file system to work with linux in minimal resources.

After you setup the Ubuntu core you get only the file system with Ubuntu repos, shell, grub and other initial items for linux. It is very good to try this out because this gives you a good knowledge of the linux file system how format the disk, how to install grub, how make the disk bootable, how will kernel interact with grub and so on.

Firstly you have to download the Ubuntu-core rootfs (root file system). You can download the ubuntu 14.04.3-core root file system in this link http://cdimage.ubuntu.com/ubuntu-core/releases/14.04/release/



Download the tar ball.Then you need a ubuntu live cd to boot the machine. Boot the machine using live CD and select try Ubuntu. Get the shell and type sudo gparted. Using gparted you can create, delete, format partitions and select which one should be the boot partition, which one is the swap and so on. Same thing can be done using fdisk also in terminal. To learn how to use fdisk follow this link. In this case using any preferred tool that you familiar create one partition including the whole size of the disk. After you create the partition the sdx will change to sdx1(x is the disk. may be a/ b/ c). And after that make it the boot partition. This can be done easily using gparted, right click on the partition create a flag. To do this in fdisk type 'a' after you created the partition and then type '1' . And make sure that the partition you've created is formated with ext4 format. Because other wise you would not be able install grub. You can easily format to ext4 in gparted but if you used fdisk to create the partition you can format the partition to ext4 format using the mkfs tool. Type the following command to do that.

mkfs.ext4 /dev/sda1

Now you have a partition to make you core file system and it's fs is ext4. So firstly you have to mount this partition to a folder in live boot cd. Because when  we are boot from live cd it's showing us the file system on that live cd. In order to access to the hard drive that you have you should mount that disk into some where in this live cd file system. We are going to mount our disk into /mnt directory. Type the following command to mount

sudo mount /dev/sda1 /mnt

Then your partition have mounted to the /mnt directory. Now go to your /mnt directory using cd /mnt . Now you are in your partition. Now we are going to extract the ubuntu core root file system in to our disk (/mnt). Firstly copy the ubuntu-core-rootfs tar file in to /tmp directory. Then execute the following command.

sudo tar -zxvf /tmp/ubuntucore-rootfilesystem.tar.gz

No error should be raised. Then go to /mnt directory and check whether there are files. You can see a file system in /mnt.

Now we have to copy the resolv.conf file because else the system cannot resolve dns. to  do this type

sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

Now we should run the following command

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i;  done

what this command does ? Before you execute this command check the /mnt/dev , /mnt/proc and /mnt/sys. Check after the command executed. You will see new files are there which was not before executing the command. This will mount the sub trees of the given directories(this case /dev /dev/pts /proc /sys) in to a mentioned directory (this case /mnt) which makes source directory content available in both destination and source directories. So the files inside live cd /dev /dev/pts /proc /sys are also available in /mnt/dev/ mnt/dev/pts /mnt/proc /mnt/sys.

Now we should chroot in /mnt inorder to execute commands in our new file system. What is chroot? In normal case you are root in live cd file system ( / ). But in this case we need to be the root file system is /mnt/ directory. Then only the changes that we are executing are affects to our new file system. Other wise our changes affects to live cd file system which will erased after reboot. So we should make chroot to /mnt directory. Type the following command

sudo chroot /mnt

If command worked now terminal should like root@ubuntu:~ 

Now we should install our linux kernel. To install kernel type the following command

apt-get update && apt-get install linux-{headers,image}-generic

If "failed to fetch" like error is on terminal try following.
edit the /etc/resolv.conf (actually in /mnt directory, /mnt/etc/resolv.conf) and at the end at the following
nameserver 8.8.8.8

Some times during the installation you may prompt to install grub. This is very important. Grub must be installed in order to boot in to kernel. When It's prompt to install grub using tab select the ok and press enter. Then you will ask to which disk you should install. You will see two or more options there make sure you are selected sda ('a' may change as to your setup.) and not sda1. You should select the device not the partition. After you highlight it using arrow keys press space bar to select it. then * mark will apear infront of it. Then using tab go to ok and press enter. Grub will install.

To make sure Grub installed correctly go to  /mnt/boot/ directory and see is there files like vmlinuz (kernel image), initrd and go to /mnt/boot/grub directory and check is there file called grub.cfg . If it's not there that means grub has not installed correctly. You have to reinstall it.

do apt-get update   # ***
note : *** is  necessary to retrieve grub packages.
 and
apt-get purge grub grub-pc grub-common

in any of above apt-get install or apt-get purge case if get an error saying use apt-get -f insatll to install the package type in the terminal

apt-get -f install

It will install, remove and upgrade relevant packages.

If you get an error in updating or apt-get install ing saying cannot resolve try ping internet host. Try to make the internet connection.

If every thing is ok you should have a file system in /mnt directory, grub.cfg file in /mnt/boot/grub, vmlinuz in /mnt/boot, initrd in /mnt/boot , resolv.conf in /mnt/etc

Now we should create a user and we should make the user to have root privileges.

type commands

useradd user_name
passwd user_name
when it's prompt to type a password type the preferred password

nano /etc/sudoers
we are editing this file to make our user to be root privileges.
the file content is as follows,
# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

This is the part we are going to change. Change it as follows
# User privilege specification
root    ALL=(ALL:ALL) ALL
user_name ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

now reboot and enjoy Ubuntu core


     

Monday, January 18, 2016

How to recover files in Linux

Recovery is necessary thing  todays computer world because of the value of the computer data is higher. I have explained how a file can be recovered if it has been deleted and I have explain how it happen in a previous post. So in this post I'm going to discus a technique/ tool to recover files in Linux systems because there are lots of tools to achieve this on windows.

There are many command line tools to recover files in Linux systems which are working in different way. Here I will mention about the Testdisk tool which is very use full tool when recovering damaged hard disks also. In this article we are focusing only how to recover a file which has been deleted from the linux file system.

Installing Testdisk

Monday, December 21, 2015

Investigating USB logs and create a amazing encrypting tool.

Universal Serial Bus controller or we most familiar USB, is a main requirement these days. We put movies to our pen drives, we watch them through USB, we connect our phones, players, External drives and lots of other stuff to our USB hubs and full fill our most important requirements. But the thing we don't know is all every time we connecting a USB device to our USB hub, our OS will keep information about the date, time, ID of the device, Manufacturer of the device, Product ID, Serial number and other unique details for a particular USB device will save on our machine.

Yes that's true. All of this stuff are saved by our OS. So these records are very important in a computer forensic investigation. These information will give very important evidence for computer crime scenes.

Hacking Tutorial released from ANONYMOUS in ghostbin.com

This the hacking tutorial released by Anonymous last week on this link https://ghostbin.com/paste/jrr89#L29


First and foremost, it is important for you to understand that 'hacking' is a broad term. There are many aspects to it, most of which require several programming skills, but that shouldn't stop you from using the tools made available by the internet for you to take advantage of. Go to the HTMLdog website and learn some HTML first, it is a great website and you will progress in no time. Also, consider Python as your first programming language; it is a tradition to recommend Python to newbies because it is the fundamental and appropriate language that will kickstart you in the world of computing. So, now that you are set and ready to continue with the quest, allow me to present to you a simplistic and minimalistic reference guide. 

Tuesday, December 8, 2015

Analise RAM dump file

In forensic investigations it's very important thing dump the RAM's data into a file and analyze the processes / tasks that were running on the dumped time. So let's look at how we can dump the RAM's content as a raw file and how we can analyze that file for get further more details.

For this we are going to use MoonSols  windows memory toolkit. This toolkit contains with four or more related tools. But for in this case we need only one tool which is "ramdumpit.exe". We can build the raw file of our ram's dump in a particular time using this tool. Just run it and it will ask the ordinary "Are you sure?" question just give yes for it. now you will see the blahblah.raw file has been created which is the dump of our RAM. Now we need our second tool which is going to analyze our dump file.

Thursday, November 12, 2015

How to use C code in Python

Python and C combination is brilliant for programmers specially who writing network tools and exploits. For this purpose there are many ways to use both of them in one code and make the use of both languages. Previous days I was looking for a easy way(not easy actually fast way to approach my object which is make use of c code inside a python code) to do this. I was noticed there are many ways to do this. Some of them are,

  1. According to Extending Python with C doc (https://docs.python.org/2/extending/extending.html).
  2. Some languages has built in combine with features of these two languages such as Pyrex, Cython.
  3. Using ctype module.
  4. Using a SWIG (Simple Wrapper Interface Generator)



There are other ways also to achieve this but I was impressed by using SWIG. It's so easy and simple to wrap the code. So here is the steps.

I'm going to wrap a simple C function called "func" on the C code "hello.c"

1 Step : Create hello.c

following is the code in hello.c

#include <stdio.h>

int func(){
printf("Hello World");
return 0;
}
 
2nd Step : Create interface file.





To add your C code to your desired language's code you need to create interface file which is input to SWIG. Here is the interface file which is "hello.i".

%module hello
%{
int func();
%}
int func();

As you can see at the first line you have to name the module you are going to create. In this case hello module will create. This is very similar to write C code. After you put brace on second line the block has been started. Inside this block you have to mention all of your headers and functions in your C code. Here I'm using C default header stdio.h so it's no need to mention in here. If you are using custom header with macros you need put it here like #include "example.h". Save the file.

3rd Step : Create setup.py file.

After 2nd step there are numerous ways to build you the shared object (so) file (in windows dll). But here I'm going to demonstrate build the so file using setup.py file. Following is the code for setup.py



#!/usr/bin/env python 
 from distutils.core import setup, Extension  
hello_module = Extension('_hello', sources=['hello_wrap.c', 'hello.c'], ) 
 setup (name = 'anyname', 
            version = '0.1', 
            author = "your name", 
            description = """docs""", 
            ext_modules = [hello_module], 
            py_modules = ["hello"], )
 
 
Be careful about bold items. First bold item type any variable name. In second bold item type "_" as prefix to your c file name. It's important. Third bold item ; when you run swig with hello.i it will generate file called "hello_wrap.c". This file is mentioned here. Forth bold item is your source code to wrap. Inside setup module fifth bold item is the variable that the first bold item. Sixth bold item is important because this module name will use when we importing module.

4th Step : run SWIG.




Type the following in shell to get the hello_wrap.c create the so file.

swig -python hello.i

5th Step : Run setup.py

To build our so file and make use the c code inside python code lets run setup.py

python setup.py build_ext --inplace

build_ext - this will build extensions
--inplace - build the so file in same directory shell opened. 



Now you can import the module that you coded from c like this

import hello

hello.func()

When you run this it will print Hello World.

Note :

Remember this. You can import the module if you are in the same directory that you have created the so file. Other wise it cannot be imported. To import module in python file while you are in different directory you have to copy the .py file, .so file and .pyc file to that directory. Then only you can run the program that you create using the module.