And that's what all the billions in planetary defense are for. Any such attempt will result in a nice brief light show far out in space, only those looking in the right place at the right time, and probably with a high power sensor will even notice it.
Now if we're talking some backwater, self-absorbed, fractious little world, like, I don't know, Terra circa 2,004 TY, then yeah you could probably pull of such a stunt, maybe even a couple of times before they knew what was happening. And even then they wouldn't be able to do much about it except plead for mercy and sue for peace.