Try using a prop to support the insides of your knees. Roll a blanket, towel, or sticky mat and place it in the crease of both knees (if you put it under just one knee, you will create imbalance in the pelvis and spine). As you lower into the pose, make sure the prop stays behind your knees. If your knees still hurt, try practicing with your lower back resting against a wall. Don’t stay in the pose if your knees continue to hurt, even with the prop or wall.
See alsoHow Yogis Do Squat: Malasana