常用命令
cmd | desp | desp1 | example |
---|---|---|---|
find | 文件查找 | find path -option [-print] [ -exec -ok command ] {} | find ./ -name "*.txt" -size -512k -perm 644 #找到以txt结尾的内存小于512k的可读(644)写文件 |
grep | 字符串查找 | grep [OPTION]... PATTERNS [FILE]... | grep --max-count=5 -n --context=1 -w "root" .bash_history # 查找前5个root |
sed | … | sed -e '1,10d' -e 's/oldstr/newstr/g' | |
awk | … | ||
cut | 字符串编辑 | cut -d'|' -f4 | |
sort | 排序 | sort -t'|' -k4n | |
tee | 从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件 |
bash回顾
ping网段主机
功能类似
fping -a -g 192.168.1.129 192.168.1.150
#!/bin/bash # 解释器
if [ "$1" == "" ] # 参数判断
then
echo "Usage: ./test.sh [ips]"
echo "Example: ./test.sh 192.168.1"
else
for x in `seq 129 150`;do
ping -c 1 $1.$x
done
fi
执行测试
root@yue:~/Documents/read/books/渗透测试/bash# ./ping.sh 192.168.1
PING 192.168.1.129 (192.168.1.129) 56(84) bytes of data.
64 bytes from 192.168.1.129: icmp_seq=1 ttl=64 time=1.07 ms
--- 192.168.1.129 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.067/1.067/1.067/0.000 ms
PING 192.168.1.130 (192.168.1.130) 56(84) bytes of data.
64 bytes from 192.168.1.130: icmp_seq=1 ttl=64 time=35.7 ms
--- 192.168.1.130 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 35.659/35.659/35.659/0.000 ms
PING 192.168.1.131 (192.168.1.131) 56(84) bytes of data.
64 bytes from 192.168.1.131: icmp_seq=1 ttl=64 time=1529 ms
--- 192.168.1.137 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
结果处理
通过简单分析,
64 bytes from 192.168.1.131: icmp_seq=1 ttl=64 time=1529 ms
为对方应答,表示在线
代码优化
#!/usr/bin/env bash
ping -c 1 $1.$x | grep "64 bytes" | cut -d"" -f4 | sed 's/\:$//'
文件处理
#!/bin/bash
bak=$IFS # 定义一个变量bak保存IFS的值
IFS=$'\n' # 将环境变量IFS的值修改为换行符
for line in `sed -e '1,15d' ~/Downloads/simpread.md | sort -t '|' -k4n`;do
line=${line// /}
IFS=$'|'
line_arr=($line) # 以IFS作为分割符,形成数组起始下标:0 ok
if [[ "${line_arr[1]}" == "10↑/10↑/10↑/10↑" ]]; then
ip=${line_arr[2]}
port=${line_arr[3]}
passwd=${line_arr[4]}
enc=${line_arr[5]}
country=${line_arr[7]}
echo -e "$country ip: $ip:$port\t$enc\t$passwd"
if [[ "$country" == "JP" && "$port"=="8099" ]]; then
str="{\n\t\"server\":\"$ip\",\n\t\"server_port\":$port,\n\t\"local_port\":1080,\n\t\"password\":\"$passwd\",\n\t\"timeout\":600,\n\t\"method\":\"$enc\"\n}"
echo -e $str > ~/shadowsocks/$ip.$port.json
fi
fi
done
IFS=$bak #将环境变量IFS的值改回原值
源文件:
处理结果: