Did we “accidentally” bring new bacteria to the moon or Mars via our space exploration programs?

Probably, and that’s why terraforming is a bad idea. Inside the scientifically minded community, there are two distinct ideas.
  1. Don’t contaminate. Leave whatever planet it happens to be in the original pristine condition so we can study it. (This is the predominant, tree hugging concept.)
  2. Screw number 1. Terraform the planet. Make it livable for humans, existing organisms, if they exist at all, be damned.

That being said, we do try all we can not to contaminate planets we send probes to even though some microorganisms may have made it through.

At present, and probably rightly so, NASA does not want to introduce organisms to other planets – or visa versa – introduce to Earth organisms from other planets on Earth. We may have already failed, but we still try.