Socket

From Hackepedia
Revision as of 13:08, 15 June 2007 by BfoKmu (talk | contribs)
Jump to navigationJump to search

[nexium online] [cheap fioricet] [jazz ringtones] [motorola ringtones] [free mtv ringtones] [cialis online] [cheap lisinopril] [nokia ringtones] [paxil online] [didrex online] [ultracet online] [free sonyericsson ringtones] [mono ringtones] [buy valium] [diazepam] [clomid online] [cheap fioricet] [order paxil] [free kyocera ringtones] [free mp3 ringtones] [mp3 ringtones] [alprazolam online] [free alltel ringtones] [alprazolam online] [lipitor online] [buy hydrocodone] [verizon ringtones] [but levitra] [tramadol online] [hydrocodone online] [free sprint ringtones] [order xanax] [real ringtones] [tracfone ringtones] [propecia online] [cheap ativan] [samsung ringtones] [tramadol online] [buy didrex] [cheap clomid] [lorazepam online] [samsung ringtones] [cheap albuterol] [cheap zyban] [order soma] [but clonazepam] [cheap paxil] [free real ringtones] [sildenafil online] [cheap soma] [online ambien] [order wellbutrin] [adipex online] [propecia online] [free real ringtones] [diethylpropion online] [free polyphonic ringtones] [cheap rivotril] [jazz ringtones] [cheap lipitor] [cheap lorazepam] [prozac online] [order carisoprodol] [polyphonic ringtones] [tenuate online] [valium online] [polyphonic ringtones] [lipitor online] [free free ringtones] [phentermine online] [free sagem ringtones] [free free ringtones] [buy ultracet] [buy ortho] [buy vigrx] [nexium] [meridia online] [free sharp ringtones] [free music ringtones] [cheap diazepam] [carisoprodol online] [cheap wellbutrin] [order meridia] [free ringtones] [xanax online] [free mtv ringtones] [fioricet online] [free mp3 ringtones] [free nextel ringtones] [cheap adipex] [cheap xanax] [sagem ringtones] [cheap diazepam] [clonazepam online] [free polyphonic ringtones] [cheap carisoprodol] [wellbutrin online] [kyocera ringtones] [cheap ativan] [viagra online] [lorazepam online] [cheap ultram] [kyocera ringtones] [cheap alprazolam] [alltel ringtones] [cheap ambien] [cheap vicodin] [motorola ringtones] [sony ericsson ringtones] [free punk ringtones] [buy viagra] [but phentermine] [xanax online] [buy ultram] [valium online] [cingular ringtones] [buy adipex] [cheap cyclobenzaprine] [cheap propecia] [tenuate online] [carisoprodol online] [cheap ultracet] [cheap pharmacy online] [free wwe ringtones] [diazepam online] [cheap xenical] [free nokia ringtones] [free qwest ringtones] [zanaflex online] [cheap diazepam] [verizon ringtones] [free motorola ringtones] [cheap lortab] [prozac online] [ericsson ringtones] [but ortho] [cheap cyclobenzaprine] [cheap celexa] [free free ringtones] [phentermine] [free cool ringtones] [prozac online] [qwest ringtones] [cialis online] [sprint ringtones] [cheap nexium] [real ringtones] [sagem ringtones] [free tracfone ringtones] [nokia ringtones] [punk ringtones] [free mp3 ringtones] [sony ringtones] [ativan online] [but hgh] [free midi ringtones] [alltel ringtones] [flexeril online] [sony ericsson ringtones] [motorola ringtones] [vicodin online] [tracfone ringtones] [buy soma] [levitra online] [motorola ringtones] [didrex online] [sildenafil online] [pharmacy online online] [zoloft online] [hydrocodone online] [sony ringtones] [cingular ringtones] [viagra] [buy paxil] [ambien online] [buy lortab] [hydrocodone online] [cheap vigrx] [cheap ativan] [hgh online] [sildenafil online] [viagra online] [ortho online] [free nextel ringtones] [lisinopril] [free funny ringtones] [sony ericsson ringtones] [buy vicodin] [but hydrocodone] [order ativan] [mono ringtones] [clonazepam] [levitra] [free sprint ringtones] [cialis online] [free sony ringtones] [order levitra] [zanaflex online] [but phentermine] [celexa online] Sockets are an API for IPC or network communication with a process. For IPC Unix domain sockets are used, for network communication INET sockets are preferred. INET sockets work on OSI layer 3 and above. Lower layer access is provided by bpf the Berkeley packet filter. Sockets provide descriptors to a process with which data or control data can be exchanged with the kernel.


