Edwin Starr famously sang about how war is good for absolutely nothing. He clearly wasn't thinking about the performance of defense stocks though.

Shares of several big contractors are trading at all-time highs and have outperformed the market by a wide margin since the Islamic State of Iraq and Syria started making headlines on a nearly daily basis this summer.

Lockheed Martin (LMT), Raytheon (RTN), General Dynamics (GD) and Northrop Grumman (NOC) each hit records on Friday. And all four stocks are up about 10% since the beginning of August , compared to a 4% gain for the S&P 500.

Given what's going on in the Middle East, it seems that investors are betting on a boost to military spending to deal with ISIS.

President Obama has called for more airstrikes against ISIS.

And several Republican lawmakers have recently suggested that there may be a need to repeal some of the planned cuts to the Department of Defense's budget that are part of the so-called sequester -- the forced pullback in overall spending by the federal government.

Related: Many stocks throughout the market are trading at record highs

But is the possibility of a military budget boost already priced in? If the rally in the stocks over the past two months is in anticipation of more defense spending, the stocks may not go much further, even if there is an actual increase. You could have a classic case of Wall Street buying the rumor and selling the news.

What's more, it's not clear if the resources needed to fight ISIS will be anything close to what was spent in Iraq during the second Gulf War from 2003 through the end of 2011.

Still, the defense sector has typically thrived during times of conflict. Many of the stocks rallied following the first Gulf War in 1991. The group also did well in late 2001 and early 2002 as the U.S. was fighting the Taliban in Afghanistan in response to the 9/11 terrorist attacks.

No matter what happens in Syria and Iraq though, there is a good chance that the stocks could continue to do well.

Keep in mind that they're at record levels despite the budget sequester. Defense companies have all cut costs to keep profits up -- even though revenue growth has become more sluggish lately. Some companies are even expected to report declining sales for the next few years.

Investors must also appreciate the big dividends from the group. That provides security at a time when the overall market has become more volatile. Raytheon, Northrop Grumman and General Dynamics have dividends that yield more than 2%. Lockheed's yield is over 3%.

So defense stocks may still have some big moves (up or down) based on the latest headlines out of Iraq and Syria. But they look like a pretty safe bet for the long haul.