搭建简易堡垒机

搭建简易堡垒机安装jailkit实现chroot

一、堡垒机简介

1.1、什么是堡垒机

        堡垒机,即在一个特定的网络环境下,为了保障网络和数据不受来自外部和内部用户的入侵和破坏,而运用各种技术手段监控和记录运维人员对网络内的服务器、网络设备、安全设备、数据库等设备的操作行为,以便集中报警、及时处理及审计定责。

        就是为了实现对于跳板机登录的信息审查和人员操作情况,并通过配置黑白名单来限制特定IP登录情况,实现审计4A标准。

        4A是指:认证Authentication、授权Authorization、账号Account、审计Audit,中文名称为统一安全管理平台解决方案。即将身份认证、授权、记账和审计定义为网络安全的四大组成部分,从而确立了身份认证在整个网络安全系统中的地位与作用。

1.2、使用场景

        简易堡垒机只适合小型公司使用,在公司服务器只有几台的情况下,可以使用,也就是跳板机。跳板机主要功能是登陆公司内网服务器,还可以去查找审计当你登陆到某台机器后做了什么操作。

1.3、堡垒机需要具备的条件

        首先要有公网IP,因为登陆公司的服务器,不只是在公司内登陆,还可能在家里办公或者是出差时要登陆。所以这服务器需要有一个公网I。除了公网IP,它还需要和我们机房其他机器连成一个局域网。假设机房里有十台机器,只有一台有公网,将这台有公网的机器作为一个跳板机,通过它来连接其他机器。

        跳板机是有公网对外开放的,所以要设置防火墙规则,需要做权限最小化的处理,需要什么端口就开放什么端口,不能开放多余的端口。登陆限制,限制I访问,又或是做一个VPN通道。还可以设置 sshd_config,只能通过密钥登陆,拒绝密码登陆。

        对用户进行限制,使用jailkit来做用户、目录权限的限制。

        除了这些之外还需要做一个日志审计,日志审计不能在跳板机上做,需要到各个客户机上做。

        使用jailkit 来实现chroot,将用户限制在一个虚拟系统中,让他只能使用有限的命令来保证我们系统的安全性。

1.4、节点规划

主机名

IP地址

准备

localhost

192.168.100.128

客户机

Client

192.168.100.129

跳板机

二、案例实施

2.1、编译安装jailkit

         下载必要工具和 jailkit 后解压并编译安装jailkit:

[root@localhost~]# yum install -y wget bzip2 bzip2     #安装wget下载工具和bzip2解压工具

[root@localhost~]# yum install-y gcc     #安装依赖包

[root@localhost~]# wget https://olivier.sessink.nl/jailkit/jailkit-2.19.tar.bz2 --no-check-certificate

#加-no-check-certificate跳过网站证书验证

[root@localhost-]# tar.jxvfjailkit-2.19.tar.bz2   # 解压bzip2包

[root@localhost -]# cd jailkit-2.19      #进入解压后的目录

[root@localhost jailkit-2.19]# /configure && make && make install   #配置编译成功后安装

 解析:

需要配置好虚拟机中的yum源以及保证虚拟机通网。

2.2、使用jailkit创建用户

        创建用户并使用jk命令将用户修改为虚拟系统中的用户,最后修改用户登陆shell,使其可以登陆。

[root@localhost jailkit-2.19]# mkdir /home/jail   #创建目录

#使用jk init 命令将一些常用的命令拷贝到home/jai中

