PoiNtEr->: December 2011

                             Difference between a dream and an aim. A dream requires soundless sleep, whereas an aim requires sleepless efforts.

Search This Blog

Thursday, December 29, 2011

Understanding ATA,SATA And SCSI

ATA (Advanced Technology Attachment)– a 16-bit parallel interface used for controlling computer drives. Introduced in 1986, it has undergone many evolutions in the last 18+ years, with the latest version being called ATA-7. Wherever an item is referred to as being an ATA device, it is commonly a Parallel ATA device. ATA devices are also commonly called IDE, EIDE, Ultra-ATA, Ultra-DMA, ATAPI, PATA, etc. (each of these acronyms actually do refer to very specific items, but are commonly interchanged)


SATA (Serial Advanced Technology Attachment)– a 1-bit serial evolution of the Parallel ATA physical storage interface.
Starting with SATA, it extends the capabilities of ATA and offers transfer rates starting at 150MB/s and, after years of development, has moved to the mainstream of disk interfaces. The successor the SCSI interface is SAS at speeds of up to 3Gb/s. Additionally, it also addresses parallel interface issues such as drive addressability and limitations on the number of device per port connection.

Short for small computer system interface, a parallel interface standard used by Apple Macintosh computers, PCs and many UNIX systems for attaching peripheral devices to computers. Nearly all Apple Macintosh computers, excluding only the earliest Macs and the recent iMac, come with a SCSI port for attaching devices such as disk drives and printers. SCSI interfaces provide for data transmission rates (up to 80 megabytes per second). In addition, you can attach multiple devices to a single SCSI port, so that SCSI is really an I/O bus rather than simply an interface.

Cables & Connectors:Another big advantage of SATA over ATA is the cabling and connectors. The serial interface reduces the amount of wires needed to transmit data, making for much smaller cable size and making it easier to route and install SATA devices. The IDE cables used in parallel ATA systems are bulkier than Serial ATA cables and can only extend to 40cm long, while Serial ATA cables can extend up to one meter. In addition to the cabling, a new design of connectors is also used that reduces the amount of crosstalk between the wires, and the connector design also provides easier routing and better air flow.
26-inch Internal
SCSI Cable
                         External SCSI4 Cable
SATA Internal
Power Splitter Cable
ATA Drive
Connection Cable

Monday, December 26, 2011

Controlling Bandwidth in Linux (ubuntu) using Trickle

Trickle is a portable lightweight userspace bandwidth shaper. It can run in collaborative mode (together with trickled) or in stand alone mode.
trickle works by taking advantage of the unix loader preloading. Essentially it provides, to the application, a new version of the functionality that is required to send and receive data through sockets. It then limits traffic based on delaying the sending and receiving of data over a socket. trickle runs entirely in userspace and does not require root privileges.

To install trickle in Ubuntu:

sudo apt-get install trickle

To start Firefox with a limit to the amount of bandwidth it consumes all you have to do is type in the command line.

trickle -d 200 firefox
this would start Firefox with a download limit of 200KB/s.

Traffic Control Using TC In Linux(ubuntu)

In the absence of infinite bandwidth there will always be a need to hand out capacity accord-
ing to rules. Traditionally this has been a main reason to add non-IP technology to a network,
like ATM or frame relay. Since IP is steadily taking over the world, Linux is well placed to
play a role in enabling IP to take over traffic controlling functions from other technologies.

What is qdisc??
• Queueing Discipline(qdisc) :An algorithm that manages the queue of a device, either in-
coming (ingress) or outgoing (egress).
• Classless qdisc A qdisc with no configurable internal subdivisions.

• Classful qdisc A classful qdisc contains multiple classes. Each of these classes
contains a further qdisc, which may again be classful, but need not be.

Some Important Available Queueing Disciplines

• pfifo_fast

• Token Bucket Filter(TBF)
• Stochastic Fairness Queueing
• Prio
• Hierarchical Token Bucket(HTB)

Token Bucket (TB){Analogy Used in Shaping Traffic}

A token bucket is nothing but a common algorithm used to control the amount of data that is injected into a network, allowing for bursts of data to be sent. It is used for network traffic shaping or rate limiting. With token bucket you can define the maximum rate of traffic allowed on an interface at a given moment in time.
                                   |   |
                                   |  | Bucket to
                                   |  | to hold b tokens
        |                                \|/
Packets |      +============+
stream  | ---> | token wait | --->  Remove token  --->  eth0
        |      +============+
  1. The TB filter puts tokens into the bucket at a certain rate.
  2. Each token is permission for the source to send a specific number of bits into the network.
  3. Bucket can hold b tokens as per shaping rules.
  4. Kernel can send packet if you've a token else traffic need to wait.
