Monday, January 30, 2012

sniffing


Cyber Attacks Explained: Network Sniffing

Cyber Attack

Sniffing involves capturing, decoding, inspecting and interpreting the information inside a network packet on a TCP/IP network. The purpose is to steal information, usually user IDs, passwords, network details, credit card numbers, etc. Sniffing is generally referred to as a “passive” type of attack, wherein the attackers can be silent/invisible on the network. This makes it difficult to detect, and hence it is a dangerous type of attack.
As we already learnt over the previous months, the TCP/IP packet contains vital information required for two network interfaces to communicate with each other. It contains fields such as source and destination IP addresses, ports, sequence numbers and the protocol type. Each of these fields is crucial for various network layers to function, and especially for the Layer 7 application that makes use of the received data.
By its very nature, the TCP/IP protocol is only meant for ensuring that a packet is constructed, mounted on an Ethernet packet frame, and reliably delivered from the sender to the receiver across networks. However, it does not by default have mechanisms to ensure data security. Thus, it becomes the responsibility of the upper network layers to ensure that information in the packet is not tampered with.
To understand why hackers sniff, we need to know what they can get from the network. Figure 1 shows the OSI layers and the information a hacker can steal at each layer by successfully sniffing a network.
Mapping of OSI layers
Figure 1. Mapping of OSI layers
The sniffing process is used by hackers either to get information directly or to map the technical details of the network in order to create a further attack. Hackers are always in favour of sniffing, because it can be done for a longer time without getting caught.

How do they ‘sniff’?

Network sniffing uses sniffer software, either open source or commercial. Broadly, there are three ways to sniff a network, as shown in Figure 2.
Sniffing attack vectors
Figure 2. Sniffing attack vectors
It is important to remember that sniffing can range from Layer 1 through Layer 7. Talking about physical connectivity, a person (who may be an employee of the firm) who is already hooked up to the internal LAN can run tools to directly capture network traffic. Using spoofing techniques, a hacker outside the target network can intercept packets at the firewall level and steal the information. In the latest form of packet sniffing, wide usage of wireless networks has made it easy to sit near the network and penetrate it to get information.
Regardless of where the hackers are located on the network being sniffed, they use packet capturing or packet sniffer software. Modern packet sniffers are supposed to be used for troubleshooting network problems, but can be used for hacking too. Please refer to the following table, which depicts the ethical and unethical side of sniffer software.
Sniffer tool usage
Ethical usageUnethical usage
  • Packet capturing
  • Network traffic usage and analysis
  • Packet conversion for data analysis
  • Network troubleshooting
  • User identity and password stealing
  • Email or instant message data stealing
  • Packet spoofing and data theft
  • Monetary or reputational damage
Regarding the technical details of how sniffing is done, we need to remember that packet capturing software always runs in promiscuous mode, whereby it is capable of intercepting and storing all packets on a network. This also means that, even though the packet is not meant for the network interface on which the sniffer is running, it is captured, stored and analysed.
Sniffer software contains its own network driver and buffer memory in order to capture a large chunk of packets. Modern sniffers are capable of analysing the captured packets and converting them into sensible statistical information. Now let’s discuss a few ways of sniffing a network, to understand how hackers get what they want.

A LAN sniff

A sniffer deployed on an internal LAN can scan the entire IP range promiscuously. This helps in providing further details such as live hosts, open ports, server inventory, etc. Once a list of open ports is gathered, a port-specific vulnerability attack is possible.

A protocol sniff

This method involves sniffing data related to the network protocols being used. First, a list of protocols is created based on the captured data. This is further segregated to create special sniffers for each attack. For example, in a network sniff capture, if the ICMP protocol is not seen, it is assumed to be blocked. However, if UDP packets are seen, a separate UDP sniffer is started to capture and decipher Telnet, PPP, DNS and other related application details.

An ARP sniff

