How to change the behaviour of a module
Most of the time you will want to try to stay away from modifying the modules directly. This can be done, but it makes it more difficult to upgrade to future versions of the module. 

A lot of modules allow for modification, and Drupal itself is designed for you to be able to modify things at many stages in the process of building a page. So if you can inject functionality it is best to do so. 

This isn't always possible to do in which case you can either modify your local copy of the module. Or you can create an issue on the modules issue queue with a patch, which may get picked up in a future release of the module.

How to inject behavior is a very broad subject (I am sure specifics are already answered or can be asked on this site).

Most of the time you will want to create a module, and implement hooks which will allow you to modify things.