Iran would do it to as a means to strike the west. The Iranians can probably disguise it well enough to not trace it back to them, or at least to the point to be able to deny it. I don't think North Korea is in this for growth, unless it's the South. Iran wants to expand their influence. Iran selling the technology, even a degraded version of it, achieves their strategy of growing their influence and striking at the evil west.
How does "striking the west" covertly serve their interest in any way?? I'm at a loss here. If nobody knows they are at the heart of this attack, how does it help? If everybody knows they are the source of the attack, how does it help?
Who are they going to sell this tech to?? They don't have loads of friends and anybody in the region would likely want to use this tech against them. If some Palestinian group were to somehow find a way to get a nuke to Israel, everybody would know where it came from. Tehran would be radioactive and uninhabitable the next day.
Iran and North Korea want nukes to keep people out of their countries and be regarded as big shots in their neighborhoods. That's all there really is to it.
I think you are assuming that the leaders of Iran and North Korea are rational and have some of the same values you have. I'm not particularly interested in assuming that your view of their motives is correct.
Turn it around a bit - consider your view of the US invading Iraq. How did that serve the US interests? And yet, it happened, didn't it.
A NK supported nuke attack on the US or Israel could serve their interest by weakening an enemy. Even if it wasn't known that NK was involved, it would still weaken an enemy.