Disclaimer: Do it at your own risk:
I had the malware problem in Safari.
Expanding on what "misodera" said. When you get to the Automation section make a note of the malicious application name. It most likely be a random generated number (let say 123456789 as an example). There will be a safari checkbox underneath. If you open the activity monitor app you will see the app name there as well. Close safari, uncheck the safari checkbox in the Automation section. The entry should be gone from there. You might need to get out of the automation section and back in to get it refresh. If it is not gone we can clean it up at the end. Open the terminal app and execute ps -ef | grep "enter the application name here" . For example, ps -ef | grep 123456789. There you will see the location of the application. Something like this:
/Users/you user name/Library/Application Support/com.13413412341/123456789 Remember, Your app name will be different.
Go to the Activity Monitor and kill the application: Select the app name (123456789) and click the stop button.
Remove the malicious app bundle (e.g., com.13413412341) using this command:
sudo rm -rf /Users/you user name/Library/Application Support/com.13413412341
Now go to the Security & Privacy and the privacy tab, select "Full Disk Access" and remove the malicious app reference from there. Finally, if you still see a grayed out reference in Automation with the malicious app name , you can run in the terminal to clean this up: sudo tccutil reset AppleEvents