FORTUNE — It’s no secret that the Defense Department faces draconian budget cuts if Congress can’t avoid its latest standoff by March. Between that and the winding down of wars in Afghanistan and Iraq, defense companies have been facing a relatively lean future, and those stocks have lagged the S&P 500 (SPX) for the past year.
But even as troops come home, the U.S. faces a new kind of military threat from hackers. To wit: A report from the computer security firm Mandiant has linked China’s People’s Liberation Army to a large number of cyberattacks on U.S. government agencies, corporations, and media companies including the New York Times and the Wall Street Journal. (The New York Times hired Mandiant to investigate a spate of computer hackings that occurred over the past four months.)
Unsurprisingly, some companies — particularly those focused on cyberwarfare — will escape the budgetary downdraft and enjoy increased funding. “Governments globally will increase spending onmaritime and border security and protecting critical infrastructure,” says Douglas Baker of Monument Capital, a private equity (PE) ﬁrm that’s raising a fund to invest in security and defense companies.
Thriving on the dividend and buyback diet
Monument isn’t the only ﬁrm raising funds to invest in high-tech defense opportunities. Last year Madison Dearborn Partners teamed with CoVant Management to form CoVant Technologies, an investment vehicle created to back cybersecurity, IT, and systems engineering companies that work with the government. And Enlightenment Capital is raising a $100 million fund that it will use to provide debt to and take equity stakes in defense and government services companies.
Investment partnerships have also begun to pick up, particularly between midsize companies and PE outﬁts. Vistronix, a provider of national security IT solutions, joined Enlightenment Capital to buy Technology Associates, which develops highly specialized geospatial and data visualization software.
Some big companies have also begun buying. In September, French aircraft maker Safran, with $15.9 billion in 2011 revenue, announced plans to buy L-1 Identity Solutions, which provides biometric security to the U.S. government, for $1.6 billion.
In fact, interest in cyberdefense has pushed valuations so high that strategic buyers are targeting companies with as little as $10 million in revenues.
Go long on the economy, and hedge on stocks
Cybersecurity is “much broader than people think,” says Mike Steed of Paladin Capital Group, a PE ﬁrm putting money in national security-focused startups. It used to mean information theft, he says, but today “it means preventing the destruction and disruption of everything from databases to the power grid.”
In a realm of startups, there are few public companies for retail folks to invest in. One promising pure play is KEYW Holding (KEYW), a small company (with a market cap of about $450 million) that provides mission-critical software for intelligence, surveillance, and reconnaissance for agencies such as the CIA and NSA. (The name reﬂects the founder’s fondness for Key West, Fla.)
Randy Gwirtzman, a senior analyst at the Baron Funds, one of the stock’s biggest holders, says KEYW’s employees are its advantage: “Most employees have a security clearance with the government and have had government jobs protecting computer systems.” Founded in 2008, the company has grown via 13 acquisitions; its earnings before interest, taxes, depreciation, and amortization grew by 44% in the most recent 12 months after doubling during the previous period.
3 lessons for Apple’s shareholders
Analysts say two recent KEYW acquisitions brought products that will attract nongovernment customers, which should mean more growth (a good thing, given that KEYW trades at a lofty 50 times forward earnings). The purchases of SenSage and Rsignia, which detect threats by monitoring and analyzing the data ﬂowing through internal networks, make KEYW’s services appealing for companies that “are underserved by the available commercial cyber- security products,” according to a Sterne Agee note. These services, which customers subscribe to via long-term contracts, should improve the steadiness of KEYW’s revenue.
Despite the bleak budgetary environment, KEYW “may not just buck the trend but also realize strong growth with its unique government and commercial cyber offerings,” RBC Capital Markets analyst R. Rama Bondada wrote in a recent note. Like any neophyte small-cap stock, KEYW shouldn’t make up more than a small part of any portfolio, but it offers potential in a burgeoning new sector.
A shorter version of this story appeared in the February 25, 2013 issue of Fortune.