In this popular method, the hacker captures a lot of data in order to create a map of IP addresses and the associated MAC addresses. Such a map is further used to create ARP poisoning attacks, packet-spoofing attacks, or to dig into router-based vulnerabilities.

TCP session stealing

This method is a very basic form of sniffing, in which a network interface in promiscuous mode captures traffic between a source and a destination IP address. Details such as port numbers, service types, TCP sequence numbers and the data itself are of interest to hackers. Upon capturing enough packets, advanced hackers can create fabricated TCP sessions to fool the source and destination, and be the man in the middle to take over the TCP session.

Application-level sniffing

Usually, from the data packets sniffed and captured, a few intricate application details are found out for information stealing or to create further attacks. As an example, the capture file can be parsed to perform OS fingerprinting, SQL query analysis, reveal application-specific TCP port data information, etc. In another approach, creating a mere list of applications running on a server is good enough to plan an application-specific attack on it.

Web password sniffing

As the name suggests, HTTP sessions are stolen and parsed for user ID and password stealing. While the Secure Socket Layers (SSL) are incorporated for securing HTTP sessions on the network, there are numerous internal websites that still use standard but less secure encryption. It is easy to capture Base64 or Base128 packets and run a deciphering agent against it to crack the password. In modern sniffers, SSL sessions can also be captured and parsed for information, though this method is not very easy.

Detecting sniffers

As mentioned earlier, since sniffers work silently, it is very difficult to detect them on a network. There are, however, a few tricks that can provide a clue to a possible sniffer presence. There are two ways to detect a sniffer — host-based and network-based.
In host-based detection, you can use small utilities to detect if the NIC is running in a promiscuous mode on any host in a network. Since the basic requirement for a sniffer to work is to put the network interface in “read all” mode, disabling it can very effectively help shutting down stray sniffers.
In case of network-based detection, anti-sniffer software can be run to detect the presence of specific signature packets. In another approach, scripts can be run to check each network host for the presence of known sniffers, processes, etc. Modern anti-virus or anti-spyware software are capable of detecting sniffing software and disabling it.

Protection from sniffers

While the very first step should be to design a tight perimeter defense system while creating network architecture, there are a few methods that could be deployed to make the infrastructure less sniffer-prone. The following tricks help achieve that to a great extent.
Disabling promiscuous mode on network interfaces results in shutting down most sniffer software. This can be done by running an admin script as a daily job on the network, or deploying a network policy at the host level to control access to the network card configuration settings.
Using switched networks can reduce the possibility of a sniffer running on the network. Unlike in a network hub, in a switched network the packets are delivered to the destination and are not visible to all nodes — thus reducing the chances of someone sniffing it on the way. Also, for network administrators it becomes easy to detect sniffers by focusing on the switched network segments, one at a time.
Anti-sniffing tools can be used to detect the network interface mode, as well as various processes and software present on servers or network hosts. Modern intrusion-detection systems have this as an integrated feature.
IPSec encryption can be used for token-based packet security in the network infrastructure, if the data is of a confidential nature. IPSec provides data encapsulation and encryption of high standards, and is available on modern routers, firewalls and other network components. Almost all operating systems do support IPSec, and it is widely used in serious IT infrastructure. For session layer protection, SSL and TLS can be used to encrypt traffic.

Protecting FOSS systems

Let us now look at a few sniffer products, in order to learn about what is used in the FOSS world today. Linux systems use the tcpdump utility, which is an excellent built-in sniffer to capture and store TCP packets. As for third-party open source tools, Wireshark (Ethereal) is very famous due to its GUI interface, and packet-filtering and viewing capabilities. Sniffit, DSniff and Ettercap are similar utilities, but meant for different purposes. DSniff is powerful in terms of capturing SSL traffic.
FOSS systems have no built-in method to protect themselves from sniffers. The methods described above could pretty much be used for various Linux distros, to make those less vulnerable to sniffer attacks. A smart utility available on Linux distros, called AntiSniff, can be used in a script to detect network interfaces in promiscuous mode.
Network sniffing is difficult to detect because it is a passive and silent type of attack. There are methods to detect and disable sniffers, and network administrators should incorporate those into their network to protect their IT infrastructure from information loss or theft.

