It almost certainly dates back to the days when a victorious army would plunder the place they had recently attacked and defeated. Obviously, the soldiers woul stuff their pockets, bags or whatever and then - so as not to miss anything - even their boots. That's why we have the modern sense of "take full advantage" when we use the saying.