Counterfeits don't happen when you buy parts from reputable distributors (digikey, mouser, Newark, TTI, arrow, etc) that are not "marketplace" items. These parts often come right from the manufacturer or from a domestic distributor for the manufacturer. You get counterfeits when you buy from brokers.
Often with older electronics designs, the parts the engineers originally picked are no longer made. It's not the end of the world, there are solutions. Sometimes the vendor changes the part number due to a process change or the part design is sold to another company and goes under a new number. You can also sometimes find drop in compatible parts (common for the 7400/5400 series chips), these may be in a different package so you might have to design an interposer or deadbug it. The worst option is finding old stock using a broker. There are legit brokers that will source old stock and "refurbish" them for you (called re-lifeing). But there are also shady brokers that will buy counterfeits (or get tricked into buying them) that may or may not actually work. Sometimes the counterfeits are relabeled parts that are compatible but the new label gets a higher price because they aren't being made any more. Sometimes the counterfeit is actually a totally different design that is shoehorned into its desired purpose (like a new microcontroller masquerading as an old processor or ASIC). Other times it's just some random junk pulled from e-waste that's been relabelled. Other times you'll get a counterfeit that comes from a stolen design. Even when the counterfeit functions, it may not perform to the same spec as the original part (very important for military spec parts) or will have other characteristics that make it incompatible with the rest of the design (like drawing too much or too little current). When it comes to engineering in ISO9001, traceability is a huge thing and brokers just can't provide that.
At my job, we have an "absolutely no brokers" rule. They simply cannot guarantee that what they provide is genuine. If a legitimate distributor doesn't have stock of a discontinued part, they'll never have stock of it. Brokers will tell you what you want to hear while they go out and try to make it happen. I'm not saying all brokers are shady but if you are considering buying from a broker, you should be instead considering how you can replace that part.