通过欺骗进行身份验证绕过¶
ID: cpp/user-controlled-bypass
Kind: path-problem
Security severity: 8.1
Severity: warning
Precision: medium
Tags:
- security
- external/cwe/cwe-290
Query suites:
- cpp-security-extended.qls
- cpp-security-and-quality.qls
依赖 IP 地址或域名进行身份验证的代码可能被攻击者利用,攻击者可以欺骗他们的地址。
建议¶
IP 地址验证可以是身份验证方案中的有用部分,但它不应是身份验证所需的唯一因素。确保也存在其他身份验证方法。
示例¶
在这个示例(来自 CWE-290:通过欺骗进行身份验证绕过)中,客户端通过检查其 IP 地址是否为 127.0.0.1
来进行身份验证。攻击者可能能够通过欺骗他们的 IP 地址来绕过此身份验证。
#define BUFFER_SIZE (4 * 1024)
void receiveData()
{
int sock;
sockaddr_in addr, addr_from;
char buffer[BUFFER_SIZE];
int msg_size;
socklen_t addr_from_len;
// configure addr
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(1234);
addr.sin_addr.s_addr = INADDR_ANY;
// create and bind the socket
sock = socket(AF_INET, SOCK_DGRAM, 0);
bind(sock, (sockaddr *)&addr, sizeof(addr));
// receive message
addr_from_len = sizeof(addr_from);
msg_size = recvfrom(sock, buffer, BUFFER_SIZE, 0, (sockaddr *)&addr_from, &addr_from_len);
// BAD: the address is controllable by the user, so it
// could be spoofed to bypass the security check below.
if ((msg_size > 0) && (strcmp("127.0.0.1", inet_ntoa(addr_from.sin_addr)) == 0))
{
// ...
}
}
参考资料¶
常见弱点枚举:CWE-290.