debian12 - 修改SSH端口连接回包

文章目录

debian12 - 修改SSH端口连接回包

概述

和同学讨论问题。

他说,用telnet去连接SSH端口,回包内容能看出系统版本和SSH版本。

用原装的debian12 + win10上的telnet连接了一下,确实如此。

bash 复制代码
telnet 192.168.236.133 22
bash 复制代码
SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u1 // 这个连接时发送给客户段的信息有点敏感。
// 光标停在上一行首,不停闪烁
// 自己主动按下回车键,断开连接。

Invalid SSH identification string.


遗失对主机的连接。

笔记

想做个实验,尝试修改用telnet连接SSH端口时的回包,隐藏linux系统版本和SSH版本这些敏感信息。

用真机和虚拟机没区别,且用虚拟机做实验,可以回到自己保存的快照。

先切到安装完debian12原版且配置好了SSH的快照。

先猜猜回包是哪个程序回的

大概率是openssh回的,因为这是ssh的服务。连接,通讯都是openssh处理的。

看看openssh的版本。

bash 复制代码
lostspeed@debian12d4x64:~$ ssh -V
OpenSSH_9.2p1 Debian-2+deb12u1, OpenSSL 3.0.11 19 Sep 2023

去下载对应版本的openssh代码工程

最方便的方法是用apt-get, 不用自己导出去找,直接从debian源中就能下载相同版本的源码工程。

bash 复制代码
lostspeed@debian12d4x64:~$ pwd
/home/lostspeed

mkdir ./src
cd ./src

## 先确认安装依赖的软件
## 所有要先附加安装的依赖软件,都是根据后续操作报错提示来安装的。
sudo apt-get install dpkg-dev

## 用apt-get自动下载系统中对应的软件源码包
sudo apt-get source openssh
## 。。。
dpkg-source: info: applying CVE-2023-51384.patch
dpkg-source: info: applying CVE-2023-51385.patch
W: 由于文件'openssh_9.2p1-2+deb12u2.dsc'无法被用户'_apt'访问,已脱离沙盒并提权为根用户来进行下载。 - pkgAcquire::Run (13: 权限不够)
lostspeed@debian12d4x64:~/src$ ls
openssh-9.2p1  openssh_9.2p1-2+deb12u2.debian.tar.xz  openssh_9.2p1-2+deb12u2.dsc  openssh_9.2p1.orig.tar.gz  openssh_9.2p1.orig.tar.gz.asc
## 下载最后,有个报错,说openssh_9.2p1-2+deb12u2.dsc不可用,但是东西都下载全了,忽略这个错误。

代码已经下载到了本地,版本和正在用的openssh相同。

源码目录已经自动解开了

开始配置,make, make install

配置时,如果错误,根据报错提示,将依赖的软件包装上。

bash 复制代码
cd openssh-9.2p1
lostspeed@debian12d4x64:~/src/openssh-9.2p1$ ls -l configure*
-rwxr-xr-x 1 root root 649619 2023年 2月 2日 configure
-rw-r--r-- 1 root root 160383  8月26日 22:57 configure.ac

## 配置时,就不要加预设路径了,等安装完,改系统中的ssh服务的配置文件去。
## 如果安装的路径和系统中现有的ssh不同,也不要紧,服务程序都是配置文件指定的。
## sudo ./configure
## configure: error: ./configure.ac newer than configure, run autoreconf

## sudo apt-get install autotools-dev
## sudo apt list *auto*conf*
sudo apt-get install autoconf
sudo autoupdate
sudo autoreconf
## sudo ./configure
## sudo apt list *zlib*
sudo apt-get install zlib1g-dev
## sudo apt list *openssl*
sudo apt install libssl-dev
sudo ./configure
sudo make
sudo make install
bash 复制代码
## /usr/local/etc/sshd_config line 86: Unsupported option UsePAM

