Git Product home page Git Product logo

smb2's Introduction

Smb2

Build Status Code Climate PullReview stats Coverage Status

A packet parsing and manipulation library for the SMB2 protocol.

See Microsoft's [MS-SMB2]

It supports authentication via NTLM using the ruby ntlm gem

Installation

This gem has not yet been released, but when it is, do this:

Add this line to your application's Gemfile:

gem 'smb2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install smb2

Usage

Using the Client class

dispatcher = Smb2::Dispatcher::Socket.connect("192.168.100.140", 445)
client = Smb2::Client.new(
  dispatcher: dispatcher,
  username:"administrator",
  password:"P@ssword1",
  domain:"asdfasdf"
)
client.negotiate
client.authenticate

tree = client.tree_connect("\\\\#{dispatcher.socket.remote_address.ip_address}\\Users")

Now you can open files on the connected share. Tree#create is intended to behave like Ruby's File.open:

# read/write by default
file = tree.create("Public\\file.txt")
file.read # => <full contents of file.txt>
file.write("\nAppend a new line to file.txt")

Or with a block, the file will be closed when the block returns:

data = tree.create("Public\\file.txt") { |file|
  file.read
}

Making packets manually

sock = TCPSocket.new("192.168.100.140", 445)
neg = Smb2::Packet::NegotiateRequest.new(
  # This is necessary until I can figure out how to set a default for
  # `rest` fields
  dialects: "\x02\x02".force_encoding("binary"),
)
nbss = [neg.length].pack("N")
sock.write(nbss + neg.to_s)
# Grab NBSS size
size = sock.read(4).unpack("N").first
data = sock.read(size)
neg_response = Smb2::Packet::NegotiateResponse.new(data)

License

Smb2 is released under a 3-clause BSD license. See LICENSE.txt for full text.

Contributing

  1. Fork it ( https://github.com/rapid7/smb2/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

smb2's People

Contributors

egypt avatar limhoff-r7 avatar wvu avatar trosen-r7 avatar jlee-r7 avatar trevrosen avatar

Watchers

James Cloos avatar Joseph avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.