dns
parent
bba6e37b05
commit
41019ddcf2
Binary file not shown.
|
@ -33,3 +33,29 @@
|
|||
3015 3112 1698266342859370576 insane_dns ff5ae500893d0be1
|
||||
3 2850 1698267381088345489 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
2850 2933 1698267381176344149 insane_dns ff5ae500893d0be1
|
||||
10 7612 1698283122564692575 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7613 7848 1698283122812690846 insane_dns ff5ae500893d0be1
|
||||
6 7337 1698283295031418468 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7338 7545 1698283295247416792 insane_dns ff5ae500893d0be1
|
||||
6 7581 1698283370006826520 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7581 7788 1698283370226824754 insane_dns ff5ae500893d0be1
|
||||
6 7399 1698283583157050199 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7400 7630 1698283583397048133 insane_dns ff5ae500893d0be1
|
||||
6 7191 1698283604768863791 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7191 7394 1698283604984861923 insane_dns ff5ae500893d0be1
|
||||
6 7249 1698283617676751990 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7249 7443 1698283617880750220 insane_dns ff5ae500893d0be1
|
||||
6 7331 1698283804351101093 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7331 7527 1698283804555099258 insane_dns ff5ae500893d0be1
|
||||
6 7452 1698283909234150605 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7452 7645 1698283909438148743 insane_dns ff5ae500893d0be1
|
||||
6 7804 1698284104328350485 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7804 8009 1698284104544348472 insane_dns ff5ae500893d0be1
|
||||
6 7259 1698284122844177882 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7259 7493 1698284123088175606 insane_dns ff5ae500893d0be1
|
||||
6 7647 1698284201587441029 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7647 7851 1698284201799439040 insane_dns ff5ae500893d0be1
|
||||
6 7309 1698284273314766360 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7309 7612 1698284273630763380 insane_dns ff5ae500893d0be1
|
||||
5 7368 1698284653019154297 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7369 7621 1698284653283151767 insane_dns ff5ae500893d0be1
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Start testing: Oct 25 16:56 EDT
|
||||
Start testing: Oct 25 21:44 EDT
|
||||
----------------------------------------------------------
|
||||
End testing: Oct 25 16:56 EDT
|
||||
End testing: Oct 25 21:44 EDT
|
||||
|
|
Binary file not shown.
7
src/ip.h
7
src/ip.h
|
@ -15,16 +15,15 @@ using asio::ip::tcp;
|
|||
struct IPAddress
|
||||
{
|
||||
unsigned char octets[4];
|
||||
std::string asString;
|
||||
|
||||
constexpr IPAddress(const std::string& str)
|
||||
constexpr IPAddress(std::string str)
|
||||
{
|
||||
auto data = blt::string::split(str, '.');
|
||||
BLT_ASSERT(data.size() == 4);
|
||||
for (size_t i = 0; i < data.size(); i++)
|
||||
{
|
||||
octets[i] = static_cast<unsigned char>(std::stoul(data[i]));
|
||||
BLT_TRACE("%d", octets[i]);
|
||||
}
|
||||
asString = std::move(str);
|
||||
}
|
||||
|
||||
constexpr IPAddress(unsigned char oct[4])
|
||||
|
|
54
src/main.cpp
54
src/main.cpp
|
@ -25,8 +25,10 @@
|
|||
*/
|
||||
// should we strictly match results? ie block *wikipedia.org* or just wikipedia.org?
|
||||
static constexpr bool STRICT_MATCHING = false;
|
||||
// true -> only match A records ; false -> match any named record (A, AAAA, CNAME)
|
||||
// true -> only match A records ; false -> match any named record (configure with NON_STRICT_REPLACE_ALL)
|
||||
static constexpr bool STRICT_FILTERING = false;
|
||||
// true -> match all records ; false -> match only records we might want to replace (A, AAAA, CNAME)
|
||||
static constexpr bool NON_STRICT_REPLACE_ALL = true;
|
||||
|
||||
// DNS server to use for forwarding to / resolving DNS requests
|
||||
static inline constexpr std::string DNS_SERVER_IP()
|
||||
|
@ -42,6 +44,7 @@ static inline constexpr IPAddress REPLACEMENT_IP()
|
|||
|
||||
static const std::unordered_set<std::string> DISALLOWED_DOMAINS{
|
||||
"en.wikipedia.org",
|
||||
"tpgc.me",
|
||||
"zombo.com"
|
||||
};
|
||||
|
||||
|
@ -158,11 +161,12 @@ class answer
|
|||
{
|
||||
friend send_buffer;
|
||||
private:
|
||||
uint16_t NAME = 0;
|
||||
mutable uint16_t NAME = 0;
|
||||
uint16_t TYPE = 0;
|
||||
uint16_t CLASS = 0;
|
||||
uint32_t TTL = 0;
|
||||
uint16_t RDLENGTH = 0;
|
||||
bool requires_reset = false;
|
||||
unsigned char* RDATA = nullptr;
|
||||
public:
|
||||
explicit answer(const byte_reader& reader)
|
||||
|
@ -183,12 +187,34 @@ class answer
|
|||
return TYPE;
|
||||
}
|
||||
|
||||
void substitute(const IPAddress& addr)
|
||||
inline void substitute(const IPAddress& addr)
|
||||
{
|
||||
BLT_DEBUG("Substituting with replacement address '%s'", REPLACEMENT_IP().asString.c_str());
|
||||
BLT_ASSERT(RDLENGTH == 4);
|
||||
std::memcpy(RDATA, addr.octets, 4);
|
||||
}
|
||||
|
||||
inline void setARecord(const IPAddress& addr)
|
||||
{
|
||||
BLT_DEBUG("Setting to A record");
|
||||
NAME = 0;
|
||||
NAME |= (0b11 << 14);
|
||||
requires_reset = true;
|
||||
BLT_INFO(NAME);
|
||||
delete[] RDATA;
|
||||
RDATA = new unsigned char[4];
|
||||
RDLENGTH = 4;
|
||||
TYPE = 1;
|
||||
CLASS = 1;
|
||||
substitute(addr);
|
||||
}
|
||||
|
||||
inline void reset(size_t offset) const
|
||||
{
|
||||
auto i16 = static_cast<uint16_t>(offset) & (~(0b11 << 14));
|
||||
NAME |= i16;
|
||||
}
|
||||
|
||||
// rule of 5
|
||||
answer(const answer& answer) = delete;
|
||||
|
||||
|
@ -207,6 +233,7 @@ class answer
|
|||
|
||||
answer& operator=(answer&& move)
|
||||
{
|
||||
NAME = 0;
|
||||
NAME = move.NAME;
|
||||
TYPE = move.TYPE;
|
||||
CLASS = move.CLASS;
|
||||
|
@ -233,7 +260,6 @@ class send_buffer
|
|||
|
||||
void write(unsigned char* data, size_t size) const
|
||||
{
|
||||
BLT_TRACE(size);
|
||||
std::memcpy(&internal_data[write_index], data, size);
|
||||
write_index += size;
|
||||
}
|
||||
|
@ -301,17 +327,24 @@ class send_buffer
|
|||
}
|
||||
};
|
||||
|
||||
bool shouldReplace(const answer& a)
|
||||
inline bool shouldReplace(const answer& a)
|
||||
{
|
||||
return a.type() == 1;
|
||||
// a records will be handled in either case, check for others like AAAA or CNAME
|
||||
// TODO: add enums to this + a way to add custom types
|
||||
return NON_STRICT_REPLACE_ALL || a.type() == 28 || a.type() == 5;
|
||||
}
|
||||
|
||||
void process_answers(std::vector<answer>& answers)
|
||||
{
|
||||
for (auto& a : answers)
|
||||
{
|
||||
if (shouldReplace(a))
|
||||
if (a.type() == 1)
|
||||
{
|
||||
a.substitute(REPLACEMENT_IP());
|
||||
} else if (!STRICT_FILTERING && shouldReplace(a))
|
||||
{
|
||||
a.setARecord(REPLACEMENT_IP());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,6 +396,7 @@ int main()
|
|||
process_answers(answers);
|
||||
else if (!STRICT_MATCHING)
|
||||
{
|
||||
// linear search the domains for contains. Maybe find a better way to do this.
|
||||
for (const auto& v : DISALLOWED_DOMAINS)
|
||||
if (blt::string::contains(q(), v))
|
||||
process_answers(answers);
|
||||
|
@ -370,10 +404,14 @@ int main()
|
|||
|
||||
send_buffer send;
|
||||
send.write(mod_recv_buf.data(), 12);
|
||||
auto question_offset = send.size();
|
||||
send.write(q);
|
||||
for (const answer& a : answers)
|
||||
{
|
||||
BLT_TRACE("Writing answer with type of %d", a.type());
|
||||
a.reset(question_offset);
|
||||
send.write(a);
|
||||
BLT_TRACE("%d - %d = %d", out_bytes, reader2.last(), out_bytes - reader2.last());
|
||||
}
|
||||
send.write(reader2.from(), out_bytes - reader2.last());
|
||||
|
||||
asio::error_code ignored_error;
|
||||
|
|
Loading…
Reference in New Issue