亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sniffers.txt

?? 500 C execises document
?? TXT
?? 第 1 頁 / 共 2 頁
字號:
Basic Packet-Sniffer Construction
from the Ground Up

by Chad Renfro
 raw_sock@hotmail.com

Packet sniffers are applications used by network administrators to monitor and
validate network traffic. Sniffers are programs used to read packets that travel across 
the network at various levels of the OSI layer. And like most security tools sniffers too
can be used for both good and destructive purposes. On the light-side of network
administration sniffers help quickly track down problems such as bottlenecks and
misplaced filters. However on the dark-side sniffers can be used to reap tremendous
amounts of havoc by gathering legitimate user names and passwords so that other
machines can be quickly compromised. Hopefully this paper will be used to help
administrators gain control of their networks by being able to analyze network traffic 
not only by using preconstructed  sniffers but by being able to create their own. This
paper will look at the packet sniffer from the bottem up, looking in depth at the sniffer
core and then gradualy adding functionality to the application. The example included
here will help illustrate some rather cumbersome issues when dealing with network
programing. In no way will this single paper teach a person to write a complete sniffing
application like tcpdump or sniffit. It will however teach some very fundamental issues
that are inherent to all packet sniffers. Like how the packets are accessed on the network
and how to work with the packets at different layers.

The most basic sniffer...

Sniffer #1.

   This sniffer will illustrate the use of the  SOCK_RAW device and show how to gather
packets from the network and print out some simple header  information to std_out.
Although the basic premise is that packet sniffers operate  in a promiscuous mode which
listens to all packets weather or not the packet is destined  for the machines mac address,
this example will collect packets in a non-promiscuous mode . This will let usconcentrate
on the SOCK_RAW device for the first example. To operate this same  code  in a
promiscous mode  the network card may be put in a promiscous mode manually. To do
this type this in after the log in :

   > su -
   Password : ********
   # ifconfig eth0 promisc

   This will now set the network interface eth0 in promiscous mode. 


/************************simple_Tcp_sniff.c********************/

1. #include <stdio.h>
2. #include <sys/socket.h>
3. #include <netinet/in.h>
4. #include <arpa/inet.h>

5. #include "headers.h"

6. int main()
7. {
8.     int sock, bytes_recieved, fromlen;
9.     char buffer[65535];
10.     struct sockaddr_in from;
11.     struct ip  *ip;
12.     struct tcp *tcp;
13.

14.     sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);

15. while(1)
16.  {
17. fromlen = sizeof from;
18. bytes_recieved = recvfrom(sock, buffer, sizeof buffer, 0,
                                         (struct sockaddr *)&from, &fromlen);
19. printf("\nBytes received ::: %5d\n",bytes_recieved);
20. printf("Source address ::: %s\n",inet_ntoa(from.sin_addr));
21. ip = (struct ip *)buffer;
22. printf("IP header length ::: %d\n",ip->ip_length);
23. printf("Protocol ::: %d\n",ip->ip_protocol);
24. tcp = (struct tcp *)(buffer + (4*ip->ip_length));
25. printf("Source port ::: %d\n",ntohs(tcp->tcp_source_port);
26. printf("Dest port  ::: %d\n",ntohs(tcp->tcp_dest_port));

27.          }
28. }
/***********************EOF**********************************/

What this means :

Line 1-4 :
   These are the header files required to use some needed c functions we will use later

<stdio.h>      =     functions like printf and std_out
<sys/socket.h> =     this will give access to the SOCK_RAW and the 
                     IPPROTO_TCP defines  
<netinet/in.h> =     structs like the sockaddr_in 
<arpa/inet.h>  =     lets us use the functions to do network to host byte 
                     order conversions
line 5 :
   This is the header file headers.h that is also included with this program to give standard
   structures to access the ip and tcp fields. The structures identify each field in the ip and
   tcp header for instance :
 
struct ip {
       unsigned int        ip_length:4;         /* length of ip-header in 32-bit
                                                           words*/
         unsigned int        ip_version:4;        /* set to "4", for Ipv4 */
       unsigned char       ip_tos;              /* type of service*/
       unsigned short      ip_total_length;     /* Total length of ip datagram in
                                                           bytes */
       unsigned short      ip_id;               /*identification field*/
       unsigned short      ip_flags;
       unsigned char       ip_ttl;              /*time-to-live, sets upper limit
                                                          for max number of routers to 
                                                          go through before the packet is
                                                          discarded*/

