In Wireless Sensor Networks (WSNs), energy consumption is the most challenging issue. The more energy is consumed during captured data transmission than the local data processing at sensor nodes. Because of this reason network lifetime is reduces. Sometimes attacker nodes are also responsible of energy wastage. Data aggregation technique is one of the solutions for this issues of network lifetime and energy loss. In this paper data aggregation technique is used for detecting attack and prevention technique. For collecting the data from the cluster head in the network, system used aggregator Node (AN). If the cluster head (CH) becomes attacker, then AN recover the data from all cluster members, So that the energy in not wasted and packet drop ratio is also minimized. Also, system makes use of the Iterative Filtering (IF) algorithm, which additionally gives trust evaluation to the numerous sources from where the information is aggregated. This IF algorithm is used to detect the Simple attack and Collusion attack on nodes. The proposed system can detect the attack on all nodes including cluster member, cluster head and aggregator node. Additionally this system check data truthfulness on cluster head when data is received from all cluster members. SHAl algorithm is used for integrity checking. Experimental results prove that the proposed system improves the energy utilization, memory management and security of data along with attack detection on CH. © 2017 IEEE.