Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Search for iPhone 3G (or 3GS) 3.1.3 IPSW on Google.

Option + Click on Restore in iTunes, and select that firmware bundle.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.