学习linux的第八十三天

什么是堡垒机

在这里插入图片描述
堡垒机,即在一个特定的网络环境下,为了保障网络和数据不受来自外部和内部用户的入侵和破坏,而运用各种技术手段实时收集和监控网络环境中每一个组成部分的系统状态、安全事件、网络活动,以便集中报警、及时处理及审计定责。

其从功能上讲,它综合了核心系统运维和安全审计管控两大主干功能,从技术实现上讲,通过切断终端计算机对网络和服务器资源的直接访问,而采用协议代理的方式,接管了终端计算机对网络和服务器的访问。形象地说,终端计算机对目标的访问,均需要经过运维安全审计的翻译。打一个比方,运维安全审计扮演着看门者的工作,所有对网络设备和服务器的请求都要从这扇大门经过。因此运维安全审计能够拦截非法访问,和恶意攻击,对不合法命令进行命令阻断,过滤掉所有对目标设备的非法访问行为,并对内部人员误操作和非法操作进行审计监控,以便事后责任追踪。

我们也把堡垒机称为跳板机,简易的跳板机功能简单,核心功能是远程登录服务器和日志审计,但堡垒机还有资产管理(CMDB)、监控及用户权限等功能。目前比较优秀的开源软件有Jumpserver、Teleport、GateOne、CrazyEye等;商业的堡垒机功能更为强大,有齐治、Citrix XenApp等。

搭建简易堡垒机

标题在这里插入图片描述

在这里插入图片描述
接下来我们尝试搭建一个简易的堡垒机,主要功能是登录内网的服务器和日志审计。
搭建堡垒机的条件是,该机器有公网ip和内网ip,其中内网和其他机器互通。
设计堡垒机的思路:
对该机器做安全限制:端口限制、登录限制(SSH)、用户和命令限制;
客户机日志审计。
下载安装jailkit实现chroot:
cd /usr/local/src/
wget https://olivier.sessink.nl/jailkit/jailkit-2.19.tar.bz2
tar jxvf jailkit-2.19.tar.bz2
cd jailkit-2.19
./configure
echo $?
0
make && make install
echo KaTeX parse error: Expected 'EOF', got '#' at position 82: …il/ basicshell #̲shell相关命令、库文件 j… #修改为下面内容
vim etc/passwd
root❌0:0:root:/root:/bin/bash
KXLZQ❌1001:1001::/home/KXLZQ:/bin/bash #修改为/bin/bash才能登录该虚拟系统用户
使用xshell登录该虚拟用户:
成功登录后,我们查看一下
[KXLZQ@~]$ ls
[KXLZQ@~]$ ll /
bash: ll: command not found
[KXLZQ@~]$ ls -l /
total 0
lrwxrwxrwx 1 root root 7 Jan 15 13:03 bin -> usr/bin
drwxr-xr-x 2 root root 44 Jan 15 13:04 dev
drwxr-xr-x 2 root root 240 Jan 15 13:25 etc
drwxr-xr-x 3 root root 22 Jan 15 13:12 home
lrwxrwxrwx 1 root root 9 Jan 15 13:03 lib64 -> usr/lib64
drwxr-xr-x 7 root root 70 Jan 15 13:09 usr
[KXLZQ@ ~]$ #按两下Tab键
Display all 116 possibilities? (y or n)
! command elif gunzip more sh typeset
./ compgen else gzip mv shift ulimit
: complete enable hash popd shopt umask
[ compopt esac help printf sleep unalias
[[ continue eval history pushd source unset
]] coproc exec if pwd ssh until
alias cp exit in read suspend vi
bash cpio export jobs readarray sync vim
bg date false kill readonly tar wait
bind dd fc let return test wget
break declare fg ln rm then while
builtin dirs fgrep local rmdir time zcat
caller disown fi logout rsync times {
case do for ls scp touch }
cat done function mapfile sed trap
cd echo getopts mkdir select true
chmod egrep grep mktemp set type #这些就是该虚拟用户所能执行的命令
限定SSH登录:
vim /etc/ssh/sshd_config //做下面修改
PasswordAuthentication no #不允许密码登录
添加防火墙规则:
iptables -I INPUT -p tcp --dport 22 -j ACCEPT #打开22端口
限定登录ip:
vim /etc/hosts.allow
sshd: 192.168.70.0/24 1.1.1.1 2.2.2.2 #类似这样限制登录的ip
vim /etc/hosts.deny
sshd: ALL #除了上面允许的可以登录,其他所有均不允许登录
接下来还要做日志审计功能,这一步需要我们在所有被登陆的机器上操作。
这里我让lzx作为跳板机,XXQ作为客户机,在XXQ上操作。
vim /etc/hosts.allow
sshd:192.168.70.129
vim /etc/hosts.deny
sshd:ALL
mkdir /usr/local/records
chmod 777 !$
chmod 777 /usr/local/records
chmod +t !$ #增加防删除权限,类似/tmp目录
chmod +t /usr/local/records
vim /etc/profile #添加下面内容
if [ ! -d /usr/local/records/ L O G N A M E ] t h e n m k d i r − p / u s r / l o c a l / r e c o r d s / {LOGNAME} ] then mkdir -p /usr/local/records/ LOGNAME]thenmkdirp/usr/local/records/{LOGNAME} #根据登录名创建同名子文件夹
chmod 300 /usr/local/records/KaTeX parse error: Expected 'EOF', got '#' at position 14: {LOGNAME} #̲赋予300权限 fi expo…{LOGNAME}/bash_history" #指定记录命令历史的文件
export PROMPT_COMMAND=’{ date “+%Y-%m-%d %T ##### $(who am i |awk “{print $1” “$2” “$5}”) #### KaTeX parse error: Expected '}', got 'EOF' at end of input: …d x cmd; echo "cmd”; })"; } >>KaTeX parse error: Expected 'EOF', got '#' at position 18: …STORY_FILE' #̲具体记录命令历史的格式 再用x… ls
[lisi@XXQ ~]$ w
13:40:50 up 37 min, 3 users, load average: 0.02, 0.02, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.70.1 13:16 2.00s 0.03s 0.01s ssh lisi@192.168.100.
root pts/1 192.168.70.1 13:34 3:54 0.00s 0.00s -bash
lisi pts/2 192.168.70.129 13:40 2.00s 0.00s 0.00s w
[lisi@XXQ ~]$ ls /usr/local/records/
lisi root
[lisi@XXQ ~]$ cd /usr/local/records/lisi/
[lisi@XXQ lisi]$ ls
ls: cannot open directory .: Permission denied #这里是无法读取内容的,只有300权限
XXQ上查看命令历史记录
cat /usr/local/records/lisi/bash_history
2020-01-15 13:40:46 ##### lisi pts/2 (192.168.70.129) ####
2020-01-15 13:40:49 ##### lisi pts/2 (192.168.70.129) #### ls
2020-01-15 13:40:50 ##### lisi pts/2 (192.168.70.129) #### w
2020-01-15 13:41:16 ##### lisi pts/2 (192.168.70.129) #### ls /usr/local/records/
2020-01-15 13:41:30 ##### lisi pts/2 (192.168.70.129) #### cd /usr/local/records/lisi/
2020-01-15 13:41:31 ##### lisi pts/2 (192.168.70.129) #### ls

这里就简单是实现了堡垒机的功能,但是这种方法是不完美的,也是可以破解的。我们想要实现比较完善的堡垒机功能,还是需要借助一些专门的工具或软件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值