Tc is used to configure Traffic Control in the Linux kernel. Traffic Control consists of the following:
When traffic is shaped, its rate of transmission is under control. Shaping may be more than lowering the available bandwidth - it is also used to smooth out bursts in traffic for better network behaviour. Shaping occurs on egress.
By scheduling the transmission of packets it is possible to improve interactivity for traffic that needs it while still guaranteeing bandwidth to bulk transfers. Reordering is also called prioritizing, and happens only on egress.
Where shaping deals with transmission of traffic, policing pertains to traffic arriving. Policing thus occurs on ingress.
Traffic exceeding a set bandwidth may also be dropped forthwith, both on ingress and on egress.
Processing of traffic is controlled by three kinds of objects: qdiscs, classes and filters.

Example Problem: We have two customers, A and B, both connected to the internet via eth0. We want to allocate 60 kbps to B and 40 kbps to A. Next we want to subdivide A's bandwidth 30kbps for WWW and 10kbps for everything else. Any unused bandwidth can be used by any class which needs it (in proportion of its allocated share).

tc qdisc add dev eth0 root handle 1: htb default 12

This command attaches queue discipline HTB to eth0 and gives it the "handle" 1:. This is just a name or identifier with which to refer to it below. The default 12 means that any traffic that is not otherwise classified will be assigned to class 1:12

tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps 
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 30kbps ceil 100kbps
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 10kbps ceil 100kbps
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 60kbps ceil 100kbps

The first line creates a "root" class, 1:1 under the qdisc 1:. The definition of a root class is one with the htb qdisc as its parent. A root class, like other classes under an htb qdisc allows its children to borrow from each other, but one root class cannot borrow from another.

We also have to describe which packets belong in which class. This is really not related to the HTB qdisc.

tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 \
   match ip src match ip dport 80 0xffff flowid 1:10
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 \
   match ip src flowid 1:11
