Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Authentication bypass by spoofing

ID: cpp/user-controlled-bypassKind: path-problemSecurity severity: 8.1Severity: warningPrecision: mediumTags:   - security   - external/cwe/cwe-290Query suites:   - cpp-security-extended.qls   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

Code which relies on an IP address or domain name for authentication can be exploited by an attacker who spoofs their address.

Recommendation

IP address verification can be a useful part of an authentication scheme, but it should not be the single factor required for authentication. Make sure that other authentication methods are also in place.

Example

In this example (taken fromCWE-290: Authentication Bypass by Spoofing), the client is authenticated by checking that its IP address is127.0.0.1. An attacker might be able to bypass this authentication by spoofing their IP address.

#define BUFFER_SIZE (4 * 1024)voidreceiveData(){intsock;sockaddr_inaddr,addr_from;charbuffer[BUFFER_SIZE];intmsg_size;socklen_taddr_from_len;// configure addrmemset(&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 socketsock=socket(AF_INET,SOCK_DGRAM,0);bind(sock,(sockaddr*)&addr,sizeof(addr));// receive messageaddr_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)){// ...}}

References

  • Common Weakness Enumeration:CWE-290.


[8]ページ先頭

©2009-2025 Movatter.jp