With the rapid development of ubiquitous network and its applications, the key technologies of the Internet of things are actively researched all over the world. The Internet of things has tremendous attraction for adversaries, and it is easily attacked due to poor resource and non-perfect distribution of sensor nodes, then false data maybe be injected into network. Security is one of the most important demands for applications in the Internet of things, an algorithm of malicious nodes detection is proposed to protect the network from destruction based on weighted confidence filter, namely, the cluster heads take charge of collecting messages from nodes and computing their average of confidence in cluster-based network, then they aggregate data from nodes with higher confidence than average and ignore the others, they update confidence of each node by comparing the aggregation value and the received data, and regard it as the weight of exactness of message from node. A sensor node is judged to be a malicious one if its weight is lower than the set threshold. The simulation results show that the algorithm can detect malicious nodes with high detection ratio, low false alarm ratio and outstanding scalability.