Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Msf restyling #855

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions msf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions msf/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apply plugin: 'java'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-codec:commons-codec:1.10'
compile 'org.msgpack:msgpack:0.6.12'
}
32 changes: 32 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Arch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.csploit.msf.api;

/**
* Machines architectures
*
* source: lib/rex/constants.rb
*/
public enum Arch {
ANY,
X86,
X86_64,
X64,
MIPS,
MIPSLE,
MIPSBE,
PPC,
PPC64,
CBEA,
CBEA64,
SPARC,
CMD,
PHP,
TTY,
ARMLE,
ARMBE,
JAVA,
RUBY,
DALVIK,
PYTHON,
NODEJS,
FIREFOX
}
9 changes: 9 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Author.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.csploit.msf.api;

/**
* Represent an author
*/
public interface Author {
String getName();
String getEmail();
}
14 changes: 14 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Auxiliary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.csploit.msf.api;

import org.csploit.msf.api.module.AuxiliaryAction;

/**
* The auxiliary class acts as a base class for all modules that perform
* reconnaissance, retrieve data, brute force logins, or any other action
* that doesn't fit our concept of an 'exploit' (involving payloads and
* targets and whatnot).
*/
public interface Auxiliary extends Module, Executable {
AuxiliaryAction[] getActions();
AuxiliaryAction getDefaultAction();
}
56 changes: 56 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.csploit.msf.api;

import org.csploit.msf.api.sessions.Interactive;

import java.io.IOException;

/**
* A console interface to a Msf instance
*/
public interface Console extends Interactive {
/**
* get the ID of the console
* @return the console ID
*/
int getId();

/**
* get the prompt of the console
* @return a string that should be used as prompt for new commands
*/
String getPrompt();

/**
* get the console busy state
* @return {@code true} if the console is busy, {@code false} otherwise
*/
boolean isBusy();

/**
* close this console
*/
void close() throws IOException, MsfException;

/**
* write to this console
* @param data the data to write
*/
void write(String data) throws IOException, MsfException;

/**
* get tab completion for a command
* @param part partial command to complete
* @return an array of possibilities
*/
String[] tab(String part) throws IOException, MsfException;

/**
* kill the session attached to this console, if any
*/
void killSession() throws IOException, MsfException;

/**
* detach from an attached session, if any
*/
void detachSession() throws IOException, MsfException;
}
64 changes: 64 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/ConsoleManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.csploit.msf.api;

import org.csploit.msf.api.exceptions.ResourceNotFoundException;
import org.csploit.msf.api.listeners.ConsoleListener;

import java.io.IOException;
import java.util.List;

/**
* Manage consoles
*/
public interface ConsoleManager extends Publisher<ConsoleListener> {
/**
* get a list of consoles managed by this {@link ConsoleManager}
* @return a list of consoles managed by this {@link ConsoleManager}
*/
List<? extends Console> getConsoles() throws IOException, MsfException;

/**
* get a console by it's id
* @param id of the console
* @return the console with the supplied id
* @throws ResourceNotFoundException when a console with
* the specified {@code id} cannot be found
*/
Console getConsole(int id) throws IOException, MsfException;

/**
* Create a new console
*
* @param allowCommandPassthru Whether to allow
* unrecognized commands to be executed by the system shell
* @param realReadline Whether to use the system's
* readline library instead of RBReadline
* @param histFile Path to a file
* where we can store command history
* @param resources A list of resource files to load.
* If no resources are given, will load the default resource script,
* 'msfconsole.rc' in the user's config directory
* @param skipDatabaseInit Whether to skip connecting to the database
* and running migrations
* @return a new {@link Console}
*/
Console create(boolean allowCommandPassthru, boolean realReadline,
String histFile, String[] resources, boolean skipDatabaseInit)
throws IOException, MsfException;

/**
* Create a new Console using framework defaults settings
*
* @return a new {@link Console}
*/
Console create() throws IOException, MsfException;

/**
* start watching for consoles output
*/
void start();

/**
* stop watching for consoles output
*/
void stop();
}
15 changes: 15 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Customizable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.csploit.msf.api;

import java.io.IOException;
import java.util.Collection;

