In what instances can use you use 干嘛 over 干吗 (and vice versa)?
Different sources seem to have to different opinions.

Most websites (for example http://zhidao.baidu.com/question/84845451.html and http://zhidao.baidu.com/question/219005473.html) say that the 吗 in 干吗 has a neutral tone and "干吗" has the same meaning as 干不干 (or 做不做）. For example: 咱们干吗？ (will we do it?)

According to these websites 干嘛 on the other hand means "干什么", asking why are are doing (with mostly a negative meaning). This 嘛 has second tone. An example: 你干嘛呢？ (what are you doing?)

If you however check dictionaries, you get a different answer.
Of course if 吗 "干吗" as a neutral tone, it still has the meaning of 干不干. But according to these the dictionaries in the other meaning it should also be written 干吗. But with this meaning he pinyin of 干吗 is gànmá, so the ma has a second tone here. The only dictionary that has 干嘛 is MDGB, but that not a reliable one (it's one made by the Internet community and it contains many errors). 

For example 现代汉语词典 has 


  干吗: gànmá 干什么：您干吗说这些话？ㄧ你问这件事干吗？


您干吗说这些话？ can be translated as "Why are you saying this?" and 你问这件事干吗？ as "Why are you asking this"?

现代汉语规范词典 writes 


  干吗 [gànmá]
  1. 代 [口] 做什么 你早干吗了，现在才说
  2. 代 为什么 你干吗不早说？


你早干吗了，现在才说 can be translated as "What where you busy doing before that you only say it now" and "你干吗不早说？" as "Why didn't you say before".

现代汉语规范词典 also adds 不宜写作"干嘛". In other words, you can't write it as 干嘛. 

This being said, especially on the Internet you more often see 干嘛 than 干吗 and I guess in the future both will be probably become accepted forms.