Friday, September 25, 2009

Wireless Chanel list in Ubuntu

Step 1: Install/Enable your Wireless Card

Step 2: Scan the media using 'iwlist scan'
root@imran-laptop:~/Desktop# iwlist scan
lo Interface doesn't support scanning.
eth0 Interface doesn't support scanning.
wlan0 Scan completed :
Cell 01 - Address: 00:1B:11:5A:BC:48
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=43/70 Signal level=-67 dBm
Encryption key:on
ESSID:"pingcom"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s
Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000008f601582180
Extra: Last beacon: 2732ms ago
IE: Unknown: 000770696E67636F6D
IE: Unknown: 010482848B96
IE: Unknown: 030101
IE: Unknown: 2A0100
IE: Unknown: 32088C129824B048606C
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
IE: Unknown: DD1E00904C334E101FFFFF000000000000000000000000000000000000000000
IE: Unknown: DD1A00904C340105070000000F000000000000000000000000000000
IE: Unknown: 2D1A4E101FFFFF000000000000000000000000000004000000000000
IE: Unknown: 3D160105030000000F000000000000000000000000000000
Cell 02 - Address: 00:19:5B:47:45:E5
Channel:2
Frequency:2.417 GHz (Channel 2)
Quality=57/70 Signal level=-53 dBm
Encryption key:on
ESSID:"Owera-Guest"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
12 Mb/s; 24 Mb/s; 36 Mb/s
Bit Rates:9 Mb/s; 18 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000000079c93363a
Extra: Last beacon: 2776ms ago
IE: Unknown: 000B4F776572612D4775657374
IE: Unknown: 010882848B960C183048
IE: Unknown: 030102
IE: Unknown: 2A0100
IE: Unknown: 32041224606C
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
IE: Unknown: DD0900037F01010006FF7F
IE: Unknown: DD0C00037F020101000002A34000

.
.
.


Step3: Change permission of script to execute , Script is at the bottom.
root@imran-laptop:~/Desktop# chmod -R +x wiscan.pl

Step 4: Run the Script
root@imran-laptop:~/Desktop# ./wiscan.pl
+ --- + ------------------------------ + ------- + -------- + --- + ------ + --------- + ---------------------- + ----------------- +
| # | Name | Quality | Sig Lvl | Enc | Enc T. | Auth T. | Channel | AP MAC |
+ --- + ------------------------------ + ------- + -------- + --- + ------ + --------- + ---------------------- + ----------------- +
| 1 | "pingcom" | 55/70 | -55 dBm | on | WPA v1 | PSK | 2.412 GHz (Channel 1) | 00:1B:11:5A:BC:48 |
| 2 | "Owera-Guest" | 57/70 | -53 dBm | on | WPA v1 | PSK | 2.417 GHz (Channel 2) | 00:19:5B:47:45:E5 |
| 3 | "Difi-Gjestenett" | 50/70 | -60 dBm | off | WEP | N/A | 2.412 GHz (Channel 1) | 00:13:F7:CA:25:D9 |
| 4 | "DVG-5802S" | 53/70 | -57 dBm | on | WPA v1 | PSK | 2.427 GHz (Channel 4) | 06:21:94:00:54:D4 |
| 5 | "Difi-Gjestenett" | 38/70 | -72 dBm | off | WEP | N/A | 2.437 GHz (Channel 6) | 00:13:F7:CA:25:D4 |
| 6 | "ft-test" | 53/70 | -57 dBm | on | WPA v1 | PSK | 2.447 GHz (Channel 8) | 0E:21:94:00:54:D4 |
| 7 | "Einar Aaland's Network" | 44/70 | -66 dBm | on | WPA v1 | PSK | 2.457 GHz (Channel 10) | 00:1F:5B:88:54:13 |
| 8 | "ap2" | 43/70 | -67 dBm | on | WEP | N/A | 2.422 GHz (Channel 3) | 00:19:5B:47:65:F3 |
| 9 | "pingcom" | 43/70 | -67 dBm | on | WPA v1 | PSK | 2.432 GHz (Channel 5) | 00:1B:11:5C:82:01 |
| 10 | "Difi_Adm" | 31/70 | -79 dBm | on | WPA v1 | 802.1x | 5.54 GHz (Channel 108) | 00:24:C4:F9:16:3F |
| 11 | "Difi_Adm" | 32/70 | -78 dBm | on | WPA v1 | 802.1x | 2.437 GHz (Channel 6) | 00:24:C4:F9:16:30 |
+ --- + ------------------------------ + ------- + -------- + --- + ------ + --------- + ---------------------- + ----------------- +


