A cyber attack on Australian politicians that breached the networks of major political parties was probably carried out by a foreign government, Prime Minister Scott Morrison has said. 

Mr Morrison said a "sophisticated state actor" has hacked the country's main political parties and parliament, just months before an expected election.

He said security agencies looking at a hack of parliament "also became aware that the networks of some political parties; Liberal, Labour and Nationals have also been affected".

"Our cyber experts believe that a sophisticated state actor is responsible for this malicious activity," he said, without mentioning any specific country.

"Our security agencies have detected this activity and acted decisively to confront it. They are securing these systems and protecting users," he said.

Earlier this month authorities reported a "security incident on the parliamentary computing network" forcing users, including the prime minister and the cabinet, to change passwords and take other security measures.

The Australian Signals Directorate confirmed it was working with the parliament in response to the attack, giving a strong indication that sophisticated actors were suspected from the start.

Speculation has focused on China, although there is no official finger pointing at Beijing and cyber experts frequently warn that attribution is time consuming and difficult.

Australians are expected to go to the polls in mid-May, raising the spectre that hackers could be trying to influence the outcome of the vote, or change the tenor of the debate.