       unsigned char       ip_protocol;         /*identifies the correct transport
                                  protocol */
       unsigned short      ip_cksum;            /*calculated for the ip header ONLY*/
               unsigned int        ip_source;           /*source ip */
               unsigned int        ip_dest;             /*dest ip*/
};



struct tcp {
                 unsigned short     tcp_source_port; /*tcp source port*/
         unsigned short     tcp_dest_port;   /*tcp dest port*/
         unsigned int       tcp_seqno;       /*tcp sequence number,
                                                       identifies the byte in the 
                                                       stream of data*/
         unsigned int       tcp_ackno;       /*contains the next seq num that
                                                       the sender expects to recieve*/
         unsigned int       tcp_res1:4,      /*little-endian*/
                                    tcp_hlen:4,      /*length of tcp header in 32-bit
                                                       words*/ 
                            tcp_fin:1,       /*Finish flag "fin"*/
                                    tcp_syn:1,       /*Synchronize sequence
                                                       numbers to start a connection
                    tcp_rst:1,       /*Reset flag */
                                    tcp_psh:1,       /*Push, sends data to the
                                                       application*/
                                    tcp_ack:1,       /*acknowledge*/
                                    tcp_urg:1,       /*urgent pointer*/
                                    tcp_res2:2;
                 unsigned short     tcp_winsize;     /*maxinum number of bytes able
                                       to recieve*/
         unsigned short     tcp_cksum;       /*checksum to cover the tcp
                                                       header and data portion of the
                                                       packet*/

         unsigned short     tcp_urgent;     /*vaild only if the urgent flag is
                              set, used to transmit
                                                      emergency data */
};


line 8-13 :
   This is the variable declaration section
      
integers :
     sock                 = socket file descriptor 
     bytes_recieved       = bytes read from the open socket "sock" 
     fromlen              = the size of the from structure char :
             buffer               = where the ip packet that is read off the 
                    wire will be held buffer will hold a datagram 
                    of 65535 bytes which is the maximum length 
                    of an ip datagram.

       Struct sockaddr_in :

   struct sockaddr_in {
short int          sin_family;  /* Address family   */
unsigned short int sin_port;    /* Port number      */
struct in_addr     sin_addr;    /* Internet address */
unsigned char      sin_zero[8]; /* Same size as struct sockaddr */
    };

      Before we go any further two topics should be covered,byte-ordering and sockaddr
   structures.  Byte-ordering,is the way that the operating system stores bytes in memory.
   There are two ways that this is done first with the low-order byte at the starting address
   this is known as "little-endian" or host-byte order. Next bytes can be stored with the
   high order byte at the starting address, this is called "big-endian" or network byte order.
   The Internet protocol uses >>>>>> network byte order.
    
       This is important because if you are working on an intel based linux box you will be
   programming on a little-endian machine and to send data via ip you must convert the
   bytes to network-byte order. For examle lets say we are going to store a 2-byte number
   in memory say the value is (in hex) 0x0203


   First this is how the value is stored on a big-endian machine:

                    ___________
                   | 02  | 03  |
                   |_____|_____| 
        address:    0       1


   And here is the same value on a little-endian machine:

                   ___________
                  |03   | 02  |
                  |_____|_____|
       address:    1       0


   The same value is being represented in both examples it is just how we order the bytes
   that changes.

   The next topic that you must understand is the sockaddr vs. the sockaddr_in structures.
   The struct sockaddr is used to hold information about the socket such as the family type
   and other address information it looks like :