Her is the script, this is written by Timothy Mills, downloaded from Internet, thanks to Timothy Mills, we just did some changes to have MAC addresses or APs. You can copy this and save it as 'wiscan.pl' and change permission to execute..
#!/usr/bin/perl
#############################################################################
# Author: Timothy Mills
# Date : 8 - 4 - 08
# File : wiscan.pl
#
# wiscan.pl takes the output of 'iwlist scan' and makes it in an easier
# to read format for those of us who still deal with the terminal :)
#############################################################################


helpCheck();

#Run the command and suppress error output
$iwlistOut = `iwlist scan 2> /dev/null`;

@myLines = split("\n", $iwlistOut);
@cellArr = [];

printHeading();
printFin("#", "Name", "Quality","Sig Lvl", "Enc", "Enc T.", "Auth T.", "Channel", "AP MAC");
printHeading();

$currNum = 0;
varInit();

foreach (@myLines)
{
if ($_ =~ "Cell [0-9][0-9]")
{
if ($currNum > 0)
{
printFin($currNum, $name, $quality, $sigLvl, $enc, $encType,
$authType, $chn, $mac);

varInit();
}
$currNum++;
}

$cellArr[$currNum] = $cellArr[$currNum]."$_"."\n";

if ($_ =~ "ESSID")
{
handleName($_);
}
elsif($_ =~ "Frequency")
{
handleChn($_);
}
elsif($_ =~ "Address:")
{
handleMAC($_);
}

elsif($_ =~ "Encryption key")
{
handleKey($_);
}
elsif($_ =~ "Quality=[0-9]+/[0-9]+")
{
handleQuality($_);
}
elsif($_ =~ "IE: WPA .+ [0-9]")
{
handleEncType($_);
}
elsif($_ =~ "Authentication Suites")
{
handleAuthType($_);
}

}


if ($currNum > 0)
{
printFin($currNum, $name, $quality, $sigLvl, $enc, $encType, $authType, $chn, $mac);
printHeading();
}
else
{
print("No scan results :'( \n");
}

if (scalar @ARGV == 1)
{
$myNum = ($ARGV[0] =~ "[0-9]+");

print $cellArr[$ARGV[0]] if($myNum && ($ARGV[0]>0 && $ARGV[0] <= $currNum)); } sub helpCheck () { foreach(@ARGV) { helpMsg() if ($_ =~ "--help"); } if (scalar @ARGV == 1 && !($ARGV[0] =~ "[0-9]+")) { helpMsg(); } elsif (scalar @ARGV > 1)
{
helpMsg();
}
}

sub helpMsg ()
{
printf("Usage: wiscan.pl [network number] \n\n");
printf("wiscan is used to make the output of 'iwlist scan' be more readable"
."\n");

printf("from within a terminal. By using the optional argument you may \n");
printf("get the full output for a network from 'iwlist scan'\n\n");

printf("EXAMPLES: \n");
printf("1: ./wiscan.pl -- Lists all wireless networks within range\n");
printf("2: ./wiscan.pl 2 -- Shows full output for second wireless network entry \n in the output of wiscan.pl\n");


exit(0);
}


sub printFin()
{
printf("| %-3s | %-30s | %-7s | %-8s | %-3s | %-6s | %-9s | %-22s | %-17s |\n", $_[0],
$_[1], $_[2], $_[3], $_[4], $_[5], $_[6], $_[7],$_[8]);
}

