Self-organizing dense sensor networks are expected to resolve the challenges of spectral efficiency, energy equilibrium, and device management. Because of cost and resource constraints, the sensor node is fragile to outside virus attacks. In this paper, we propose a community-based network model to depict complex network structures. Virus attacking behaviors and the virus propagation are theoretically analyzed in three cases when it spreads over the network. The mathematical analysis shows that the total number of infected nodes increases exponentially with the epidemic time. Structures of networks, the infection probability and the shortcut probability affect the rate and extent of spreading of viruses simultaneously. The conclusions are validated through simulations and evaluations, and are envisioned to have future applications in the immunization of wireless sensor networks.