Internet of Things (IoT) is a concept that aims to make the real world more intelligent but susceptible to various attacks. In this paper, we focus on wireless sensor networks (WSNs), as a founding block in the IoT presenting the vulnerability of routing attacks against Routing Protocol for Low power and Lossy Network (RPL). Besides, we discuss some existing research proposals to detect intrusions, and we develop a technique for detecting three types of attacks against RPL. We simulate using Contiki-Cooja four network scenarios one normal and three malicious presenting different attacks, to be able to generate the training and the test sets that are used in the machine learning phase, in which we used WEKA, to decide according to the database whether the behavior is normal or malicious. For this phase, we use different classification algorithms, which enable us to obtain a high precision value that is superior to 96% in all cases.