In a quest to make online accounts safer, many services now offer two-factor authentication. The system typically sends a code to a user's mobile phone that they need log in, along with a username and password. Cybersecurity professionals have advised enabling two-factor to add an extra layer of security — but according to at least one expert, this may not be a silver-bullet. Kevin Mitnick, who was once the FBI's most wanted hacker and now helps companies defend themselves, found that two factor authentication can be vulnerable. "Just by enabling two-factor authentication, you can't relax…a smart attacker could get access to your account," Mitnick said in an interview with CNBC. He is the chief hacking officer at KnowBe4, a cybersecurity company that trains people to spot phishing, or spoofed emails.

Kevin Mitnick, the chief hacking officer at Knowbe4, was once the FBI's most wanted hacker. He demonstrates how a cybercriminal could get around two-factor authentication. CNBC

Mitnick told CNBC he found out about the vulnerability when it was posted online for anyone to find. "The tool to actually pull these attacks off has been made public. So any 13-year-old could download the tool and actually carry out these attacks," he said. According to Mitnick, the attack begins when a cybercriminal sends an email that looks real, and asks the receiver to click on a link. Once the user clicks on the link, they are directed to log into the real website, including entering the code sent to their cellphone. Secretly, however, the log in went through the hacker's server and they were able to get the session cookie, the expert explained. "If we can steal the user session cookie, we could become them, and we don't need their username, their password, or their two-factor," Mitnick said.

This code shows a session cookie, which Kevin Mitnick, the chief hacking officer at KnowBe4, a cybersecurity company that trains people to spot phishing, or spoofed emails, says can be used to bypass two-factor authentication. CNBC

Mitnick showed CNBC that he was able to enter that code into his browser. "When I hit refresh I'm going to be magically logged into the victims account," he said. Mitnick used LinkedIn to demo the attack for CNBC, but said many other websites are also vulnerable. The email he clicked on looked like a real LinkedIn connection request — but actually came from a fake domain, lnked.com. He said most people may not realize the difference. "It's not LinkedIn that's vulnerable. It's the actual user… It's a security flaw with the human," Mitnick said. In a statement, Mary-Katharine Juric, a LinkedIn spokesperson, told CNBC that the professional network took Mitnick's demonstration "very seriously," and that LinkedIn has "a number of technical measures in place to protect our members from fraudulent activity including phishing scams." She added: "When we detect this type of activity, we work to quickly remove it and prevent future re-occurrences. We strongly encourage members to report any messages or postings they believe are scams, and utilize our member help center as a resource to educate and protect themselves from frauds online." This attack is part of what is known as social engineering, when hackers take advantage of human behavior to get you to do something, like click on a link. Another way to protect yourself is to pay close attention to email you get, even if you use two-factor authentication. "Social engineering if you do it right can be used to get into almost anything," said Stu Sjouwerman, KnowBe4'S CEO. To protect from attacks like this one, some companies are making tools called security keys. Instead of sending a code to your cell phone, security keys — which look like a keychain — contain a hardware chip, and use Bluetooth or USB to be the additional factor needed to log into your account. Recently, Google released its own version of the device, which it calls the Titan Security Key.

The Bluetooth version of the Titan Key. Google