PHP script to create mule accounts

Posts 1–11 of 11 · Page 1 of 1
PHP script to create mule accounts
Whats up everyone, this is my first post here. I felt i should contribute on here since i have been finding a lot of great info from everyone.


I wanted to create a script that would allow me to use 1 gmail email address and create as many mule accounts as i wanted using that one email. That way i wouldnt have to go check a bunch of different emails to verify the accounts or anything like that. The current mule creator i was using didnt have an option to create a bunch of accounts using 1 gmail address all at once, i had to do it one at a time.

All the instructions for how to use the script are located in the readme inside the zip, as well as instructions on how to modify the script if you want to make changes to how it runs. This script does require that you have php installed, or you can use a web server that supports php.

If you have any questions just ask, ill do my best to answer!
mule_script_mpgh.net.zip3 KB · 67 downloads Clean
@Joe @Luis @Raple Needs approval.

Btw. There is already a mule creator that creates this. But if this is the source code, then its probably more useful than without.
The one ive been using, Easy Mule [V.7.0.0], you have to create the gmail account mules one by one. It doesnt allow for mass creating accounts using 1 gmail address all at once. So thats why i created this. So i could run the script and create 50+ mules in 1 go instead of having to do it one by one. Although i still use Easy Mule for everything else it offers of course. This script is just for creating the mules, not for managing them or anything like that.
Quote Originally Posted by toddddd View Post
The one ive been using, Easy Mule [V.7.0.0], you have to create the gmail account mules one by one. It doesnt allow for mass creating accounts using 1 gmail address all at once. So thats why i created this. So i could run the script and create 50+ mules in 1 go instead of having to do it one by one. Although i still use Easy Mule for everything else it offers of course. This script is just for creating the mules, not for managing them or anything like that.
Gotcha. Good job with the release.
Excellent first post, it's rare people put this much effort in at the beginning.

Approved, report back with results.
Nice script, took a look at it myself. very nice.
Thank you guys, I appreciate all of your comments
Thank you , really !
So ive been playing around with my script here every now and then, and i just wanted to post an update for anyone that either uses this or is interested in it. I know some people dont like PHP, but i actually work in php for my job and dont have any issues with it ever, so this is what i like to use to make quick little scripts like this.

I added a few new features to the script. You can now set the security questions for the mule it just created as well as the name and everything. I added this for a few reason, the first is that i get really annoyed when i go to open a mule from muledump and i have to answer the stupid security questions before i can login. The other reason is to keep track of the security questions i use, if i only use the same 3 security questions (maybe not too smart) then i wont forget or type it wrong/etc anytime.

I also added the ability to open your gmail and get the link from the "verify email" messages. If you run this through the command prompt/terminal then it will try to launch chrome with the url (you can change that int he script if you dont use chrome). But if you used a web browser to run the script then it will just echo out a link for you to click that takes you to the verify page. For the script to do this you will need to go into your gmail settings first and enable the IMAP settings. Then i also had to go to "My Account > Sign-in & security" and at the very bottom there is an option called "Allow less secure apps", that has to be enabled for the script to login to your gmail.

With these changes its now super easy for me to get a mule created, named, security questions answered, and verified.

Here is the code, i did my best to comment stuff so hopefully it is easy to understand.
 
CODE
Code:
<?php set_time_limit(0);

// Determin if the script was called from command line or web browser
$terminal = false;
if (php_sapi_name() == "cli") {
	$terminal = true;
}

//Set this to false if you dont want it to generate a randon name for the mule
$set_name = true;
// Set this to false if you dont want it to set the mules security ansers
$set_security_answers = true;
// Set this to false if you dont want the script to try and check your email for you
$check_email = true;

// Set these variables to be used in the script
$base_email = "YOUR_GMAIL";
$gmail_pass = "GMAIL_PASSWORD"; // dont need this unless you have $check_email set as true
$start_num  = 1;
$total      = 10;

// API Base URL
$base_url = "http://realmofthemadgod.appspot.com/";
// Location of accounts.js file
$accountsjs = "PATH/TO/accounts.js";

// Security Answers that will get set if $set_security_answers is true
$security_answers = array(
	base64_encode("security answer 1"),
	base64_encode("security answer 2"),
	base64_encode("security answer 3")
);

