LoginSignup
0
1

More than 5 years have passed since last update.

NSE Librariesを触ってみる

Last updated at Posted at 2016-03-16

NSE Librariesとは

NSE LibrariesとはNmapが提供しているスクリプトライブラリです。略してnselibと言いたいのですが、Nselibという研究目的のソフトウェアリポジトリがあるそうなのでNSE Librariesと表記した方が良さそうです。ライブラリはluaで書かれており、ライブラリを使用する際にも基本的にluaで書く形になります。

何ができるん?

普段コマンドを手入力して使っているNmapをコマンドラインオプション以上に詳細に、かつ簡単に指定ができます。そのため、複数台サーバを対象にした検証スクリプトを簡単に作成することができます。

サンプルコード

スキャン対象サーバがHTTPSに対応している場合にスキャン対象サーバのホスト情報を出力するスクリプトです。

hello_nselib.nse
local nmap = require "nmap"
local shortport = require "shortport"

description = [[This is test scripts]]

---
--@usage
--nmap --script hello_nselib

author = "Your name"

license = "Same as Nmap--See https://nmap.org/book/man-legal.html"

categories = {
    "test_nselib",
}

-- スクリプトを実行する条件を指定(今回はHTTPS)
portrule = shortport.portnumber({443})

-- 条件に一致した際に実行する処理
function action(host, port)
    local ret_list = {}
    ret_list["port"] = port
    ret_list["host"] = host
    return ret_list
end

以下のスクリプトで実行できます。(適宜置き換えてください)

nmap ${対象サーバのIP} --script=${スクリプトのパス名}

出力結果

ローカル(nemumu.com → nemumu.com)にスキャンをしているためRTTやIPが少し異なるかもしれませんが、以下の様な結果が出力されると思います。

[nemumu@nemumu ~]$ nmap nemumu.com -p 443 --script=./hello_nselib.nse

Starting Nmap 7.01 ( https://nmap.org ) at 2016-03-16 19:40 JST
Nmap scan report for nemumu.com (127.0.0.1)
Host is up (0.00014s latency).
Other addresses for nemumu.com (not scanned): ::1
rDNS record for 127.0.0.1: localhost.localdomain
PORT    STATE SERVICE
443/tcp open  https
| hello_nselib: 
|   host: 
|     reason: syn-ack
|     reason_ttl: 0
|     interface_mtu: 0
|     times: 
|       srtt: 0.000137
|       rttvar: 0.003777
|       timeout: 0.1
|     targetname: nemumu.com
|     name: localhost.localdomain
|     bin_ip: \x7F\x00\x00\x01
|     ip: 127.0.0.1
|     registry: 
| 
|   port: 
|     protocol: tcp
|     reason: syn-ack
|     reason_ttl: 0
|     service: https
|     version: 
|       service_dtype: table
|       name: https
|       name_confidence: 3
|       cpe: 
| 
|       service_tunnel: none
|     number: 443
|_    state: open

スクリプト内でjson出力してごにょごにょできるため大量のサーバを検証する場合には有用かもしれません。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1