Nmap脚本引擎

Nmap的库文件以及如何利用Nmap的自身库将nmap的扫描结果保存在数据中。

0×01 NSE 中的库文件

NSE中的库文件实现了代码的分离和重构,有助于脚本的开发。斗哥的所用的Nmap库文件数目前有128个,存放在/nselib/文件夹中。

0×02 NSE库文件的编写

1. 创建一个测试库文件

NSE的库文件就是一个lua文件。要编写一个库文件,如我们在/nselib/文件夹中新建一个名为testlib.lua的文件,该库文件返回参数port是开启的。

在新建的文件中,创建一个测试方法Porttest()

function Porttest(port)
    return string.format("The port '%s' is open",port)
end

2. 在NSE脚本中引用测试库

scripts文件中新建一个测试脚本,testlib.nse文件,,如果端口开启则把端口传入Porttest()方法中。

local shortport = require "shortport"
local testlib = require "testlib"

description = [[引用库文件测试]]

author = "reborn"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"default"}

portrule = function( host, port )
    return true
end

action = function(host,port)
    return Porttest(port.number)
end

可以看到,引用库文件使用local,格式一般为:local 库文件名 = require "库文件名",引用完毕即可直接使用库里面的方法和属性值了。Nmap 命令:nmap -Pn 10.10.10.39 --script testlib,如果需要脚本或者库需要调试,可以加上-d参数进入调试模式。

0×03 利用自有库和自定义库实现MySql写库

todo

猜你喜欢

转载自blog.csdn.net/weixin_41010318/article/details/79891439
今日推荐