Wednesday, January 25, 2012

SSH client

SSH, Telnet and Rlogin are three ways of doing the same thing: logging in to a multi-user computer from another computer, over a network.Multi-user operating systems, such as Unix and VMS, usually present a command-line interface to the user, much like the ‘Command Prompt’ or ‘MS-DOS Prompt’ in Windows. The system prints a prompt, and you type commands which the system will obey.


SSH, Telnet and Rlogin are network protocols that allow you to do this. On the computer you sit at, you run a client, which makes a network connection to the other computer (the server). The network connection carries your keystrokes and commands from the client to the server, and carries the server's responses back to you.



You might want to use SSH, Telnet or Rlogin if:
  • you have an account on a Unix or VMS system which you want to be able to access from somewhere else
  • your Internet Service Provider provides you with a login account on a web server. (This might also be known as a shell account. A shell is the program that runs on the server and interprets your commands for you.)
  • you want to use a bulletin board system, talker or MUD which can be accessed using Telnet.
You probably do not want to use SSH, Telnet or Rlogin if:
  • you only use Windows. Windows computers have their own ways of networking between themselves, and unless you are doing something fairly unusual, you will not need to use any of these remote login protocols.

Tuesday, January 24, 2012

Vi editor

What is vi?

The default editor that comes with the UNIX operating system is called vi (visual editor). [Alternate editors for UNIX environments include pico and emacs, a product of GNU.]
The UNIX vi editor is a full screen editor and has two modes of operation:
  1. Command mode commands which cause action to be taken on the file, and
  2. Insert mode in which entered text is inserted into the file.
In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the <Esc> (Escape) key turns off the Insert mode.
While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, this Web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become automatic.
NOTE: Both UNIX and vi are case-sensitive. Be sure not to use a capital letter in place of a lowercase letter; the results will not be what you expect. 
 

To Get Into and Out Of vi

To Start vi

To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.

* vi filename edit filename starting at line 1
  vi -r filename recover filename that was being edited when system crashed

To Exit vi


Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file.
Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the <Return> (or <Enter>) key.

* :x<Return> quit vi, writing out modified file to file named in original invocation
  :wq<Return> quit vi, writing out modified file to file named in original invocation
  :q<Return> quit (or exit) vi
* :q!<Return> quit vi even though latest changes have not been saved for this vi call
 

Moving the Cursor

Unlike many of the PC and MacIntosh editors, the mouse does not move the cursor within the vi editor screen (or window). You must use the the key commands listed below. On some UNIX platforms, the arrow keys may be used as well; however, since vi was designed with the Qwerty keyboard (containing no arrow keys) in mind, the arrow keys sometimes produce strange effects in vi and should be avoided.
If you go back and forth between a PC environment and a UNIX environment, you may find that this dissimilarity in methods for cursor movement is the most frustrating difference between the two.
In the table below, the symbol ^ before a letter means that the <Ctrl> key should be held down while the letter key is pressed.

* j or <Return>
  [or down-arrow]
move cursor down one line
* k [or up-arrow] move cursor up one line
* h or <Backspace>
  [or left-arrow]
move cursor left one character
* l or <Space>
  [or right-arrow]
move cursor right one character
* 0 (zero) move cursor to start of current line (the one with the cursor)
* $ move cursor to end of current line
  w move cursor to beginning of next word
  b move cursor back to beginning of preceding word
  :0<Return> or 1G move cursor to first line in file
  :n<Return> or nG move cursor to line n
  :$<Return> or G move cursor to last line in file


Screen Manipulation