安装报错。
修改/home/lostspeed/src/openssh-9.2p1/sshd_config,注释掉UsePAM选项, 重新安装
sudo vi /home/lostspeed/src/openssh-9.2p1/sshd_config
bash 复制代码
sudo make clean
sudo make
sudo rm /usr/local/share/man/man5/authorized_keys.5 /usr/local/etc/sshd_config /usr/local/etc/ssh_config /usr/local/etc/moduli
clear && sudo make install

## 记录一下安装提示,方便后面改ssh服务脚本
Makefile:688: warning: ignoring prerequisites on suffix rule definition
(cd openbsd-compat && make)
make[1]: 进入目录"/home/lostspeed/src/openssh-9.2p1/openbsd-compat"
make[1]: 对"all"无需做任何事。
make[1]: 离开目录"/home/lostspeed/src/openssh-9.2p1/openbsd-compat"
/usr/bin/mkdir -p /usr/local/bin
/usr/bin/mkdir -p /usr/local/sbin
/usr/bin/mkdir -p /usr/local/share/man/man1
/usr/bin/mkdir -p /usr/local/share/man/man5
/usr/bin/mkdir -p /usr/local/share/man/man8
/usr/bin/mkdir -p /usr/local/libexec
/usr/bin/mkdir -p -m 0755 /var/empty
/usr/bin/install -c -m 0755 -s ssh /usr/local/bin/ssh
/usr/bin/install -c -m 0755 -s scp /usr/local/bin/scp
/usr/bin/install -c -m 0755 -s ssh-add /usr/local/bin/ssh-add
/usr/bin/install -c -m 0755 -s ssh-agent /usr/local/bin/ssh-agent
/usr/bin/install -c -m 0755 -s ssh-keygen /usr/local/bin/ssh-keygen
/usr/bin/install -c -m 0755 -s ssh-keyscan /usr/local/bin/ssh-keyscan
/usr/bin/install -c -m 0755 -s sshd /usr/local/sbin/sshd
/usr/bin/install -c -m 4711 -s ssh-keysign /usr/local/libexec/ssh-keysign
/usr/bin/install -c -m 0755 -s ssh-pkcs11-helper /usr/local/libexec/ssh-pkcs11-helper
/usr/bin/install -c -m 0755 -s ssh-sk-helper /usr/local/libexec/ssh-sk-helper
/usr/bin/install -c -m 0755 -s sftp /usr/local/bin/sftp
/usr/bin/install -c -m 0755 -s sftp-server /usr/local/libexec/sftp-server
/usr/bin/install -c -m 644 ssh.1.out /usr/local/share/man/man1/ssh.1
/usr/bin/install -c -m 644 scp.1.out /usr/local/share/man/man1/scp.1
/usr/bin/install -c -m 644 ssh-add.1.out /usr/local/share/man/man1/ssh-add.1
/usr/bin/install -c -m 644 ssh-agent.1.out /usr/local/share/man/man1/ssh-agent.1
/usr/bin/install -c -m 644 ssh-keygen.1.out /usr/local/share/man/man1/ssh-keygen.1
/usr/bin/install -c -m 644 ssh-keyscan.1.out /usr/local/share/man/man1/ssh-keyscan.1
/usr/bin/install -c -m 644 moduli.5.out /usr/local/share/man/man5/moduli.5
/usr/bin/install -c -m 644 sshd_config.5.out /usr/local/share/man/man5/sshd_config.5
/usr/bin/install -c -m 644 ssh_config.5.out /usr/local/share/man/man5/ssh_config.5
/usr/bin/install -c -m 644 sshd.8.out /usr/local/share/man/man8/sshd.8
ln -s ../man8/sshd.8 /usr/local/share/man/man5/authorized_keys.5
/usr/bin/install -c -m 644 sftp.1.out /usr/local/share/man/man1/sftp.1
/usr/bin/install -c -m 644 sftp-server.8.out /usr/local/share/man/man8/sftp-server.8
/usr/bin/install -c -m 644 ssh-keysign.8.out /usr/local/share/man/man8/ssh-keysign.8
/usr/bin/install -c -m 644 ssh-pkcs11-helper.8.out /usr/local/share/man/man8/ssh-pkcs11-helper.8
/usr/bin/install -c -m 644 ssh-sk-helper.8.out /usr/local/share/man/man8/ssh-sk-helper.8
/usr/bin/mkdir -p /usr/local/etc
/usr/local/sbin/sshd -t -f /usr/local/etc/sshd_config

