The attack left the boy with serious injuries, a court heard