In the Chamber of Secrets, when Dobby first appears in Harry’s bedroom, Dobby tells Harry about how he has heard all about Harry’s greatness.
But if he serves the Malfoys and rarely leaves the Manor, who told Dobby these things?
My money is on Draco.
Maybe, just maybe, Dobby used his brains. The Malfoys would have been talking about everything Harry has done, including refusing to be friends with Draco just because he’s a ‘pure blood’ and Dobby, who isn’t stupid at all, would have realised that Harry really is a caring soul.