struct sockaddr {
          unsigned short sa_family;         /*address family*/ 
                  char           sa_data[14];       /*address data*/
};
 
      The first element in the structure "sa_family" will be used to reference what the family
   type is for the socket, in our sniffer it will be AF_INET. Next the "sa_data" element
   holds the destination port and address for the socket. To make it easier to deal with the
   sockaddr struct the use of the sockaddr_in structure is commonly used. Sockaddr_in 
   makes it easier to reference all of the elements that are contained by sockaddr.

   Sockaddr_in looks like:

   struct sockaddr_in {
             short int          sin_family;    /* Address family               */
             unsigned short int sin_port;      /* Port number                  */
             struct in_addr     sin_addr;      /* Internet address             */
             unsigned char      sin_zero[8];   /* Same size as struct sockaddr */
   };

      We will use this struct and declare a variable "from" which will give us the information
   on the packet that we will collect from the raw socket. For instance the var
   "from.sin_addr" will give access to the packets source address (in 
   network byte order). The thing to mention here is that all items in the sockaddr_in
   structure must be in network-byte order. When we receive the data in the sockaddr_in
   struct we must then convert it back to Host-byte order. To do this we can use some
   predefined functions to convert back and forth between  host and network byteorder.

   Here are the functions we will use:

ntohs       : this function converts  network byte order to host byte order
                      for a 16-bit short

ntohl       : same as above but for a 32-bit long

inet_ntoa   : this function converts a 32-bit network binary value to a
                      dotted decimal ip address

inet_aton   : converts a character string  address to the 32-bit network
                      binary value

inet_addr   : takes a char string dotted decimal addr and returns a 32-bit
                      network binary value

   To further illustrate ,say I want to know the port number that this packet originated from:

int packet_port; packet_port =ntohs(from.sin_port);
                         ^^^^^ 

   If I want the source IP address of the packet we will use a special function to get it to the
   123.123.123.123 format:

char *ip_addr; ip_addr =inet_ntoa(from.sin_addr)
                 ^^^^^^^^^

line 11-12:

   struct ip *ip :
   struct tcp *tcp :

      This is a structure that we defined in our header file "headers.h". This structure is
   declared so that we can access individual fields of the ip/tcp header. The structure is like
   a transparent slide with predefined fields drawn on it. When a packet is taken off 
   the wire it is a stream of bits, to make sense of it the "transparency" (or cast) is laid on
   top of or over the bits so the individual fields can be referenced.