(We identify A by its IP address which we imagine here to be
u32 is a filter that matches on IP destination port 80 *exactly* and send it to band 1:10 and 1:11.

Thursday, December 22, 2011

Disable Traceroute(tracert) using iptables

To disable traceroute coming from Linux box (tested on ubuntu 11.0 4):
# iptables -t filter -A OUTPUT -p icmp -m icmp --icmp-type port-unreachable -j DROP

And to disable traceroute coming from Windows box (tested on Windows7):
# iptables -t filter -A OUTPUT -p icmp -m icmp --icmp-type echo-reply -j DROP

Tuesday, December 20, 2011

HACKER's Diary 3

Protect Yourself From DDOS and Brute Force Attacks using IPTABLES in linux

The Linux firewall is called iptables. Iptables is very powerful and features include :
1:Filtering - (blocking unwanted traffic). You can filter incoming and outgoing traffic by user, group, time/date, or service (application).
2:NAT (Routing). If your computer has two or more network cards (or if you are using virtualization) you can use a spare computer as a router, one network card connected to the Internet and the other to your LAN with iptables monitoring and filtering traffic.
3:Logging (monitoring) network traffic.
4:Block brute force or DOS attacks.

Block Brute Force attempts (SSH or other connections)
1:iptables -A INPUT -p tcp -m tcp --dport 22 -m tcp -m state --state NEW -m recent --set --name SSH --rsource
2:iptables -A INPUT -p tcp -m tcp --dport 22 -m recent --update --seconds 600 --hitcount 8 --rttl 3:name SSH --rsource -j DROP
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT

In Dos attack generally Attacker tries to flood the victim with large number of packets using hping3.
The Internet Control Message Protocol (ICMP) has many messages that are identified by a "type" field. You need to use 0 and 8 ICMP code types.
1:Zero (0) is for echo-reply
2:Eight (8) is for echo-request.

iptables -A OUTPUT -p icmp --icmp-type echo-request -j DROP  
iptables -A OUTPUT -p icmp --icmp-type 8 -j DROP

Socket Programming in C

//Simple Hello Server


    int sock,cli;
    unsigned int len;
    char mesg[]= "Hello to the World to Socket Programming";
   int sent;
    struct sockaddr_in server,client;
    if((sock = socket(AF_INET,SOCK_STREAM,0)) == -1)
        perror("socket: ");
    server.sin_family = AF_INET;
    server.sin_port = htons(9335);
    server.sin_addr.s_addr = INADDR_ANY;
    len = sizeof(struct sockaddr_in);
    if ((bind(sock,(struct sockaddr *)&server,len ))== -1)
    if((listen(sock,5))== -1)



    if((cli =accept(sock,(struct sockaddr *)&client,&len)))



printf("sent %d bytes to client : %s\n",sent,inet_ntoa(client.sin_addr));


English is tough stuff

Dearest creature in creation,
Study English pronunciation.
I will teach you in my verse
Sounds like corpse, corps, horse, and worse.
I will keep you, Suzy, busy,
Make your head with heat grow dizzy.
Tear in eye, your dress will tear.

So shall I! Oh hear my prayer.
Just compare heart, beard, and heard,
Dies and diet, lord and word,
Sword and sward, retain and Britain.
(Mind the latter, how it's written.)
Now I surely will not plague you
With such words as plaque and ague.
But be careful how you speak:
Say break and steak, but bleak and streak;
Cloven, oven, how and low,
Script, receipt, show, poem, and toe.

Hear me say, devoid of trickery,
Daughter, laughter, and Terpsichore,
Typhoid, measles, topsails, aisles,
Exiles, similes, and reviles;
Scholar, vicar, and cigar,
Solar, mica, war and far;
One, anemone, Balmoral,
Kitchen, lichen, laundry, laurel;
Gertrude, German, wind and mind,
Scene, Melpomene, mankind.

Billet does not rhyme with ballet,
Bouquet, wallet, mallet, chalet.
Blood and flood are not like food,
Nor is mould like should and would.
Viscous, viscount, load and broad,
Toward, to forward, to reward.
And your pronunciation's OK
When you correctly say croquet,
Rounded, wounded, grieve and sieve,
Friend and fiend, alive and live.

Ivy, privy, famous; clamour
And enamour rhyme with hammer.
River, rival, tomb, bomb, comb,
Doll and roll and some and home.
Stranger does not rhyme with anger,
Neither does devour with clangour.
Souls but foul, haunt but aunt,
Font, front, wont, want, grand, and grant,
Shoes, goes, does. Now first say finger,
And then singer, ginger, linger,
Real, zeal, mauve, gauze, gouge and gauge,
Marriage, foliage, mirage, and age.

Query does not rhyme with very,
Nor does fury sound like bury.
Dost, lost, post and doth, cloth, loth.
Job, nob, bosom, transom, oath.
Though the differences seem little,
We say actual but victual.
Refer does not rhyme with deafer.
Foeffer does, and zephyr, heifer.
Mint, pint, senate and sedate;
Dull, bull, and George ate late.
Scenic, Arabic, Pacific,
Science, conscience, scientific.

Liberty, library, heave and heaven,
Rachel, ache, moustache, eleven.
We say hallowed, but allowed,
People, leopard, towed, but vowed.
Mark the differences, moreover,
Between mover, cover, clover;
Leeches, breeches, wise, precise,
Chalice, but police and lice;
Camel, constable, unstable,
Principle, disciple, label.

Petal, panel, and canal,
Wait, surprise, plait, promise, pal.
Worm and storm, chaise, chaos, chair,
Senator, spectator, mayor.
Tour, but our and succour, four.
Gas, alas, and Arkansas.
Sea, idea, Korea, area,
Psalm, Maria, but malaria.
Youth, south, southern, cleanse and clean.
Doctrine, turpentine, marine.

Compare alien with Italian,
Dandelion and battalion.
Sally with ally, yea, ye,
Eye, I, ay, aye, whey, and key.
Say aver, but ever, fever,
Neither, leisure, skein, deceiver.
Heron, granary, canary.
Crevice and device and aerie.

Face, but preface, not efface.
Phlegm, phlegmatic, ass, glass, bass.
Large, but target, gin, give, verging,
Ought, out, joust and scour, scourging.
Ear, but earn and wear and tear
Do not rhyme with here but ere.
Seven is right, but so is even,
Hyphen, roughen, nephew Stephen,
Monkey, donkey, Turk and jerk,
Ask, grasp, wasp, and cork and work.

Pronunciation -- think of Psyche!
Is a paling stout and spikey?
Won't it make you lose your wits,
Writing groats and saying grits?
It's a dark abyss or tunnel:
Strewn with stones, stowed, solace, gunwale,
Islington and Isle of Wight,
Housewife, verdict and indict.

Finally, which rhymes with enough --
Though, through, plough, or dough, or cough?
Hiccough has the sound of cup.
My advice is to give up!!!

(Apparently excerpted from The Chaos by Gerard Nolst Trenité.)



1:sudo -i

2:fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000080

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1           12750       19458    53882881    5  Extended
/dev/sda2              13        7650    61337600    7  HPFS/NTFS
/dev/sda3   *        7651       12749    40957717+   7  HPFS/NTFS
/dev/sda5           12750       19458    53882880   83  Linux

so linux is installed in sda5 as you can see above.

3:mount /dev/sda5 /mnt

4:mount /dev/sda5 /mnt/boot            #skip this one if not have a separate /boot partition

5:grub-install --root-directory=/mnt/ /dev/sda

6:sudo reboot

voila your dead ubuntu is up !!!

Friday, December 9, 2011

Download already buffered youtube video ubuntu11.04

1:file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:


Now go to this path and that's it voila we are done :-)

2: cp $(file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d: | head -n 1) VideoName.avi  

Above command will save this video in your current working directory ....