使用Nikto检查任何站点的漏洞

大家好! OTUS在三月启动了一个新的Kali Linux Workshop。预期课程的开始,我们已为您准备了有用材料的翻译。我们也想邀请大家关于这一主题的免费课程:“拒绝服务攻击和防御他们





在攻击任何站点之前,黑客或pentester会首先制定目标列表。在进行了良好的侦查并发现“瞄准”的弱点之后,他将需要Web服务器扫描工具(例如Nikto),这将帮助他发现漏洞-潜在的攻击媒介。

Nikto是一个简单的开源Web服务器扫描程序,它扫描网站并报告发现的可被利用或黑客攻击的漏洞。此外,它是在整个行业中用于扫描网站漏洞的最广泛使用的工具之一,在许多圈子中,它被认为是行业标准。

尽管此工具非常有效,但它并不暗中起作用。任何具有入侵检测系统或其他安全措施的站点都将了解正在对其进行扫描。Nikto旨在测试安全性,没有人想到其工作的保密性。

如何使用Nikto


如果仅在目标网站上运行Nikto,则可能不了解如何处理扫描后获得的信息。 Nikto实际上更像是激光指示器,需要进行拍摄,一段时间后,您将看到其工作原理。

首先,让我们谈谈目标。目标几乎可以是黑客可以攻击的任何地方,例如网络打印机或Web服务器。稍后再使用Nikto时,我们将需要为它提供以下三种信息之一:本地服务的IP地址,攻击域或SSL / HTTPS网站。

开始使用Nikto扫描之前,最好使用Maltego之类的开放工具进行初步探索此类工具可用于创建概要文件并形成要关注的更具体的目标列表。完成此操作后,您可以使用Nikto从列表中搜索目标的潜在漏洞。

幸运的是,将发现一个漏洞利用漏洞众所周知的漏洞,这意味着已经有一个工具可以帮助利用这一弱点。黑客使用适当的工具来自动利用此漏洞,黑客可以访问目标,以执行任何数量的隐藏攻击,例如添加恶意代码。

步骤1:安装Nikto


如果您使用的是Kali Linux,则将预先安装Nikto,因此您无需下载和安装任何东西。它将位于“漏洞分析”类别中。如果由于某种原因没有它,则可以从GitHub上的 Nikto存储库下载Nikto 或只使用命令apt install

apt install nikto

如果您使用的是Mac,则可以使用Homebrew安装Nikto。

brew install nikto

第2步:了解Nikto


使用Nikto扫描Web服务器之前,请使用-Help参数查看使用此工具可以执行的所有操作:

nikto -Help

