27
Fuzzing 101 NYU/Poly.edu October 23, 2008 Mike Zusman

Fuzzing 101 - · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

  • Upload
    buidang

  • View
    223

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Fuzzing 101

NYU/Poly.edu

October 23, 2008

Mike Zusman

Page 2: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 2

  Find as much data as you can about the target application

  Google is your friend

  Maybe someone has fuzzed it

  Maybe it uses some standard protocol

Protocol Fuzzing

Page 3: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 3

  What is the transport layer?

  TCP or UDP?

  Effects anomaly detection

Protocol Fuzzing

Page 4: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 4

  What type of protocol?

  SIMPLE

  Text Based

  COMPLEX

  Binary

Protocol Fuzzing

Page 5: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 5

  What type of protocol?

  SIMPLE

  Text Based

  COMPLEX

  Binary

Protocol Fuzzing

Page 6: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Protocol Fuzzing

 Do we need to authenticate?

  What authentication protocol?

 Scoping your assessment

  You may only care about pre-auth

Intrepidus Group, Inc. © 2008 6

Page 7: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 7

  Reversing the Protocol

  Generate Traffic and Sniff

  Use wireshark (check for plug-ins!)

  It never hurts to ask Google

Protocol Fuzzing

Page 8: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 8

  Reversing the Protocol

  Establish syntax (authenticate first, then command1, followed by command2)

  Establish a list of commands

  Establish a list of arguments

Protocol Fuzzing

Page 9: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 9

  Reversing the Protocol   Build Command Prototypes

<argument> : required [argument] : optional {CONSTANT1|CONSTANT2 …}: Required constant argument

  Example:   PASS {SYS | USER <Username>} <Password>

Protocol Fuzzing

Page 10: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 10

  Once you understand how to communicate with a service, you can send packets to it.

  Simple Protocols   Use telnet, nc.exe, openssl

  Complex Protocols   Write Code

Protocol Fuzzing

Page 11: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 11

  Now that you can communicate with the protocol…

  Fuzzing Strategy   How would you fuzz it?

  What can you fuzz in this prototype?   PASS {SYS | USER <Username>} <Password>

Protocol Fuzzing

Page 12: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 12

  Fuzzing is repetitive   Open/Close connections to hosts   Build a UDP packet   Write data to a socket   Read Data from a socket   Loop through a sequence   Fuzz each parameter   etc

Protocol Fuzzing

Page 13: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 13

  If you try to write a network protocol fuzzer, you will eventually end up re-inventing the wheel

  SPIKE is a fuzzing framework/API   Written in C by Dave Aitel

  It takes care of the busy work

Protocol Fuzzing

Page 14: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 14

  If you try to write a network protocol fuzzer, you will eventually end up re-inventing the wheel

  SPIKE is a fuzzing framework/API   Written by Dave Aitel

  It takes care of the busy work

SPIKE

Page 15: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 15

  Simple Text Based Protocol Fuzzing   line_send_tcp.c

  Accepts a “script” of SPIKE commands   Example:

SPIKE

s_string_variable("PASS"); s_string(" "); s_string_variable("USER"); s_string(" "); s_string_variable("devel_user"); s_string(" "); s_string_variable("secretpassword"); s_string("\r\n");

Page 16: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 16

  Simple Text Based Protocol Fuzzing

  line_send_tcp.c

  ./line_send_tcp <IP> <PORT> script.spk 00

SPIKE

Page 17: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 17

  SPIKE’s real value   Complex Protocols have length fields and data

fields

  Tracking length fields while fuzzing data is complicated

  SPIKE does this for you

  Block Based Protocol Representation

SPIKE

Page 18: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 18

  What is a SPIKE?   “A SPIKE is a simple list of structures which

contain block size information and a queue of bytes.”

SPIKE

s_block_size_binary_bigendian_word(“somepacketdata”); s_block_start(“somepacketdata”) s_binary(“01020304”); s_block_end(“somepacketdata”);

Page 19: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 19

  Push 4 NULLs onto BYTE queue (size place holder)

  Then a new BLOCK listener is allocated named “somepacketdata”

SPIKE

s_block_size_binary_bigendian_word(“somepacketdata”); s_block_start(“somepacketdata”) s_binary(“01020304”); s_block_end(“somepacketdata”);

Page 20: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 20

  Script starts searching the block listeners for one named “somepacketdata”

  Block “start” pointers are updated to reflect the blocks position in the queue

SPIKE

s_block_size_binary_bigendian_word(“somepacketdata”); s_block_start(“somepacketdata”) s_binary(“01020304”); s_block_end(“somepacketdata”);

Page 21: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 21

  4 bytes of data are pushed onto the queue

SPIKE

s_block_size_binary_bigendian_word(“somepacketdata”); s_block_start(“somepacketdata”) s_binary(“01020304”); s_block_end(“somepacketdata”);

Page 22: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 22

  The block is ended, and the sizes are finalized

  The original 4 null bytes are updated with the appropriate size value

SPIKE

s_block_size_binary_bigendian_word(“somepacketdata”); s_block_start(“somepacketdata”) s_binary(“01020304”); s_block_end(“somepacketdata”);

Page 23: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 23

SPIKE

s_block_size_binary_bigendian_word(“somepacketdata”); s_block_start(“somepacketdata”) s_binary(“01020304”); s_block_end(“somepacketdata”);

Page 24: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Intrepidus Group, Inc. © 2007 24

SPIKE

  Given Prototype Data (length 100 byte) { Element1 (length 75 bytes) { B x 50 SubElement1(length 25 bytes) {A x 25} } }

Page 25: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Writing SPIKE

 Walk Through the Code   Citrix.c

Intrepidus Group, Inc. © 2008 25

Page 26: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Writing SPIKE

 Walk Through the Code   line_send_tcp.c

Intrepidus Group, Inc. © 2008 26

Page 27: Fuzzing 101 -   · PDF fileUse telnet, nc.exe, openssl Complex Protocols ... Tracking length fields while fuzzing data is complicated SPIKE does this for you

Writing SPIKE

  That’s it!

Intrepidus Group, Inc. © 2008 27