Hasan Mahmud became the first Bangladeshi fast bowler to take a Test hat-trick during a match against Afghanistan in Abu Dhabi.