Line 14 :

   sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品一区男女天堂| 欧美日韩亚洲综合在线 | 久久先锋影音av| 狠狠狠色丁香婷婷综合激情| 精品久久人人做人人爱| 国产高清一区日本| 国产精品麻豆欧美日韩ww| 91日韩一区二区三区| 亚洲成人av一区二区| 欧美一区二区播放| 高清不卡一区二区| 亚洲精品视频观看| 日韩网站在线看片你懂的| 国内精品免费**视频| 国产精品久久久久aaaa| 欧美性一级生活| 美女免费视频一区二区| 久久精品在线观看| 色偷偷久久一区二区三区| 日韩中文字幕不卡| 久久久99精品久久| 91高清视频免费看| 激情五月激情综合网| 国产精品久久影院| 欧美电影一区二区| 成熟亚洲日本毛茸茸凸凹| 亚洲资源中文字幕| 精品处破学生在线二十三| av在线不卡电影| 日韩成人伦理电影在线观看| 中文字幕av一区二区三区免费看| 欧美曰成人黄网| 国产精品一品视频| 亚洲电影一区二区三区| 欧美经典三级视频一区二区三区| 欧美日韩久久一区| 成人aaaa免费全部观看| 久久精工是国产品牌吗| 亚洲精品日日夜夜| 国产视频一区二区在线观看| 6080国产精品一区二区| 色综合色狠狠综合色| 久久66热偷产精品| 亚州成人在线电影| 亚洲视频一区二区在线观看| 欧美岛国在线观看| 欧美人xxxx| 色久优优欧美色久优优| 成人一区二区在线观看| 韩国欧美国产1区| 午夜精品久久久久影视| 亚洲男人天堂av| 欧美国产精品中文字幕| 久久五月婷婷丁香社区| 91精品国产综合久久精品麻豆| 91亚洲精品一区二区乱码| 国产精品一品二品| 国内成人免费视频| 久久99精品久久久久久国产越南| 亚洲www啪成人一区二区麻豆| 一区在线播放视频| 国产精品理伦片| 国产亚洲精品免费| 国产亚洲一区二区在线观看| 欧美变态tickle挠乳网站| 91麻豆精品国产91久久久久久久久 | 国产欧美一区二区精品仙草咪| 91精品国产综合久久精品图片| 欧美在线观看视频一区二区| 色先锋资源久久综合| 色综合久久久久久久久久久| www.欧美色图| 97精品国产97久久久久久久久久久久| 国产福利视频一区二区三区| 国产美女精品一区二区三区| 久久97超碰色| 国产一区欧美日韩| av电影在线不卡| 一区二区成人在线| 欧美最猛性xxxxx直播| 国产精品亚洲专一区二区三区 | 久久精品噜噜噜成人88aⅴ| 精品久久久久一区| 在线免费一区三区| 成人黄色在线网站| 成人看片黄a免费看在线| 国产成人在线电影| 成人黄色在线视频| 91国产免费看| 欧美三级中文字| 欧美日韩精品欧美日韩精品一| 欧美美女一区二区在线观看| 5566中文字幕一区二区电影| 精品国产乱码久久久久久久| 久久久久免费观看| 国产精品电影院| 亚洲综合丝袜美腿| 男人操女人的视频在线观看欧美| 九九九精品视频| 国产91综合一区在线观看| 99视频超级精品| 欧美性生活大片视频| 91精品国产一区二区| 久久久久国色av免费看影院| 国产精品久久久久久久久免费相片 | 制服丝袜国产精品| 久久久久久99精品| 亚洲免费在线观看| 青青青爽久久午夜综合久久午夜| 国产一区二区三区蝌蚪| 99re6这里只有精品视频在线观看| 欧美午夜电影网| 久久一日本道色综合| 亚洲精品免费在线| 久久99国产乱子伦精品免费| 99re6这里只有精品视频在线观看| 欧美日韩国产经典色站一区二区三区| 久久综合九色综合久久久精品综合| 国产精品久久久久久久浪潮网站| 视频一区视频二区中文字幕| 成人深夜福利app| 337p亚洲精品色噜噜| 国产精品丝袜黑色高跟| 热久久国产精品| 97精品久久久久中文字幕| 日韩视频一区二区在线观看| 国产精品电影一区二区| 男女性色大片免费观看一区二区| 99久久久久免费精品国产| 日韩女优视频免费观看| 一区二区成人在线观看| 国产精品88888| 日韩午夜在线播放| 亚洲欧美激情在线| 国产麻豆一精品一av一免费| 欧美日韩国产一区| 国产精品国产三级国产aⅴ入口 | 26uuu国产一区二区三区| 亚洲图片欧美综合| 91小视频免费看| 国产拍揄自揄精品视频麻豆| 日本欧美一区二区三区| 在线看日本不卡| 欧美国产一区视频在线观看| 精品无人码麻豆乱码1区2区| 精品视频1区2区| 亚洲精品一二三| www.色精品| 中文字幕的久久| 国产一区二区久久| 日韩午夜三级在线| 日韩av中文字幕一区二区三区| 日本精品视频一区二区三区| 中文字幕一区av| 99久久精品一区| 中文字幕一区二区三区蜜月| 国产成人亚洲精品狼色在线| 精品国产一区二区亚洲人成毛片| 日本伊人色综合网| 91精品国产手机| 日韩av网站在线观看| 制服丝袜激情欧洲亚洲| 午夜av一区二区| 欧美日本一区二区三区| 亚洲国产cao| 欧美人与性动xxxx| 日本人妖一区二区| 欧美电影免费观看高清完整版在线观看 | 欧美福利一区二区| 日韩在线观看一区二区| 91精品午夜视频| 麻豆成人av在线| 久久久影院官网| 成人美女视频在线观看18| 中文字幕的久久| 色婷婷亚洲婷婷| 亚洲成av人影院| 欧美一区二区三区视频免费| 另类中文字幕网| 日本一区二区免费在线观看视频| 成人精品小蝌蚪| 一区二区三区在线观看国产| 欧美四级电影网| 九九久久精品视频| 中文字幕av在线一区二区三区| 91麻豆自制传媒国产之光| 亚洲一区二区三区国产| 日韩一区二区免费在线电影| 国产一区在线看| 国产精品国产成人国产三级| 在线视频综合导航| 奇米精品一区二区三区在线观看| 精品国产制服丝袜高跟| a亚洲天堂av| 亚洲成国产人片在线观看| 欧美电影免费观看高清完整版在线| 国产盗摄精品一区二区三区在线 | 久久综合九色综合97婷婷| 高清久久久久久| 一区二区三区日韩欧美精品|