找一下系统中的sshd

bash 复制代码
lostspeed@debian12d4x64:~/src/openssh-9.2p1$ whereis sshd
sshd: /usr/sbin/sshd /usr/local/sbin/sshd /usr/share/man/man8/sshd.8.gz
## /usr/sbin/sshd 是系统中原始的
## /usr/local/sbin/sshd 是咱自己编译安装的

看一下ssh服务在哪里?

bash 复制代码
clear && systemctl status ssh

可知:

服务脚本为/lib/systemd/system/ssh.service

服务程序是 /usr/sbin/sshd

现在去修改/lib/systemd/system/ssh.service,来运行我们自己编译安装的sshd

sudo vi /lib/systemd/system/ssh.service

原始内容如下:

bash 复制代码
[Unit]
Description=OpenBSD Secure Shell server
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
RuntimeDirectory=sshd
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
Alias=sshd.service

修改如下

bash 复制代码
[Unit]
Description=OpenBSD Secure Shell server
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target auditd.service
# ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
# /etc/ssh/ => /usr/local/etc/
ConditionPathExists=!/usr/local/etc/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
# /usr/sbin/sshd => /usr/local/sbin/sshd
ExecStartPre=/usr/local/sbin/sshd -t
ExecStart=/usr/local/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/local/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
RuntimeDirectory=sshd
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target
Alias=sshd.service

关闭ssh服务/重启ssh服务

bash 复制代码
sudo systemctl status ssh
sudo systemctl daemon-reload
sudo systemctl status ssh ## 此时旧位置的服务已经停了
sudo systemctl stop ssh
sudo systemctl start ssh
sudo systemctl status ssh ## 此时启动的已经是新服务

为了拷贝文件方便,将ssh配置改为可以root登录。

bash 复制代码
lostspeed@debian12d4x64:~/src$ whereis sshd_config
sshd_config: /usr/local/etc/sshd_config /usr/share/man/man5/sshd_config.5.gz
sudo vi /usr/local/etc/sshd_config

修改内容如下:

bash 复制代码
#PermitRootLogin prohibit-password
PermitRootLogin yes

#PasswordAuthentication yes
PasswordAuthentication yes

重启ssh服务

bash 复制代码
sudo systemctl restart ssh
sudo systemctl status ssh

然后启动windTerm,用root用户登录。

bash 复制代码
## 传文件不方便,改变一下分组
sudo chown lostspeed:lostspeed openssh-9.2p1

openssh用的是syslog, 为了查看日志,需要安装rsyslog.

安装syslog(debian12 - rsyslog的安装/配置/使用)

查看实时日志 sudo tail -f /var/log/syslog

现在用telnet去连接debian12, 看看回的啥?日志里面记录的啥

bash 复制代码
telnet 192.168.236.133 22
bash 复制代码
SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u1

Invalid SSH identification string.


遗失对主机的连接。

/var/log/syslog 内容无变化。

那看看 /var/log/auth.log

sudo tail -f /var/log/auth.log

现在用telnet去连接debian12, 看看回的啥?日志里面记录的啥

bash 复制代码
2024-08-27T21:12:34.853546+08:00 debian12d4x64 sshd[14872]: error: kex_exchange_identification: client sent invalid protocol identifier ""
2024-08-27T21:12:34.854058+08:00 debian12d4x64 sshd[14872]: banner exchange: Connection from 192.168.236.1 port 58166: invalid format

有反应,但是显示的日志级别比较高。

改一下syslog日志的显示级别。

bash 复制代码
sudo systemctl status syslog

可以看到syslog的配置文件为rsyslog.conf

查一下这个配置文件的位置。

