"knock on wood" is an old saying. It means that you hope that something will happen but some event or evil may prevent it. In the past, loud noises where meant to ward off evil spirits, so knocking on wood (not literally), made that something happen.
"what got into you" - someone did something so obviously wrong or stupid, that another person is expressing amazement. It derives from an old belief that the person was possessed (gotten into) by an evil spirit.
So both sayings have their origin in old superstitious beliefs.