Options:
       -ask+               Whether to ask about submitting updates
                               yes   Ask about each (default)
                               no    Don't ask, don't send
                               auto  Don't ask, just send
       -Cgidirs+           Scan these CGI dirs: "none", "all", or values like "/cgi/ /cgi-a/"
       -config+            Use this config file
       -Display+           Turn on/off display outputs:
                               1     Show redirects
                               2     Show cookies received
                               3     Show all 200/OK responses
                               4     Show URLs which require authentication
                               D     Debug output
                               E     Display all HTTP errors
                               P     Print progress to STDOUT
                               S     Scrub output of IPs and hostnames
                               V     Verbose output
       -dbcheck           Check database and other key files for syntax errors
       -evasion+          Encoding technique:
                               1     Random URI encoding (non-UTF8)
                               2     Directory self-reference (/./)
                               3     Premature URL ending
                               4     Prepend long random string
                               5     Fake parameter
                               6     TAB as request spacer
                               7     Change the case of the URL
                               8     Use Windows directory separator (\)
                               A     Use a carriage return (0x0d) as a request spacer
                               B     Use binary value 0x0b as a request spacer
        -Format+           Save file (-o) format:
                               csv   Comma-separated-value
                               htm   HTML Format
                               nbe   Nessus NBE format
                               sql   Generic SQL (see docs for schema)
                               txt   Plain text
                               xml   XML Format
                               (if not specified the format will be taken from the file extension passed to -output)
       -Help              Extended help information
       -host+             Target host
       -404code           Ignore these HTTP codes as negative responses (always). Format is "302,301".
       -404string         Ignore this string in response body content as negative response (always). Can be a regular expression.
       -id+               Host authentication to use, format is id:pass or id:pass:realm
       -key+              Client certificate key file
       -list-plugins      List all available plugins, perform no testing
       -maxtime+          Maximum testing time per host (e.g., 1h, 60m, 3600s)
       -mutate+           Guess additional file names:
                               1     Test all files with all root directories
                               2     Guess for password file names
                               3     Enumerate user names via Apache (/~user type requests)
                               4     Enumerate user names via cgiwrap (/cgi-bin/cgiwrap/~user type requests)
                               5     Attempt to brute force sub-domain names, assume that the host name is the parent domain
                               6     Attempt to guess directory names from the supplied dictionary file
       -mutate-options    Provide information for mutates
       -nointeractive     Disables interactive features
       -nolookup          Disables DNS lookups
       -nossl             Disables the use of SSL
       -no404             Disables nikto attempting to guess a 404 page
       -Option            Over-ride an option in nikto.conf, can be issued multiple times
       -output+           Write output to this file ('.' for auto-name)
       -Pause+            Pause between tests (seconds, integer or float)
       -Plugins+          List of plugins to run (default: ALL)
       -port+             Port to use (default 80)
       -RSAcert+          Client certificate file
       -root+             Prepend root value to all requests, format is /directory
       -Save              Save positive responses to this directory ('.' for auto-name)
       -ssl               Force ssl mode on port
       -Tuning+           Scan tuning:
                               1     Interesting File / Seen in logs
                               2     Misconfiguration / Default File
                               3     Information Disclosure
                               4     Injection (XSS/Script/HTML)
                               5     Remote File Retrieval - Inside Web Root
                               6     Denial of Service
                               7     Remote File Retrieval - Server Wide
                               8     Command Execution / Remote Shell
                               9     SQL Injection
                               0     File Upload
                               a     Authentication Bypass
                               b     Software Identification
                               c     Remote Source Inclusion
                               d     WebService
                               e     Administrative Console
                               x     Reverse Tuning Options (i.e., include all except specified)
       -timeout+          Timeout for requests (default 10 seconds)
       -Userdbs           Load only user databases, not the standard databases
                               all   Disable standard dbs and load only user dbs
                               tests Disable only db_tests and load udb_tests
       -useragent         Over-rides the default useragent
       -until             Run until the specified time or duration
       -update            Update databases and plugins from CIRT.net
       -useproxy          Use the proxy defined in nikto.conf, or argument http://server:port
       -Version           Print plugin and database versions
       -vhost+            Virtual host (for Host header)
   		+ requires a value

步骤3:使用基本语法


从上一步中可以看到,Nikto有很多用例,但是出于我们的目的,我们将使用基本语法<IP或主机名>以及不带尖括号的实际IP地址或主机名。

nikto -h <IP or hostname>

但是,Nikto能够扫描HTTPS站点使用的SSL和端口443(默认情况下,HTTP使用端口80)。因此,我们不仅限于爬网旧站点,还可以使用SSL评估站点的漏洞,而今天,SSL已成为对搜索结果建立索引的几乎强制性要求。

如果我们知道目标站点具有SSL,则可以在Nikto中指定此站点,以在命令末尾添加-ssl节省一些爬网时间

nikto -h <IP or hostname> -ssl

步骤4:使用SSL扫描网站


例如,让我们开始扫描站点pbs.org以查看Nikto爬网可以提供的信息类型。在连接到端口443之后,我们会看到一些有关加密的有用信息和其他详细信息,例如,服务器正在nginx上运行,但是这里没有太多有趣的信息。

nikto -h pbs.org -ssl

