diff --git a/misc/start-jar.sh b/misc/start-jar.sh
new file mode 100644
index 0000000..2ff7b54
--- /dev/null
+++ b/misc/start-jar.sh
@@ -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
+
+
diff --git a/misc/stop.sh b/misc/stop.sh
new file mode 100644
index 0000000..9a23235
--- /dev/null
+++ b/misc/stop.sh
@@ -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
diff --git a/pom.xml b/pom.xml
index da71e31..a135198 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.example.sshd
echo-sshd-server
- 1.2.0
+ 1.2.1
ECHO SSH SERVER
Learning Apache Mina SSHD library
diff --git a/src/main/java/com/example/sshd/util/ReplyUtil.java b/src/main/java/com/example/sshd/util/ReplyUtil.java
index 1250ceb..0515fd0 100644
--- a/src/main/java/com/example/sshd/util/ReplyUtil.java
+++ b/src/main/java/com/example/sshd/util/ReplyUtil.java
@@ -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> o = regexMapping.entrySet().stream()
.filter(e -> command.trim().matches(((String) e.getKey())))