The following commands allow the vi editor screen (or window) to move up or down several lines and to be refreshed.

  ^f move forward one screen
  ^b move backward one screen
  ^d move down (forward) one half screen
  ^u move up (back) one half screen
  ^l redraws the screen
  ^r redraws the screen, removing deleted lines


Adding, Changing, and Deleting Text

Unlike PC editors, you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables.
Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step.

* u UNDO WHATEVER YOU JUST DID; a simple toggle

The main purpose of an editor is to create, add, or modify text for a file.

Inserting or Adding Text

The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode.
* i insert text before cursor, until <Esc> hit
  I insert text at beginning of current line, until <Esc> hit
* a append text after cursor, until <Esc> hit
  A append text to end of current line, until <Esc> hit
* o open and put text in a new line below current line, until <Esc> hit
* O open and put text in a new line above current line, until <Esc> hit

Changing Text

The following commands allow you to modify text.
* r replace single character under cursor (no <Esc> needed)
  R replace characters, starting with current cursor position, until <Esc> hit
  cw change the current word with new text,
starting with the character under cursor, until <Esc> hit
  cNw change N words beginning with character under cursor, until <Esc> hit;
  e.g., c5w changes 5 words
  C change (replace) the characters in the current line, until <Esc> hit
  cc change (replace) the entire current line, stopping when <Esc> is hit
  Ncc or cNc change (replace) the next N lines, starting with the current line,
stopping when <Esc> is hit

Deleting Text

The following commands allow you to delete text.
* x delete single character under cursor
  Nx delete N characters, starting with character under cursor
  dw delete the single word beginning with character under cursor
  dNw delete N words beginning with character under cursor;
  e.g., d5w deletes 5 words
  D delete the remainder of the line, starting with current cursor position
* dd delete entire current line
  Ndd or dNd delete N lines, beginning with the current line;
  e.g., 5dd deletes 5 lines

Cutting and Pasting Text

The following commands allow you to copy and paste text.
  yy copy (yank, cut) the current line into the buffer
  Nyy or yNy copy (yank, cut) the next N lines, including the current line, into the buffer
  p put (paste) the line(s) in the buffer into the text after the current line


Other Commands


Searching Text

A common occurrence in text editing is to replace one word or phase by another. To locate instances of particular sets of characters (or strings), use the following commands.
  /string search forward for occurrence of string in text
  ?string search backward for occurrence of string in text
  n move to next occurrence of search string
  N move to next occurrence of search string in opposite direction

Determining Line Numbers

Being able to determine the line number of the current line or the total number of lines in the file being edited is sometimes useful.
  :.= returns line number of current line at bottom of screen
  := returns the total number of lines at bottom of screen
  ^g provides the current line number, along with the total number of lines,
in the file at the bottom of the screen


Saving and Reading Files

These commands permit you to input and output files other than the named file with which you are currently working.

  :r filename<Return> read file named filename and insert after current line
(the line with cursor)
  :w<Return> write current contents to file named in original vi call
  :w newfile<Return> write current contents to a new file named newfile
  :12,35w smallfile<Return> write the contents of the lines numbered 12 through 35 to a new file named smallfile
  :w! prevfile<Return> write current contents over a pre-existing file named prevfile

Moving the Cursor

Unlike many of the PC and MacIntosh editors, the mouse does not move the cursor within the vi editor screen (or window). You must use the the key commands listed below. On some UNIX platforms, the arrow keys may be used as well; however, since vi was designed with the Qwerty keyboard (containing no arrow keys) in mind, the arrow keys sometimes produce strange effects in vi and should be avoided.
If you go back and forth between a PC environment and a UNIX environment, you may find that this dissimilarity in methods for cursor movement is the most frustrating difference between the two.
In the table below, the symbol ^ before a letter means that the <Ctrl> key should be held down while the letter key is pressed.

* j or <Return>
  [or down-arrow]
move cursor down one line
* k [or up-arrow] move cursor up one line
* h or <Backspace>
  [or left-arrow]