sub printHeading()
{
printf("+ %-3s + %-30s + %-7s + %-8s + %-3s + %-6s + %-9s + %-22s + %-17s +",
"---", "------------------------------", "-------", "--------", "---", "------", "---------","----------------------","-----------------");


printf("\n");
}

sub varInit()
{
$name = "";
$quality = "";
$sigLvl = "";
$enc = "";
$chn = "";
$mac = "";
$encType = "WEP";
$authType = "N/A";
}

sub handleEncType ()
{
$encType = "WPA v".($_ =~ ".*[0-9]");
}

sub handleQuality ()
{
$qual = $_[0];

@qualArr = split(" ", $qual);

$quality = (split("=", $qualArr[0]))[1];
$sigLvl = (split("=", $qualArr[2]))[1]." dBm";
}

sub handleChn ()
{
$chn = (split(":", $_[0]))[1];
}

sub handleMAC ()
{
$mac = (split(": ", $_[0]))[1];
}

sub handleKey ()
{
$enc = (split(":", $_[0]))[1];
}

sub handleName ()
{
$name = (split(":", $_[0]))[1];
}

sub handleAuthType ()
{
$authType = (split(" ", $_[0]))[4];
}

Tuesday, September 15, 2009

DHCP-RELAY Agent in Ubunt 8.04 hardy

I am using I386 Machine with fresh install of ubuntu 8.04 Server and two interfaces.
eth0----Internet
eth2----use to listen dhcp request

Step 1: Install the dhcp3-package
First add following in /etc/apt/sources.list
root@ubuntu:~# nano /etc/apt/sources.list

deb http://security.ubuntu.com/ubuntu hardy-security main universe

add and exit,then
root@ubuntu:~# apt-get install dhcp3-relay
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
dhcp3-relay
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 103kB of archives.
After this operation, 274kB of additional disk space will be used.


During Installation it will ask you,
a) DHCP server IP address e.g your dhcp server address and
b) Interface which you will listen for dhcp requests e.g eth2.

Step 2: Enable forwarding.
root@ubuntu:~# echo 1 > /proc/sys/net/ipv4/ip_forward
root@ubuntu:~# echo 1 > /proc/sys/net/ipv4/tcp_syncookies
root@ubuntu:~# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts


Step 3: Testing

Attach cable on eth2 to a pc and wait for responce

Thursday, September 10, 2009

Setup ITERATIVE DNS in Ubuntu 8.04 Server

Step 1: Fresh Install the Ubuntu server with option of DNS server during installation or you can install DNS latter in step 2.

Step 2: Install DNS if not installed before
root@ins# apt-get install bind9

Step 3: Edit /etc/bind/named.conf.options to disable recursion.

By default the recursion is enables(yes), you can add /uncomment the follwoing line in option field.

//recursion yes; //default

recursion no;

root@ins:/etc/bind# nano named.conf.options

options {
directory "/var/cache/bind";

// If there is a firewall between you and nameservers you want
// to talk to, you might need to uncomment the query-source
// directive below. Previous versions of BIND always asked
// questions using port 53, but BIND 8.1 and later use an unprivileged
// port by default.

// query-source address * port 53;

// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.

// forwarders {
// 0.0.0.0;
// };

recursion no;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};

Step 4: Restart the bind
root@ins:/etc/bind# /etc/init.d/bind9 restart

Step 5: Testing

You can run wireshark in your machine and try to ping a host e.g ping www.google.com

In trace you will see the response from dns server, expand the Domain Name System, Flags and Authoritative Server list can be seen.

Wednesday, September 9, 2009

iRED Mail Installation on Ubuntu Server 8.04

Installation of useful tools.

root@redmail:~# apt-get install acl wget dialog

Copy following to /etc/apt/sources.list
root@redmail:~# nano /etc/apt/sources.list

deb http://ppa.launchpad.net/lidaobing/iredmail-804/ubuntu hardy main
deb-src http://ppa.launchpad.net/lidaobing/iredmail-804/ubuntu hardy main
Add key, you can replace your key, I used this "61270A939E324B12" and update.

