adding cancer
parent
7d0fdd3899
commit
cda834f7a8
Binary file not shown.
|
@ -15,3 +15,48 @@
|
|||
10 3017 1698364332817742883 libraries/BLT/CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o 741b5851e86130d2
|
||||
7 1462 1698364331269782326 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o 5171d83ac5d9e0dc
|
||||
7 2341 1698364332145759998 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/assert.cpp.o 2ae218d9777469fd
|
||||
7 1509 1698365470130178340 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/filesystem.cpp.o 5171d83ac5d9e0dc
|
||||
7 2371 1698365470990161624 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/assert.cpp.o 2ae218d9777469fd
|
||||
8 2403 1698365471022161002 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/format.cpp.o 9a4151eb8a13165e
|
||||
8 2542 1698365471162158281 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/loader.cpp.o 3bb9d28d25c10d3b
|
||||
10 3135 1698365471754146775 libraries/BLT/CMakeFiles/BLT.dir/src/blt/nbt/nbt.cpp.o 741b5851e86130d2
|
||||
9 3812 1698365472426133713 libraries/BLT/CMakeFiles/BLT.dir/src/blt/profiling/profiler.cpp.o 66984105eaba6834
|
||||
9 4302 1698365472918124152 libraries/BLT/CMakeFiles/BLT.dir/src/blt/profiling/profiler_v2.cpp.o 4f10bd0279063873
|
||||
9 4764 1698365473378115210 libraries/BLT/CMakeFiles/BLT.dir/src/blt/std/logging.cpp.o 9f9b2e297e48c5fc
|
||||
4764 5149 1698365473750107981 libraries/BLT/libBLT.a f5b601d9b774b003
|
||||
6 7837 1698365476446055583 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7838 8044 1698365476662051385 insane_dns fcdf287f9aefd888
|
||||
6 7254 1698365917317503170 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7254 7468 1698365917541498830 insane_dns fcdf287f9aefd888
|
||||
6 7505 1698366054014854656 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7506 7702 1698366054222850627 insane_dns fcdf287f9aefd888
|
||||
7 7319 1698366211779798565 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7319 7519 1698366211987794535 insane_dns fcdf287f9aefd888
|
||||
6 8592 1698367303946647053 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8592 8859 1698367304230641554 insane_dns fcdf287f9aefd888
|
||||
6 8071 1698367320318330001 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8071 8287 1698367320546325586 insane_dns fcdf287f9aefd888
|
||||
6 8167 1698367422284355356 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8167 8387 1698367422516350864 insane_dns fcdf287f9aefd888
|
||||
6 8348 1698367484463151242 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8348 8574 1698367484703146594 insane_dns fcdf287f9aefd888
|
||||
7 8181 1698367506734719932 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8181 8401 1698367506970715362 insane_dns fcdf287f9aefd888
|
||||
6 8288 1698367575485388519 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8288 8501 1698367575709384182 insane_dns fcdf287f9aefd888
|
||||
6 8295 1698367684455278289 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8295 8502 1698367684683273874 insane_dns fcdf287f9aefd888
|
||||
6 8324 1698367750501999231 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8324 8545 1698367750737994661 insane_dns fcdf287f9aefd888
|
||||
6 8008 1698367909266924662 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8009 8220 1698367909490920324 insane_dns fcdf287f9aefd888
|
||||
6 8356 1698368166305946965 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8356 8566 1698368166529942627 insane_dns fcdf287f9aefd888
|
||||
6 8231 1698368217532954914 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
8232 8440 1698368217756950577 insane_dns fcdf287f9aefd888
|
||||
6 7948 1698368247688370934 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7948 8160 1698368247912366596 insane_dns fcdf287f9aefd888
|
||||
6 7937 1698368301247333758 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7937 8146 1698368301471329420 insane_dns fcdf287f9aefd888
|
||||
5 7889 1698368377473857559 CMakeFiles/insane_dns.dir/src/main.cpp.o 727da43cdbc82421
|
||||
7889 8097 1698368377693853299 insane_dns fcdf287f9aefd888
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Start testing: Oct 26 20:10 EDT
|
||||
Start testing: Oct 26 21:04 EDT
|
||||
----------------------------------------------------------
|
||||
End testing: Oct 26 20:10 EDT
|
||||
End testing: Oct 26 21:04 EDT
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -37,8 +37,11 @@ namespace blt
|
|||
const size_t _size;
|
||||
mutable size_t _current_byte = DNS_HEADER_END;
|
||||
public:
|
||||
explicit byte_reader(unsigned char* data, size_t size): _data(data), _size(size)
|
||||
{}
|
||||
explicit byte_reader(unsigned char* data, size_t size, bool tcp = false): _data(data), _size(size)
|
||||
{
|
||||
if (tcp)
|
||||
_current_byte += 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next byte in the data stream then increment the internal counter by 1
|
||||
|
|
15
src/ip.h
15
src/ip.h
|
@ -38,7 +38,6 @@ template<typename IN, typename OUT>
|
|||
void sendUDPMessage(const std::string& host, const IN& in, size_t in_size, OUT& out, size_t& out_size)
|
||||
{
|
||||
asio::io_context io_context;
|
||||
udp::resolver resolver(io_context);
|
||||
udp::endpoint receiver_endpoint(asio::ip::address::from_string(host), 53);
|
||||
|
||||
udp::socket socket(io_context);
|
||||
|
@ -50,4 +49,18 @@ void sendUDPMessage(const std::string& host, const IN& in, size_t in_size, OUT&
|
|||
out_size = socket.receive_from(asio::buffer(out), sender_endpoint);
|
||||
}
|
||||
|
||||
template<typename IN, typename OUT>
|
||||
void sendTCPMessage(const std::string& host, const IN& in, size_t in_size, OUT& out, size_t& out_size){
|
||||
asio::io_context io_context;
|
||||
tcp::resolver resolver(io_context);
|
||||
tcp::resolver::results_type endpoints = resolver.resolve(host, "53");
|
||||
|
||||
tcp::socket socket(io_context);
|
||||
asio::connect(socket, endpoints);
|
||||
|
||||
asio::write(socket, asio::buffer(in, in_size));
|
||||
|
||||
out_size = socket.read_some(asio::buffer(out));
|
||||
}
|
||||
|
||||
#endif //INSANE_DNS_IP_H
|
||||
|
|
106
src/main.cpp
106
src/main.cpp
|
@ -25,6 +25,9 @@
|
|||
* | CONFIG |
|
||||
* ----------------------------
|
||||
*/
|
||||
/** What port to run the server on */
|
||||
static constexpr unsigned short int SERVER_PORT = 5555;
|
||||
|
||||
/** should we strictly match results? ie block `*wikipedia.org*` or just `wikipedia.org`? */
|
||||
static constexpr bool STRICT_MATCHING = false;
|
||||
|
||||
|
@ -324,13 +327,14 @@ void process_answers(std::vector<answer>& answers)
|
|||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
void run_udp_server()
|
||||
{
|
||||
try
|
||||
{
|
||||
asio::io_context io_context;
|
||||
|
||||
udp::socket socket(io_context, udp::endpoint(udp::v6(), 5555));
|
||||
//udp::socket socket(io_context, udp::endpoint(udp::v6(), 5555));
|
||||
udp::socket socket(io_context, udp::endpoint(asio::ip::address::from_string("::1"), SERVER_PORT));
|
||||
|
||||
std::array<unsigned char, 65535> recv_buf{};
|
||||
std::array<unsigned char, 65535> mod_recv_buf{};
|
||||
|
@ -354,7 +358,7 @@ int main()
|
|||
|
||||
blt::byte_reader reader(mod_recv_buf.data(), mod_recv_buf.size());
|
||||
|
||||
BLT_INFO("Bytes answered %d with %d answers", out_bytes, num_of_answers);
|
||||
BLT_INFO("Bytes answered: %d with %d answers", out_bytes, num_of_answers);
|
||||
|
||||
// no one actually does multiple questions. trying to do it in dig is not easy
|
||||
// and the standard isn't really designed for this (how do we handle if one question errors but the other doesn't? there is only
|
||||
|
@ -396,9 +400,101 @@ int main()
|
|||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
BLT_ERROR(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Hello, World!" << std::endl;
|
||||
void run_tcp_server()
|
||||
{
|
||||
try
|
||||
{
|
||||
asio::io_context io_context;
|
||||
|
||||
tcp::acceptor acceptor(io_context, tcp::endpoint(asio::ip::address::from_string("::1"), SERVER_PORT));
|
||||
|
||||
std::array<unsigned char, 65535> recv_buf{};
|
||||
std::array<unsigned char, 65535> mod_recv_buf{};
|
||||
while (true)
|
||||
{
|
||||
tcp::socket socket(io_context);
|
||||
acceptor.accept(socket);
|
||||
|
||||
asio::error_code error;
|
||||
size_t bytes = socket.read_some(asio::buffer(recv_buf), error);
|
||||
if (error == asio::error::eof)
|
||||
break;
|
||||
else if (error)
|
||||
throw asio::system_error(error);
|
||||
|
||||
// get the number of questions
|
||||
uint16_t questions; // yes I made this part of my library just for this :3
|
||||
blt::mem::fromBytes(&recv_buf[6], questions); // i hate little endian
|
||||
|
||||
BLT_INFO("TCP Bytes received: %d with %d questions", bytes, questions);
|
||||
|
||||
// forward to google.
|
||||
size_t out_bytes;
|
||||
sendTCPMessage(DNS_SERVER_IP(), recv_buf.data(), bytes, mod_recv_buf, out_bytes);
|
||||
|
||||
uint16_t num_of_answers;
|
||||
blt::mem::fromBytes(&mod_recv_buf[8], num_of_answers);
|
||||
|
||||
blt::byte_reader reader(mod_recv_buf.data(), mod_recv_buf.size(), true);
|
||||
|
||||
BLT_INFO("TCP Bytes answered: %d with %d answers", out_bytes, num_of_answers);
|
||||
|
||||
// no one actually does multiple questions. trying to do it in dig is not easy
|
||||
// and the standard isn't really designed for this (how do we handle if one question errors but the other doesn't? there is only
|
||||
// one return code.)
|
||||
question q(reader);
|
||||
std::vector<answer> answers;
|
||||
for (int i = 0; i < num_of_answers; i++)
|
||||
{
|
||||
answer a(reader);
|
||||
answers.push_back(std::move(a));
|
||||
}
|
||||
|
||||
BLT_INFO("TCP DOMAIN: %s", q().c_str());
|
||||
if (STRICT_MATCHING && BLT_CONTAINS(DISALLOWED_DOMAINS, q()))
|
||||
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);
|
||||
}
|
||||
|
||||
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("TCP Writing answer with type of %d", a.type());
|
||||
a.reset(question_offset);
|
||||
send.write(a);
|
||||
}
|
||||
send.write(reader.from(), out_bytes - reader.last());
|
||||
|
||||
asio::write(socket, send.buffer());
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
BLT_ERROR(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BLT_INFO("Creating UDP Server");
|
||||
std::thread udp_server(run_udp_server);
|
||||
BLT_INFO("Creating TCP Server");
|
||||
std::thread tcp_server(run_tcp_server);
|
||||
|
||||
BLT_INFO("Awaiting");
|
||||
udp_server.join();
|
||||
tcp_server.join();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue