Muting.
Muting is your friend, if done correctly it makes the difference between a clean guitarist and a messy guitarist.
There are 2 main types of hammer-ons: hammer-ons from 'nowhere', for example, playing an open string and then hammering on at the 2nd fret. Secondly there's your usual hammer on; such as hammering from your 5th to 7th fret with 1st and 3rd fingers (or whatever fingering the situation requires)
There are several ways you can mute surrounding strings so that the pressure of you hammering your finger onto the string doesn't cause other strings to vibrate slightly (although subtle, this is very noticeable when using amplification/gain as i'm sure you've noticed), if you are doing the 2nd method, try doing a fake barre with your first finger - lay your first finger over the higher strings (if there are any) for instance, if you were hammering 5-7 on your D string, lay your first finger over so it mutes the G,B and E strings, make sure it does not barre them correctly, but mutes them, this should prevent them from ringing out into a mush. Be aware that there are several other types of fretting hand muting depending on what you're actually playing, for example there may be times where using your 2nd finger to mute the low E string may be appropriate, for instance if you're bashing out some chords rooted from your A string etc.
The other half of the technique which is equally important and should be experimented with along with the first method is your right hand (or picking hand as to not offend the lefties - freaks). Use the fleshy part of your picking hand to mute strings above
and below the string you are hammering on, to do this the cleanest and avoid muting the string you want to hear you should practise making a sort of tunnel with the curveature of your right hand.
That's the general technique sorted, when you're hammering-on from nowhere it is more difficult, specifically in reference to your fretting hand muting, as you have to make sure that as soon as you hammer-on your desired note that you also position your muting fingers/picking hand palm at the presise time to get the muting effect and once again make sure you don't mute the string you're hoping to hear.
Edit: By the way, you may also be getting noise if you're not actually picking an initial note to hammer from, you ARE picking a note first and THEN hammering-on aren't you? If you're literally hammering-on and not picking the initial note you're hammering from then this technique is even harder, but still possible, it just requires a precise hammer with appropriate strength (less than you would imagine, placement is more improant) and very good muting.