[root@localhostjailkit-2.191#jk_init -v -j /home/jail/ basicshell

[root@localhostjailkit-2.19]4jk_init -v -j /home/jail/ editors

[root@localhost jailkit-2.19]#jk_init-v -j /home/jail/netatils

[root@localhostjailkit-2.19]# jk_init -v -j /home/jail ssh

创建用户

[root@localhost jailkit-2.19]# useradd zhangsan     #创建用户

[root@localhost jailkit-2.191# echo "000000” passwd --stdin zhangsan   #设置密码

[root@localhost jailkit-2.19]# mkdir /home/jail/usr/sbin    

[root@localhostiailkit-2.191# cp /usr/sbin/jk_lsh home/iail/usr/sbin/     



[root@localhost jailkit-2.19]# jk_jailuser -m -j /home/jail zhangsan    #将张三创建成虚拟系统中的用户

2.3、登陆系统

        使用jailgit用户测试登陆系统。

        出于安全考虑,更改linux sshd配置文件,取消密码登陆,并设置黑白名单,限制登陆。

#使用jailgit的用户登录系统

[root@localhost jailkit-2.19]# ssh zhangsan@127.0.0.1  #SSH 登陆zhangsan用户

[zhangsan@localhost-]S ls /usr/bin    #可以看到/usr/bin下面有了一些命令

 bash chmod cpio dd egrep fgrep gunzip in mkdir more pwd rmdir sed sleep sync touch vi zcat cat cp date echo false grep gzip ls mktemp mv scp sh ssh tar true wget

#对登陆进行限制

#既然是跳板机我们还可以设置只能使用密钥登陆

[root@localhost jailkit-2.191# cat /ete/ssh/ssh_config ntication    #将PasswordAuthentication yes改为PasswordAuthentication no



[ro0t@localhostjailkit-2.19]# cat /etc/hosts.allow      #添加主机白名单

# hosts.allow   This file contains access rules which are used to

# allow or deny connections to network services that

# either use the tcp_wrappers library or that have been

# started through a tcp_ wrappers-enabled xinetd.

#

# See 'man 5 hosts options' and man 5 hosts access'

# for information on rule syntax.

# See 'man tcpd' for information on tcp_ wrappers

sshd:192.168.100.0/24

#只允许192.168.100.0/24网段的IP来访问



[root@localhostjailkit-2.19]# cat /etc/hosts.deny    #添加黑名单

#

# deny connections to network services that either use

# the tcp wrappers library or that have been

# started through a tep wrappers-enabled xinetd

#

# The rules in this file can also be set up in

# etc/hosts.allow with a 'deny' option instead.

#

# See 'man 5 hosts options' and 'man 5 hosts access

# for information on rule syntax.

# See 'man tcpd' for information on tcp_wrappers

sshd:ALL      #拒绝除了白名单内的所有IP连接

到这里jailkit差不多就配完了 。

三、日志审计

        在一个完整的信息系统里面,日志系统是一个非常重要的功能组成部分。它可以记录下系统所产生的所有行为,并按照某种规范表达出来。我们可以使用日志系统所记录的信息为系统进行排错,优化系统的性能,或者根据这些信息调整系统的行为。

3.1、配置客户机使其只能使用跳板机登陆

配置client机器的黑白名单:

[root@client~]# cat /etc/hosts.allow      #配置白名单,只允许跳板机192.168.100.128这台机器登陆

# hosts.allow   This file contains access rules which are used to

# allow or deny connections to network services that

# either use the tcp_wrappers library or that have been

# started through a tcp_ wrappers-enabled xinetd.

#

# See 'man 5 hosts options' and man 5 hosts access'

# for information on rule syntax.

# See 'man tcpd' for information on tcp_ wrappers

sshd:192.168.100.128



[root@client~]# cat /etc/hosts.deny    #配置黑名单

#

# deny connections to network services that either use

# the tcp wrappers library or that have been

# started through a tep wrappers-enabled xinetd

#

# The rules in this file can also be set up in

# etc/hosts.allow with a 'deny' option instead.

#

# See 'man 5 hosts options' and 'man 5 hosts access

# for information on rule syntax.

# See 'man tcpd' for information on tcp_wrappers

sshd:ALL      

#之后重新连接就会连不上了,只能使用允许的跳板机去登陆

[root@localhost jailkit-2.19]# ssh 192.168.100.129

The authenticity of host '192.168.100.129 (192.168.100.129)' can't be

established.

ECDSA key fingerprint is 72:ce:89:6f:18:10:11:fa:57:a2:ba:fe:23:fl:ad:66.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168100.129' (ECDSA) to the list of known

hosts.

root@192.168.100.129's password:

Last login: Fri Feb 28 08:28:23 2020 from 192.168.100.1

[root@client-]#

3.2、配置日志审计

        配置client收集命令的环境变量

[root@client~]#mkdir /usr/local/records   #创建存放日志审计的目录

[root@client~]#chmod 777/usr/local/records   #给予777权限

[root@client~]# chmod +t/usr/local/records   #给予t特殊权限

[root@client~]#cat /etc/profile    #在最后添加以下判断语句

......

if [ ! -d  /usr/local/records/${LOGNAME} ]

then

    mkdir -p /usr/local/records/${LOGNAME}

    chmod 700 /usr/local/records/${LOGNAME}

fi

export HISTORY_FILE="/usr/local/records/${LOGNAME}/bash_history"

export PROMPT_COMMAND='{ date +"%Y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") ### $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTORY_FILE'

#LOGNAME变量为当前用户名

#PROMPT_COMMAND变量,它会在用户交互的提示信息出现之间将设定在其中的内容作为可执行的命令执行。

[root@client~]# source /etc/profile     #使/etc/profile文件中的配置生效

#以zhangsan身份在客户机上随便执行几个命令,可以看到

[root@client~]#cat/nst/loeal/records/zhangsan/bash_history

2020-02-28 10:03:50 #H## root pts/2 (192.168.174.1)### df-h

2020-02-28 10:03:54 HHH## root pts/2 (192.168.174.1) ### Is

2020-02-28 10:04:34 #HH## root pts/2(192.168.174.1) ### clear

总结:

最后总结一下简易堡垒机的作用:

        集中访问控制:简易堡垒机充当集中式访问点,用户可以通过该点访问内部网络资源。它通过身份验证和授权机制来控制对资源的访问,确保只有经过授权的用户才能访问他们有权访问的资源。

        会话记录和审计:简易堡垒机记录并审计用户会话,包括用户活动、连接时间和访问的资源。这有助于检测可疑活动并进行取证调查。

        访问限制:简易堡垒机可以限制用户对内部网络资源的访问,例如只允许他们访问特定主机或应用程序。这有助于减少攻击面并保护敏感数据。

        双因素认证:简易堡垒机可以强制实施双因素认证,要求用户提供额外的身份验证因子(例如一次性密码)才能访问内部网络。这增加了安全性并降低了未经授权访问的风险。

        SSH 密钥管理:简易堡垒机可以集中管理和分发 SSH 密钥,用于安全地连接到内部主机。这消除了手动管理 SSH 密钥的需要,并提高了安全性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值