Skip to content

Commit c0fcf8e

Browse files
committed
expose stuff as less as possible
1 parent 3f2e76f commit c0fcf8e

10 files changed

Lines changed: 51 additions & 11 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.csploit.msf;
2+
3+
import java.util.Collection;
4+
5+
/**
6+
* An object that can be tuned up
7+
* by editing it's options.
8+
*/
9+
public interface Customizable {
10+
void setOption(String key, String value);
11+
Collection<Option> getOptions();
12+
Collection<String> getInvalidOptions();
13+
<T> T getOptionValue(Option<T> option);
14+
}

msf/src/main/java/org/csploit/msf/DataHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
/**
44
* A class that hold a DataStore instance
55
*/
6-
public interface DataHolder {
6+
interface DataHolder {
77
DataStore getDataStore();
88
}

msf/src/main/java/org/csploit/msf/Framework.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
package org.csploit.msf;
22

3+
import java.util.Collection;
4+
35
/**
46
* Represent a MetaSploit Framework instance
57
*/
68
public class Framework implements DataHolder {
79

810
private DataStore dataStore;
911
private ModuleManager moduleManager;
12+
private JobContainer jobs;
13+
private SessionManager sessions;
1014

1115
public Framework() {
1216
dataStore = new DataStore();
1317
moduleManager = new ModuleManager(this, "all");
18+
jobs = new JobContainer();
19+
sessions = new SessionManager(this);
1420
}
1521

1622
@Override
@@ -21,4 +27,8 @@ public DataStore getDataStore() {
2127
public ModuleManager getModuleManager() {
2228
return moduleManager;
2329
}
30+
31+
public void setGlobalOption(String key, String value) {
32+
getDataStore().put(key, value);
33+
}
2434
}

msf/src/main/java/org/csploit/msf/JobContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
* keeping track of arbitrary contexts that may or may not require a dedicated
99
* thread.
1010
*/
11-
public class JobContainer extends HashMap<Integer, Job> {
11+
class JobContainer extends HashMap<Integer, Job> {
1212
}

msf/src/main/java/org/csploit/msf/Module.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Represent a module of the MSF
1212
*/
13-
public abstract class Module implements Offspring, DataHolder {
13+
public abstract class Module implements Offspring, DataHolder, Customizable {
1414
protected Author[] authors;
1515
protected ArchSet arch;
1616
protected PlatformList platform;
@@ -87,10 +87,26 @@ public void registerOption(String name, Option option, boolean advanced, boolean
8787
options.addOption(name, option, advanced, evasion);
8888
}
8989

90-
public Collection<String> getinvalidOptions() {
90+
@Override
91+
public void setOption(String key, String value) {
92+
getDataStore().put(key, value);
93+
}
94+
95+
@Override
96+
public Collection<Option> getOptions() {
97+
return options.values();
98+
}
99+
100+
@Override
101+
public Collection<String> getInvalidOptions() {
91102
return options.getInvalidOptions(getDataStore());
92103
}
93104

105+
@Override
106+
public <T> T getOptionValue(Option<T> option) {
107+
return option.normalize(getDataStore().get(option.getName()));
108+
}
109+
94110
@Override
95111
public int hashCode() {
96112
return refname != null ? refname.hashCode() : 0;

msf/src/main/java/org/csploit/msf/ModuleManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Manage all framework modules
88
*/
9-
public class ModuleManager implements Offspring {
9+
class ModuleManager implements Offspring {
1010

1111
private final static String[] validModuleTypes = {
1212
"encoder",

msf/src/main/java/org/csploit/msf/ModuleSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* A module set contains zero or more named module classes of an arbitrary
1010
* type.
1111
*/
12-
public class ModuleSet extends HashMap<String, Module> implements Offspring {
12+
class ModuleSet extends HashMap<String, Module> implements Offspring {
1313
protected String type;
1414
private Framework framework;
1515

msf/src/main/java/org/csploit/msf/Offspring.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* CLasses that ave a reference to the framework
55
*/
6-
public interface Offspring {
6+
interface Offspring {
77
boolean haveFramework();
88
Framework getFramework();
99
void setFramework(Framework framework);

msf/src/main/java/org/csploit/msf/SessionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* applicable to the way that the command interpreter is communicated
1414
* with.
1515
*/
16-
public class SessionManager extends HashMap<Integer, Session> implements Offspring {
16+
class SessionManager extends HashMap<Integer, Session> implements Offspring {
1717
private Framework framework;
1818

1919
public SessionManager(Framework framework) {

msf/src/test/java/org/csploit/msf/RpcSampleTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ public void putExploitTest() {
168168

169169
// exploit settings should not be valid without the required RHOST options
170170

171-
assertThat(exploit.getinvalidOptions().isEmpty(), is(false));
171+
assertThat(exploit.getInvalidOptions().isEmpty(), is(false));
172172

173173
framework.getDataStore().put("RHOST", "invalid address");
174174

175-
assertThat(exploit.getinvalidOptions().isEmpty(), is(false));
175+
assertThat(exploit.getInvalidOptions().isEmpty(), is(false));
176176

177177
framework.getDataStore().put("RHOST", "127.0.0.1");
178178

179-
assertThat(exploit.getinvalidOptions().isEmpty(), is(true));
179+
assertThat(exploit.getInvalidOptions().isEmpty(), is(true));
180180
}
181181

182182
private static Option getOptionForInfo(String name, ModuleOptionInfo info) {

0 commit comments

Comments
 (0)