rust-proof solution for attaching 2x4 to 4x4?
People use the wrong screws outside quite a lot, but thankfully there are good alternatives.  Outdoor decking and fencing are commonly assembled with coated screws advertised for such.  They typically come in tan or green depending on the application and can hold up for a long time without rust or staining the wood.

Stainless steel screws are another option for even more rust prevention, but they will be quite a bit more expensive.  This is pretty over the top unless you're building a boat dock or similar.

For larger fasteners, hot-dipped galvanized lag bolts are good.  Galvanized screws might exist, but I'm not familiar with them.  Certainly you can get galvanized nails, but I think that the coated deck screws must have filled the need that galvanized screws would have because I never see them.