How can I know if the rooting files have malware? I'm learning about how cellphone rooting works. Every procedure I've seen this far asks you to install a series of files that you download from random websites. Is it possible to know for sure that the files you are downloading will only root your phone, and that they are not 'trojans' or other types of malware?

Thanks,
There are two possible counter possibilities:

First possibility:
In case the rooting is done by scripts and certain binary tools you can check if the binary tools are standard tools, and e.g. included in the Android Open Source Project (AOSP). In such a case you could compile the tool yourself or search the net for multiple sources. In the ned use the one from the most trustworthy.

Second possibility:
Use a virtual machine for executing the rooting software. Using a virtual machine like VMware you can connect an USB device like an Android phone into the guest OS. Therefore rooting the device from within the guest OS is usually possible and does not affect the host OS.