In recent years, with the development of the Internet of things industry, wireless sensor networks, as one of the most important technologies in its sensing layer, have been further studied and applied. However, the security threats it faces are becoming more and more diverse, and the security needs are becoming more and more urgent. However, wireless sensor network nodes are mutually exclusive, which leads to low accuracy of attack path prediction when malicious attacks occur. In order to ensure the security of wireless sensor networks, a hidden Markov based malicious attack path prediction method for wireless sensor networks is designed. The method of authentication coding is introduced to realize data integrity authentication. Extract the malicious software gene sequence, define the constraint conditions of the state transition probability matrix, build the attack means deduction model based on Hidden Markov, and realize the malicious attack path prediction. Experimental results: the average accuracy of the proposed method in four malicious attack scenarios is 73.583%, 55.674%, 32.923% and 85.014%, respectively. The results also verify that the proposed method improves the accuracy of malicious attack path prediction in wireless sensor networks based on Hidden Markov model, and has good feasibility. It provides an important basis for wireless sensor network administrators to implement defense strategies in time.