bash 复制代码
lostspeed@debian12d4x64:~/src/openssh-9.2p1$ whereis rsyslog.conf
rsyslog.conf: /etc/rsyslog.conf /usr/share/man/man5/rsyslog.conf.5.gz

查到rsyslog的配置文件位置 = /etc/rsyslog.conf

修改配置

bash 复制代码
sudo vi /etc/rsyslog.conf

/etc/rsyslog.conf 不需要改

暂时不知道syslog日志的显示级别怎么改,先这么用吧。

我自己做实验时(debian12 - rsyslog的安装/配置/使用), 每个级别的日志都能显示在/var/log/syslog中。

不知道为啥openssh的日志不显示在/var/log/syslog中。

好像是要配置sshd的日志显示级别才行,并不是配置syslog(因为syslog配置,默认全部级别的日志都是显示的)。

配置sshd日志

备注 - 如果自己还要make install, 还是要改工程目录下的sshd_config。
因为make install时,会将工程中的sshd_config覆盖到系统中的/usr/local/etc/sshd_config

bash 复制代码
lostspeed@debian12d4x64:~/src/openssh-9.2p1$ whereis sshd_config
sshd_config: /usr/local/etc/sshd_config /usr/share/man/man5/sshd_config.5.gz

配置文件为 /usr/local/etc/sshd_config
sudo vi /usr/local/etc/sshd_config
bash 复制代码
sudo systemctl restart ssh
sudo systemctl status ssh
sudo tail -f /var/log/syslog

现在将源码目录拷贝到研发本本上的win10, 研究一下该改哪里?

sudo tail -f /var/log/auth.log
现在用telnet去连接debian12, 看看回的啥?日志里面记录的啥

