You've already got two good definitions of 'hack' from Brad C and Nick.
And as for 'What the hack', I think you have confused this with 'What the heck'. 'What the heck' was used a milder form of 'What the hell' at a time when people were offended by the inappropriate use of the words with a religious connotation. Nowadays 'heck' is completely inoffensive, and although 'hell' is stronger, it wouldn't upset many people. By the way, neither phrase is 'dirty' : 'dirty words' refer to the body and bodily functions.
If you google the phrase 'What the hack!' what you will find is lots of puns, particularly titles of articles and game shows. These is a joke phrase, invented deliberately to catch your eye because it's not quite right. I don't know if the same happens in Chinese, but English-speaking journalists, TV and marketing people love using this kind of word-play to attract people's attention.