The most likely route is through fertilization of the crop. There is also currently no sterilization process used in the preparation of flour, unlike products like dairy and eggs, which are pasteurized.
One article on the topic: Fate of Escherichia coli during Ensiling of Wheat and Corn