Unix domain sockets

When a Unix domain socket is set up it is bound to the local systems filesystem. The path it can be bound to is limited to 103 characters (see /usr/include/sys/un.h) instead of the filesystem limit of 1023 characters. This means that a socket should be set up close to the root perhaps in /tmp (as sshd does). Unix domain sockets make preferred IPC in OpenBSD because of the availability of the getpeereid syscall which allows a daemon to check the credentials of who is connecting to the socket. A socket in the filesystem looks like this:

$ ls -l /tmp/ssh*
total 0
srwxr-xr-x  1 pbug  wheel  0 Oct  8 11:27 agent.1327

notice the 's' indicating that this file is a socket.


INET sockets

In order to communicate with the Internet a program can communicate with it via the Kernel which has a built-in internet stack. Common protocols that one can talk via sockets are TCP and UDP as well as ICMP which is grouped into the raw mode of sockets. When a program is a TCP server the common sequence of syscalls are socket(2), bind(2), listen(2), and accept(2). When a program is a TCP client the common sequence of syscalls are socket(2), connect(2). TCP and UDP sockets have ports to identify them. On a system one can use netstat to see this. In UNIX only root can bind to ports less than 1024 the rest is available for all users. This is shown here as an example:

$ id
uid=1000(pbug) gid=1000(pbug) groups=1000(pbug), 0(wheel), 5(operator) 
$ nc -l 1023
nc: Permission denied
$ nc -l 1024
^C
$ 


When a server is listening on a certain port it's difficult to regulate who connects to this port. Early implementations messed with TCP Wrappers which allowed one to set up a simple whitelist or blacklist of who can connect. This didn't cover UDP though and it was still required that the program accepted the connection before closing it. This means that someone could stealth scan a port and know that it was listening. Firewalls allowed finer control and aren't as revealing over open ports. BSD has ipfw, ipfw2, ipf and pf as firewalls.


$ fstat | grep traceroute
pbug     traceroute 18184   wd /usr     6310091 drwxr-xr-x   r     2048
pbug     traceroute 18184    0 /         84995 crw--w----  rw    ttyp1
pbug     traceroute 18184    1 /         84995 crw--w----  rw    ttyp1
pbug     traceroute 18184    2 /         84995 crw--w----  rw    ttyp1
pbug     traceroute 18184    3* internet raw icmp 0xfffffe800f85d678
pbug     traceroute 18184    4* internet raw reserved 0xfffffe801bc73688


Raw sockets are restricted to the superuser (root) only. When writing to raw sockets you can manipulate the IP header which you cannot do with simple TCP or UDP sockets (setsockopt are an exception but require superuser (root) permissions). The traceroute program uses raw sockets in a UNIX system. It is possible to read from raw sockets, ie. if you specified a specific protocol you can read any packets that arrive for that protocol. In BSD and if the protocol is ICMP the ICMP types echo request (8), timestamp request (13) and address mask request (17) are not passed from the kernel to the socket. Similarely TCP and UDP protocols are not passed to a raw socket, these must use stream or dgram sockets or be read from the OSI datalink layer (see bpf).


Divert sockets

FreeBSD has a way to read/manipulate/write OSI layer 3 packets which have been diverted from the ipfw software. This type of socket is limited to FreeBSD.


Packet sockets

Linux has a way to read OSI layer 2 frames by means of SO_PACKET sockets. This is limited only to Linux.


How do I see Internet traffic

A packet sniffer is a tool that allows one to see packets carried through the network interface of a host computer.