Here, are the download links for the official firmware files of the iPhone 3GS. This files are in .ipsw format. These can be uploaded via iTunes aswell as used with redsn0w for jailbreaking.
Firmware files for the iPhone ‘3GS’ / ‘3G s’ (third generation)
Firmware 3.1.3
Firmware v3.1.2
Firmware 3.1
Firmware v3.01 {iPhone 3G S (3.0.1/7A400)}
Firmware v3.0 {iPhone 3G S (3.0/7A341)}