Skip to content

Commit 3f2e76f

Browse files
committed
created Job and Session classes and interfaces
1 parent bda9c1c commit 3f2e76f

11 files changed

Lines changed: 347 additions & 0 deletions
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.csploit.msf;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* This class is the concrete representation of an abstract job.
7+
*/
8+
public class Job {
9+
10+
private JobContainer container;
11+
private int id;
12+
private String name;
13+
protected Exploit exploit;
14+
protected Payload payload;
15+
private Date startTime;
16+
17+
public Job(JobContainer container, int id, String name, Exploit exploit, Payload payload) {
18+
this.container = container;
19+
this.id = id;
20+
this.name = name;
21+
this.exploit = exploit;
22+
this.payload = payload;
23+
}
24+
25+
public void setStartTime(Date startTime) {
26+
this.startTime = startTime;
27+
}
28+
29+
public int getId() {
30+
return id;
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public Date getStartTime() {
38+
return startTime;
39+
}
40+
41+
public void stop() {
42+
container.remove(id);
43+
}
44+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.csploit.msf;
2+
3+
import java.util.HashMap;
4+
5+
/**
6+
* This class contains zero or more abstract jobs that can be enumerated and
7+
* stopped in a generic fashion. This is used to provide a mechanism for
8+
* keeping track of arbitrary contexts that may or may not require a dedicated
9+
* thread.
10+
*/
11+
public class JobContainer extends HashMap<Integer, Job> {
12+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package org.csploit.msf;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* The session class represents a post-exploitation, uh, session.
8+
* Sessions can be written to, read from, and interacted with. The
9+
* underlying medium on which they are backed is arbitrary. For
10+
* instance, when an exploit is provided with a command shell,
11+
* either through a network connection or locally, the session's
12+
* read and write operations end up reading from and writing to
13+
* the shell that was spawned. The session object can be seen
14+
* as a general means of interacting with various post-exploitation
15+
* payloads through a common interface that is not necessarily
16+
* tied to a network connection.
17+
*/
18+
public abstract class Session implements Offspring {
19+
private Framework framework;
20+
private int id;
21+
private String localTunnel;
22+
private String peerTunnel;
23+
private Exploit exploit;
24+
private Payload payload;
25+
private String description;
26+
private String info;
27+
private String workspace;
28+
private String sessionHost;
29+
private int sessionPort;
30+
private String targetHost;
31+
private String username;
32+
private String uuid;
33+
private List<String> routes = new ArrayList<>();
34+
35+
public Session(int id) {
36+
this.id = id;
37+
}
38+
39+
public int getId() {
40+
return id;
41+
}
42+
43+
public String getLocalTunnel() {
44+
return localTunnel;
45+
}
46+
47+
public void setLocalTunnel(String localTunnel) {
48+
this.localTunnel = localTunnel;
49+
}
50+
51+
public String getPeerTunnel() {
52+
return peerTunnel;
53+
}
54+
55+
public void setPeerTunnel(String peerTunnel) {
56+
this.peerTunnel = peerTunnel;
57+
}
58+
59+
public Exploit getExploit() {
60+
return exploit;
61+
}
62+
63+
public void setExploit(Exploit exploit) {
64+
this.exploit = exploit;
65+
}
66+
67+
public Payload getPayload() {
68+
return payload;
69+
}
70+
71+
public void setPayload(Payload payload) {
72+
this.payload = payload;
73+
}
74+
75+
public String getDescription() {
76+
return description;
77+
}
78+
79+
public void setDescription(String description) {
80+
this.description = description;
81+
}
82+
83+
public String getInfo() {
84+
return info;
85+
}
86+
87+
public void setInfo(String info) {
88+
this.info = info;
89+
}
90+
91+
public String getWorkspace() {
92+
return workspace;
93+
}
94+
95+
public void setWorkspace(String workspace) {
96+
this.workspace = workspace;
97+
}
98+
99+
public String getSessionHost() {
100+
return sessionHost;
101+
}
102+
103+
public void setSessionHost(String sessionHost) {
104+
this.sessionHost = sessionHost;
105+
}
106+
107+
public int getSessionPort() {
108+
return sessionPort;
109+
}
110+
111+
public void setSessionPort(int sessionPort) {
112+
this.sessionPort = sessionPort;
113+
}
114+
115+
public String getTargetHost() {
116+
return targetHost;
117+
}
118+
119+
public void setTargetHost(String targetHost) {
120+
this.targetHost = targetHost;
121+
}
122+
123+
public String getUsername() {
124+
return username;
125+
}
126+
127+
public void setUsername(String username) {
128+
this.username = username;
129+
}
130+
131+
public String getUuid() {
132+
return uuid;
133+
}
134+
135+
public void setUuid(String uuid) {
136+
this.uuid = uuid;
137+
}
138+
139+
@Override
140+
public boolean haveFramework() {
141+
return framework != null;
142+
}
143+
144+
@Override
145+
public Framework getFramework() {
146+
return framework;
147+
}
148+
149+
@Override
150+
public void setFramework(Framework framework) {
151+
this.framework = framework;
152+
}
153+
154+
public abstract String getType();
155+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.csploit.msf;
2+
3+
import java.util.HashMap;
4+
5+
/**
6+
* The purpose of the session manager is to keep track of sessions that are
7+
* created during the course of a framework instance's lifetime. When
8+
* exploits succeed, the payloads they use will create a session object,
9+
* where applicable, there will implement zero or more of the core
10+
* supplied interfaces for interacting with that session. For instance,
11+
* if the payload supports reading and writing from an executed process,
12+
* the session would implement SimpleCommandShell in a method that is
13+
* applicable to the way that the command interpreter is communicated
14+
* with.
15+
*/
16+
public class SessionManager extends HashMap<Integer, Session> implements Offspring {
17+
private Framework framework;
18+
19+
public SessionManager(Framework framework) {
20+
this.framework = framework;
21+
}
22+
23+
@Override
24+
public Framework getFramework() {
25+
return framework;
26+
}
27+
28+
@Override
29+
public boolean haveFramework() {
30+
return framework != null;
31+
}
32+
33+
@Override
34+
public void setFramework(Framework framework) {
35+
this.framework = framework;
36+
}
37+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.csploit.msf.session;
2+
3+
import org.csploit.msf.Session;
4+
5+
/**
6+
* This class provides basic interaction with a command shell on the remote
7+
* endpoint. This session is initialized with a stream that will be used
8+
* as the pipe for reading and writing the command shell.
9+
*/
10+
public abstract class CommandShell extends Session implements SingleCommandShell, Scriptable {
11+
public CommandShell(int id) {
12+
super(id);
13+
}
14+
15+
@Override
16+
public String getType() {
17+
return "shell";
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.csploit.msf.session;
2+
3+
import org.csploit.msf.Session;
4+
5+
/**
6+
* This class represents a session compatible interface to a meterpreter server
7+
* instance running on a remote machine. It provides the means of interacting
8+
* with the server instance both at an API level as well as at a console level.
9+
*/
10+
public abstract class Meterpreter extends Session implements SingleCommandShell, Scriptable {
11+
public Meterpreter(int id) {
12+
super(id);
13+
}
14+
15+
@Override
16+
public String getType() {
17+
return "meterpreter";
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.csploit.msf.session;
2+
3+
/**
4+
* Executes multiple commands and optionally allows for reading/writing I/O
5+
* to the new processes.
6+
*/
7+
public interface MultiCommandExecution extends SingleCommandExecution {
8+
int exec(String cmd, String[] args, boolean hidden);
9+
String read(int length, int id);
10+
int write(String data, int id);
11+
void close(int id);
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.csploit.msf.session;
2+
3+
/**
4+
* This interface is to be implemented by a session that is capable of
5+
* providing multiple command shell interfaces simultaneously. Inherently,
6+
* MultiCommandShell classes must also provide a mechanism by which they can
7+
* implement the SingleCommandShell interface.
8+
*/
9+
public interface MultiCommandShell extends SingleCommandShell {
10+
int open();
11+
String read(int length, int id);
12+
int write(String data, int id);
13+
void close(int id);
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.csploit.msf.session;
2+
3+
/**
4+
* Represent a session that can run scripts
5+
*/
6+
public interface Scriptable {
7+
boolean executeFile(String path, String[] args);
8+
int executeScript(String scriptName, String[] args);
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.csploit.msf.session;
2+
3+
/**
4+
* Executes a single command and optionally allows for reading/writing I/O
5+
* to the new process.
6+
*
7+
* footnote: I didn't found any implementors of this interface in the framework
8+
*/
9+
public interface SingleCommandExecution {
10+
void init(String cmd, String[] args); // TODO: options ??
11+
String read(int length);
12+
int write(String data);
13+
void close();
14+
}

0 commit comments

Comments
 (0)