当前位置:网站首页>gethostbyname \ getaddrinfo 解析域名IP地址不安全的原因
gethostbyname \ getaddrinfo 解析域名IP地址不安全的原因
2022-08-01 07:18:00 【kim-2006】
第 1 步:
使目标域名指向假的服务器IP,格式如下:
假服务器IP地址 网站域名在 %Systemroot%\System32\Drivers\Etc\hosts 文件中写入:
127.0.0.1 blog.csdn.net第 2 步:
运行以下测试代码就会发现域名已被指向假的服务器IP地址, 会造成什么危害呢?导致软件轻易被破解,用户访问假的服务器后,导致用户数据被盗窃。
测试代码:
// ----解析域名IP测试开始----
/*
在 hosts 文件写入: 127.0.0.1 blog.csdn.com 后,
gethostbyname \ getaddrinfo 获得的 ip 地址将是 127.0.0.1, 这就是所谓的不安全的原因
*/
//WSADATA wsaData;
//WSAStartup(MAKEWORD(2, 2), &wsaData);
struct addrinfo *result = nullptr, *curr = nullptr;
struct addrinfo hints = { 0 };
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
int nRet = getaddrinfo("blog.csdn.net", "443", &hints, &result);
if (0 != nRet)
{
int nError = WSAGetLastError();
CString szMSG;
szMSG.Format(_T("getaddrinfo 调用失败, 错误代码: %d.\r\n"), nError);
Log(szMSG);
return;
}
char chIP[16];
for (curr = result; curr != nullptr; curr = curr->ai_next) {
inet_ntop(AF_INET, &(((struct sockaddr_in *)(curr->ai_addr))->sin_addr), chIP, 16);
Log(CString(chIP) + CString(_T("\r\n")));
}
freeaddrinfo(result);
//WSACleanup();
// ----解析域名IP测试结束----边栏推荐
猜你喜欢

Dbeaver connect the MySQL database and error Connection refusedconnect processing

Golang:go静态文件处理

Datagrip error "The specified database userpassword combination is rejected..."Solutions

企业员工人事管理系统(数据库课设)

爆肝3万字,最硬核丨Mysql 知识体系、命令全集 【建议收藏 】

从购买服务器到网站搭建成功保姆级教程~超详细

聊一聊ICMP协议以及ping的过程

Practical training Navicat Chinese and English mode switching

Golang:go开启web服务

信息系统项目管理师必背核心考点(五十六)配置控制委员会(CCB)的工作
随机推荐
聊一聊ICMP协议以及ping的过程
Vim三种模式
Leetcode第 304 场周赛
LeetCode Question of the Day (309. Best Time to Buy and Sell Stock with Cooldown)
Detailed explanation of the crawler framework Scrapy
I have three degrees, and I have five faces. I was "confessed" by the interviewer, and I got an offer of 33*15.
Sound Signal Processing Fundamental Frequency Detection and Time-Frequency Analysis
【MySQL】操作表DML相关语句
Golang:go获取url和表单属性值
Xiaobai's 0 Basic Tutorial SQL: An Overview of Relational Databases 02
05-SDRAM: Arbitration
小程序更多的手势事件(左右滑动、放大缩小、双击、长按)
配置我的kitty
LeetCode 415:字符串相加
R语言使用tidyquant包的tq_transmute函数计算持有某只股票的天、月、周收益率、ggplot2使用条形图可视化股票月收益率数据、使用百分比显示Y轴坐标数据、使用不同的色彩表征正负收益率
rhcsa 第四天
Practical training Navicat Chinese and English mode switching
MVVM项目开发(商品管理系统一)
pytest接口自动化测试框架 | parametrize叠加使用
pytest接口自动化测试框架 | parametrize中ids的用法