1. yum私有仓库的实现及博客输出
1.1安装yum扩展软件
yum -y install yum-utils
1.2 同步源
yum repolist
yum reporsync --repoid=xx --download-metadata -p /path
#客户端建repo文件
cat /etc/yum.repos.d/local.repo
[local]
name=shudun local yum
baseurl=http://10.1.10.65
enabled=1
1.3配置nginx.conf
server {
listen 80;
server_name 127.0.0.1
client_max_body_size 100m;
location /centos7 {
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
root /usr/local/nginx/html;
allow 10.0.80.0/24;
allow 10.1.0.0/16;
allow 10.3.0.0/16;
deny all;
}
location / {
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
root /usr/local/nginx/html/centos;
allow 10.0.80.0/24;
allow 10.1.0.0/16;
allow 10.3.0.0/16;
deny all;
}
}
2. 阅读《图解TCP/IP》一书,地址:https://leon-wtf.github.io/doc/%E5%9B%BE%E8%A7%A3TCPIP.pdf,有时间的可以写下读书笔记
3。画图 TCP协议和三次握手及四次挥手,可以参考别人的,但是需要自己画一次
攻击者在第一次握手的数据表里面,通过伪造"Source Address",让服务器(接收端)在进行第二次握手的时候,将确认包发向一个伪造的IP地址,由于IP地址是伪造的,因此服务器端迟迟等不到第三次的确认包,导致服务器打开了大量的SYNC_RECV半连接。
用#统计SYN_RECV状态数量(ESTABLISHED 很少的情况);
netstat -an|awk ‘/^tcp/ {print $NF}’|sort -n|uniq -c|sort -nr top
为什么第三次挥手回来时候为什么布里克进入close状态中间等2msl才进入断开closed状态
因为前面可能有数据在传,不要以为数据是先传的我是后分手的,对方发给我,难道我还收不到吗?网络是很复杂的,不一定是先发的数据先到
B wait1告诉A你的请求我收到了,但是我还没有同意分手
我还可以把一些数据发给A,发完了我才提出分手,一旦提出分手我就不再给你发送其他数据了
4. 静态配置网卡IP,centos/ubuntu实现
#centos
TYPE=Ethernet
BOOTPROTO=static
NAME=ens192
DEVICE=ens192
ONBOOT=yes
IPADDR=10.1.10.65
GATEWAY=10.1.10.1
NETMASK=255.255.255.0
DNS1=119.29.29.29
#ubuntu
cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens160
iface ens160 inet static
address 10.1.10.191
netmask 255.255.255.0
gateway 10.1.10.1
dns_nameservers 8.8.8.8 114.114.114.114 172.16.2.1
脚本题
5. 实现免密登陆脚本, expect登陆远程主机,将生成的密钥写入到目标主机, expect测试远程登陆。
1)通过shift读取脚本参数
2)通过select来选择功能.例如功能有
- 安装mysql
- 安装apache
- 免密钥登陆主机
当前我们只实现免密钥登陆主机
3)通过函数封装每个功能
4)将免密钥登陆的过程可以重复进行, while 循环实现重复,需要有退出过程。当用户输入exit时,退出免密钥功能。
5)支持输入一批主机免密钥,使用数组 实现
#********************************************************************
#Author: Mr.Song
#QQ: 1132197391
#Date: 2022-08-24
#FileName: ssh_key_push.sh
#Description: 多主机基于ssh key 互相验证
#Copyright (C): 2022 All rights reserved
#********************************************************************
#当前用户密码
PASS=123
#设置网段最小和最大的地址的尾数
BEGIN=120
END=122
IP=`ip a s ens192 | awk -F'[ /]+' 'NR==3{print $3}'`
NET=${IP%.*}.
. /etc/os-release
color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$1" && $MOVE_TO_COL
echo -n "["
if [ $2 = "success" -o $2 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $2 = "failure" -o $2 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}
#安装sshpass
install_sshpass() {
if [[ $ID =~ centos|rocky|rhel ]];then
rpm -q sshpass &> /dev/null || yum -y install sshpass
else
dpkg -l sshpass &> /dev/null || { sudo apt update;sudo apt -y install sshpass; }
fi
if [ $? -ne 0 ];then
color '安装 sshpass 失败!' 1
exit 1
fi
}
scan_host() {
[ -e ./SCANIP.log ] && rm -f SCANIP.log
for((i=$BEGIN;i<="$END";i++));do
ping -c 1 -w 1 ${NET}$i &> /dev/null && echo "${NET}$i" >> SCANIP.log &
done
wait
}
push_ssh_key() {
#生成ssh key
[ -e ~/.ssh/id_rsa ] || ssh-keygen -P "" -f ~/.ssh/id_rsa
[ -e ~/.ssh/authorized_keys ] || sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no ${USER}@$IP &>/dev/null
#把本机的ssh目录(包含公钥)拷贝给列表的服务器
local ip_list=(`sort -t . -k 4 -n SCANIP.log`)
for ip in ${ip_list[*]};do
sshpass -p $PASS scp -o StrictHostKeyChecking=no -r ~/.ssh ${USER}@${ip}: &>/dev/null
done
#把.ssh/known_hosts拷贝到所有主机,使它们第一次互相访问时不需要输入yes回车
for ip in ${ip_list[*]};do
scp ~/.ssh/known_hosts ${USER}@${ip}:.ssh/ &>/dev/null
color "$ip" 0
done
}
delete_ssh_key() {
#把本机的ssh目录(包含公钥)拷贝给列表的服务器
local ip_list=(`sort -t . -k 4 -n SCANIP.log`)
for ip in ${ip_list[*]};do
sshpass -p $PASS ssh -o StrictHostKeyChecking=no ${USER}@${ip} mv ~/.ssh/known_hosts ~/.ssh/known_hosts.bak && mv ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak &>/dev/null
color "sshpass -p shudun@123 ssh -o StrictHostKeyChecking=no ${USER}@${ip} mv ~/.ssh/known_hosts ~/.ssh/known_hosts.bak && mv ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak" 0
done
}
install_mysql() {
yum -y install mysql
}
install_apache() {
yum -y install apche
}
PS3="请选择功能(1-4): "
select MENU in ssh-key互相验证 取消基于key验证 安装软件 退出;do
case $REPLY in
1)
install_sshpass
scan_host
push_ssh_key
;;
2)
install_sshpass
scan_host
delete_ssh_key
;;
3)
install_mysql
install_apache
;;
4)
echo "退出"
break
;;
*)
echo "输入错误,重新选择"
;;
esac
done
shift高阶用法
TEMP=$(getopt -o i:u:stn --long install:,upgrade:,skip -- "$@")
if [ "$?" != "0" ]; then
echo "Terminating..." >&2
exit 1
fi
# 用"$TEMP"参数--前的字符串重置$1.$2.$3.$4...
eval set -- "$TEMP"
echo $TEMP
# 解析$1.$2.$3.$4...
while true; do
case "$1" in
-i | --install)
APP=$2
if [ $ACTION ]; then
echo "(-i|--install) & (-u|--upgrade) cannot be used together!"
exit 1
fi
ACTION=install
shift 2
;;
-u | --upgrade)
APP=$2
if [ $ACTION ]; then
echo "(-i|--install) & (-u|--upgrade) cannot be used together!"
exit 1
fi
ACTION=upgrade
shift 2
;;
-t)
if [ $NGINX ]; then
echo "-t & -n cannot be used together!"
exit 1
fi
NGINX=tengine
shift 1
;;
-n)
if [ $NGINX ]; then
echo "-t & -n cannot be used together!"
exit 1
fi
NGINX=nginx
shift 1
;;
-s | --skip)
ifInstalledSkip=true
shift 1
;;
"--")
shift
break
;;
*)
echo "Parameter error!"
exit 1
;;
esac
done
function check_parameter() {
if [ ! $ACTION ]; then
echo -e "Usage: ucmp_install -i|-u [ service_name ]\n-i|--install Install\n-u|--upgrade Upgrade"
exit 1
fi
}