/* Uncomment this block if you want the script to take arguments when it runs instead of having the values hardcoded above this
// Check if this script was called with arguments
	if (isset($argv) && is_array($argv)) {
	// Make sure there are 3 arguments after the script name
		if (count($argv) < 4) {
			echo "This script takes 3 arguments. The email without the domain, the starting number, and the total number of accounts to create.\n";
			exit();
		} else {
			$base_email = $argv[1];
			$start_num  = $argv[2];
			$total      = $argv[3];
		}
	} else {
	// Make sure the email is set
		if (empty( $_REQUEST['e'])) {
			die( 'No email provided.' );
		} else {
			$base_email = urldecode($_REQUEST['e']);
		}

	// Make sure the starting number is set
		if (empty($_REQUEST['s'])) {
			die( 'Missing starting number.' );
		} else {
			$start_num = $_REQUEST['s'];
		}
	// Make sure the number of accounts is set
		if (empty($_REQUEST['q'])) {
			die( 'Missing number of accounts to create.' );
		} else {
			$total = $_REQUEST['q'];
		}
	}
*/

// Make sure the email doesnt have the domain attached
	if (stripos($base_email, '@') !== FALSE) {
		list($base_email, $domain) = explode('@', $base_email);
	}

// Create cURL handle
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Array to hold new accounts
	$new_accounts = array();

	for ($i = 0; $i < $total; $i++) {
	// Create the email
		$email = $base_email . '+' . str_pad($i + $start_num, 4, '0', STR_PAD_LEFT) . '@gmail.com';
	// Generate a random password 11 characters long
		$pass = randomValue(11, array('lower','upper','number','symbol'));
	// Account info
		$info = array(
			'guid'          => randomValue(26, array('upper','number')), // This is just a random (and useless?) value
			'newGUID'       => $email, 
			'ignore'        => randomValue(4, array('number')),
			'newPassword'   => $pass,
			'isAgeVerified' => 1
		);
	// Create full url
		$acc_url = $base_url . 'account/register?' . http_build_query($info);

		echo "Creating \"$email:$pass\"....";

		curl_setopt($ch, CURLOPT_URL, $acc_url);
		$data = curl_exec($ch);

		if (stripos($data, 'Success') !== FALSE) {
			echo "Success! ";
			$new_accounts[] = array($email, $pass);

			if ($set_name) {
			// Create a random name for the account
				$name = randomValue(10, array('lower'));
				$info = array(
					'guid'     => $email,
					'password' => $pass,
					'ignore'   => randomValue(4, array('number')),
					'name'     => $name
				);
				$name_url = $base_url . 'account/setName?' . http_build_query($info);

				curl_setopt($ch, CURLOPT_URL, $name_url);
				$data = curl_exec($ch);

				if (stripos($data, 'Success')) {
					echo "New name set as \"$name\"!\n";
				} else {
					echo "Failed to set new name: $data\n";
				}
			}

			if ($set_security_answers) {
			// Set the security answers for the mule to the answers defined at the top
				$info = array(
					'guid'          => $email,
					'password'      => $pass,
					'signedRequest' => '',
					'answers'       => implode("|", $security_answers)
				);
				$security_url = $base_url . 'account/saveSecurityQuestions?' . http_build_query($info);

				curl_setopt($ch, CURLOPT_URL, $security_url);
				$data = curl_exec($ch);

				if( stripos($data, 'Success')) {
					echo "Security answers saved!\n";
				} else {
					echo "Failed to save security answers: $data\n";
				}
			}
		} else {
			echo "Failed: $data\n";
		}
	}

	curl_close($ch);


// Make sure the accounts.js file exists, that we can read it and write to it
	if (file_exists($accountsjs) && is_readable($accountsjs) && is_writable($accountsjs)) {
	// Create new accounts.js
		$old = file_get_contents($accountsjs);

	// Locate the end of the accounts variable
		$pos = 0;
		$lines = explode( "\n", $old );
		foreach( $lines as $key => $line ) {
			if( stripos($line, "}// don't delete this line!") !== FALSE ) {
				$pos = $key;
				break;
			}
		}
	// Find the very last email:password line in the accounts variable
		while( empty( trim( $lines[ $pos-1 ] ))) $pos--;


		$new = array();
		for($i = 0; $i < $pos; $i++ ) {
			$new[] = $lines[$i];
		}

		foreach( $new_accounts as $acc ) {
			$new[] = "'{$acc[0]}':'{$acc[1]}',";
		}

		for($i = $pos; $i < count($lines); $i++ ) {
			$new[] = $lines[$i];
		}

		$new_accountsjs = implode("\n", $new);

		file_put_contents( $accountsjs, $new_accountsjs );
	}

