The low level speeds of the Mosquito were what kept is safe, rather than the heavier construction and armour of the B-25. Its a matter of building philisophy more than anything else.
Both were excellent straffers and antiship A/c. Actually, pretty much all of the Allied twin engine anti shippping aricraft had devestating foward firpower;
B-25: up to 12 forward firing 12.7 mm Hmgs (thats about 160 rounds per second!), or
1 75mm cannon and 8 forward firing HMG
Mosquito: 4 20mm cannon and 4 .303 Mmgs, (about or
1 57mm cannon 4 20mm cannon and 2 .303 Mmgs
A-20: 6 forward firing 12.7mm Hmgs
A-26: 6 foward firing 12.7 Hmgs
Beaufighter; 4 20mm cannon and 6 .303 Mmgs, or
4 20mm cannon and 4 12.7 Hmgs
The main sriking weapon of the twins wasn't really the machine guns or various calibre of cannon. It was rockets and skip-bombing that had the most devestating effect on Axis shipping.
The Beaufighter was the first plane to conducts anti-shipping strikes with rockets, debuting against German shipping in Norway in May of 1943. The standard tactic was to mix striking forces of Mosquitos and Beaufighters. Mosquitos would be used in flak supression and Beaufighters would act as strike aircraft.