Is there a practical way to prevent this kind of attack? Also, what the name for this class of exploitation so I can read more?
By the way, this is why Microsoft invented the UAC prompt: rather than a password, which can be intercepted, it generates a window which (presumably) cannot, thanks to User Interface Privilege Isolation.
For example, the attacker could inject a LD_PRELOAD library that redirects execve() calls from /usr/bin/sudo to a fake version of sudo.
Or, if the server is running Debian, you can set environment variables the .pam_environment file:
The .pam_environment one is interesting, thanks for the link.