Saturday 31 August 2013

Install NVIDIA Proprietary Driver in Kali Linux and Debian wheezy

If you are using Linux and have NVIDIA graphics card then most likely you are using open source NVIDIA driver nouveau. It works quite well, but if you want to use 3D acceleration feature or want to use GPU based applications then you need to install NVIDIA proprietary driver. Here is how to do it. First Install linux headers as those will be required to build nvidia modules. Issue following command at terminal
$ aptitude -r install linux-headers-$(uname -r)
Now install required nvidia components. Following command will install and build nvidia modules, and also disable nouveau module.
$ aptitude install nvidia-kernel-dkms
Now we should create new Xorg server configuration file or modify existing to tell it to load nvidia module. nvidia-xconfig package make this task quite easy, install and execute it.
$ aptitude install nvidia-xconfig
$ nvidia-xconfig
Now reboot and check if system is using nvidia graphics driver. On start of xsession nvidia splash screen should be displayed. You can also confirm it by issuing following commands
First check if system is using glx module.
$ glxinfo | grep -i "direct rendering"
It should output "direct rendering: Yes"
If you do not have glxinfo then first install mesa-utils package then again issue above command and check output
$ aptitude install mesa-utils
Check if nvidia module loaded.
$ lsmod | grep nvidia
If it produces output like 'nvidia      11239499  45' or something similar (numbers could be different at your system) then nvidia module is loaded.
Just to be sure nouveau module NOT loaded, issue following command
$ lsmod | grep nouveau
It should NOT produce any output. If it produces output then something is wrong.
If you are planning to use NVIDIA Graphics Driver just for better disply and 3D rendering then it is almost finished. But if you want to run applications that uses NVIDIA CUDA for processing (like cudahashcat+) then you will also need to install CUDA drivers as below
$ aptitude install nvidia-cuda-toolkit nvidia-opencl-icd
 Now you should be able to use applications designed to utilize GPU.

Thursday 4 July 2013

Boot KALI Linux in console mode (command line) as it was in BackTrack

A good thing i like in BackTrack was it boot in console mode. It is quite helpful if we have to run few console commands instead of using full GUI.

But Kali linux directly boot into graphical mode. To make it boot into command line mode we need to remove auto start of xdm service (or kdm or gdm based on your desktop manager) from current runlevel.

To do it first we need to know current runlevel. Issue following command

$ who -r

Remember your current runlevel from output of previous command. Mine is 2.

We also need to know service name of display manager we are running, check it with following command (replace 2 with your run level)

$ chkconfig --list | grep '2:on'

It will list all services set to autostart for run level 2. Look here for entry similar to gdm or kdm or xdm etc. I am running gdm3.

Ok, now we have identified which service (gdm3 in my case) we have to turn off at which run level (mine is 2).

Now issue following command to stop gdm3 service for run level 2.

$ chkconfig --level 2 gdm3 off

Now on next boot it will boot into command line login. After login use startx command to start xsession.

Failsafe: If something went wrong or later you decided to boot again into graphical mode, revert it back with following

$ chkconfig --level 2 gdm3 on

Note: I do not remember if chkconfig is pre-installed with Kali or i installed it manually. In case it say 'chconfig command not found' then you can install it with following command

apt-get install chkconfig

That's all. Happy pentesting with Kali linux :)

Sunday 9 June 2013

Customize workspace, change wallpaper, execute script on workspace switching

