Skip to content
Merged
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
7 changes: 2 additions & 5 deletions RAVEN/RAVEN-SERVER/src/main/java/com/raven/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ private static void StartInterface(String Host, int Port, ListenerMode Mode, Str
case "gui" -> GUI.Launch(Config);
case "teamserver" -> {
int ApiPort = ParseInt(Arg(Args, "-tp", "-tport", String.valueOf(Config.GetTeamServerPort())), Config.GetTeamServerPort());
int WebPort = ParseInt(Arg(Args, "-wp", "-web-port", "-1"), -1);
TeamServer BackendServer = new TeamServer(Config, Mode);
BackendServer.RunAsBackend(Config.GetWebHost(), ApiPort);
if (WebPort > 0) BackendServer.StartWebPanel(Config.GetWebHost(), WebPort);
new TeamServer(Config, Mode).RunAsBackend(Config.GetWebHost(), ApiPort);
Thread.currentThread().join();
}
case "teamserver-cli" -> {
Expand Down Expand Up @@ -216,7 +213,7 @@ private static void RevokeAgent(String AgentId) {

private static void DeployAgent(String AgentId, String CertPath, String Host, int Port,
boolean UseMtls, boolean Persist, boolean Hide, String Lang) throws IOException {
String OutputDir = "IMPLANT/" + AgentId.toUpperCase();
String OutputDir = Config.GetAgentOutputDir() + "/" + AgentId.toUpperCase();
Files.createDirectories(Paths.get(OutputDir));
Files.copy(Paths.get(CertPath), Paths.get(OutputDir + "/agent.p12"), StandardCopyOption.REPLACE_EXISTING);
Files.copy(Paths.get(Config.GetCaPath()), Paths.get(OutputDir + "/ca.p12"), StandardCopyOption.REPLACE_EXISTING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public Map<Integer, CommandResult> BroadcastDispatch(List<Integer> SessionIds, S

public Map<Integer, CommandResult> BroadcastAllDispatch(String UserCommand) {
Map<Integer, CommandResult> Results = new LinkedHashMap<>();
for (Session S : Server.GetSessions().GetAll()) Results.put(S.GetId(), Dispatch(S.GetId(), UserCommand));
if (Server == null || !Server.IsRunning()) return Results;
for (Session AgentSession : Server.GetSessions().GetAll())
Results.put(AgentSession.GetId(), Dispatch(AgentSession.GetId(), UserCommand));
return Results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,19 @@ public DispatchResult Dispatch(String Command, String[] Parts) {
}
}
case "webstart" -> {
String WebHost = Parts.length > 1 ? Parts[1] : Config.GetWebHost();
int WebPort = Parts.length > 2 ? TaskCommands.ParseIntSafe(Parts[2], Config.GetWebPort()) : Config.GetWebPort();
String WebHost = Config.GetWebHost();
int WebPort = Config.GetWebPort();
for (int FlagIndex = 1; FlagIndex < Parts.length - 1; FlagIndex++) {
switch (Parts[FlagIndex].toLowerCase()) {
case "-lhost", "-host", "-h" -> { WebHost = Parts[FlagIndex + 1]; FlagIndex++; }
case "-lport", "-port", "-p" -> { WebPort = TaskCommands.ParseIntSafe(Parts[FlagIndex + 1], WebPort); FlagIndex++; }
}
}
if (Parts.length == 2 && !Parts[1].startsWith("-")) WebHost = Parts[1];
if (Parts.length == 3 && !Parts[1].startsWith("-")) {
WebHost = Parts[1];
WebPort = TaskCommands.ParseIntSafe(Parts[2], WebPort);
}
WebPanelManager.Start(WebHost, WebPort, ServerManager.GetServer(), ServerManager.GetServerStartTime());
}
case "webstop" -> WebPanelManager.Stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public record CommandDef(String Name, String Usage, String Description, Category

Register("status", "status", "Show server mode, uptime, and database status", Category.SERVER, false);
Register("logs", "logs", "Show recent server event logs", Category.SERVER, false);
Register("start", "start -lhost <host> -lport <port> -M <mode>", "Start agent listener (modes: multi, raw, http, https, tls, mtls, fmtls)", Category.SERVER, false);
Register("start", "start [-lhost <host>] [-lport <port>] [-M <mode>]", "Start agent listener modes: multi|raw|http|https|tls|mtls|fmtls flags: -h/-host/-lhost -p/-port/-lport -m/-M/-mode", Category.SERVER, false);
Register("stop", "stop", "Stop the running agent listener", Category.SERVER, false);

Register("sessions", "sessions", "List all active agent sessions", Category.SESSION, false);
Expand Down Expand Up @@ -134,7 +134,7 @@ public record CommandDef(String Name, String Usage, String Description, Category
Register("cloneprofile", "cloneprofile <source> <target>", "Clone an existing profile under a new name", Category.PROFILE, false);
Register("editprofile", "editprofile <name> <key> <value>", "Set a single key in a saved profile", Category.PROFILE, false);

Register("webstart", "webstart [host] [port]", "Start the web panel server", Category.WEB, false);
Register("webstart", "webstart [-lhost <host>] [-lport <port>]", "Start web panel flags: -h/-host/-lhost -p/-port/-lport (or positional: webstart <host> <port>)", Category.WEB, false);
Register("webstop", "webstop", "Stop the web panel server", Category.WEB, false);
Register("webstatus", "webstatus", "Show web panel current status", Category.WEB, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,27 @@ public void Run(String TargetStr, String FormatStr) {
}
}

@SuppressWarnings("unchecked")
private void ExportAll(Format ExportFormat) {
Map<String, Object> Bundle = new LinkedHashMap<>();
Bundle.put("exported_at", LocalDateTime.now().format(LogFmt));
Bundle.put("logs", CollectLogs());
Bundle.put("chat", CollectChat());
Bundle.put("history", CollectHistory());
Bundle.put("sessions", CollectSessions());
Bundle.put("operators", CollectOperators());
Bundle.put("notes", CollectNotes());
Bundle.put("logs", CollectLogs());
Bundle.put("chat", CollectChat());
Bundle.put("history", CollectHistory());
Bundle.put("sessions", CollectSessions());
Bundle.put("operators", CollectOperators());
Bundle.put("notes", CollectNotes());
if (ExportFormat == Format.JSON) {
WriteRaw("export_all", "json", Gson.toJson(Bundle));
} else {
StringBuilder Builder = new StringBuilder();
Builder.append("RAVEN FULL EXPORT — ").append(LocalDateTime.now().format(LogFmt)).append("\n\n");
AppendSection(Builder, "SERVER LOGS", CollectLogs());
AppendSection(Builder, "CHAT HISTORY", CollectChat());
AppendSection(Builder, "COMMAND HISTORY", CollectHistory());
AppendSection(Builder, "SESSION HISTORY", CollectSessions());
AppendSection(Builder, "OPERATORS", CollectOperators());
AppendSection(Builder, "AGENT NOTES", CollectNotes());
AppendSection(Builder, "SERVER LOGS", (List<Map<String, Object>>) Bundle.get("logs"));
AppendSection(Builder, "CHAT HISTORY", (List<Map<String, Object>>) Bundle.get("chat"));
AppendSection(Builder, "COMMAND HISTORY", (List<Map<String, Object>>) Bundle.get("history"));
AppendSection(Builder, "SESSION HISTORY", (List<Map<String, Object>>) Bundle.get("sessions"));
AppendSection(Builder, "OPERATORS", (List<Map<String, Object>>) Bundle.get("operators"));
AppendSection(Builder, "AGENT NOTES", (List<Map<String, Object>>) Bundle.get("notes"));
WriteRaw("export_all", "txt", Builder.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ public CertificateManager(ServerConfig Config) {
}

private void EnsureDirs() {
for (String Dir : new String[] { Config.GetAgentCertDir(), Paths.get(Config.GetKeystorePath()).getParent().toString(), Paths.get(Config.GetCaPath()).getParent().toString(), Paths.get(Config.GetTruststorePath()).getParent().toString() }) {
java.util.List<String> Dirs = new java.util.ArrayList<>();
Dirs.add(Config.GetAgentCertDir());
for (String PathStr : new String[] {
Config.GetKeystorePath(),
Config.GetCaPath(),
Config.GetTruststorePath() }) {
java.nio.file.Path Parent = Paths.get(PathStr).getParent();
if (Parent != null) Dirs.add(Parent.toString());
}
for (String Dir : Dirs) {
try {
Files.createDirectories(Paths.get(Dir));
} catch (IOException E) {
Logger.Warn("Cannot create dir [" + Dir + "]: " + E.getMessage());
} catch (IOException DirException) {
Logger.Warn("Cannot create dir [" + Dir + "]: " + DirException.getMessage());
}
}
}
Expand Down Expand Up @@ -244,7 +253,8 @@ private void RemoveFromTruststore(String Alias) throws Exception {
}

private void SaveP12(String Path, String Password, String Alias, PrivateKey Key, X509Certificate[] Chain) throws Exception {
Files.createDirectories(Paths.get(Path).getParent());
java.nio.file.Path Parent = Paths.get(Path).getParent();
if (Parent != null) Files.createDirectories(Parent);
KeyStore Ks = EmptyPkcs12();
Ks.setKeyEntry(Alias, Key, Password.toCharArray(), Chain);
SaveKeystore(Ks, Path, Password);
Expand All @@ -270,7 +280,8 @@ private void ExportPem(String Path, X509Certificate Cert, PrivateKey Key) {
}

private static void SaveKeystore(KeyStore Ks, String Path, String Password) throws Exception {
Files.createDirectories(Paths.get(Path).getParent());
java.nio.file.Path Parent = Paths.get(Path).getParent();
if (Parent != null) Files.createDirectories(Parent);
try (OutputStream Out = new FileOutputStream(Path)) {
Ks.store(Out, Password == null ? new char[0] : Password.toCharArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,29 @@ public EventLog(int MaxEntries) {
this.Entries = new CopyOnWriteArrayList<>();
}

public void Add(String Message, boolean PrintNow) {
String Entry = "[" + LocalDateTime.now().format(RavenConstants.TimestampFmt) + "] " + Message;
public void Add(String Level, String Message, boolean PrintNow) {
String Entry = "[" + LocalDateTime.now().format(RavenConstants.TimestampFmt) + "] [" + Level + "] " + Message;
Entries.add(Entry);
if (Entries.size() > MaxEntries) Entries.remove(0);
if (PrintNow) Logger.Info(Entry);
if (PrintNow) {
switch (Level) {
case "WARN" -> Logger.Warn(Entry);
case "ERROR" -> Logger.Error(Entry);
default -> Logger.Info(Entry);
}
}
}

public void Add(String Level, String Message) {
Add(Level, Message, false);
}

public void Add(String Message, boolean PrintNow) {
Add("INFO", Message, PrintNow);
}

public void Add(String Message) {
Add(Message, false);
Add("INFO", Message, false);
}

public int Count() {
Expand Down
93 changes: 49 additions & 44 deletions RAVEN/RAVEN-SERVER/src/main/java/com/raven/core/output/Logger.java
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
package com.raven.core.output;

import com.raven.core.output.PromptManager;
import com.raven.utils.AnsiColor;
import com.raven.utils.RavenConstants;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.raven.utils.RavenConstants;
import java.time.LocalDateTime;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public final class Logger {

public enum Level {
VERBOSE,
DEBUG,
INFO,
WARN,
ERROR
VERBOSE, DEBUG, INFO, WARN, ERROR
}

private static volatile Level CurrentLevel = Level.INFO; private static volatile boolean Verbose = false;
private static volatile boolean FileEnabled = false;
private static volatile String LogFilePath = "logs/raven.log";
private static volatile int MaxEntries = 1000;
private static volatile Level CurrentLevel = Level.INFO;
private static volatile boolean Verbose = false;
private static volatile boolean FileEnabled = false;
private static volatile String LogFilePath = "logs/raven.log";
private static volatile int MaxEntries = 1000;

private static final BlockingQueue<String> FileQueue = new ArrayBlockingQueue<>(4096);
private static Thread WriterThread;

private Logger() {}

public static void Configure(String Level, boolean IsVerbose, boolean EnableFile, String FilePath, int MaxEnt) {
CurrentLevel = ParseLevel(Level);
Verbose = IsVerbose;
FileEnabled = EnableFile;
LogFilePath = FilePath;
MaxEntries = MaxEnt;
public static void Configure(String LevelName, boolean IsVerbose, boolean EnableFile, String FilePath, int MaxEnt) {
CurrentLevel = ParseLevel(LevelName);
Verbose = IsVerbose;
FileEnabled = EnableFile;
LogFilePath = FilePath;
MaxEntries = MaxEnt;
if (EnableFile) StartFileWriter(FilePath);
}

private static Level ParseLevel(String LogLevel) {
private static Level ParseLevel(String LevelName) {
try {
return Level.valueOf(LogLevel.toUpperCase());
} catch (Exception E) {
return Level.valueOf(LevelName.toUpperCase());
} catch (Exception Ignored) {
return Level.INFO;
}
}

private static void StartFileWriter(String Path) {
try {
Files.createDirectories(Paths.get(Path).getParent());
} catch (Exception Ignored) {}
java.nio.file.Path Parent = Paths.get(Path).getParent();
if (Parent != null) {
try { Files.createDirectories(Parent); } catch (Exception Ignored) {}
}
WriterThread = new Thread(() -> {
try (BufferedWriter StrObject = new BufferedWriter(new FileWriter(Path, true))) {
try (BufferedWriter Writer = new BufferedWriter(new FileWriter(Path, true))) {
while (!Thread.currentThread().isInterrupted()) {
try {
StrObject.write(FileQueue.take());
StrObject.newLine();
StrObject.flush();
} catch (InterruptedException E) {
Writer.write(FileQueue.take());
Writer.newLine();
Writer.flush();
} catch (InterruptedException InterruptedException) {
Thread.currentThread().interrupt();
break;
}
}
} catch (IOException WriteException) {
PromptManager.PrintLine("[ERROR] Log file writer failed: " + WriteException.getMessage());
PromptManager.PrintLine(
AnsiColor.White + "[" + AnsiColor.Red + "ERROR" + AnsiColor.White + "] " +
"Log file writer failed: " + WriteException.getMessage() + AnsiColor.Reset);
}
}, "LogFileWriter");
WriterThread.setDaemon(true);
Expand All @@ -76,34 +76,34 @@ private static String Timestamp() {
return LocalDateTime.now().format(RavenConstants.TimestampFmt);
}

private static String Format(String Message, Object[] Args) {
if (Args == null || Args.length == 0) return Message;
private static String Format(String Message, Object... Args) {
if (Args == null || Args.length == 0) return Message.replace("%n", System.lineSeparator());
try {
return String.format(Message, Args);
} catch (java.util.IllegalFormatException E) {
return Message + " [FORMAT_ERROR: " + E.getMessage() + "]";
} catch (java.util.IllegalFormatException FormatException) {
return Message + " [FORMAT_ERROR: " + FormatException.getMessage() + "]";
}
}

private static void Emit(Level MessageLevel, String PlainTag, String ColorCode, String Message, Object[] Args) {
private static void Emit(Level MessageLevel, String PlainTag, String LevelColor, String Message, Object[] Args) {
if (MessageLevel.ordinal() < CurrentLevel.ordinal()) return;
String Formatted = Format(Message, Args);
String ColorLine = ColorCode + "[" + PlainTag + "]" + AnsiColor.Reset + " " + Formatted;
String Formatted = Format(Message, Args);
String ColorLine = AnsiColor.White + "[" + LevelColor + PlainTag + AnsiColor.White + "] " + Formatted + AnsiColor.Reset;
String PlainLine = "[" + Timestamp() + "] [" + PlainTag + "] " + Formatted;
PromptManager.PrintLine(ColorLine);
if (FileEnabled) FileQueue.offer(PlainLine);
}

public static void Info(String Message, Object... Args) {
Emit(Level.INFO, "INFO", AnsiColor.Cyan, Message, Args);
Emit(Level.INFO, "INFO", AnsiColor.Blue, Message, Args);
}

public static void Warn(String Message, Object... Args) {
Emit(Level.WARN, "WARN", AnsiColor.Orange, Message, Args);
Emit(Level.WARN, "WARN", AnsiColor.Yellow, Message, Args);
}

public static void Error(String Message, Object... Args) {
Emit(Level.ERROR, "ERROR", AnsiColor.BrightRed, Message, Args);
Emit(Level.ERROR, "ERROR", AnsiColor.Red, Message, Args);
}

public static void Debug(String Message, Object... Args) {
Expand All @@ -114,13 +114,18 @@ public static void Success(String Message, Object... Args) {
Emit(Level.INFO, "OK", AnsiColor.Green, Message, Args);
}

public static void Ok(String Message, Object... Args) {
Emit(Level.INFO, "OK", AnsiColor.Green, Message, Args);
}

public static void Verbose(String Message, Object... Args) {
if (!Verbose) return;
Emit(Level.VERBOSE, "TRACE", AnsiColor.Dim, Message, Args);
}

public static void Custom(String Text) {
System.out.println(Text);
System.out.print(Format(Text));
System.out.flush();
}

public static void Custom(String Text, Object... Args) {
Expand All @@ -129,11 +134,11 @@ public static void Custom(String Text, Object... Args) {
}

public static void Custom(String Text, long DelayMs) {
System.out.println(Text);
System.out.print(Format(Text));
System.out.flush();
if (DelayMs > 0) {
try {
Thread.sleep(DelayMs);
} catch (InterruptedException Ignored) {}
try { Thread.sleep(DelayMs); }
catch (InterruptedException InterruptedException) { Thread.currentThread().interrupt(); }
}
}

Expand Down
Loading
Loading