mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
207 lines
7.9 KiB
Markdown
207 lines
7.9 KiB
Markdown
|
四个Linux网络嗅探工具
|
|||
|
======
|
|||
|
|
|||
|
在计算机网络中,数据是暴露的,因为数据包传输是无法隐藏的,所以让我们来使用 `whois`,`dig`,`nmcli` 和 `nmap` 这四个工具来嗅探网络吧。
|
|||
|
|
|||
|
请注意,不要运行 `nmap` 在不属于自己的网络上,因为这有可能会被其他人解读成为恶意攻击。
|
|||
|
|
|||
|
### 精简和详细域名信息查询
|
|||
|
|
|||
|
您可能已经注意到,之前我们用心爱的 `whois` 命令查询域名信息,但现如今似乎没有提供同过去一样的详细程度。我们使用该命令查询 Linux.com 域名描述信息:
|
|||
|
|
|||
|
```
|
|||
|
$ whois linux.com
|
|||
|
Domain Name: LINUX.COM
|
|||
|
Registry Domain ID: 4245540_DOMAIN_COM-VRSN
|
|||
|
Registrar WHOIS Server: whois.namecheap.com
|
|||
|
Registrar URL: http://www.namecheap.com
|
|||
|
Updated Date: 2018-01-10T12:26:50Z
|
|||
|
Creation Date: 1994-06-02T04:00:00Z
|
|||
|
Registry Expiry Date: 2018-06-01T04:00:00Z
|
|||
|
Registrar: NameCheap Inc.
|
|||
|
Registrar IANA ID: 1068
|
|||
|
Registrar Abuse Contact Email: abuse@namecheap.com
|
|||
|
Registrar Abuse Contact Phone: +1.6613102107
|
|||
|
Domain Status: ok https://icann.org/epp#ok
|
|||
|
Name Server: NS5.DNSMADEEASY.COM
|
|||
|
Name Server: NS6.DNSMADEEASY.COM
|
|||
|
Name Server: NS7.DNSMADEEASY.COM
|
|||
|
DNSSEC: unsigned
|
|||
|
[...]
|
|||
|
|
|||
|
```
|
|||
|
有很多令人讨厌的法律声明。但在哪有联系信息呢?该网站位于 whois.namecheap.com 站点上(见上面输出的第三行):
|
|||
|
|
|||
|
```
|
|||
|
$ whois -h whois.namecheap.com linux.com
|
|||
|
|
|||
|
```
|
|||
|
我就不复制出来,因为这实在太长了,包含了注册人,管理员和技术人员的联系信息。怎么回事啊,露西尔?(LCTT 译注:《行尸走肉》中尼根的棒子)有一些注册表,比如.com和.net是精简注册表,保存了一部分有限的域名信息。为了获取完整信息请使用 `-h` 或 `--host` 参数,该参数便会从域名的 `注册服务机构` 中获取。
|
|||
|
|
|||
|
大部分顶级域名是需要详细的注册信息,如.info。试着使用`whois blockchain.info`命令来查看。
|
|||
|
|
|||
|
想要摆脱这些烦人的法律声明?使用 `-H` 参数。
|
|||
|
|
|||
|
### DNS解析
|
|||
|
|
|||
|
使用 `dig` 命令比较从不同的域名服务器返回的查询结果,去除陈旧的信息。域名服务器记录缓存各地的解析信息,并且不同的域名服务器有不同的刷新间隔。以下是一个简单的用法:
|
|||
|
|
|||
|
```
|
|||
|
$ dig linux.com
|
|||
|
<<>> DiG 9.10.3-P4-Ubuntu <<>> linux.com
|
|||
|
;; global options: +cmd
|
|||
|
;; Got answer:
|
|||
|
;; ->>HEADER<<<- opcode: QUERY, status: NOERROR, id: 13694
|
|||
|
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
|
|||
|
|
|||
|
;; OPT PSEUDOSECTION:
|
|||
|
; EDNS: version: 0, flags:; udp: 1440
|
|||
|
;; QUESTION SECTION:
|
|||
|
;linux.com. IN A
|
|||
|
|
|||
|
;; ANSWER SECTION:
|
|||
|
linux.com. 10800 IN A 151.101.129.5
|
|||
|
linux.com. 10800 IN A 151.101.65.5
|
|||
|
linux.com. 10800 IN A 151.101.1.5
|
|||
|
linux.com. 10800 IN A 151.101.193.5
|
|||
|
|
|||
|
;; Query time: 92 msec
|
|||
|
;; SERVER: 127.0.1.1#53(127.0.1.1)
|
|||
|
;; WHEN: Tue Jan 16 15:17:04 PST 2018
|
|||
|
;; MSG SIZE rcvd: 102
|
|||
|
|
|||
|
```
|
|||
|
注意下靠近末尾的这行信息:SERVER: 127.0.1.1#53(127.0.1.1),这是您默认的缓存解析器。当地址是本地时,就相当于在您的电脑上安装DNS服务。在我看来这就是一个Dnsmasq工具(LCTT 译注:是一个小巧且方便地用于配置DNS和DHCP的工具),该工具被用作网络管理:
|
|||
|
|
|||
|
```
|
|||
|
$ ps ax|grep dnsmasq
|
|||
|
2842 ? S 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground
|
|||
|
--no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid
|
|||
|
--listen-address=127.0.1.1
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
`dig` 命令默认是返回A记录,也就是域名。IPv6则有AAAA记录:
|
|||
|
|
|||
|
```
|
|||
|
$ $ dig linux.com AAAA
|
|||
|
[...]
|
|||
|
;; ANSWER SECTION:
|
|||
|
linux.com. 60 IN AAAA 64:ff9b::9765:105
|
|||
|
linux.com. 60 IN AAAA 64:ff9b::9765:4105
|
|||
|
linux.com. 60 IN AAAA 64:ff9b::9765:8105
|
|||
|
linux.com. 60 IN AAAA 64:ff9b::9765:c105
|
|||
|
[...]
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
仔细检查下,发现Linux.com有IPv6地址。很好!如果您的网络服务支持IPv6那么您就可以用IPv6连接。(令人难过的是,我的移动宽带则没提供IPv6)
|
|||
|
|
|||
|
|
|||
|
假设您能使DNS改变您的域名,又或是您使用 `dig` 查询的结果有误。试着用一个公共DNS,如OpenNIC:
|
|||
|
|
|||
|
```
|
|||
|
$ dig @69.195.152.204 linux.com
|
|||
|
[...]
|
|||
|
;; Query time: 231 msec
|
|||
|
;; SERVER: 69.195.152.204#53(69.195.152.204)
|
|||
|
|
|||
|
```
|
|||
|
`dig` 回应您正在的查询是来自 69.195.152.204。您可以查询各种服务并且比较结果。
|
|||
|
|
|||
|
### 上游域名服务器
|
|||
|
|
|||
|
我想知道我的上游域名服务器是谁。为了查询,我首先看下`/etc/resolv/conf` 的配置信息:
|
|||
|
|
|||
|
```
|
|||
|
$ cat /etc/resolv.conf
|
|||
|
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
|
|||
|
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
|
|||
|
nameserver 127.0.1.1
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
很幸运,不过我是已经知道。您的Linux发行版可能配置不同,您会看到您的上游服务器。接下来我们来试试网络管理器命令行工具 `nmcli`:
|
|||
|
|
|||
|
```
|
|||
|
$ nmcli dev show | grep DNS
|
|||
|
IP4.DNS[1]: 192.168.1.1
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
很好,现在我们已经知道了,其实那是我的移动热点,并且我已经确认那是我的热点。我能够登录到简易管理面板,来查询上游服务器。然而许多消费者互联网网关不会让您看到或改变这些设置,因此只能尝试其他的方法,如 [我的域名服务器是什么?][1]
|
|||
|
|
|||
|
### 查找在您的网络中IPv4地址
|
|||
|
|
|||
|
您的网络上有哪些IPv4地址已启用并正在使用中?
|
|||
|
|
|||
|
```
|
|||
|
$ nmap -sn 192.168.1.0/24
|
|||
|
Starting Nmap 7.01 ( https://nmap.org ) at 2018-01-14 14:03 PST
|
|||
|
Nmap scan report for Mobile.Hotspot (192.168.1.1)
|
|||
|
Host is up (0.011s latency).
|
|||
|
Nmap scan report for studio (192.168.1.2)
|
|||
|
Host is up (0.000071s latency).
|
|||
|
Nmap scan report for nellybly (192.168.1.3)
|
|||
|
Host is up (0.015s latency)
|
|||
|
Nmap done: 256 IP addresses (2 hosts up) scanned in 2.23 seconds
|
|||
|
|
|||
|
```
|
|||
|
每个人都想去扫描自己的局域网中开放的端口。下面的例子是寻找服务和他们的版本号:
|
|||
|
|
|||
|
```
|
|||
|
$ nmap -sV 192.168.1.1/24
|
|||
|
|
|||
|
Starting Nmap 7.01 ( https://nmap.org ) at 2018-01-14 16:46 PST
|
|||
|
Nmap scan report for Mobile.Hotspot (192.168.1.1)
|
|||
|
Host is up (0.0071s latency).
|
|||
|
Not shown: 997 closed ports
|
|||
|
PORT STATE SERVICE VERSION
|
|||
|
22/tcp filtered ssh
|
|||
|
53/tcp open domain dnsmasq 2.55
|
|||
|
80/tcp open http GoAhead WebServer 2.5.0
|
|||
|
|
|||
|
Nmap scan report for studio (192.168.1.102)
|
|||
|
Host is up (0.000087s latency).
|
|||
|
Not shown: 998 closed ports
|
|||
|
PORT STATE SERVICE VERSION
|
|||
|
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
|
|||
|
631/tcp open ipp CUPS 2.1
|
|||
|
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
|
|||
|
|
|||
|
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
|
|||
|
Nmap done: 256 IP addresses (2 hosts up) scanned in 11.65 seconds
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
这些是有趣的结果。让我们尝试从不同的网络帐户进行相同的操作,以查看这些服务是否暴露于互联网中。如果您有智能手机,相当于您有第二个网络。您可以下载应用程序,还可以为您的Linux电脑提供热点。从热点控制面板获取广域网IP地址,然后重试:
|
|||
|
|
|||
|
```
|
|||
|
$ nmap -sV 12.34.56.78
|
|||
|
|
|||
|
Starting Nmap 7.01 ( https://nmap.org ) at 2018-01-14 17:05 PST
|
|||
|
Nmap scan report for 12.34.56.78
|
|||
|
Host is up (0.0061s latency).
|
|||
|
All 1000 scanned ports on 12.34.56.78 are closed
|
|||
|
|
|||
|
```
|
|||
|
果然不出所料,结果和我想象的一样。可以用手册来查询这些命令,以便了解更多有趣的嗅探技术。
|
|||
|
|
|||
|
|
|||
|
了解更多Linux的相关知识可以从Linux基金会和edX(LCTT译者注:edX是麻省理工和哈佛大学于2012年4月联手创建的大规模开放在线课堂平台)中获取免费的 ["介绍Linux" ][2]课程。
|
|||
|
|
|||
|
|
|||
|
--------------------------------------------------------------------------------
|
|||
|
|
|||
|
via: https://www.linux.com/learn/intro-to-linux/2018/1/4-tools-network-snooping-linux
|
|||
|
|
|||
|
作者:[Carla Schroder][a]
|
|||
|
译者:[wyxplus](https://github.com/wyxplus)
|
|||
|
校对:[校对者ID](https://github.com/校对者ID)
|
|||
|
|
|||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|||
|
|
|||
|
[a]:https://www.linux.com/users/cschroder
|
|||
|
[1]:http://www.whatsmydnsserver.com/
|
|||
|
[2]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux
|