One of the most discomforting thoughts when sin attacks is the thought that you are so wicked because you are having such bad thoughts. But before you condemn yourself as the most wicked person on earth think on what the Bible speaks about this:“No temptation has seized you except what is common to man” (1 Corinthians 10:13a NIV).
So you need not think that it is you alone who has to suffer these kind of vile thoughts. Others all struggle the same way you do when you are tempted. But they don’t speak openly of it. Because they also think that they are the only ones going through these wicked kind of thoughts.
Now you need to remember that we all have a common enemy. So he will use all his weapons to make us sin. He does not invent new weapons. All his weapons have been there from the time he tempted Adam and Eve in the garden of Eden. So do not think that you are alone in the struggle.
You can approach God when these kind of vile thoughts attack you. But this enemy after bringing such wicked thoughts to your mind will tell you that you now cannot approach God because of these thoughts. But that is not true. It is at this time that you need to approach Jesus because He will not break a bruised reed nor snuff out a smoldering wick (Matthew 12:20). That means that when you are suffering with sin and failure He will not destroy you; for He will not despise a broken and contrite heart (Psalm 51:17b).