root@redmail:~#apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 61270A939E324B12
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv-keys 61270A939E324B12
gpg: requesting key 9E324B12 from hkp server keyserver.ubuntu.com
gpg: key 9E324B12: public key "Launchpad PPA for LI Daobing" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
root@redmail:~# apt-get update

Add mount option 'acl' in /etc/fstab
which contains '/etc/' directory if it doesn't there yet. Copy it as a new line, and comment the old one, add 'acl' like below.
    # /dev/sda1
    UUID=63b655fe-5959-46bc-b9db-09ad2d746b78 / ext3 relatime,errors=remount-ro 0 1

    Note: It seems you don't need to add this 'acl' option in /etc/fstab if you use VPS which hosted by OpenVZ, because you can't edit /etc/fstab file, and it already supports acl.

Remount the mount point which contains '/etc/' directory. e.g. '/':
    root@iredmail:/var/tmp/iRedMail-0.5.0# mount -o remount,rw,acl /


Download the package " iRedMail-0.5.0.tar.bz2 " from
http://code.google.com/p/iredmail/downloads/list
and move it to /var/tmp directory.
#cd /var/tmp
#tar -xvf iRedMail-0.5.0.tar.bz2
#cd iRedMail-0.5.0/pkgs

Run the script get_all.sh


This will fetch the required packages from source, please make sure that your Internet is working ok.

root@redmail:/var/tmp/iRedMail-0.5.0/pkgs# bash get_all.sh
<> Creating necessary directories ...
<> ==================== Fetching Source Tarballs ====================
<> * 1/16: http://www.iredmail.org/apt/misc/postfixadmin-2.2.1.1.tar.gz
<> * 2/16: http://www.iredmail.org/apt/misc/phpMyAdmin-2.11.9.5-all-languages.tar.bz2
<> * 3/16: http://www.iredmail.org/apt/misc/roundcubemail-0.2.1.tar.gz
<> * 4/16: http://www.iredmail.org/apt/misc/phpldapadmin-1.1.0.7.tar.gz
<> * 5/16: http://www.iredmail.org/apt/misc/squirrelmail-1.4.19.tar.bz2
<> * 6/16: http://www.iredmail.org/apt/misc/change_ldappass-2.2-1.4.0.tar.gz
<> * 7/16: http://www.iredmail.org/apt/misc/change_sqlpass-3.3-1.2.tar.gz
<> * 8/16: http://www.iredmail.org/apt/misc/compatibility-2.0.14-1.0.tar.gz
<> * 9/16: http://www.iredmail.org/apt/misc/check_quota-2.2-1.4.0.tar.gz
<> * 10/16: http://www.iredmail.org/apt/misc/select_language-1.1-1.4.0.tar.gz
<> * 11/16: http://www.iredmail.org/apt/misc/autosubscribe-1.1-1.4.2.tar.gz
<> * 12/16: http://www.iredmail.org/apt/misc/email_footer-0.5-1.4.2.tar.gz
<> * 13/16: http://www.iredmail.org/apt/misc/login_auto-1.1-1.2.tar.gz
<> * 14/16: http://www.iredmail.org/apt/misc/avelsieve-1.0.1.tar.gz
<> * 15/16: http://www.iredmail.org/apt/misc/all_locales-1.4.13-20071220.tar.gz
<> * 16/16: http://www.iredmail.org/apt/misc/add_address-1.0.1-1.4.0.tar.gz
<> Validate Packages via md5sum ... [ OK ]
<> Checking necessary command/package: dialog/dialog ...
<> Checking necessary command/package: setfacl/acl ...
********************************************************
* All tasks had been finished Successfully. Next step:
*
* # cd ..
* # bash iRedMail.sh
*
********************************************************

Make Sure devcot is installted
root@redmail:/var/tmp/iRedMail-0.5.0/pkgs# apt-cache policy dovecot-common dovecot-pop3d dovecot-imapd | grep 'Candidate'
Candidate: 1:1.1.11-0ubuntu4~hardy2
Candidate: 1:1.1.11-0ubuntu4~hardy2
Candidate: 1:1.1.11-0ubuntu4~hardy2

