Analysis and Design of Networked Control Systems under Attacks