Poos are about 75% water. The remaining 25% is made up of a mixture of things: stuff your body can’t break down (have you ever noticed whole corn kernels in your poo), some salt, bile (bile is made up of dead red blood cells from your liver) and, of course, bacteria. Excrement is not very nice stuff and transmits lots of nasty diseases via the nasty bacteria that lurks in it. It is bacteria combined with food waste that turn bile in poo brown, explaining the characteristic brown colour .
The smelly substance in excrement is called skatole (3-methylindole), and it is the substance to which the human nose is most sensitive on a per molecule basis. It is present in faeces because it is a breakdown product from hemoglobin (found in red blood cells) that enters the gut via bile. The reason we have evolved to be so sensitive to the smell of this substance is that, by making poo smell so terrible to us, evolution has ensured that we remain repelled by our own poo and don't go catching any nasty diseases from it. If we hate the smell, we know that it's bad and we steer clear of it as much as possible.
However, skatole doesn't always trigger the disgust reaction in humans, nor is the reaction shared by the whole animal kingdom. The substance is used in small amounts as flavoring in food, notably in vanilla ice cream (you heard me right). Dung flies are attracted to it, and the phallus-like spadix of the arum lily (Zantedeschia aethiopica) synthesizes skatole to attract flies that pollinate the flowers. The civet cat also has glands that produce skatole, presumably to mark territory and repel others. This gland is used in perfumery.