Demons, before their fall, were angels. That means, before they corrupted themselves, they were in heaven with God. During their time in heaven, they learned many things. That might include supernatural powers and other abilities to do some of the things God does.
After their fall, they carried some of that knowledge and skills with them. That is why some demonic signs and wonders can be very powerful.
We cannot judge solely by the power of a miracle that it must come from God. That can be dangerous, because demons can gather and work together to create very big miracles to deceive a person. And we might become easily impressed. The Bible tells us that in the end times, miracles will be so great that they might mislead even the elect.
Jesus said, "For false Christs and false prophets will arise and will show great signs and wonders, so as to mislead, if possible, even the elect." (Matthew 24:24)
The only sure way to tell if a miracle is from God is to see what kind of teaching is being taught. You are right that if there is false teaching, then the miracle comes from a bad source as well.
---
The Bible tells us that demons can perform very powerful signs and wonders.
For example, the Bible tells us that some demoniacs could not be bound with chains and no one could control them (Mark 5:2-4).
The Bible also tells us that in the end time, the beast will have a fatal wound that will be healed. This will be the kind of healing that mimics resurrection from the dead. So demons can perform great "healings" as well.
"I saw one of his heads as if it had been slain, and his fatal wound was healed. And the whole earth was amazed and followed after the beast..." (Revelation 13:3)
Whether the wound will be fake and hence the healing will be fake, we do not know. But we do know that before human eyes, it would seem that an amazing healing will take place.
However, just as during the time of Moses, God's miracles were greater and could not be replicated, so also in the end times, the world will see that God's judgement is supreme.
In the end time, it won't just be the Nile becoming foul or darkness falling on Egypt. God will rain plagues from heaven to turn a third of all fresh water into blood (Revelation 16:4-6) and cause darkness to fall on Satan's entire kingdom (Revelation 16:10-11).
People will see at that time that God's power is the greatest, just as even the Egyptian magicians acknowledged God at work thousands of years ago.
---
In the meantime, we should remember what the Bible says, so that we are not misled by signs and wonders. If any teaching is against the Bible, we should reject it.
"Then that lawless one will be revealed whom the Lord will slay with the breath of His mouth and bring to an end by the appearance of His coming; that is, the one whose coming is in accord with the activity of Satan, with all power and signs and false wonders, and with all the deception of wickedness for those who perish, because they did not receive the love of the truth so as to be saved." (2 Thessalonians 2:8-10)