Skip to content

Commit

Permalink
add dump function
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1t3p1g committed Oct 15, 2023
1 parent 40675e6 commit 6c0766b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
33 changes: 25 additions & 8 deletions cli/src/main/java/ysomap/cli/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public void dispatch(List<String> words) throws Exception {
break;
case "dump":
dump();
Logger.success("Dump to dumped.yso.");
break;
case "":
//do nothing
Expand Down Expand Up @@ -378,34 +377,52 @@ public void list() throws ArgumentsMissMatchException {
}

public void dump(){
if(args.isEmpty()){
args.add("dumped.yso");
}

if(args.size() == 1 && curSession != null){
StringBuilder sb = new StringBuilder();
Map<String, String> parameters = new HashMap<>();
if(curSession.exploit != null){
sb.append("# exploit settings\n");
sb.append(curSession.exploit.dump());
parameters.putAll(curSession.exploit.getAllParameters());
Map<String, String> parameters = curSession.exploit.getAllParameters();

for(Map.Entry<String, String> entry:parameters.entrySet()){
sb.append(String.format("set %s %s\n", entry.getKey(), entry.getValue()));
}
}

if(curSession.payload != null){
if(curSession.bullet != null){
curSession.payload.setBullet(curSession.bullet);
}
sb.append("\n");
sb.append("# payload settings\n");
sb.append(curSession.payload.dump());
parameters.putAll(curSession.payload.getAllParameters());
}

for(Map.Entry<String, String> entry:parameters.entrySet()){
sb.append(String.format("set %s %s\n", entry.getKey(), entry.getValue()));
sb.append("# serializer settings\n");
sb.append(String.format("set serializeType %s\n", curSession.payload.getSerializeType()));
sb.append(String.format("set encoder %s\n", curSession.payload.getEncoder()));
sb.append(String.format("set output %s\n", curSession.payload.getOutputType()));
sb.append(String.format("set serialVersionUID %s\n", curSession.payload.getSerialVersionUID()));
sb.append(String.format("set checkRunning %s\n", curSession.payload.getCheckRunning()));
Map<String, String> parameters = curSession.payload.getAllParameters();
sb.append("# bullet settings\n");
for(Map.Entry<String, String> entry:parameters.entrySet()){
sb.append(String.format("set %s %s\n", entry.getKey(), entry.getValue()));
}
}

if(sb.toString().isEmpty()){
Logger.normal("Nothing to dump.");
return;
}

sb.append("# start to run\n");
sb.append("run\n");
try {
FileHelper.filePutContent(args.get(0), sb.toString().getBytes());
Logger.success(String.format("Dump settings to '%s'.", args.get(0)));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
5 changes: 5 additions & 0 deletions cli/src/main/java/ysomap/cli/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public HashMap<String, Object> update(Class<?> clazz){
}

public void setValue(String key, String value) throws ArgumentsMissMatchException {
if("null".equals(value)){
value = null;
}

if("serializeType".equals(key) && payload != null){
payload.setSerializeType(value);
return;
Expand All @@ -137,6 +141,7 @@ public void setValue(String key, String value) throws ArgumentsMissMatchExceptio
return;
}else if("checkRunning".equals(key)){
isCheckRunning = Boolean.parseBoolean(value);
payload.setCheckRunning(isCheckRunning);
return;
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/ysomap/payloads/AbstractPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class AbstractPayload<T> implements Payload<T>{
// 自由定义
public String serializerEncoder;
public String serializerSerialVersionUID;
public boolean checkRunning = false;
public Bullet bullet;

public AbstractPayload(){
Expand Down Expand Up @@ -54,6 +55,16 @@ public void setSerialVersionUID(String uid) {
this.serializerSerialVersionUID = uid;
}

@Override
public void setCheckRunning(boolean flag) {
checkRunning = flag;
}

@Override
public boolean getCheckRunning() {
return checkRunning;
}

@Override
final public T getObject() throws Exception {
// check bullet args first
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/ysomap/payloads/Payload.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public interface Payload<T> {
void setOutputType(String outputType);

void setSerialVersionUID(String uid);
void setCheckRunning(boolean flag);

boolean getCheckRunning();
String getSerializeType();

String getEncoder();
Expand Down

0 comments on commit 6c0766b

Please sign in to comment.