mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
@@ -3,7 +3,10 @@ FIND_PACKAGE(Threads QUIET)
|
|||||||
|
|
||||||
IF(libtins_FOUND)
|
IF(libtins_FOUND)
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||||
INCLUDE_DIRECTORIES(${LIBTINS_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES(
|
||||||
|
${LIBTINS_INCLUDE_DIRS}
|
||||||
|
${PCAP_INCLUDE_DIR}
|
||||||
|
)
|
||||||
LINK_LIBRARIES(${LIBTINS_LIBRARIES})
|
LINK_LIBRARIES(${LIBTINS_LIBRARIES})
|
||||||
|
|
||||||
IF(HAVE_CXX11)
|
IF(HAVE_CXX11)
|
||||||
@@ -32,7 +35,6 @@ IF(libtins_FOUND)
|
|||||||
ADD_EXECUTABLE(arpmonitor EXCLUDE_FROM_ALL arpmonitor.cpp)
|
ADD_EXECUTABLE(arpmonitor EXCLUDE_FROM_ALL arpmonitor.cpp)
|
||||||
ADD_EXECUTABLE(dns_queries EXCLUDE_FROM_ALL dns_queries.cpp)
|
ADD_EXECUTABLE(dns_queries EXCLUDE_FROM_ALL dns_queries.cpp)
|
||||||
ADD_EXECUTABLE(dns_spoof EXCLUDE_FROM_ALL dns_spoof.cpp)
|
ADD_EXECUTABLE(dns_spoof EXCLUDE_FROM_ALL dns_spoof.cpp)
|
||||||
ADD_EXECUTABLE(dns_stats EXCLUDE_FROM_ALL dns_stats.cpp)
|
|
||||||
ADD_EXECUTABLE(wps_detect EXCLUDE_FROM_ALL wps_detect.cpp)
|
ADD_EXECUTABLE(wps_detect EXCLUDE_FROM_ALL wps_detect.cpp)
|
||||||
ENDIF(HAVE_CXX11)
|
ENDIF(HAVE_CXX11)
|
||||||
|
|
||||||
@@ -41,14 +43,19 @@ IF(libtins_FOUND)
|
|||||||
if(THREADS_FOUND)
|
if(THREADS_FOUND)
|
||||||
IF(HAVE_CXX11)
|
IF(HAVE_CXX11)
|
||||||
ADD_EXECUTABLE(traceroute EXCLUDE_FROM_ALL traceroute.cpp)
|
ADD_EXECUTABLE(traceroute EXCLUDE_FROM_ALL traceroute.cpp)
|
||||||
|
ADD_EXECUTABLE(dns_stats EXCLUDE_FROM_ALL dns_stats.cpp)
|
||||||
TARGET_LINK_LIBRARIES(traceroute ${CMAKE_THREAD_LIBS_INIT})
|
TARGET_LINK_LIBRARIES(traceroute ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
TARGET_LINK_LIBRARIES(dns_stats ${CMAKE_THREAD_LIBS_INIT})
|
||||||
ENDIF(HAVE_CXX11)
|
ENDIF(HAVE_CXX11)
|
||||||
|
IF(WIN32)
|
||||||
ADD_EXECUTABLE(portscan EXCLUDE_FROM_ALL portscan.cpp)
|
MESSAGE(WARNING "Disabling portscan example since it doesn't compile on Windows.")
|
||||||
TARGET_LINK_LIBRARIES(portscan ${CMAKE_THREAD_LIBS_INIT})
|
ELSE()
|
||||||
ELSE(THREADS_FOUND)
|
ADD_EXECUTABLE(portscan EXCLUDE_FROM_ALL portscan.cpp)
|
||||||
|
TARGET_LINK_LIBRARIES(portscan ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
ENDIF()
|
||||||
|
ELSE()
|
||||||
MESSAGE(WARNING "Disabling portscan and traceroute examples since pthreads library was not found.")
|
MESSAGE(WARNING "Disabling portscan and traceroute examples since pthreads library was not found.")
|
||||||
ENDIF(THREADS_FOUND)
|
ENDIF()
|
||||||
ELSE(libtins_FOUND)
|
ELSE(libtins_FOUND)
|
||||||
MESSAGE(
|
MESSAGE(
|
||||||
WARNING
|
WARNING
|
||||||
|
|||||||
@@ -32,7 +32,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <unistd.h>
|
#ifdef _WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif // _WIN32
|
||||||
#include <tins/arp.h>
|
#include <tins/arp.h>
|
||||||
#include <tins/network_interface.h>
|
#include <tins/network_interface.h>
|
||||||
#include <tins/utils.h>
|
#include <tins/utils.h>
|
||||||
@@ -78,7 +83,11 @@ void do_arp_spoofing(NetworkInterface iface, IPv4Address gw, IPv4Address victim,
|
|||||||
// Just send them once every 5 seconds.
|
// Just send them once every 5 seconds.
|
||||||
sender.send(to_gw, iface);
|
sender.send(to_gw, iface);
|
||||||
sender.send(to_victim, iface);
|
sender.send(to_victim, iface);
|
||||||
sleep(5);
|
#ifdef _WIN32
|
||||||
|
Sleep(5);
|
||||||
|
#else
|
||||||
|
sleep(5);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,8 @@ public:
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
using packet_info = std::tuple<IPv4Address, IPv4Address, uint16_t>;
|
using packet_info = std::tuple<IPv4Address, IPv4Address, uint16_t>;
|
||||||
using clock_type = std::chrono::steady_clock;
|
using clock_type = std::chrono::system_clock;
|
||||||
using time_point_type = std::chrono::time_point<clock_type>;
|
using time_point_type = clock_type::time_point;
|
||||||
|
|
||||||
bool callback(const PDU& pdu);
|
bool callback(const PDU& pdu);
|
||||||
static packet_info make_packet_info(const PDU& pdu, const DNS& dns);
|
static packet_info make_packet_info(const PDU& pdu, const DNS& dns);
|
||||||
@@ -161,15 +161,20 @@ auto dns_monitor::make_packet_info(const PDU& pdu, const DNS& dns) -> packet_inf
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if(argc != 2) {
|
std::string iface;
|
||||||
std::cout << "Usage: " << *argv << " <interface>\n";
|
if (argc == 2) {
|
||||||
return 1;
|
// Use the provided interface
|
||||||
|
iface = argv[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Use the default interface
|
||||||
|
iface = NetworkInterface::default_interface().name();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
SnifferConfiguration config;
|
SnifferConfiguration config;
|
||||||
config.set_promisc_mode(true);
|
config.set_promisc_mode(true);
|
||||||
config.set_filter("udp and dst port 53");
|
config.set_filter("udp and port 53");
|
||||||
Sniffer sniffer(argv[1], config);
|
Sniffer sniffer(iface, config);
|
||||||
dns_monitor monitor;
|
dns_monitor monitor;
|
||||||
std::thread thread(
|
std::thread thread(
|
||||||
[&]() {
|
[&]() {
|
||||||
|
|||||||
@@ -46,10 +46,9 @@ public:
|
|||||||
: iface(interface), addr(address) { }
|
: iface(interface), addr(address) { }
|
||||||
|
|
||||||
result_type trace() {
|
result_type trace() {
|
||||||
// ICMPs that aren't sent from us.
|
|
||||||
SnifferConfiguration config;
|
SnifferConfiguration config;
|
||||||
config.set_snap_len(500);
|
|
||||||
config.set_promisc_mode(false);
|
config.set_promisc_mode(false);
|
||||||
|
// ICMPs that aren't sent from us.
|
||||||
config.set_filter(
|
config.set_filter(
|
||||||
"ip proto \\icmp and not src host " + iface.addresses().ip_addr.to_string());
|
"ip proto \\icmp and not src host " + iface.addresses().ip_addr.to_string());
|
||||||
Sniffer sniffer(iface.name(), config);
|
Sniffer sniffer(iface.name(), config);
|
||||||
@@ -65,10 +64,9 @@ public:
|
|||||||
running = true;
|
running = true;
|
||||||
// Start the sniff thread
|
// Start the sniff thread
|
||||||
std::thread sniff_thread(
|
std::thread sniff_thread(
|
||||||
&Sniffer::sniff_loop<decltype(handler)>,
|
[&]() {
|
||||||
&sniffer,
|
sniffer.sniff_loop(handler);
|
||||||
handler,
|
}
|
||||||
0
|
|
||||||
);
|
);
|
||||||
send_packets(sender);
|
send_packets(sender);
|
||||||
sniff_thread.join();
|
sniff_thread.join();
|
||||||
|
|||||||
Reference in New Issue
Block a user