- Nikto v2.1.6
------------------------------------------------------------------------------
- STATUS: Starting up!
+ Target IP:			54.225.198.196
+ Target Hostname:		pbs.org
+ Traget Port:			443
------------------------------------------------------------------------------
+ SSl Info:			Subject:	/CN=www.pbs.org
					Altnames:	account.pbs.org, admin.pgs.org, dipsy-tc.pbs.org, docs.pbs.org, ga.video.cdn.pbs.org, git.pbs.org, heart.ops.pbs.org, hub-dev.pbs.org, image.pbs.org,
                    			jaws..pbs.org, kids.pbs.org, koth-qa.svp.pbs.org, login.pbs.org, ops.pbs.org, pbs.org, player.pbs.org, projects.pbs.org, sentry.pbs.org, teacherline.pbs.org,
                                urs.pbs.org, video.pbs.org, weta-qa.svp.pbs.org, whut-qa.svp.pbs.org, wnet.video-qa.pbs.org, wnet.video-staging.pbs.org, www-cache.pbs.org, www.pbs.org
                    Ciphers:	ECDHE-RSA-AES128-GCM-SHA256
                    Issuer:		/C-US/0=Let's Encrypt/CN=Let's Encrypt Authority X3
+ Start Time:			2018-12-05 23:34:06 (GMT-8)
------------------------------------------------------------------------------
+ Server: nginx
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ Uncommon header 'x-pbs-fwsrvname' found, with contents: fwcacheproxy1
+ The site uses SSL and the Strict-Transport-Security HTTP header is not defined.
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ Root page / redirects to: https://www.pbs.org/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ RC-1918 IP address found in the 'x-pbs-appsvrip' header: The IP is "10.137.181.52".
+ Uncommon header 'x-cache-fs-status' found, with contents: EXPIRED
+ Uncommon header 'x-pbs-appsvrname' found, with contents: fwcacheproxy1
+ Uncommon header 'x-pbs-appsvrip' found, with contents: 10.137.181.52
+ Server leaks inodes via ETags, header found with file /pbs.org.zip, fields: 0x5b96537e 0x1678
+ 7446 requests: 0 error(s) and 10 item(s) reported on remote host
+ End Time:				2018-12-06 00:30:29 (GMT-8) (3383 seconds)
------------------------------------------------------------------------------
+ 1 host(s) tested

步骤5:扫描IP地址


现在,我们已经完成了对网站的快速扫描,我们可以尝试在本地网络上使用Nikto查找嵌入式服务器,例如路由器的登录页面或另一台机器上的HTTP服务,这仅仅是一个没有网站的服务器。要查找IP地址,我们将使用ifconfig

我们需要的IP地址是inet。在它上面我们可以使用ipcalc以获得网络范围。如果没有ipcalc,则可以使用命令进行安装apt install ipcalc,然后重试。范围将在“网络”之后,在我的情况下为192.168.0.0/24。

ifconfig

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST>  mtu 1500
        inet 192.168.0.48  netmask 0xffffff00  broadcast 192.168.0.255
        inet6 XXXX::XXX:XXXX:XXXX:XXXX%en0  prefixlen 64  secured scopeid 0x8
        ether XX:XX:XX:XX:XX:XX  txqueuelen 1000  (Ethernet)
        inet6 XXXX::XXX:XXXX:XXXX:XXXX%en0  prefixlen 64 autoconf secured
        inet6 XXXX::XXX:XXXX:XXXX:XXXX%en0  prefixlen 64 autoconf temporary
        nd6 options=201<PERFORMNUD,DAD>
        media: autoselect
        status: active

en2: flags=8863<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST>  mtu 1500
        options=60<TS04,TS06>
        ether XX:XX:XX:XX:XX:XX
        media: autoselect <full-duplex>
        status: inactive

现在,我们要启动Nmap来查找在此网络范围内可用的服务。让我们使用范围扫描端口80,为此,我们添加-oG(可重复输出),以仅获取那些正在运行的主机,即通过说端口80已打开进行响应的主机。然后,我们将所有这些都保存在一个文件中,我将其命名为nullbyte.txt,您可以随意命名。

ipcalc 192.168.0.48

Address:   192.168.0.48         11000000.10101000.00000000. 00110000
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   192.168.0.0/24       11000000.10101000.00000000. 00000000
HostMin:   192.168.0.1          11000000.10101000.00000000. 00000001
HostMax:   192.168.0.254        11000000.10101000.00000000. 11111110
Broadcast: 192.168.0.255        11000000.10101000.00000000. 11111111
Hosts/Net: 254                   Class C, Private Internet

