0%

kali linux攻防学习

一、被动信息收集

1. dns域名解析信息收集

1.1. dns域名解析原理

域名服务器

  • dns服务器分为根域dns服务器和顶级域名服务器
  • 根域dns服务器一般有13个,储存了所有顶级域名服务器的地址
  • 顶级域名服务器储存了每位客户所注册的主机地址

域名记录

  • A: 正向解析,一个域名对应一个IP地址
  • Cname: 别名,允许多个域名对应一个主机
  • NS: 域名服务器记录,用于指定该域名由那个域名服务器解析
  • MX: 邮件交换记录,通过@xxx.xxx来对应邮件服务器
  • PTR: 反向解析,通过IP查域名,记录保存在in-addr.arpa域中

dns缓存服务器

  • 不负责解析,只用来缓存结果

dns域名解析过程

1.2. dns解析命令

  1. ping
  2. nslookup
  3. dig

nslookup

1

二、wireShark使用

2. 抓包技巧

2.1. 过滤器使用

一些基本使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
###### 过滤ip ######
# 所有ip
ip.addr == 1.1.1.1
# 目标和来源
ip.src_host == 1.1.1.1
ip.dst_host == 1.1.1.1

###### 协议 ######
# 协议直接打协议名,tcp/udp/icmp/arp/http等
tcp

###### 逻辑 ######
# 与和或
ip.src_host == 1.1.1.1 or ip.dst_host == 1.1.1.1
ip.src_host == 1.1.1.1 and ip.dst_host == 1.1.1.1

三、一些好用的命令

1. namp

1.1. 选项

  • -v: 显示详细信息
  • -p <port>: 指定端口范围,例:1-100,135,199,1234
  • -O: 显示操作系统类型
  • -A: 对操作系统和软件版本号进行探测,并进行traceroute路由探测
  • -T<0-5>: 扫描过程中使用的时序,级别越高扫描速度越快,但容易被防火墙或IDS检测屏蔽,推荐使用T4
  • --randomize-host: 对目标主机顺序随机划分
  • --scan-delay <time>: 探针之间的延迟,单位s,可以指定,例:3000ms
  • -F: 快速模式
  • --version-light: 设定侦测等级为2

扫描类型

  • -sS: TCP同步扫描(SYN),半开扫描,只发送sync包,如果回了syn|ack就说明端口开放
  • -sn: ping扫描
  • -sV: 探测端口及服务版本信息

1.2. 实例

1
2
3
4
5
6
7
# 扫描网段
=> nmap -sS -O 192.168.1.0/24
=> nmap -sS -O 1.*.2.3-8
# 扫描单个ip
=> nmap -sS -O 192.168.1.1
# 扫描域名
=> nmap -sS -O www.baidu.com

2. hashcat

1
hashcat [options]... hash|hashfile|hccapxfile [dictionary|mask|directory]...

2.1. 选项解释

  • -m [algorithm_code]: 算法指定,下面列举几个常用的
1
2
900 md4加密算法
0 md5加密算法
  • -a [attack_mode]: 破解模式
1
2
3
4
5
6
7
8
 # | Mode
===+======
0 | Straight # 字典破解 指定字典文件进行破解
1 | Combination # 组合破解
3 | Brute-force # 掩码暴力破解 给定掩码,暴力枚举来破解密码
6 | Hybrid Wordlist + Mask # 字典+掩码破解
7 | Hybrid Mask + Wordlist # 掩码+字典破解
9 | Association #

1) 掩码格式

1
2
3
4
5
6
7
8
9
10
11
12
- [ Built-in Charsets ] -

? | Charset
===+=========
l | abcdefghijklmnopqrstuvwxyz [a-z]
u | ABCDEFGHIJKLMNOPQRSTUVWXYZ [A-Z]
d | 0123456789 [0-9]
h | 0123456789abcdef [0-9a-f]
H | 0123456789ABCDEF [0-9A-F]
s | !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
a | ?l?u?d?s
b | 0x00 - 0xff

示例用法

  • ?a?a?a?a?a: 5位数字大小写和特殊字符的组合
  • abc?l: abc跟随一个a-z

2.2. 示例用法

1
2
3
4
5
6
7
# -a 3 使用掩码破解
# ?a?a?a?a?a 认为是5位数字大小写和特殊字符的组合
# -m 900 md4加密算法
# -m 0 md5加密算法
hashcat -a 3 -m 900 45d5e0ff62cf31019d1c53d9f13f378a '?a?a?a?a?a'
# 已经解出来的,使用--show查看
hashcat -a 3 -m 900 45d5e0ff62cf31019d1c53d9f13f378a '?a?a?a?a?a' --show

2.3. 破解linux的shadow文件

  • 先查看文件中的加密算法
1
2
=> cat /etc/shadow | grep admin
admin:$6$EzFzlOJKGd9kKCS8$SjbWh9P8M7UcJ5tJ0Ao5iiDuqfy57BZlJl5P9PSOnfaQJv9dSDEBxsYvWv8S0O4/akkt6WZ7gDMyXvYMF1Pvp/:19198:0:99999:7:::
  • 可以看出是$6$的算法,那么在hashcat中找此算法对应1800