```bash
2024-08-27T21:12:34.853546+08:00 debian12d4x64 sshd[14872]: error: kex_exchange_identification: client sent invalid protocol identifier ""
2024-08-27T21:12:34.854058+08:00 debian12d4x64 sshd[14872]: banner exchange: Connection from 192.168.236.1 port 58166: invalid format

在sshd.c的main()入口附近,加一句print, 防止运行的不是我们改的最新版本。(这是错误的想法和做法)
这是服务,程序里面不能随便加printf, 但是可以加日志。
原因是:
应该是有命令行传值的用法。
这里有害, 不能加printf, 影响SFTP的建立
sshd.c的main()入口加了printf, 会使客户端(windTerm)无法建立SFTP连接。
还好改一改试一试,否则将对的东西改成错的,真不好找。

在日志初始化后面,再加一句日志,方便分清我们修改的版本。

将这个版本上传到debian12, 编译安装。

bash 复制代码
sudo make
sudo rm /usr/local/share/man/man5/authorized_keys.5 /usr/local/etc/sshd_config /usr/local/etc/ssh_config /usr/local/etc/moduli
clear && sudo make install
## 先实时查看日志 sudo tail -f /var/log/syslog
sudo systemctl restart ssh

现在可以确定,我们修改的sshd在被运行。

下面就可以看看SSH端口连接回包处理在哪里?

用win10的telnet去连接debian12的SSH端口。

/var/log/syslog 没动静。

那么看 auth.log

bash 复制代码
sudo tail -f /var/log/auth.log

用win10的telnet去连接debian12的SSH端口。

看到下面的日志。

bash 复制代码
2024-08-27T22:11:12.876836+08:00 debian12d4x64 sshd[15434]: sshd.c log init ok
2024-08-27T22:11:19.656429+08:00 debian12d4x64 sshd[15434]: error: kex_exchange_identification: client sent invalid protocol identifier ""
2024-08-27T22:11:19.656619+08:00 debian12d4x64 sshd[15434]: banner exchange: Connection from 192.168.236.1 port 59798: invalid format

结合auth.log中的日志信息和telnet上的回包信息,在源码中查找关心的提示字符串

在这个函数中翻了一下,函数名称为kex_exchange_identification(), 这里包含回包的字符串信息的逻辑。

就改这个函数,直接将回包敏感值不给telnet客户端, 加一些syslog日志,用logit()函数,记录INFO级别的日志信息。

修改后kex_exchange_identification()如下:

实质性的修改就是屏蔽了SSH版本回包,其他地方就是加几句日志确认一下流程

c 复制代码
/*
 * Sends our identification string and waits for the peer's. Will block for
 * up to timeout_ms (or indefinitely if timeout_ms <= 0).
 * Returns on 0 success or a ssherr.h code on failure.
 */
int
kex_exchange_identification(struct ssh *ssh, int timeout_ms,
    int debian_banner, const char *version_addendum)
{
	int remote_major, remote_minor, mismatch, oerrno = 0;
	size_t len, n;
	int r, expect_nl;
	u_char c;
	struct sshbuf *our_version = ssh->kex->server ?
	    ssh->kex->server_version : ssh->kex->client_version;
	struct sshbuf *peer_version = ssh->kex->server ?
	    ssh->kex->client_version : ssh->kex->server_version;
	char *our_version_string = NULL, *peer_version_string = NULL;
	char *cp, *remote_version = NULL;

	logit(">> kex_exchange_identification()"); // add by ls

	/* Prepare and send our banner */
	sshbuf_reset(our_version);
	if (version_addendum != NULL && *version_addendum == '\0')
		version_addendum = NULL;
	if ((r = sshbuf_putf(our_version, "SSH-%d.%d-%.100s%s%s\r\n",
	    PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2,
	    debian_banner ? SSH_RELEASE : SSH_RELEASE_MINIMUM,
	    version_addendum == NULL ? "" : " ",
	    version_addendum == NULL ? "" : version_addendum)) != 0) {
		oerrno = errno;
		error_fr(r, "sshbuf_putf");
		goto out;
	}

	// modify by ls
	// 这里发版本包的敏感信息给telnet客户端
	// 直接注释掉,不发给客户端了
	// 或者直接改为其他信息(e.g. "welcome to home")
	// 但是sshbuf数据结构的赋值,现在暂时还没做实验,就先不发送
//	if (atomicio(vwrite, ssh_packet_get_connection_out(ssh),
//	    sshbuf_mutable_ptr(our_version),
//	    sshbuf_len(our_version)) != sshbuf_len(our_version)) {
//		oerrno = errno;
//		debug_f("write: %.100s", strerror(errno));
//		r = SSH_ERR_SYSTEM_ERROR;
//		goto out;
//	}
	

	if ((r = sshbuf_consume_end(our_version, 2)) != 0) { /* trim \r\n */
		oerrno = errno;
		error_fr(r, "sshbuf_consume_end");
		goto out;
	}
	our_version_string = sshbuf_dup_string(our_version);
	if (our_version_string == NULL) {
		error_f("sshbuf_dup_string failed");
		r = SSH_ERR_ALLOC_FAIL;
		goto out;
	}
	debug("Local version string %.100s", our_version_string);
	logit("kex.c Local version string %.100s", our_version_string); // add by ls

	/* Read other side's version identification. */
	for (n = 0; ; n++) {
		if (n >= SSH_MAX_PRE_BANNER_LINES) {
			send_error(ssh, "No SSH identification string "
			    "received.");
			error_f("No SSH version received in first %u lines "
			    "from server", SSH_MAX_PRE_BANNER_LINES);
			r = SSH_ERR_INVALID_FORMAT;
			goto out;
		}
		sshbuf_reset(peer_version);
		expect_nl = 0;
		for (;;) {
			if (timeout_ms > 0) {
				r = waitrfd(ssh_packet_get_connection_in(ssh),
				    &timeout_ms);
				if (r == -1 && errno == ETIMEDOUT) {
					send_error(ssh, "Timed out waiting "
					    "for SSH identification string.");
					error("Connection timed out during "
					    "banner exchange");
					r = SSH_ERR_CONN_TIMEOUT;
					goto out;
				} else if (r == -1) {
					oerrno = errno;
					error_f("%s", strerror(errno));
					r = SSH_ERR_SYSTEM_ERROR;
					goto out;
				}
			}

			len = atomicio(read, ssh_packet_get_connection_in(ssh),
			    &c, 1);
			if (len != 1 && errno == EPIPE) {
				error_f("Connection closed by remote host");
				r = SSH_ERR_CONN_CLOSED;
				goto out;
			} else if (len != 1) {
				oerrno = errno;
				error_f("read: %.100s", strerror(errno));
				r = SSH_ERR_SYSTEM_ERROR;
				goto out;
			}
			if (c == '\r') {
				expect_nl = 1;
				continue;
			}
			if (c == '\n')
				break;
			if (c == '\0' || expect_nl) {
				error_f("banner line contains invalid "
				    "characters");
				goto invalid;
			}
			if ((r = sshbuf_put_u8(peer_version, c)) != 0) {
				oerrno = errno;
				error_fr(r, "sshbuf_put");
				goto out;
			}
			if (sshbuf_len(peer_version) > SSH_MAX_BANNER_LEN) {
				error_f("banner line too long");
				goto invalid;
			}
		}
		/* Is this an actual protocol banner? */
		if (sshbuf_len(peer_version) > 4 &&
		    memcmp(sshbuf_ptr(peer_version), "SSH-", 4) == 0)
			break;
		/* If not, then just log the line and continue */
		if ((cp = sshbuf_dup_string(peer_version)) == NULL) {
			error_f("sshbuf_dup_string failed");
			r = SSH_ERR_ALLOC_FAIL;
			goto out;
		}
		/* Do not accept lines before the SSH ident from a client */
		if (ssh->kex->server) {
			error_f("client sent invalid protocol identifier "
			    "\"%.256s\"", cp);
			free(cp);
			goto invalid;
		}
		debug_f("banner line %zu: %s", n, cp);
		free(cp);
	}
	peer_version_string = sshbuf_dup_string(peer_version);
	if (peer_version_string == NULL)
		error_f("sshbuf_dup_string failed");
	/* XXX must be same size for sscanf */
	if ((remote_version = calloc(1, sshbuf_len(peer_version))) == NULL) {
		error_f("calloc failed");
		r = SSH_ERR_ALLOC_FAIL;
		goto out;
	}

	/*
	 * Check that the versions match.  In future this might accept
	 * several versions and set appropriate flags to handle them.
	 */
	if (sscanf(peer_version_string, "SSH-%d.%d-%[^\n]\n",
	    &remote_major, &remote_minor, remote_version) != 3) {
		error("Bad remote protocol version identification: '%.100s'",
		    peer_version_string);
 invalid:
		send_error(ssh, "Invalid SSH identification string.");
		logit("Invalid SSH identification string."); // add by ls
		r = SSH_ERR_INVALID_FORMAT;
		goto out;
	}
	debug("Remote protocol version %d.%d, remote software version %.100s",
	    remote_major, remote_minor, remote_version);
	compat_banner(ssh, remote_version);

	mismatch = 0;
	switch (remote_major) {
	case 2:
		break;
	case 1:
		if (remote_minor != 99)
			mismatch = 1;
		break;
	default:
		mismatch = 1;
		break;
	}
	if (mismatch) {
		error("Protocol major versions differ: %d vs. %d",
		    PROTOCOL_MAJOR_2, remote_major);
		send_error(ssh, "Protocol major versions differ.");
		r = SSH_ERR_NO_PROTOCOL_VERSION;
		goto out;
	}

	if (ssh->kex->server && (ssh->compat & SSH_BUG_PROBE) != 0) {
		logit("probed from %s port %d with %s.  Don't panic.",
		    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh),
		    peer_version_string);
		r = SSH_ERR_CONN_CLOSED; /* XXX */
		goto out;
	}
	if (ssh->kex->server && (ssh->compat & SSH_BUG_SCANNER) != 0) {
		logit("scanned from %s port %d with %s.  Don't panic.",
		    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh),
		    peer_version_string);
		r = SSH_ERR_CONN_CLOSED; /* XXX */
		goto out;
	}
	if ((ssh->compat & SSH_BUG_RSASIGMD5) != 0) {
		logit("Remote version \"%.100s\" uses unsafe RSA signature "
		    "scheme; disabling use of RSA keys", remote_version);
	}
	/* success */
	r = 0;
 out:
	free(our_version_string);
	free(peer_version_string);
	free(remote_version);
	if (r == SSH_ERR_SYSTEM_ERROR)
		errno = oerrno;
	return r;
}

将kex.c更新到debian12中的src/openssh-9.2p1源码目录,重新编译安装。
每次在研发本本上修改后,最好是一股脑都传到debian12. 一定要在本地改,不要倒过来。防止漏改漏传漏归档。

值得注意的是工程目录中的sshd_config要修改成自己想要的(e.g. root)

bash 复制代码
sudo make
sudo rm /usr/local/share/man/man5/authorized_keys.5 /usr/local/etc/sshd_config /usr/local/etc/ssh_config /usr/local/etc/moduli
clear && sudo make install

sudo systemctl restart ssh
sudo tail -f /var/log/auth.log

如果在实验中,发现自己改的没效果,需要确认一下,是否启动ssh服务时,启动的是自己改的sshd. make install时,是否覆盖的是ssh服务中指定的位置和名称。

我中间就遇到了改来改去没效果,但是改的地方也对。最后发现,make install的位置和ssh服务中的位置不一样:P

将改过的openssh-9.2p1,通过windTerm整个拖到debian12, 更新到debian12中去编译/安装。

bash 复制代码
sudo systemctl stop ssh
sudo ./configure --prefix=/usr/sbin
## sudo make clean
sudo make clean
sudo make
## sudo make uninstall
sudo rm /usr/sbin/share/man/man5/authorized_keys.5 /usr/sbin/etc/ssh_config /usr/sbin/etc/sshd_config /usr/sbin/etc/moduli /usr/sbin/sshd
sudo make install

sudo systemctl start ssh

用telnet连接SSH端口看了一下效果,好使,已经将连接时的敏感信息(SSH版本号 + OS版本号)不显示了。

用telnet测试的效果

回车执行命令

未修改前,这里显示的是敏感信息(SSH版本 + OS版本)。

修改后,这里不显示东西。可以根据情况,在这里显示一个伪造的信息。

再回车一下。

再回车一下,就断开连接了。

这里显示的信息就是原版SSHD的实现。

可以根据情况,将这里的提示去掉,或者伪造一个信息返回给telnet.

@todo 关于ssh状态为active(start)的原因

在debian12中的命令行,执行 sudo systemctl start ssh, 回车后不返回。所以查询状态时,为active(start).

这个状态不太正常,但是能用,不耽误干活。

具体原因,有时间再查一下。

如果原版源码编译完,状态可以是active(start), 那好查。因为问题都出在自己改的这一部分。

如果原版也是active(start), 那就不好搞了,毕竟不是原作者。

END

相关推荐
查士丁尼·绵1 天前
openssh8.6p1编译安装
openssh
白80807 天前
openssh 命令注入 (CVE-2020-15778)
scp·openssh
weixin_431697202 个月前
ubuntu2204升级openssh
ubuntu·openssh
庞德公3 个月前
CVE-2024-6387漏洞预警:尽快升级OpenSSH
安全·openssh
一条代码鱼3 个月前
升级最新版openssh-9.7p1及openssl-1.1.1h详细步骤及常见问题总结
linux·openssl·openssh
IT WorryFree4 个月前
离线安装gcc,openssh9.7,zlib,perl,openssl
开发语言·perl·openssl·openssh·zlib
风行無痕7 个月前
Ubuntu20.04升级openssh9.4(源码升级)
linux·openssh
Lz__Heng7 个月前
Suse 12更新操作系统Openssl(3.2.0)、OpenSSH(9.6p1)及ntp(4.2.8p17)(源码编译安装)
linux·运维·服务器·openssh·ntp·suse
以有崖求无崖8 个月前
debian12部署Gitea服务
debian·gitea·debian12