V1.2.1 Allow base64 output in hash-replies.properties

master
Ng Yat Yan 1 month ago
parent a0143e96f5
commit 7714bcba1a

@ -0,0 +1,13 @@
#!/bin/bash
PID=`ps -ef | grep echo-sshd-server.jar | grep -v grep | awk '{print $2}'`
if [ -z "$PID" ]
then
sudo nohup /opt/jdk-17/bin/java -jar echo-sshd-server.jar conf > logs/exec.log 2>&1 &
sleep 1
PID=`ps -ef | grep echo-sshd-server.jar | grep -v grep | awk '{print $2}'`
echo "started echo-sshd-server.jar pid: $PID"
else
echo "already exist echo-sshd-server.jar pid: $PID"
fi

@ -0,0 +1,9 @@
#!/bin/bash
PID=`ps -ef | grep echo-sshd-server | grep -v grep | awk '{print $2}'`
if [ -z "$PID" ]
then
echo "echo-sshd-server is already dead! $PID"
else
sudo kill -9 $PID
echo "killed echo-sshd-server pid: $PID"
fi

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.sshd</groupId>
<artifactId>echo-sshd-server</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<name>ECHO SSH SERVER</name>
<description>Learning Apache Mina SSHD library</description>
<parent>

@ -11,6 +11,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.sshd.server.session.ServerSession;
import org.bouncycastle.util.encoders.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -33,18 +34,19 @@ public class ReplyUtil {
public boolean replyToCommand(String command, OutputStream out, String prompt, ServerSession session)
throws IOException {
String remoteIpAddress = "";
String cmdHash = DigestUtils.md5Hex(command.trim()).toUpperCase();
if (session.getIoSession().getRemoteAddress() instanceof InetSocketAddress) {
InetSocketAddress remoteAddress = (InetSocketAddress) session.getIoSession().getRemoteAddress();
remoteIpAddress = remoteAddress.getAddress().getHostAddress();
} else {
remoteIpAddress = session.getIoSession().getRemoteAddress().toString();
}
Thread.currentThread().setName(remoteIpAddress);
if (StringUtils.equals(command.trim(), "about")) {
logger.info("[{}] About command detected: {}", cmdHash, command.trim());
if (session.getIoSession().getRemoteAddress() instanceof InetSocketAddress) {
InetSocketAddress remoteAddress = (InetSocketAddress) session.getIoSession().getRemoteAddress();
String remoteIpAddress = remoteAddress.getAddress().getHostAddress();
out.write(String.format("\r\n%s\r\n%s", ipInfoMapping.get(remoteIpAddress), prompt).getBytes());
} else {
out.write(String.format("\r\n%s\r\n%s", session.getIoSession().getRemoteAddress(), prompt).getBytes());
}
out.write(String.format("\r\n%s\r\n%s", ipInfoMapping.get(remoteIpAddress), prompt).getBytes());
} else if (StringUtils.equals(command.trim(), "exit")) {
logger.info("[{}] Exiting command detected: {}", cmdHash, command.trim());
out.write(String.format("\r\nExiting...\r\n%s", prompt).getBytes());
@ -59,6 +61,11 @@ public class ReplyUtil {
String reply = hashReplies.getProperty(cmdHash).replace("\\r", "\r").replace("\\n", "\n").replace("\\t",
"\t");
out.write(String.format("\r\n%s\r\n%s", reply, prompt).getBytes());
} else if (hashReplies.containsKey(String.format("base64(%s)",cmdHash))) {
logger.info("[{}] Known base64-hash detected: {}", cmdHash, command.trim());
String reply = hashReplies.getProperty(String.format("base64(%s)",cmdHash));
reply = new String(Base64.decode(reply));
out.write(String.format("\r\n%s\r\n%s", reply, prompt).getBytes());
} else {
Optional<Pair<String, String>> o = regexMapping.entrySet().stream()
.filter(e -> command.trim().matches(((String) e.getKey())))

Loading…
Cancel
Save