move cursor left one character
* l or <Space>
  [or right-arrow]
move cursor right one character
* 0 (zero) move cursor to start of current line (the one with the cursor)
* $ move cursor to end of current line
  w move cursor to beginning of next word
  b move cursor back to beginning of preceding word
  :0<Return> or 1G move cursor to first line in file
  :n<Return> or nG move cursor to line n
  :$<Return> or G move cursor to last line in file


Screen Manipulation

The following commands allow the vi editor screen (or window) to move up or down several lines and to be refreshed.

  ^f move forward one screen
  ^b move backward one screen
  ^d move down (forward) one half screen
  ^u move up (back) one half screen
  ^l redraws the screen
  ^r redraws the screen, removing deleted lines


Adding, Changing, and Deleting Text

Unlike PC editors, you cannot replace or delete text by highlighting it with the mouse. Instead use the commands in the following tables.
Perhaps the most important command is the one that allows you to back up and undo your last action. Unfortunately, this command acts like a toggle, undoing and redoing your most recent action. You cannot go back more than one step.

* u UNDO WHATEVER YOU JUST DID; a simple toggle

The main purpose of an editor is to create, add, or modify text for a file.

Inserting or Adding Text

The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode.
* i insert text before cursor, until <Esc> hit
  I insert text at beginning of current line, until <Esc> hit
* a append text after cursor, until <Esc> hit
  A append text to end of current line, until <Esc> hit
* o open and put text in a new line below current line, until <Esc> hit
* O open and put text in a new line above current line, until <Esc> hit

Changing Text

The following commands allow you to modify text.
* r replace single character under cursor (no <Esc> needed)
  R replace characters, starting with current cursor position, until <Esc> hit
  cw change the current word with new text,
starting with the character under cursor, until <Esc> hit
  cNw change N words beginning with character under cursor, until <Esc> hit;
  e.g., c5w changes 5 words
  C change (replace) the characters in the current line, until <Esc> hit
  cc change (replace) the entire current line, stopping when <Esc> is hit
  Ncc or cNc change (replace) the next N lines, starting with the current line,
stopping when <Esc> is hit

Deleting Text

The following commands allow you to delete text.
* x delete single character under cursor
  Nx delete N characters, starting with character under cursor
  dw delete the single word beginning with character under cursor
  dNw delete N words beginning with character under cursor;
  e.g., d5w deletes 5 words
  D delete the remainder of the line, starting with current cursor position
* dd delete entire current line
  Ndd or dNd delete N lines, beginning with the current line;
  e.g., 5dd deletes 5 lines

Cutting and Pasting Text

The following commands allow you to copy and paste text.
  yy copy (yank, cut) the current line into the buffer
  Nyy or yNy copy (yank, cut) the next N lines, including the current line, into the buffer
  p put (paste) the line(s) in the buffer into the text after the current line


Other Commands


Searching Text

A common occurrence in text editing is to replace one word or phase by another. To locate instances of particular sets of characters (or strings), use the following commands.
  /string search forward for occurrence of string in text
  ?string search backward for occurrence of string in text
  n move to next occurrence of search string
  N move to next occurrence of search string in opposite direction

Determining Line Numbers

Being able to determine the line number of the current line or the total number of lines in the file being edited is sometimes useful.
  :.= returns line number of current line at bottom of screen
  := returns the total number of lines at bottom of screen
  ^g provides the current line number, along with the total number of lines,
in the file at the bottom of the screen


Saving and Reading Files

These commands permit you to input and output files other than the named file with which you are currently working.

  :r filename<Return> read file named filename and insert after current line
(the line with cursor)
  :w<Return> write current contents to file named in original vi call
  :w newfile<Return> write current contents to a new file named newfile
  :12,35w smallfile<Return> write the contents of the lines numbered 12 through 35 to a new file named smallfile
  :w! prevfile<Return> write current contents over a pre-existing file named prevfile