home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / crh / freebsd / rootkit / sniffit.0.3.5 / PLUGIN-HOWTO < prev    next >
Encoding:
Text File  |  2002-05-27  |  6.0 KB  |  178 lines

  1.                        --=[Sniffit - PLUGIN-HOWTO]=--   
  2.                     --=['Shipped' with Sniffit 0.3.5]=--
  3.                            by Brecht Claerhout
  4.  
  5. 1. What are Sniffit plugins (READ)
  6. 2. How to install a plugin  (READ)
  7. 3. How to make a plugin     (Only for programmers)
  8. 4. Contense of structs      (Only for programmers)
  9. 5. Standard Plugins         (READ)
  10.  
  11.  
  12. 1. What are Sniffit plugins
  13. ---------------------------
  14.  
  15. Sniffit Plugins are a very fancy name for a very primitive system. The 
  16. plugins allow you to add your own code to Sniffit without many problems.
  17. This has the advantage you can create your own sniffer within Sniffit, 
  18. without having to worry about the packet filtering.
  19.  
  20. 2. How to install a plugin
  21. --------------------------
  22.  
  23. Well, as I plan to release some plugins myself, and maybe ppl are going 
  24. to share their own plugins, a little word on the installation.
  25.  
  26. It's pretty simple, you get the plugin, put it in the sniffit directory 
  27. and you edit the sn_plugin.h file like this:
  28.  
  29. #define PLUGIN1_NAME    "My plugin"
  30. #define PLUGIN1(x)      main_plugin_function(x)
  31. #include "my_plugin.plug"
  32.  
  33. Some notes:
  34. a) You can have plugins from 0 to 9 so PLUGIN0_NAME to PLUGIN1_NAME. 
  35.    Numbers don't have to be consecutive.
  36.    (so also a PLUGIN0(x) to PLUGIN9(x) corresponding with the PLUGIN?_NAMES)
  37.  
  38. b) The PLUGIN?_NAME contains the name that will be displayed when just 
  39.    typing sniffit.
  40.  
  41. c) main_plugin_function should be a name provided by the author of the 
  42.    plugin. It is the name of the function that should be called by Sniffit. 
  43.    Details on this for making your own plugins are explained below.
  44.  
  45. d) #include "my_plugin.plug"
  46.    Where my_plugin.plug is the name of the plugin source code file.
  47.  
  48. 3. How to make a plugin
  49. -----------------------
  50.  
  51. I know it's primitive, but it pretty much works and is very easy.
  52. A plugins should consists of a function (here PL_dummy) 
  53.  
  54. void PL_dummy (struct Plugin_data *PLD)
  55. {
  56. ....
  57. }
  58.  
  59. It's no problem to use several functions.
  60. It's no problem to use global data, as long as it doesn't interfer with 
  61. sniffits global data (or other plugins global data). 
  62. So it is wise to make all global variables and functions like: 
  63.     PL_nameofplugin_nameofvariable/function
  64.  
  65.  
  66. 4. Contense of structs
  67. ----------------------
  68.  
  69. NOTE: I don't use the standard structures for packets. This has it's 
  70.       'historical' reasons, and has rather become a drag than a positive 
  71.       point. But it would be even a greater drag (time loss) to overturn 
  72.       everything completely and recode the appropriate parts of Sniffit, maybe
  73.       I will do it someday, maybe I won't.
  74.       I hope you can live with it...
  75.  
  76. Notice you get a pointer to a structure ('struct Plugin_data *PLD') when 
  77. your plugin is called. 
  78. This structure is totally yours and you may modify it without any problems.
  79. It is defined as:
  80.  
  81. struct Plugin_data {
  82.         struct unwrap PL_info;
  83.         struct IP_header PL_iphead;
  84.         struct TCP_header PL_tcphead;
  85.         struct UDP_header PL_udphead;
  86.         unsigned char PL_data[MTU];
  87.         unsigned char PL_packet[MTU];
  88. };
  89.  
  90.  
  91. PL_info   : contains some general usefull info 
  92. PL_iphead : contains the IP_header (no options)
  93. PL_tcphead: contains the TCP_header if it is a TCP packet (no options) 
  94. PL_udphead: contains the TCP_header if it is a UDP packet (no options) 
  95. PL_data   : contains the packet data (no headers)
  96. PL_packet : contains the entire packet
  97.  
  98. Details on the Packet structures below (You know, the unconventional ones)
  99. (It is best that you grab your book on packets and have a look at the 
  100. fields. The structures are composed the same way, and are an exact copy 
  101. of those headers. So watch it! You might need to use ntohs() and ntohl() 
  102. now and then!)
  103. (Have a look at the Dummy Plugin and the DNS Plugin for examples)
  104.  
  105. struct IP_header                        /* The IPheader (without options) */
  106. {
  107.         unsigned char verlen, type;
  108.         unsigned short length, ID, flag_offset;
  109.         unsigned char TTL, protocol;
  110.         unsigned short checksum;
  111.         unsigned long int source, destination;
  112. };
  113.  
  114.  
  115. struct TCP_header                       /* The TCP header (without options) */
  116. {
  117.         unsigned short source, destination;
  118.         unsigned long int seq_nr, ACK_nr;
  119.         unsigned short offset_flag, window, checksum, urgent; 
  120. };
  121.  
  122.  
  123. struct UDP_header                                /* The UDP header */ 
  124. {
  125.         unsigned short source, destination;
  126.         unsigned short length, checksum;
  127. };
  128.  
  129.  
  130. 5. Standard Plugins
  131. -------------------
  132.  
  133. There are 2 Plugins that are currently included in the distribution of 
  134. Sniffit: A dummy Plugin, and a DNS Plugin.
  135.  
  136. The Dummy Plugin:
  137.   As it says, it does nothing ;)
  138.   example: sniffit -M 0 -bN -t foo.bar
  139.            Will output some useless information on the intercepted packet 
  140.            (that has passed the filtering you defined).
  141.            Example of output: 
  142.           
  143.            Dummy Plugin Report:
  144.             IP header: 20 bytes
  145.              TCP header: 20 bytes / 1 Databytes
  146.  
  147. The DNS Plugin:
  148.   The DNS plugin will examine any UDP packet that is passes the filter 
  149.   you have setup for sniffit from/to port 53.
  150.   These packets are DNS packets, and that plugin will decode them and 
  151.   output some information to the standard output.
  152.   NOTE: '-P UDP' is needed because Sniffit needs to pass UDP packets to 
  153.         the Plugin.
  154.  
  155.   e.g.: sniffit -M1 -N -P UDP -t @
  156.         Will examine all DNS traffic.
  157.    
  158.         An example of output is:     
  159.  
  160.         DNS Sniffit Plugin Report:
  161.         Packet: 111.33.111.11 53 -> 111.111.66.33 53
  162.         ID: 5782 
  163.           STATUS: Answer (opcode: 0) ,  ,  ,  , rec. NOT Av. , ret: 0
  164.           Q: 1  Answ: 0  Auth: 2  Add: 2
  165.           Query: 21.158.245.200.in-addr.arpa.
  166.             Type: 12   Class: IP
  167.           Answer 1/4: 245.200.IN-ADDR.ARPA.
  168.             Type: 2   Class: IP
  169.           Answer 2/4: 245.200.IN-ADDR.ARPA.
  170.             Type: 2   Class: IP
  171.           Answer 3/4: DIXIT.ANSP.BR.
  172.             Type: 1   Class: IP
  173.             Data: 143.108.1.17.
  174.           Answer 4/4: FPSP.FAPESP.BR.
  175.             Type: 1   Class: IP
  176.             Data: 143.108.1.1.
  177.  
  178.