// Check the email to get all the new "verify your email" messages
	if ($check_email) {
	// Make sure the IMP extension is loaded
		if (extension_loaded('imap')) {
			echo PHP_EOL . "Checking GMail. This may take awhile." . PHP_EOL;
			if(!$terminal) {
			// This isnt from a terminal so lets try to flush all the output above
				ob_flush();
				flush();
			}
		// Sleep for a few seconds so we dont check the mailbox before any emails have arrived
			sleep(5);

			$inbox  = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $base_email, $gmail_pass) or die('Cannot connect to Gmail: ' . imap_last_error());
			$emails = imap_search($inbox, 'FROM "noreply@wildshadow.com"'); // Only find emails we need
			if ($emails) {
				foreach ($emails as $id) {
				// Get the email overview before we get the entire message
					$overview = imap_fetch_overview($inbox, $id);
				// Check if it is a new "Verify Email" message
					if (stripos($overview[0]->subject, "Verify email") !== false && !$overview[0]->seen) {
						$message = imap_fetchbody($inbox, $id, 1);
					// Break the message body into lines so we can find the link
						$lines = explode("\n", $message);
						foreach ($lines as $line) {
							if (stripos($line, "realmofthemadgod.appspot.com") !== false) {
								if ($terminal) {
								// Open web browser to the verify link
									shell_exec( "start chrome \"$line\"");
								} else {
								// Output a link to click since we cant use shell_exec from the browser
									echo "<a href=\"$line\" target=\"_blank\">$line</a> |";
								}
								break;
							}
						}
					}
				}
			} else {
				echo "Didnt find any emails.";
			}
		} else {
			echo "You are missing the IMAP extension.";
		}
	}


// Function to generate a random value
	function randomValue( $length, $base = array( 'lower' )) {
		$char_array = array();
		foreach( $base as $val ) {
			if( $val == 'lower' ) {
				$char_array[] = 'abcdefghijklmnopqrstuvwxyz';
			} elseif( $val == 'upper' ) {
				$char_array[] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
			} elseif( $val == 'number' ) {
				$char_array[] = '0123456789';
			} elseif( $val == 'symbol' ) {
				$char_array[] = '_-!#$@';
			}
		}
		$chars = implode($char_array);

		$charLength = strlen($chars) - 1;
		$return = array();
		$good = false;
		while( !$good ) {
			$return = array();
			for ($i = 0; $i < $length; $i++) {
				$n = rand(0, $charLength);
				$return[] = $chars[$n];
			}
		// If number was specified, then make sure the return value has atleast 1 number in it
			if( in_array('number', $base)) {
				for($i = 0; $i < count( $return ); $i++ ) {
					if( is_numeric( $return[$i] )) {
						$good = true;
						break;
					}
				}
			} else {
				$good = true;
			}
		}
		return implode( $return );
	}

?>
Quote Originally Posted by toddddd View Post
So ive been playing around with my script here every now and then, and i just wanted to post an update for anyone that either uses this or is interested in it. I know some people dont like PHP, but i actually work in php for my job and dont have any issues with it ever, so this is what i like to use to make quick little scripts like this.

I added a few new features to the script. You can now set the security questions for the mule it just created as well as the name and everything. I added this for a few reason, the first is that i get really annoyed when i go to open a mule from muledump and i have to answer the stupid security questions before i can login. The other reason is to keep track of the security questions i use, if i only use the same 3 security questions (maybe not too smart) then i wont forget or type it wrong/etc anytime.

I also added the ability to open your gmail and get the link from the "verify email" messages. If you run this through the command prompt/terminal then it will try to launch chrome with the url (you can change that int he script if you dont use chrome). But if you used a web browser to run the script then it will just echo out a link for you to click that takes you to the verify page. For the script to do this you will need to go into your gmail settings first and enable the IMAP settings. Then i also had to go to "My Account > Sign-in & security" and at the very bottom there is an option called "Allow less secure apps", that has to be enabled for the script to login to your gmail.

With these changes its now super easy for me to get a mule created, named, security questions answered, and verified.

