The online hack that led to the posting of hundreds of explicit photos of some of Hollywood's most famous female stars could have been down to an attack on their passwords.

Stars including actress Jennifer Lawrence and model Kate Upton saw intimate photos posted on forum site 4chan on Sunday evening, with some reports initially concluding that Apple's iCloud service had been compromised to access the images.

A piece of computer code that repeatedly guesses passwords has been found online. The script was posted to software site GitHub, but a message has since appeared saying that Apple has issued a "patch" or fix for the bug.

"The end of the fun, Apple has just patched," read an update on the post. The technology giant is yet to make any comment on the incident.

According to the post, the script uses the top 500 most common passwords approved by Apple in order to try and gain access to user accounts. If successful, it would give the hacker full access to the iCloud account, and therefore photos.

Owen Williams from technology site The Next Web, who discovered the bug, said: "The Python script found on GitHub appears to have allowed a malicious user to repeatedly guess passwords on Apple's 'Find my iPhone' service without alerting the user or locking out the attacker.

"Given enough patience and the apparent hole being open long enough, the attacker could use password dictionaries to guess common passwords rapidly. Many users use simple passwords that are the same across services so it's entirely possible to guess passwords using a tool like this.

"If the attacker was successful and gets a match by guessing passwords against Find my iPhone, they would be able to, in theory, use this to log into iCloud and sync the iCloud Photo Stream with another Mac or iPhone in a few minutes, again, without the attacked user's knowledge. We can't be sure that this is related to the leaked photos, but the timing suggests a possible correlation."

Experts have pointed to the weakness of many internet users' passwords, and basic security knowledge as being the cause for the widespread leak.

iCloud is Apple's own cloud service, a wireless storage facility that can be used to access files remotely. Other notable services include Dropbox and Google Drive, which enable users to keep more of their files close to hand without taking up huge amounts of memory on their devices.

Rob Cotton, CEO at web security experts NCC Group said: "Cyber security is not just a technology problem, humans are very much key to its success. In our day-to-day work we see too many cases of employees divulging sensitive information without first verifying the legitimacy of the request.

"People often point the finger at technology when they've been the victim of a cyber attack, but poor password choices or naivety in the face of a seemingly innocent email is regularly to blame."

Human error, in a variety of ways, said Mr Cotton, often played a part.

"Last year NCC Group successfully compromised the iCloud account of a journalist as part of an authorised demonstration using a mixture of social engineering techniques and subterfuge - and the amount of information we were able to access was shocking," he said.

Separately, Wired reporter Mat Honan had his iCloud account breached and his devices wiped after hackers used a mixture of public information and social engineering when contacting Apple technical support, in order to gain access.

Stefano Ortolani, security researcher at online experts Kaspersky Lab said: "In order to make your private data more secure, you should cherry-pick the data you store in the cloud and know, and control when the data is set to automatically leave your device.

"For instance, in iCloud there is a feature called "My Photo Stream" which uploads new photos to the cloud as soon as the device is connected to Wi-Fi; this is to keep photos synchronised across all your devices. Disabling this option might be a good starting point to be a bit more in control."

While the security of the cloud will now come under increased scrutiny, Mr Ortolani points out that some element of risk has always existed.

"The security of a cloud service depends on its provider," he said. "However, it's important to consider that as soon as you hand over any data including photos to a third-party service, you need to be aware that you automatically lose some control of it. This is also the case for when you upload something online."

Other stars said to have been affected by the nude picture leak include Avril Lavigne, Cara Delevingne and Rihanna, with actress Mary Elizabeth Winstead, whose movies include A Good Day to Die Hard, already acknowledging pictures in which she is featured are genuine.

She wrote online: "To those of you looking at photos I took with my husband years ago in the privacy of our home, hope you feel great about yourselves."

However representatives for the former Coronation Street star Michelle Keegan, who was reportedly on a list of stars whose pictures had been obtained, say she does not appear to have affected.

A spokeswoman for the actress said: "There's no evidence that her phone or computer has been hacked, and nothing has appeared online to suggest otherwise either."

A publicist for Lawrence said the actress had contacted US authorities over the photos.

Liz Mahoney described the posts as "a flagrant violation of privacy" and said Lawrence had asked authorities to prosecute whoever is posting the photos.