I can't think of any legit reason to want/need to modify your HWID.
You can attempt to 'spoof' it, but as far as permanently changing it, no it cannot be done AFAIK.
Is it "illegal" though? I can't imagine you could be arrested for it, so no, it's probably not "illegal". It is likely against the EULA of most programs/OS though.