According to Merriam Webster, duh is an interjection which has two meanings:
- used to express actual or feigned ignorance or stupidity
- used derisively to indicate that something just stated is all too obvious or self-evident
Apparently this first appeared in 1966 (per Merriam Webster). If you look at Google NGrams, "duh" has appeared even in the 1800s but a quick look at the results shows that in the early cases "duh" was used mostly as a syllable in a foreign language or as a form of "the". You can see that there is an increase over time, regardless, after 1960.
The etymology of the interjection is, as you suggested, onomatopoeic in origin. One site, Think-Ink, devotes an entire page to the discussion of the word. One thing they mention is an etymology, from the American Heritage Dictionary:
Imitative of the utterance attributed to slow-witted people.