They tend to have farms (but instead of a field and sheep, think of a building and loads of computers.)
They then employ people who get paid peanuts to grind their gold etc, how much they make (real life) is usually tied into how much they make (virtual.)
This practice is quite often conducted by chinese, hence the bad reputation the nation now has with the online community.
The other way is also as you mentioned through hacked accounts etc, one big rule of thumb, is to always be careful where you download your addons, as quite frequently you will end up downloading more than you bargained for.