VesselFinder and MarineTraffic use the data broadcast by vessels on AIS[0]. The AIS devices can be programmed with the dimensions of the vessel, location of the AIS GPS antenna relative to the vessel (ie, is it right aft, or in the middle, etcetera), and uses sensor data from the network bus to get direction, speed and the like. So yeah, if the ship's AIS is saying "I'm at latitude, longitude doing 0 knots, last reported course was 73 degrees", the websites can generate a somewhat accurate picture.
0: https://en.wikipedia.org/wiki/Automatic_identification_syste...