Start Installation
root@redmail:/var/tmp/iRedMail-0.5.0# bash iRedMail.sh

It will ask question about path of directory, options, etc.... press next next and Y at the end.

It will installed every thing you need with options you select.


Component URL Access via HTTP Access via HTTPS
Roundcube webmail http://your_server/mail/ (or /webmail, /roundcube) YES YES
SquirrelMail webmail http://your_server/squirrelmail/ (or /squirrel) YES YES
PostfixAdmin https://your_server/postfixadmin/ NO YES
phpMyAdmin https://your_server/phpmyadmin/ (or /mysql) NO YES
phpLDAPAdmin https://your_server/ldap/ (or /phpldapadmin) NO YES
Awstats https://your_server/awstats/awstats.pl NO YES

Now you can login and send your first mail to any other account for testing.

References
http://code.google.com/p/iredmail/wiki/Installation_on_Debian
http://code.google.com/p/iredmail/downloads/list
http://code.google.com/p/iredmail/wiki/Admin_Guide
http://code.google.com/p/iredmail/wiki/DNS_SPF
http://code.google.com/p/iredmail/wiki/DNS_DKIM

Tuesday, September 1, 2009

How to make Ubuntu/Debian as a router

Here is your Ubuntu serve box with two interfaces,
eth0-------------Internet
eth2-------------Internal
Note: Your Internet is running using eth0.
Step1: Install DHCP Server

#apt-get install dhcp3-server

Step 2: Configure the DHCP server

Edit the /etc/dhcp3/dhcpd.conf file and add your domain, dns, ip range and other options.

option domain-name "oslohosting.com";
option domain-name-servers ns1.yourdns.com, xx.xx.xx.xx;
#
# Internal network
#
subnet 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.100 192.168.50.200;
option broadcast-address 192.168.50.255;
option routers 192.168.50.1;
default-lease-time 600;
max-lease-time 7200;
}

Step 3: Configure the Internal interface (eth2) with static IP.
Edit the /etc/network/interfaces file and add following

iface eth2 inet static
address 192.168.50.1
netmask 255.255.255.0
network 192.168.50.0
broadcast 192.168.50.255
gateway 192.168.50.1

Step 4: Restart network and verify the eth2 interface's IP.

#/etc/init.d/network restart

check ip by ifconfig eth2, it will have 192.168.50.1 ip, if not please restart the interface/netwrok service, you can also restart your machine if it is not in production environment.


Step 5: Restart the DHCP server.

#/etc/init.d/dhcp3-server restart

If every thing is ok, it should run successfully,
Note: If your interface does not have any IP it might give error and does not restart, first configure you internal interface.

Step 6: Test the DHCP server.

connect the cable on interface eth2 and other side to your second pc, you will get the IP from 192.168.50.x range.
Open the syslog messeges with
#tail -f /var/log/syslog
of your debian box, it will also notify with leased ip and detail of requested machine.

Step 7: Enable forwarding
# cat /proc/sys/net/ipv4/ip_forward
0
# echo 1 > /proc/sys/net/ipv4/ip_forward

or open the file manually and uncomment

# nano /etc/sysctl.conf

net.ipv4.ip_forward = 1

Step 8: Add IPTABLES rule for NAT

Type following at command line

#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Step 9: Final Testing

Your second Pc attached to LAN have internal ip, ping to www.google.com, it should get reply, if not review and trouble shoot carefully.

imran@imran-laptop:~$ ping www.google.com
PING www.l.google.com (74.125.77.103) 56(84) bytes of data.
64 bytes from ew-in-f103.google.com (74.125.77.103): icmp_seq=1 ttl=52 time=30.7 ms
64 bytes from ew-in-f103.google.com (74.125.77.103): icmp_seq=2 ttl=52 time=30.2 ms
64 bytes from ew-in-f103.google.com (74.125.77.103): icmp_seq=3 ttl=52 time=30.3 ms
^C
--- www.l.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 30.298/30.451/30.729/0.242 ms

Huraaaa!