Here is the code, i did my best to comment stuff so hopefully it is easy to understand.
 
CODE
Code:
<?php set_time_limit(0);

// Determin if the script was called from command line or web browser
$terminal = false;
if (php_sapi_name() == "cli") {
	$terminal = true;
}

//Set this to false if you dont want it to generate a randon name for the mule
$set_name = true;
// Set this to false if you dont want it to set the mules security ansers
$set_security_answers = true;
// Set this to false if you dont want the script to try and check your email for you
$check_email = true;

// Set these variables to be used in the script
$base_email = "YOUR_GMAIL";
$gmail_pass = "GMAIL_PASSWORD"; // dont need this unless you have $check_email set as true
$start_num  = 1;
$total      = 10;

// API Base URL
$base_url = "http://realmofthemadgod.appspot.com/";
// Location of accounts.js file
$accountsjs = "PATH/TO/accounts.js";

// Security Answers that will get set if $set_security_answers is true
$security_answers = array(
	base64_encode("security answer 1"),
	base64_encode("security answer 2"),
	base64_encode("security answer 3")
);

/* Uncomment this block if you want the script to take arguments when it runs instead of having the values hardcoded above this
// Check if this script was called with arguments
	if (isset($argv) && is_array($argv)) {
	// Make sure there are 3 arguments after the script name
		if (count($argv) < 4) {
			echo "This script takes 3 arguments. The email without the domain, the starting number, and the total number of accounts to create.\n";
			exit();
		} else {
			$base_email = $argv[1];
			$start_num  = $argv[2];
			$total      = $argv[3];
		}
	} else {
	// Make sure the email is set
		if (empty( $_REQUEST['e'])) {
			die( 'No email provided.' );
		} else {
			$base_email = urldecode($_REQUEST['e']);
		}

	// Make sure the starting number is set
		if (empty($_REQUEST['s'])) {
			die( 'Missing starting number.' );
		} else {
			$start_num = $_REQUEST['s'];
		}
	// Make sure the number of accounts is set
		if (empty($_REQUEST['q'])) {
			die( 'Missing number of accounts to create.' );
		} else {
			$total = $_REQUEST['q'];
		}
	}
*/

// Make sure the email doesnt have the domain attached
	if (stripos($base_email, '@') !== FALSE) {
		list($base_email, $domain) = explode('@', $base_email);
	}

// Create cURL handle
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Array to hold new accounts
	$new_accounts = array();

	for ($i = 0; $i < $total; $i++) {
	// Create the email
		$email = $base_email . '+' . str_pad($i + $start_num, 4, '0', STR_PAD_LEFT) . '@gmail.com';
	// Generate a random password 11 characters long
		$pass = randomValue(11, array('lower','upper','number','symbol'));
	// Account info
		$info = array(
			'guid'          => randomValue(26, array('upper','number')), // This is just a random (and useless?) value
			'newGUID'       => $email, 
			'ignore'        => randomValue(4, array('number')),
			'newPassword'   => $pass,
			'isAgeVerified' => 1
		);
	// Create full url
		$acc_url = $base_url . 'account/register?' . http_build_query($info);

		echo "Creating \"$email:$pass\"....";

		curl_setopt($ch, CURLOPT_URL, $acc_url);
		$data = curl_exec($ch);

		if (stripos($data, 'Success') !== FALSE) {
			echo "Success! ";
			$new_accounts[] = array($email, $pass);

			if ($set_name) {
			// Create a random name for the account
				$name = randomValue(10, array('lower'));
				$info = array(
					'guid'     => $email,
					'password' => $pass,
					'ignore'   => randomValue(4, array('number')),
					'name'     => $name
				);
				$name_url = $base_url . 'account/setName?' . http_build_query($info);

				curl_setopt($ch, CURLOPT_URL, $name_url);
				$data = curl_exec($ch);

				if (stripos($data, 'Success')) {
					echo "New name set as \"$name\"!\n";
				} else {
					echo "Failed to set new name: $data\n";
				}
			}

			if ($set_security_answers) {
			// Set the security answers for the mule to the answers defined at the top
				$info = array(
					'guid'          => $email,
					'password'      => $pass,
					'signedRequest' => '',
					'answers'       => implode("|", $security_answers)
				);
				$security_url = $base_url . 'account/saveSecurityQuestions?' . http_build_query($info);

				curl_setopt($ch, CURLOPT_URL, $security_url);
				$data = curl_exec($ch);

				if( stripos($data, 'Success')) {
					echo "Security answers saved!\n";
				} else {
					echo "Failed to save security answers: $data\n";
				}
			}
		} else {
			echo "Failed: $data\n";
		}
	}

	curl_close($ch);


