Same as any crime. They have to prove that you did it (both that you did the act, and that you intended to do the act) to a judge or a jury beyond a reasonable doubt.
> what if you have malware on one of your devices and it accesses something banned?
If your concern is about being framed via malware, there are plenty of existing ways of doing so. eg. laws against CSAM or laws against funding terrorists (hope that the malware doesn't use your paypal session to send money to ISIS!).