It is possible to get them directly from dogs but it is not the most common means.
Hook worms are on the ground and enter the skin when touched. Their eggs are everywhere and laying on everything and floating in the air.
If you look closely at uncooked rice you will see hook worms. This is the reason the rice producers industry has added arsenic to the rice. They would rather take the heat for the arsenic content than admit to the public that rice is naturally full of hook worms.
Whipworms generally come from eating contaminated meat. Same as all parasites. The eggs are blowing in the wind.
If you eat or breath you have parasites. I have accepted that human immune systems are no longer capable of fighting off parasites.