mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 05:24:26 +01:00
DNS pdu forging and sniffing is working. Copy constructor/assignment operator are still pending.
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Tins {
|
||||
ARP(uint32_t target_ip = 0, uint32_t sender_ip = 0, const uint8_t *target_hw = 0, const uint8_t *sender_hw = 0);
|
||||
|
||||
/**
|
||||
* \brief Constructor which creates an TCP object from a buffer and adds all identifiable
|
||||
* \brief Constructor which creates an ARP object from a buffer and adds all identifiable
|
||||
* PDUs found in the buffer as children of this one.
|
||||
* \param buffer The buffer from which this PDU will be constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
|
||||
@@ -111,6 +111,7 @@ namespace Tins {
|
||||
|
||||
Query(const std::string &nm, uint16_t t, uint16_t c) :
|
||||
name(nm), type(t), qclass(c) {}
|
||||
Query() {}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -133,6 +134,16 @@ namespace Tins {
|
||||
*/
|
||||
DNS();
|
||||
|
||||
/**
|
||||
* \brief Constructor which creates a DNS object from a buffer
|
||||
* and adds all identifiable PDUs found in the buffer as
|
||||
* children of this one.
|
||||
* \param buffer The buffer from which this PDU will be
|
||||
* constructed.
|
||||
* \param total_sz The total size of the buffer.
|
||||
*/
|
||||
DNS(const uint8_t *buffer, uint32_t total_sz);
|
||||
|
||||
/**
|
||||
* \brief Destructor.
|
||||
*/
|
||||
@@ -431,66 +442,60 @@ namespace Tins {
|
||||
uint32_t ttl;
|
||||
} __attribute__((packed)) info;
|
||||
|
||||
virtual ~ResourceRecord() {}
|
||||
virtual uint32_t write(uint8_t *buffer) const = 0;
|
||||
virtual uint32_t do_write(uint8_t *buffer) const = 0;
|
||||
virtual uint32_t size() const = 0;
|
||||
virtual bool matches(const std::string &dname) { return false; }
|
||||
virtual uint32_t data_size() const = 0;
|
||||
virtual const uint8_t *data_pointer() const = 0;
|
||||
virtual const std::string *dname_pointer() const { return 0; }
|
||||
};
|
||||
|
||||
template<unsigned S> struct SizedResourceRecord : public ResourceRecord {
|
||||
uint8_t data[S];
|
||||
uint8_t *data;
|
||||
uint16_t data_sz;
|
||||
|
||||
SizedResourceRecord(uint8_t *d) {
|
||||
std::memcpy(data, d, S);
|
||||
ResourceRecord(uint8_t *d = 0, uint16_t len = 0) : data_sz(len) {
|
||||
if(d)
|
||||
std::memcpy(data, d, data_sz);
|
||||
}
|
||||
|
||||
virtual ~ResourceRecord() {}
|
||||
uint32_t write(uint8_t *buffer) const {
|
||||
uint32_t sz(do_write(buffer));
|
||||
buffer += sz;
|
||||
std::memcpy(buffer, &info, sizeof(info));
|
||||
buffer += sizeof(info);
|
||||
*((uint16_t*)buffer) = Utils::net_to_host_s(S);
|
||||
*((uint16_t*)buffer) = Utils::net_to_host_s(data_sz);
|
||||
buffer += sizeof(uint16_t);
|
||||
std::memcpy(buffer, data, S);
|
||||
return sz + sizeof(info) + sizeof(uint16_t) + S;
|
||||
std::memcpy(buffer, data, data_sz);
|
||||
return sz + sizeof(info) + sizeof(uint16_t) + data_sz;
|
||||
}
|
||||
|
||||
virtual uint32_t do_write(uint8_t *buffer) const = 0;
|
||||
virtual uint32_t size() const = 0;
|
||||
virtual bool matches(const std::string &dname) { return false; }
|
||||
uint32_t data_size() const {
|
||||
return S;
|
||||
return data_sz;
|
||||
}
|
||||
|
||||
const uint8_t *data_pointer() const {
|
||||
return data;
|
||||
}
|
||||
virtual const std::string *dname_pointer() const { return 0; }
|
||||
};
|
||||
|
||||
template<unsigned S> struct OffsetedResourceRecord : public SizedResourceRecord<S> {
|
||||
struct OffsetedResourceRecord : public ResourceRecord {
|
||||
uint16_t offset;
|
||||
|
||||
OffsetedResourceRecord(uint16_t off, uint8_t *data) : SizedResourceRecord<S>(data), offset(off | 0xc0) {}
|
||||
OffsetedResourceRecord(uint16_t off, uint8_t *data = 0, uint16_t len = 0) : ResourceRecord(data,len), offset(off | 0xc0) {}
|
||||
|
||||
uint32_t do_write(uint8_t *buffer) const {
|
||||
std::memcpy(buffer, &offset, sizeof(offset));
|
||||
return sizeof(offset);
|
||||
}
|
||||
uint32_t size() const { return sizeof(ResourceRecord::info) + sizeof(offset) + S + sizeof(uint16_t); }
|
||||
uint32_t size() const { return sizeof(ResourceRecord::info) + sizeof(offset) + data_sz + sizeof(uint16_t); }
|
||||
};
|
||||
|
||||
template<unsigned S> struct NamedResourceRecord : public SizedResourceRecord<S> {
|
||||
struct NamedResourceRecord : public ResourceRecord {
|
||||
std::string name;
|
||||
|
||||
NamedResourceRecord(const std::string &nm, uint8_t *data) : SizedResourceRecord<S>(data), name(nm) {}
|
||||
NamedResourceRecord(const std::string &nm, uint8_t *data = 0, uint16_t len = 0) : ResourceRecord(data,len), name(nm) {}
|
||||
|
||||
uint32_t do_write(uint8_t *buffer) const {
|
||||
std::memcpy(buffer, name.c_str(), name.size() + 1);
|
||||
return name.size() + 1;
|
||||
}
|
||||
|
||||
uint32_t size() const { return sizeof(ResourceRecord::info) + name.size() + 1 + S + sizeof(uint16_t); }
|
||||
uint32_t size() const { return sizeof(ResourceRecord::info) + name.size() + 1 + data_sz + sizeof(uint16_t); }
|
||||
|
||||
bool matches(const std::string &dname) {
|
||||
return dname == name;
|
||||
@@ -503,6 +508,7 @@ namespace Tins {
|
||||
|
||||
typedef std::map<uint16_t, std::string> SuffixMap;
|
||||
|
||||
const uint8_t *build_resource_list(std::list<ResourceRecord*> &lst, const uint8_t *ptr, uint32_t &sz, uint16_t nrecs);
|
||||
uint32_t find_domain_name(const std::string &dname);
|
||||
bool find_domain_name(const std::string &dname, const std::list<ResourceRecord*> &lst, uint16_t &out);
|
||||
void parse_domain_name(const std::string &dn, std::string &out) const;
|
||||
@@ -513,7 +519,7 @@ namespace Tins {
|
||||
void compose_name(const uint8_t *ptr, uint32_t sz, std::string &out);
|
||||
void convert_resources(const std::list<ResourceRecord*> &lst, std::list<Resource> &res);
|
||||
ResourceRecord *make_record(const std::string &name, QueryType type, QueryClass qclass, uint32_t ttl, uint32_t ip);
|
||||
void build_suffix_map(uint32_t index, const uint8_t *data, uint32_t sz);
|
||||
void add_suffix(uint32_t index, const uint8_t *data, uint32_t sz);
|
||||
uint32_t build_suffix_map(uint32_t index, const std::list<ResourceRecord*> &lst);
|
||||
uint32_t build_suffix_map(uint32_t index, const std::list<Query> &lst);
|
||||
void build_suffix_map();
|
||||
|
||||
Reference in New Issue
Block a user