Many efforts have been taken by the Internet Engineering Task Force to fill the gap between the Internet of Things and the real life, by means of the 6LoWPAN protocol. The 6LoWPAN protocol allows a huge number of smart objects to be connected using the large address space of IPv6. IoT becomes successful by 6LoWPAN and the new Routing Protocol RPL. However, these two protocols are less secured and very much vulnerable to Denial of Service attacks. In this paper we design, implement and evaluate a novel intrusion detection and prevent mechanism called IMBF to secure the IoT from Denial of Sleep Attack. The proposed mechanism utilizes a lightweight modularized system to detect and prevent the Denial of Sleep Attack by means of Malicious Node Alert messages. The simulation results establish that the proposed technique is successful in detecting and preventing Denial of Sleep attacks in IoT.