// Make sure the accounts.js file exists, that we can read it and write to it
	if (file_exists($accountsjs) && is_readable($accountsjs) && is_writable($accountsjs)) {
	// Create new accounts.js
		$old = file_get_contents($accountsjs);

	// Locate the end of the accounts variable
		$pos = 0;
		$lines = explode( "\n", $old );
		foreach( $lines as $key => $line ) {
			if( stripos($line, "}// don't delete this line!") !== FALSE ) {
				$pos = $key;
				break;
			}
		}
	// Find the very last email:password line in the accounts variable
		while( empty( trim( $lines[ $pos-1 ] ))) $pos--;


		$new = array();
		for($i = 0; $i < $pos; $i++ ) {
			$new[] = $lines[$i];
		}

		foreach( $new_accounts as $acc ) {
			$new[] = "'{$acc[0]}':'{$acc[1]}',";
		}

		for($i = $pos; $i < count($lines); $i++ ) {
			$new[] = $lines[$i];
		}

		$new_accountsjs = implode("\n", $new);

		file_put_contents( $accountsjs, $new_accountsjs );
	}

// Check the email to get all the new "verify your email" messages
	if ($check_email) {
	// Make sure the IMP extension is loaded
		if (extension_loaded('imap')) {
			echo PHP_EOL . "Checking GMail. This may take awhile." . PHP_EOL;
			if(!$terminal) {
			// This isnt from a terminal so lets try to flush all the output above
				ob_flush();
				flush();
			}
		// Sleep for a few seconds so we dont check the mailbox before any emails have arrived
			sleep(5);

			$inbox  = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $base_email, $gmail_pass) or die('Cannot connect to Gmail: ' . imap_last_error());
			$emails = imap_search($inbox, 'FROM "noreply@wildshadow.com"'); // Only find emails we need
			if ($emails) {
				foreach ($emails as $id) {
				// Get the email overview before we get the entire message
					$overview = imap_fetch_overview($inbox, $id);
				// Check if it is a new "Verify Email" message
					if (stripos($overview[0]->subject, "Verify email") !== false && !$overview[0]->seen) {
						$message = imap_fetchbody($inbox, $id, 1);
					// Break the message body into lines so we can find the link
						$lines = explode("\n", $message);
						foreach ($lines as $line) {
							if (stripos($line, "realmofthemadgod.appspot.com") !== false) {
								if ($terminal) {
								// Open web browser to the verify link
									shell_exec( "start chrome \"$line\"");
								} else {
								// Output a link to click since we cant use shell_exec from the browser
									echo "<a href=\"$line\" target=\"_blank\">$line</a> |";
								}
								break;
							}
						}
					}
				}
			} else {
				echo "Didnt find any emails.";
			}
		} else {
			echo "You are missing the IMAP extension.";
		}
	}


// Function to generate a random value
	function randomValue( $length, $base = array( 'lower' )) {
		$char_array = array();
		foreach( $base as $val ) {
			if( $val == 'lower' ) {
				$char_array[] = 'abcdefghijklmnopqrstuvwxyz';
			} elseif( $val == 'upper' ) {
				$char_array[] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
			} elseif( $val == 'number' ) {
				$char_array[] = '0123456789';
			} elseif( $val == 'symbol' ) {
				$char_array[] = '_-!#$@';
			}
		}
		$chars = implode($char_array);

		$charLength = strlen($chars) - 1;
		$return = array();
		$good = false;
		while( !$good ) {
			$return = array();
			for ($i = 0; $i < $length; $i++) {
				$n = rand(0, $charLength);
				$return[] = $chars[$n];
			}
		// If number was specified, then make sure the return value has atleast 1 number in it
			if( in_array('number', $base)) {
				for($i = 0; $i < count( $return ); $i++ ) {
					if( is_numeric( $return[$i] )) {
						$good = true;
						break;
					}
				}
			} else {
				$good = true;
			}
		}
		return implode( $return );
	}

?>
Cool stuff
That's really amazing, I'm super impressed with all the features you added.
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?