I mostly switch to dfferent workspace and i really like if i could have different settings on different workspace like different wallpaper.
A few solutions like using compiz along with few plugins already exist (i don't know if they work or not because i have never tried them), but they are limited only to wallpaper change. I was looking for something where i can run my own commands on changing workspace.
After googling a lot i found a small C program here. It was really cool (thanks to Isaac) and showing a notification on workspace switching. I had taken C (wsn.c) code from there, modified and added support to call scripts on each workspace change.
You can download modified C code along with the compiled binary here. Binary is compiled on Debian Wheezy Stable x64, it may or may not work on your configuration. If it doesn't work then compile it from C code, don't worry compiling it is quite easy.
Using the wsnd program
USAGE:  wsnd [-s] [-1:script -2:script -3:script -4:script]

OPTIONS
-s           Silent mode. Turn off displaying notification,
             but passed scripts will be executed.
-1:script    Path to script to be executed when workspace 1 activated.
-2:script    Path to script to be executed when workspace 2 activated.
-3:script    Path to script to be executed when workspace 3 activated.
-4:script    Path to script to be executed when workspace 4 activated.

Example
    wsdn -1:~/w1.sh -2:~/w2.sh
Ok, so what we have to do is, just pass path to a script that we want to execute when a particular workspace activated.
In above example i set wsdn to execute w1.sh when i switch to wroskspace 1 and execute w2.sh when i switch to workspace 2. I use only two workspaces so i skipped passing arguments for workspace 3 and 4.
We can also pass -s argument, to stop showing notification on workspace switching but passed scripts will still execute.
What the scripts wh1.sh and wh2.sh doing?
Both scripts are doing three things-
First changing the wallpaper, second mute/unmute sound and third toggling touchpad.
In Workspace-1 i usually do my work, lot of typing etc. so i simply turnoff touchpad and also mute sound.
In workspace-2, i do browsing, listening songs etc., so again i turned touchpad on and unmute sound.
Here is how my wh1.sh looks like
#!/bin/sh

# change wallpaper
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s /home/samtech/Pictures/evolution.jpg

# turn off touchpad
synclient touchpadoff=1

# mute sound
/usr/bin/amixer --quiet set Master toggle
You are free to use different commands as per your needs.
Set wsnd to run on startup
Set wsnd to auto start by adding it to 'Application Menu' > Settings > 'Session and Startup'. Do not forget to pass scripts to execute.

Compiling from the code
If attached binary doesn't work for you then you can compile the application with following command
gcc -O2 -o wsnd pkg-config  --cflags --libs libnotify --libs libwnck-1.0 wsn.c
It it doesn's work then try this
gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wsnd pkg-config  --cflags --libs libnotify --libs libwnck-1.0 wsn.c
It it complain for libnotify and libwnck not found then run following to install missing libraries
sudo apt-get install libnotify-dev libwnck-dev
Then again try to compile.
Hope it will help you customize your different workspace as you want it to be.
It is working well on my XFCE 4.8, i have not  tested but it should work on other desktops too. On other desktops you may need to use different commands, like for changing wallpaper in GNOME use gconftool-2.

Saturday 8 June 2013

Listing network connections along with associated application name in conky

Conky's TCP port monitor (tcp_portmon) is quite useful to list inbound/outbound connections. You can find many examples of tcp_portmon by googling concy inbound outbound connections.

Only the problem i see with tcp_portmon is that it doesn't provide name of associated application/process using that connection.

To list application name along with connection details we can make use of netstat command with conky's texeci.

After applying it in conky, it will look similar to this

Here is how to do it
Open your .conkyrc file in text editor

gedit ~/.conkyrc

Paste following at the end of TEXT section

${color Tan2}ESTABLISHED Connections${color DarkSlateGray}${hr 2}

${offset 10}${color lightgrey}Inbound: ${color white}${tcp_portmon 1 32767 count}    ${color lightgrey}Outbound: ${color white}${tcp_portmon 32768 61000 count}${alignr}${color lightgrey}Total: ${color white}${tcp_portmon 1 65535 count}

${color slate grey}Process                 ${color slate grey}Remote Host                     ${color slate grey}L-Port ${alignr}${color slate grey}R-Port${color lightgrey}

${font Ubuntu Mono:size=8}${texeci 30 netstat -ap | grep 'ESTABLISHED' | sed -r 's|.*[0-9.]+:([0-9]*)\s*([^:]+):([a-zA-Z]+)[^/]+/([a-zA-Z0-9]*)|\4 \2 \1 \3|' | awk '{printf("%-14s %-20s %5s %7s\n",$1,$2,$3,$4)}'}

Save and close file.

Now conky will display established connections along with associated process name and refresh it every 30 seconds.

Instead of remote host and port name you can display remote IP and port number like below

Conky displaying connection list with remote IP and port

For this layout paste following in your .conkyrc files instead of above.

${color Tan2}ESTABLISHED Connections${color DarkSlateGray}${hr 2}

${offset 10}${color lightgrey}Inbound: ${color white}${tcp_portmon 1 32767 count}    ${color lightgrey}Outbound: ${color white}${tcp_portmon 32768 61000 count}${alignr}${color lightgrey}Total: ${color white}${tcp_portmon 1 65535 count}

${color slate grey}Process                 ${color slate grey}Remote IP              ${color slate grey}L-Port ${alignr}${color slate grey}R-Port${color lightgrey}

${font Ubuntu Mono:size=8}${texeci 30 netstat -anp | grep 'ESTABLISHED' | sed -r 's|.*192.[0-9.]+:([0-9]*)\s*([0-9.]+):([0-9]+)[^/]+/([a-zA-Z0-9]*)|\4 \2 \1 \3|' | awk '{printf("%-14s %-15s %5s %5s\n",$1,$2,$3,$4)}'}

Friday 7 June 2013

Using Kali Linux as main Operating System

If you are a fan of kali linux then probably you may want to use it as your main operating system (i do).
Here are following thumbs Up to use it as main OS
  • It is based on most popular rock solid debian wheezy, which is now stable release of debian.
  • It is as stable as debian wheezy
  • Large package repository. One can use almost all the packages that can be used on debian wheezy
  • Regular updates available.
And following thumbs Down for not to use it as main OS
  • It is designed for pentesting (with some modifications in kernel) and has lot of pentest/exploiting tools pre-installed
  • It work with root (super user) account

That's ok, but what's the verdict? Should we use it as main OS or not?
In my openion we can use it as main OS but we should use it with non-root user for regular use, and use root login only for pentesting.
Here is how you can create regular (non-root) user
Open terminal and type following to create new user (replace user1 with your desired user name)
useradd -m user1
Now set password for this user
passwd user1
    Enter desired password twice.
Add user to sudo group so  you can run common commands (like fdisk -l)
usermod -a -G sudo user1
4. Change default shell of previously created user to bash
chsh -s /bin/bash user1
All done! Now logout from root account and login as non-root user.
Enjoy Kali Linux as your main OS.
Note: If you like to strenghten the secuity then you should also setup firewall rules using gufw or firestarter.