/**
* An object that can be tuned up
* by editing it's options.
*/
public interface Customizable {
void setOption(String key, String value);
Collection<Option> getOptions() throws IOException, MsfException;
Collection<String> getInvalidOptions();
<T> T getOptionValue(Option<T> option);
}
10 changes: 10 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Executable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.csploit.msf.api;

import java.io.IOException;

/**
* Something that can be executed
*/
public interface Executable {
void execute() throws IOException, MsfException;
}
29 changes: 29 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Exploit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.csploit.msf.api;

import org.csploit.msf.api.module.Target;

import java.io.IOException;
import java.util.List;

/**
* Represent an exploit module
*/
public interface Exploit extends Module, Executable {
Target[] getTargets();

/**
* Returns the active target for this exploit. If not target has been
* defined, {@code null} is returned. If no target was defined but there is a
* default target, that one will be automatically used.
* @return the active target for this exploit.
*/
Target getTarget();
void setTarget(int i);

/**
* get compatible {@link Payload} for this exploit against the selected target.
*
* @return a list of compatible {@link Payload}
*/
List<? extends Payload> getCompatiblePayloads() throws IOException, MsfException;
}
20 changes: 20 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Framework.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.csploit.msf.api;

import java.io.IOException;
import java.util.EventListener;
import java.util.List;

/**
* A Metasploit Framework interface
*/
public interface Framework extends Publisher<EventListener> {
List<? extends Session> getSessions() throws IOException, MsfException;
List<? extends Exploit> getExploits() throws IOException, MsfException;
List<? extends Payload> getPayloads() throws IOException, MsfException;
List<? extends Post> getPosts() throws IOException, MsfException;
Module getModule(String refname) throws IOException, MsfException;
List<? extends Job> getJobs() throws IOException, MsfException;
Job getJob(int id) throws IOException, MsfException;
void setGlobalOption(String key, String value);
void unsetGlobalOption(String key);
}
13 changes: 13 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Job.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.csploit.msf.api;

import java.util.Date;

/**
* This class is the representation of an abstract job.
*/
public interface Job {
int getId();
String getName();
Date getStartTime();
void stop();
}
32 changes: 32 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/License.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.csploit.msf.api;

/**
* A license
*/
public enum License {
MSF("Metasploit Framework License (BSD)"),
GPL("GNU Public License v2.0"),
BSD("BSD License"),
ARTISTIC("Perl Artistic License"),
UNKNOWN("Unknown License");

String name;

License(String name) {
this.name = name;
}

public String toString() {
return name;
}

public static License fromString(String value) {
if(value != null) {
for (License l : values()) {
if (l.name.toLowerCase().startsWith(value.toLowerCase()))
return l;
}
}
return UNKNOWN;
}
}
24 changes: 24 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.csploit.msf.api;

import org.csploit.msf.api.module.Platform;
import org.csploit.msf.api.module.Rank;
import org.csploit.msf.api.module.Reference;

import java.util.Set;

/**
* Represent a module of the MSF
*/
public interface Module extends Customizable, Comparable<Module> {
String getRefname();
String getFullName();
String getShortName();
String getDescription();
String getName();
License getLicense();
Rank getRank();
Reference[] getReferences();
Author[] getAuthors();
Set<Arch> getArches();
Set<Platform> getPlatforms();
}
14 changes: 14 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/MsfException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.csploit.msf.api;

/**
* An error occurred in the framework
*/
public class MsfException extends Exception {
public MsfException(String message) {
super(message);
}

public MsfException(String message, Throwable cause) {
super(message, cause);
}
}
36 changes: 36 additions & 0 deletions msf/src/main/java/org/csploit/msf/api/Option.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.csploit.msf.api;

/**
* An option
*/
public interface Option<T> {
boolean isAdvanced();
boolean haveDefaultValue();
boolean isEvasion();
boolean isRequired();
T getDefaultValue();
String getDescription();
String getName();
Module getOwner();

/**
* show a string representation of an option
* @param input the value to display
* @return a string representation of an option
*/
String display(T input);

/**
* check if a value is suitable for this option
* @param value the value to check
* @return {@code true} if value is valid, {@code false} otherwise
*/
boolean isValid(T value);

/**
* normalize a string for this option
* @param value the String to normalize
* @return the normalized value
*/
T normalize(String value);
}
Loading