1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fixed bug in Utils::pseudoheader_checksum.

This commit is contained in:
Matias Fontanini
2012-03-06 09:16:31 -03:00
parent 21c864afb0
commit a49ac24972
6 changed files with 4177 additions and 25 deletions

26
examples/Makefile.in Normal file
View File

@@ -0,0 +1,26 @@
CXX=@CXX@
CFLAGS=-c -Wall @CFLAGS@
LDFLAGS=-lpcap -ltins -lpthread
SOURCES=arpspoofing.cpp portscan.cpp
OBJECTS=$(SOURCES:.cpp=.o)
INCLUDE=
EXECUTABLES=arpspoof portscan
all: $(SOURCES) $(EXECUTABLES)
compile: $(OBJECTS)
recompile: clean all
arpspoof: arpspoofing.o
$(CXX) arpspoofing.o $(LDFLAGS) -o arpspoof
portscan: portscan.o
$(CXX) portscan.o $(LDFLAGS) -o portscan
.cpp.o:
$(CXX) $(CFLAGS) $(INCLUDE) $< -o $@
clean:
rm $(OBJECTS) $(EXECUTABLE)

View File

@@ -24,9 +24,9 @@
#include <string>
#include <stdint.h>
#include <cstdlib>
#include "arp.h"
#include "utils.h"
#include "ethernetII.h"
#include <tins/arp.h>
#include <tins/utils.h>
#include <tins/ethernetII.h>
using namespace std;
using namespace Tins;

4116
examples/configure vendored Executable file

File diff suppressed because it is too large Load Diff

16
examples/configure.ac Normal file
View File

@@ -0,0 +1,16 @@
AC_INIT(myconfig, 0.1)
AC_PROG_CXX()
AC_LANG(C++)
if test -n "$debug"
then
CFLAGS="-DDEBUG -g"
else
CFLAGS="-O3"
fi
AC_CHECK_HEADERS([pcap.h])
AC_CHECK_LIB(pcap, pcap_loop, [], [AC_MSG_ERROR([pcap library is needed!])])
AC_SUBST(CFLAGS)
AC_OUTPUT(Makefile)

View File

@@ -23,12 +23,12 @@
#include <string>
#include <cstdlib>
#include <pthread.h>
#include "ip.h"
#include "tcp.h"
#include "ethernetII.h"
#include "sniffer.h"
#include "utils.h"
#include "packetsender.h"
#include <tins/ip.h>
#include <tins/tcp.h>
#include <tins/ethernetII.h>
#include <tins/sniffer.h>
#include <tins/utils.h>
#include <tins/packetsender.h>
using namespace std;
@@ -40,19 +40,14 @@ using namespace Tins;
*/
struct ScanHandler {
bool operator() (PDU *pdu) {
// Down-cast the inner PDU to IP.
IP *ip = dynamic_cast<IP*>(pdu->inner_pdu());
if(ip) {
// Down-cast IP's inner PDU to TCP.
TCP *tcp = dynamic_cast<TCP*>(ip->inner_pdu());
if(tcp) {
// Ok, it's a TCP PDU. Is RST flag on? Then port is closed.
if(tcp->get_flag(TCP::RST))
cout << "Port: " << tcp->sport() << " closed\n";
// Is SYN flag on? Then port is open!
else if(tcp->get_flag(TCP::SYN))
cout << "Port: " << tcp->sport() << " open\n";
}
TCP *tcp = (pdu->find_inner_pdu<TCP>(PDU::TCP));
if(tcp) {
// Ok, it's a TCP PDU. Is RST flag on? Then port is closed.
if(tcp->get_flag(TCP::RST))
cout << "Port: " << tcp->sport() << " closed\n";
// Is SYN flag on? Then port is open!
else if(tcp->get_flag(TCP::SYN))
cout << "Port: " << tcp->sport() << " open\n";
}
return true;
}
@@ -91,8 +86,9 @@ void *thread_proc(void *param) {
// The required subclass of AbstractSnifferHandler which will serve as
// a proxy to our handler.
AbstractSnifferHandler *my_handler = new SnifferHandler<ScanHandler>(&handler);
sniffer->set_filter("tcp and ip src " + *data + " and tcp[tcpflags] & (tcp-rst|tcp-syn) != 0");
// Sniff loop. Only sniff TCP PDUs comming from the given IP and have either RST or SYN flag on.
sniffer->sniff_loop(my_handler, "tcp and ip src " + *data + " and tcp[tcpflags] & (tcp-rst|tcp-syn) != 0");
sniffer->sniff_loop(my_handler);
delete my_handler;
return 0;
}

View File

@@ -269,8 +269,6 @@ uint32_t Tins::Utils::do_checksum(const uint8_t *start, const uint8_t *end) {
uint32_t Tins::Utils::pseudoheader_checksum(uint32_t source_ip, uint32_t dest_ip, uint32_t len, uint32_t flag) {
uint32_t checksum(0);
source_ip = Utils::net_to_host_l(source_ip);
dest_ip = Utils::net_to_host_l(dest_ip);
uint16_t *ptr = (uint16_t*)&source_ip;
checksum += (uint32_t)(*ptr) + (uint32_t)(*(ptr+1));