beginner's guide to the nmap scripting engine - redspin engineer, david shaw

34
Beginner's Guide to the nmap Scripting Engine David Shaw ([email protected])

Upload: redspin-inc

Post on 09-Jun-2015

2.409 views

Category:

Technology


2 download

DESCRIPTION

Redspin Engineer, David Shaw at Toorcon Information Security Conference giving his talk titled, Beginner's Guide to the nmap Scripting Engine.

TRANSCRIPT

Page 1: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Beginner's Guideto the

nmap Scripting Engine

David Shaw ([email protected])

Page 2: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

First Things First

- These slides (and all code used) are available online at:http://github.com/davidshaw/toorcon2010

Page 3: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Who is this?

Page 4: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- Versatile lua framework for nmap

What is the NSE?

Page 5: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- Versatile lua framework for nmap

- Allows users to script scans natively

What is the NSE?

Page 6: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- Versatile lua framework for nmap

- Allows users to script scans natively

- Great at picking low-hanging fruit

What is the NSE?

Page 7: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Why lua?

Page 8: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Why lua?

- Fyodor likes it (isn't that enough?)

Page 9: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Why lua?

- Fyodor likes it (isn't that enough?)

- I prefer Ruby (Metasploit, anyone?), so I looked up some benchmarks

Page 10: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Benchmarks

Credit: http://shootout.alioth.debian.org/

Page 11: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

What's already out there?

- There are a lot of awesome of scripts in every nmap install

- http://nmap.org/nsedoc/

Page 12: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

What's already out there?

Starting Nmap 5.35DC1 ( http://nmap.org ) at 2010-10-18 15:02 PDT

NSE: Loaded 131 scripts for scanning.

Page 13: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

What's already out there?

nmap <target> -sC all

Page 14: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Page 15: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Moving on...

- Great documentation at http://nmap.org/book/nse.html

Page 16: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Moving on...

- Great documentation at http://nmap.org/book/nse.html

- NSE's true power: anything you want

Page 17: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

A Common Problem

- JMX Consoles

Page 18: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

A Common Problem

- JMX Consoles

- Fairly common

Page 19: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

A Common Problem

- JMX Consoles

- Fairly common

- Often run on non-standard ports, such as 8080

Page 20: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Internals of an NSE

- NSE's are simple (even if you don't code)

Page 21: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Internals of an NSE

- NSE's are simple (even if you don't code)

- Let's create one, line by line, from scratch

Page 22: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

jmx_detect.nse

description = [[This is an nmap script to search for accessible JMX web consoles.

]]

Page 23: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

jmx_detect.nse

author = "David Shaw" -- hello, Toorcon!

Page 24: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

jmx_detect.nse

author = "David Shaw" -- hello, Toorcon!

license = "see http://nmap.org/book/man-legal.htm"

Page 25: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

jmx_detect.nse

author = "David Shaw" -- hello, Toorcon!

license = "see http://nmap.org/book/man-legal.htm"

categories = {"default", "discovery", "safe"}

Page 26: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- We want to trigger on certain ports, and JMX consoles are served over HTTP

require “shortport”require “http”

Page 27: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- “portrule” lets us tell nmap when to trigger our script

- “shortport” further simplifies this process

portrule

Page 28: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- “portrule” lets us tell nmap when to trigger our script

- “shortport” further simplifies this process

portrule = shortport.port_or_service({80, 443, 8080}, {“http”, “https”}

)

portrule

Page 29: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

- The “action” function runs when portrule is matched

action = function(host, port) -- do stuff in hereend

action

Page 30: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

action = function(host, port) -- we only care about the HTTP status (quick demo!) local stat = http.get(host, port, '/jmx-console/').statusend

action

Page 31: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

action = function(host, port) -- we only care about the HTTP status (quick demo!) local stat = http.get(host, port, '/jmx-console/').status

-- HTTP 200 (OK) means we probably found a JMX console! if stat == 200 then

return “[+] Found possible JMX Console!” endend

action

Page 32: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

require 'http'require 'shortport'portrule = shortport.port_or_service({80, 443, 8080},

{“http”, “https”})action = function(host, port) local stat = http.get(host, port, '/jmx-console/').status if stat == 200 then return “[+] Found possible JMX Console!” endend

Bringing it all together

Page 33: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Execution

Page 34: Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw

Thank you to:

Fyodor & the nmap team

My incredible coworkers, past and present(Mark, Joel, DB, Paul, Jason, Nate: that means you!)

We Did It!