1
2
3
=> hashcat --help | grep '$6\$'
1800 | sha512crypt $6$, SHA512 (Unix) | Operating System
22921 | RSA/DSA/EC/OpenSSH Private Keys ($6$) | Private Key
  • 将上述的密文也就是用户名后面的一段到冒号,输出到另一个文件
1
2
3
=> cat /etc/shadow | grep '^admin' | awk -F':' '{print $2}' > pwd.hash
=> cat pwd.hash
$6$EzFzlOJKGd9kKCS8$SjbWh9P8M7UcJ5tJ0Ao5iiDuqfy57BZlJl5P9PSOnfaQJv9dSDEBxsYvWv8S0O4/akkt6WZ7gDMyXvYMF1Pvp/
  • 准备一份爆破字典
  • 使用爆破字典,对应1800算法,爆破密码
1
=> hashcat -a 0 -m 1800 -o found.txt pwd.hash hashcat_wordlist.txt
  • 最终输出到found.txt
1
2
=> cat found.txt
$6$EzFzlOJKGd9kKCS8$SjbWh9P8M7UcJ5tJ0Ao5iiDuqfy57BZlJl5P9PSOnfaQJv9dSDEBxsYvWv8S0O4/akkt6WZ7gDMyXvYMF1Pvp/:sangfortool

3. hydra 爆破登陆

3.1. ssh爆破

  • 容易被封,小心点

1) 示例用法

  • -l <user>: 指定用户名
  • -L <user.txt>: 指定一个用户名列表
  • -p <passwd>: 指定密码
  • -P <passwd.txt>: 指定一个密码列表
  • -t <threadNum>: 几个线程进行爆破
1
2
3
4
5
6
7
8
9
10
=> hydra -l admin -P ~/work/src/local/hashcat_wordlist.txt -t 64 199.200.2.170 ssh
Hydra v9.3 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2022-09-14 10:38:49
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 56 tasks per 1 server, overall 56 tasks, 56 login tries (l:1/p:56), ~1 try per task
[DATA] attacking ssh://199.200.2.170:22/
[22][ssh] host: 199.200.2.170 login: admin password: test@123
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2022-09-14 10:38:51

4. fping ping探测

1
2
3
4
# 对 192.168.80.0/24 网段进行ping扫描,结果输出到a.txt
fping -g 192.168.80.0/24 -c 1 > a.txt
# 对 192.168.1.0-192.168.1.255 网段进行ping扫描,结果输出到a.txt
fping -g 192.168.1.0 192.168.1.255 -c 1 > a.txt

5. rar2john rar压缩包密码获取

1
2
3
=> rar2john test.rar
Created directory: /root/.john
test.rar:$rar5$16$1e71cb65fbc2e25d134279f2cb5be013$15$f6115d7dee842c1f8901b057e2bc8952$8$1988f3ce18017cdb
  • 破解
1
2
=> hashcat -m 13000 -a 3 '$rar5$16$1e71cb65fbc2e25d134279f2cb5be013$15$f6115d7dee842c1f8901b057e2bc8952$8$1988f3ce18017cdb' 'abc?l'
$rar5$16$1e71cb65fbc2e25d134279f2cb5be013$15$f6115d7dee842c1f8901b057e2bc8952$8$1988f3ce18017cdb:abcd

6. binwalk 隐写文件

6.1. 选项

  • -e: 自动解压已知类型

6.2. 示例用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 查看文件内容
=> binwalk mianju.jpg

DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 JPEG image data, EXIF standard
12 0xC TIFF image data, little-endian offset of first image directory: 8
478718 0x74DFE Zip archive data, at least v2.0 to extract, compressed size: 153767, uncompressed size: 3145728, name: flag.vmdk
632615 0x9A727 End of Zip archive, footer length: 22

# 解压文件
=> binwalk -e ../mianju.jpg

DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 JPEG image data, EXIF standard
12 0xC TIFF image data, little-endian offset of first image directory: 8

WARNING: Extractor.execute failed to run external extractor 'jar xvf '%e'': [Errno 2] No such file or directory: 'jar', 'jar xvf '%e'' might not be installed correctly
478718 0x74DFE Zip archive data, at least v2.0 to extract, compressed size: 153767, uncompressed size: 3145728, name: flag.vmdk
632615 0x9A727 End of Zip archive, footer length: 22

=> tree
.
└── _mianju.jpg.extracted
├── 74DFE.zip
└── flag.vmdk

2 directories, 2 files

四、Metasploiut Framework

https://zhuanlan.zhihu.com/p/68927033

1. 启动

1
msfconsole

2. 使用

1
2
3
4
5
6
7
8
# 初始化数据库
msf6 > msfdb init
# 查看可用模块
use
# 查看模块详细信息
info
# 执行模块
run

小技巧与踩坑记

1. apt update 提示key问题

1
2
wget archive.kali.org/archive-key.asc
sudo apt-key add archive-key.asc

2. 黑客入侵终端模拟

  • 使用hollywood,安装后使用tmux执行即可