Rangana Herath claimed his maiden test hat-trick to consign Australia to their lowest total against Sri Lanka.