Generally the devices poke holes in the firewall with UPnP. There are also other vectors (ZeroConf, STUN, CWMP).
The problem is that, once past the firewall, many of these devices have weak to no security, e.g. open telnet daemons, root:root default user/password, and other trivial vulnerabilities.