Websites can become infected through various means. Common methods include phishing attacks, exploiting software vulnerabilities, and SQL injection attacks. In some cases, websites may inadvertently host malicious advertisements or be part of a larger botnet.