According to this post I found, you can indeed get a virus on Xbox 360, at least. However, it would be a pretty rare occurrence for several reasons:
- You can't actually download anything from IE on Xbox, so that eliminates the easiest way to get a virus. Basically, the only way to get it without connecting it to a PC would be to open a website or e-mail attachment that could, let's say, inject malicious code targeted towards Xbox into your system. Again, pretty rare nowadays with all the website safety warnings and e-mail filtering.
- Most computer viruses target PC specific software or hardware (for example, a Windows system file, or registry) since the creators of malicious software get very little gain from targeting a gaming console. I doubt that just messing with your machine is a prime goal for most viruses.
The bad thing, though, is that game consoles don't have any virus protection systems in place, as far as I know. Also, with the Xbox One switching to Windows 10 as its OS viruses could potentially be a bigger threat for all Windows systems.
So, based on some of the research I did on this matter - yes, in theory you could get malicious software on your console, however, in practice it's nearly impossible as of now.