I got problems installing the version from repository...:S If I can later I will post you the concrete error that I get.
I have two virtual machines running on my computer (VM1 and VM2).
eth0 (PC) ------------------------ vboxnet1 (PC) ----------eth0 (Virtual Machine 1) --------eth1 (Virtual Machine 1) --------eth0 (Virtual Machine 2)
In VM2 I run an internet browser and in eth1 of VM1 I capture the packets generated by the browser. In VM1 I have to add to the IP packets received some lower layer propietary protocols and send through eth0 of VM1. Then in my PC I have to undo the process and remove the lower layers in order to send my packets through internet.
I've configured the interfaces as follows:
eth0(PC):
192.168.1.190/24vboxnet1(PC):
192.168.23.1/24eth0(VM1):
192.168.23.2/24eth1(VM1):
192.168.57.1/24eth0(VM2):
192.168.57.2/24In VM1 there isn't any route between eth0 and eth1 because I want to control the net connection of the browser, enabling and disabling it when I want.
In PC there is a route with
192.168.57.0/24.
I am trying a first test that consists on:
-> ping
www.google.es from my VM2
->capture the packets with libcrafter in VM1 (eth1)
->resend the packet with libcrafter in VM1(eth0)
->capture the ping response in VM1(eth0)
->resend the respone in VM!(eth1)
->receive the ping response in VM2
But I don't receive the response in VM2. However, if I use wireshark on eth0(VM1) I can prove that I am receiving ARP messages with the content:
Who is 192.168.57.2? Tell 192.168.23.1.
And in eth1(VM1) I receive malformed packets. :S
Any idea??
My program test is this:
#include <iostream>
#include <fstream>
#include <string>
#include <crafter.h>
/* Collapse namespaces */
using namespace std;
using namespace Crafter;
void SendToSocket_Femto(Packet* sniff_packet, void* user)
{
//Print the packet intercepted
cout << "Packet captured " << endl;
/* Print Packet Information */
cout << "Before sending" << endl;
if(sniff_packet)
sniff_packet->Print();
/* Get the Payload of the Ethernet Packet */
Ethernet *mypacket_eth = sniff_packet->GetLayer<Ethernet>();
cout << "GetLayer de EthLayer" << endl;
if(sniff_packet)
{
mypacket_eth->Print();
cout << "Paquete ethernet, me quedo con las capas superiores" << endl;
LayerStack::const_iterator it = sniff_packet->begin() + 1; /* <-- If you know that the 1st one is Ethernet */
Packet resend_p;
if(sniff_packet->begin() < sniff_packet->end())
{
for(; it != sniff_packet->end() ; it++)
{
/* (*it) gives a pointer to the layer */
resend_p.PushLayer( *(*it) );
}
//Reenvio el paquete
resend_p.Send("eth0");
resend_p.Print();
cout << "Tras enviar" << endl;
}
}
}
void SendToSocket_App(Packet* sniff_packet, void* user)
{
//Print the packet intercepted
cout << "Packet captured in eth0" << endl;
/* Print Packet Information */
cout << "Before sending" << endl;
// if(sniff_packet)
// sniff_packet->Print();
/* Get the Payload of the Ethernet Packet */
Ethernet *mypacket_eth = sniff_packet->GetLayer<Ethernet>();
cout << "GetLayer de EthLayer" << endl;
if(sniff_packet)
{
mypacket_eth->Print();
//cout << "Paquete ethernet, me quedo con las capas superiores" << endl;
LayerStack::const_iterator it = sniff_packet->begin() + 1; /* <-- If you know that the 1st one is Ethernet */
Packet resend_p;
if(sniff_packet->begin() < sniff_packet->end())
{
for(; it != sniff_packet->end() ; it++)
{
/* (*it) gives a pointer to the layer */
if(*it->)
resend_p.PushLayer( *(*it) );
}
//Reenvio el paquete
resend_p.Send("eth1");
//resend_p.Print();
//cout << "Tras enviar" << endl;
}
}
}
int main()
{
/* Init the library */
InitCrafter();
/* Set the interface */
string eth1 = "eth1";
string eth0 = "eth0";
/*
* First, you should create a sniffer
* - 1st argument: Filter expression (tcpdump syntax)
* - 2nd argument: Interface
* - 3rd argument: A function that will be executed when a packet
* captured satisfies the filter expression (the default behavior is to
* print the packets to STDOUT).
*/
//Sniffer sniff("tcp and dst port 80",iface,PacketHandler);
Sniffer sniff_eth1("src host 192.168.57.2 and dst host 8.8.8.8",eth1,SendToSocket_Femto);
Sniffer sniff_eth0("",eth0,SendToSocket_App);
/* Spawn the sniffer (ad-infinitum) */
sniff_eth1.Spawn(-1);
sniff_eth0.Spawn(-1);
while(1);
/* Shut down cleanly the sniffer */
sniff_eth1.Cancel();
/* Clean up library stuff... */
CleanCrafter();
return 0;