Wireless sensor networks (WSN) are a type of wireless network composed of numerous sensors that collaborate to sense, collect, process, and transmit information about the physical environment within the network's geographical area. The information is ultimately received by the network owner. However, typical attacks such as Blackhole, Grayhole, Flooding, and Scheduling can pose a significant threat to the WSN, potentially causing significant damage to the system in a short period. Detection methods, such as snooping, have demonstrated low detection and high false alarm rates, and require significant computational resources. Additionally, they tend to produce redundant network data. To address these limitations, we propose a novel intervention approach called "Ensemble Bagged Trees," which employs a squared backward sequence selection (SBS) algorithm to reduce data dimensionality and computational overhead in the feature space of native traffic data. The Ensemble Bagged Trees algorithm is then utilized to detect various network attacks. Experimental results using the WSN-DS dataset demonstrate that the proposed method outperforms typical machine learning detection algorithms, with a detection rate of 99.1% for the normal black hole, gray hole, flood, and tabulation attacks.