有一个小技巧可以帮助将所有主机直接发送到Nikto进行扫描。我们习惯于cat读取存储在我们文档中的输入nullbyte.txt(或者您自己所说的)。之后,我们使用awk(Linux中的特殊工具),它将帮助您找到下一个模板,其中Up表示主机已启动,print $ 2表示您需要在每行上打印第二个单词,即仅打印IP地址。然后,我们会将接收到的数据发送到一个名为targetIP.txt(或任何您想要的文件)的文件中

cat nullbyte.txt | awk '/Up$/{print $2}' | cat >> targetIP.txt

现在,我们可以使用cat查看新文件的内容,以查看打开了端口80的所有IP地址。

cat targetIP.txt

192.168.0.1
192.168.0.2
192.168.0.4
192.168.0.5
192.168.0.11
192.168.0.24
192.168.0.31
192.168.0.48
192.168.0.60

这种格式非常适合Nikto,因为它可以轻松解释此类文件。因此,我们可以使用以下命令将此输出发送给Nikto。

nikto -h targetIP.txt

结果将类似于我们使用SSL扫描时获得的结果。

步骤6:扫描HTTP站点


我们扫描了本地网络上的安全网站和IP地址,现在是时候寻找使用端口80的不安全Web域了。对于此示例,我使用的是afl.com.au,在我扫描此文件时没有SSL。

nikto -h www.afl.com.au

- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          159.180.84.10
+ Target Hostname:    www.afl.com.au
+ Target Port:        80
+ Start Time:         2018-12-05 21:48:32 (GMT-8)
---------------------------------------------------------------------------
+ Server: instart/nginx
+ Retried via header: 1.1 varnish (Varnish/6.1), 1.1 e9ba0a9a729ff2960a04323bf1833df8.cloudfront.net (CloudFront)
+ The anti-clickjacking X-Frame-Options header is not present.
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ Uncommon header 'x-cache' found, with contents: Miss from cloudfront
+ Uncommon header 'x-instart-cache-id' found, with contents: 17:12768802731504004780::1544075250
+ Uncommon header 'v-cache-hit' found, with contents: Hit
+ Uncommon header 'x-amz-cf-id' found, with contents: Dr-r6OwO5kk9ABt4ejzpc7R7AIF6SuH6kfJHQgP0v6xZoHwMLE55rQ==
+ Uncommon header 'x-instart-request-id' found, with contents: 12814413144077601501:BEQ01-CPVNPPRY18:1552504721:0
+ Uncommon header 'x-oneagent-js-injection' found, with contents: true
+ Uncommon header 'grace' found, with contents: cache
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ Uncommon header 'x-ruxit-js-agent' found, with contents: true
+ Cookie dtCookie created without the httponly flag
+ Server banner has changed from 'instart/nginx' to 'nginx' which may suggest a WAF, load balancer or proxy is in place
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Entry '/sites/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '/search/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ Entry '*.mobileapp' in robots.txt returned a non-forbidden or redirect HTTP code (400)
+ Entry '*.liveradio' in robots.txt returned a non-forbidden or redirect HTTP code (400)
+ Entry '*.smartmobile' in robots.txt returned a non-forbidden or redirect HTTP code (400)
+ Entry '*.responsive' in robots.txt returned a non-forbidden or redirect HTTP code (400)
+ Entry '/stats?*/' in robots.txt returned a non-forbidden or redirect HTTP code (200)
+ "robots.txt" contains 8 entries which should be manually viewed.
+ OSVDB-3092: /sitemap.xml: This gives a nice listing of the site content.
+ OSVDB-3092: /psql_history: This might be interesting...
+ OSVDB-3092: /global/: This might be interesting...
+ OSVDB-3092: /home/: This might be interesting...
+ OSVDB-3092: /news: This might be interesting...
+ OSVDB-3092: /search.vts: This might be interesting...
+ OSVDB-3092: /stats.htm: This might be interesting...
+ OSVDB-3092: /stats.txt: This might be interesting...
+ OSVDB-3092: /stats/: This might be interesting...
+ OSVDB-3092: /Stats/: This might be interesting...
+ OSVDB-3093: /.wwwacl: Contains authorization information
+ OSVDB-3093: /.www_acl: Contains authorization information
+ OSVDB-3093: /.htpasswd: Contains authorization information
+ OSVDB-3093: /.access: Contains authorization information
+ OSVDB-3093: /.addressbook: PINE addressbook, may store sensitive e-mail address contact information and notes
+ OSVDB-3093: /.bashrc: User home dir was found with a shell rc file. This may reveal file and path information.
+ OSVDB-3093: /.bash_history: A user's home directory may be set to the web root, the shell history was retrieved. This should not be accessible via the web.
+ OSVDB-3093: /.forward: User home dir was found with a mail forward file. May reveal where the user's mail is being forwarded to.
+ OSVDB-3093: /.history: A user's home directory may be set to the web root, the shell history was retrieved. This should not be accessible via the web.
+ OSVDB-3093: /.htaccess: Contains configuration and/or authorization information
+ OSVDB-3093: /.lynx_cookies: User home dir found with LYNX cookie file. May reveal cookies received from arbitrary web sites.
+ OSVDB-3093: /.mysql_history: Database SQL?
+ OSVDB-3093: /.passwd: Contains authorization information
+ OSVDB-3093: /.pinerc: User home dir found with a PINE rc file. May reveal system information, directories and more.
+ OSVDB-3093: /.plan: User home dir with a .plan, a now mostly outdated file for delivering information via the finger protocol
+ OSVDB-3093: /.proclog: User home dir with a Procmail rc file. May reveal mail traffic, directories and more.
+ OSVDB-3093: /.procmailrc: User home dir with a Procmail rc file. May reveal subdirectories, mail contacts and more.
+ OSVDB-3093: /.profile: User home dir with a shell profile was found. May reveal directory information and system configuration.
+ OSVDB-3093: /.rhosts: A user's home directory may be set to the web root, a .rhosts file was retrieved. This should not be accessible via the web.
+ OSVDB-3093: /.sh_history: A user's home directory may be set to the web root, the shell history was retrieved. This should not be accessible via the web.
+ OSVDB-3093: /.ssh: A user's home directory may be set to the web root, an ssh file was retrieved. This should not be accessible via the web.
+ OSVDB-5709: /.nsconfig: Contains authorization information
+ /portal/changelog: Vignette richtext HTML editor changelog found.
+ 7587 requests: 4 error(s) and 55 item(s) reported on remote host
+ End Time:           2018-12-05 22:42:41 (GMT-8) (3249 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

根据上面的信息,我们了解到有一个Varnish服务器和一些标头可以告诉您网站的配置方式。但是,发现了更多有用的信息,这些目录可以帮助捕获包含凭据或其他未正确配置并且无意提供的凭据的配置文件。

带有OSVDB前缀的元素是在“ 开源漏洞数据库”(该网站于2016年关闭)中报告的漏洞。它类似于其他漏洞数据库,例如SecurityFocusMicrosoft Technet以及漏洞和披露(https://cve.mitre.org/)。就个人而言,我更接近国家漏洞数据库

尽管我们的扫描没有发现任何可以利用的严重漏洞,但是您可以使用CVE帮助工具将OSVDB标识符转换为CVE记录,以便可以使用上面列出的站点之一。

假设您发现值得探索的东西,例如CVE-2018-10933(Libssh漏洞),我们之前已对其进行了详细讨论。 CVE包含有关如何利用它,漏洞的严重程度(例如,严重漏洞)的信息以及其他一些有助于确定攻击媒介的信息。如果这值得,您可以使用Metasploit进行搜索,因为很可能有人已经开发了一个有助于轻松利用此漏洞的模块。



步骤7:使用Metasploit进行扫描


Nikto最好的事情之一就是您可以简单地将扫描中收到的信息导出为Metasploit可以读取的格式。为此,只需使用命令执行上述扫描,然后在末尾添加-Format msf +标志这种格式可以帮助您快速匹配通过漏洞利用获得的数据。

nikto -h <IP or hostname> -Format msf+

因此,在今天的指南中,我们从定义目标到发现其中的漏洞,然后将漏洞与漏洞利用相关联,因此我们不必手动完成所有工作。由于Nikto不能秘密运行,因此最好通过VPN,Tor或其他类型的服务运行这些扫描,以免您的IP地址被标记为可疑。

→  注册免费课程

All Articles