2010-06-16 17:03:30 +00:00
|
|
|
# $Id$
|
2010-05-09 20:16:48 +00:00
|
|
|
|
2010-06-18 22:06:53 +00:00
|
|
|
This file contains some brief instructions on contributing to the
|
|
|
|
Metasploit Framework.
|
2010-05-09 20:16:48 +00:00
|
|
|
|
|
|
|
Code Style
|
2010-06-18 22:06:53 +00:00
|
|
|
==========
|
|
|
|
|
2010-08-14 21:37:29 +00:00
|
|
|
In order to maintain consistency and readability, we ask that you
|
|
|
|
adhere to the following style guidelines:
|
2010-06-18 22:06:53 +00:00
|
|
|
|
2013-09-09 14:34:48 +00:00
|
|
|
- Standard Ruby two-space soft tabs, not hard tabs.
|
2013-09-05 16:25:12 +00:00
|
|
|
- Try to keep your lines under 100 columns (assuming two-space tabs)
|
2010-05-09 20:16:48 +00:00
|
|
|
- do; end instead of {} for a block
|
2010-08-23 16:39:39 +00:00
|
|
|
- Always use str[0,1] instead of str[0]
|
2011-07-30 09:11:48 +00:00
|
|
|
(This avoids a known ruby 1.8/1.9 incompatibility.)
|
2011-04-25 02:48:23 +00:00
|
|
|
- Method names should always be lower_case and words separated by "_"
|
|
|
|
- Variable names should be lower case with words separated by "_"
|
|
|
|
- Don't depend on any external gems or libraries without talking to
|
2011-10-12 16:01:06 +00:00
|
|
|
todb to resolve packaging and licensing issues
|
2010-05-09 20:16:48 +00:00
|
|
|
|
2010-12-03 21:02:12 +00:00
|
|
|
You can use the the "./tools/msftidy.rb" script to do some rudimentary
|
|
|
|
checking for various violations.
|
|
|
|
|
2010-05-09 20:16:48 +00:00
|
|
|
|
2010-06-18 22:06:53 +00:00
|
|
|
Code No-Nos
|
|
|
|
===========
|
|
|
|
|
2011-04-25 02:48:23 +00:00
|
|
|
1. Don't print to standard output. Doing so means that users of
|
2011-03-06 06:49:00 +00:00
|
|
|
interfaces other than msfconsole, such as msfrpc and msfgui, won't see
|
2010-06-18 22:06:53 +00:00
|
|
|
your output. You can use print_line to accomplish the same thing as
|
|
|
|
puts.
|
|
|
|
|
2012-06-18 16:34:18 +00:00
|
|
|
2. Don't read from standard input, doing so will make your code
|
2011-04-25 02:48:23 +00:00
|
|
|
lock up the entire module when called from other interfaces. If you
|
|
|
|
need user input, you can either register an option or expose an
|
2012-10-06 07:24:30 +00:00
|
|
|
interactive session type specific for the type of exploit.
|
2011-04-25 02:48:23 +00:00
|
|
|
|
2013-11-13 22:45:21 +00:00
|
|
|
3. Always use Rex sockets, not ruby sockets. This includes
|
2010-06-18 22:06:53 +00:00
|
|
|
third-party libraries such as Net::Http. There are several very good
|
|
|
|
reasons for this rule. First, the framework doesn't get notified on
|
|
|
|
the creation of ruby sockets and won't know how to clean them up in
|
|
|
|
case your module raises an exception without cleaning up after itself.
|
|
|
|
Secondly, non-Rex sockets do not know about routes and therefore can't
|
|
|
|
be used through a meterpreter tunnel. Lastly, regular sockets miss
|
2012-10-06 07:24:30 +00:00
|
|
|
out on msf's proxy and SSL features. Msf includes many protocols
|
2010-06-18 22:06:53 +00:00
|
|
|
already implemented with Rex and if the protocol you need is missing,
|
|
|
|
porting another library to use them is straight-forward. See our
|
|
|
|
Net::SSH modifications in lib/net/ssh/ for an example.
|
|
|
|
|
2013-11-13 22:45:21 +00:00
|
|
|
4. When opening an IO stream, always force binary with "b" mode (or
|
2010-06-23 17:29:56 +00:00
|
|
|
using IO#binmode). This not only helps keep Windows and non-Windows
|
|
|
|
runtime environments consistent with each other, but also guarantees
|
|
|
|
that files will be treated as ASCII-8BIT instead of UTF-8.
|
2010-06-18 22:06:53 +00:00
|
|
|
|
2013-11-13 22:45:21 +00:00
|
|
|
5. Don't use String#[] for a single character. This returns a Fixnum in
|
2010-06-25 05:36:05 +00:00
|
|
|
ruby 1.8 and a String in 1.9, so it's safer to use the following idiom:
|
2013-11-13 22:45:21 +00:00
|
|
|
str[idx,1]
|
2010-06-25 05:36:05 +00:00
|
|
|
which always returns a String. If you need the ASCII byte, unpack it like
|
2013-11-13 22:45:21 +00:00
|
|
|
so:
|
|
|
|
tr[idx,1].unpack("C")[0]
|
2010-06-25 05:36:05 +00:00
|
|
|
|
2013-11-13 22:45:21 +00:00
|
|
|
6. Whenever possible, avoid using '+' or '+=' to concatenate strings.
|
2010-07-09 16:19:22 +00:00
|
|
|
The '<<' operator is significantly faster. The difference will become
|
|
|
|
even more apparent when doing string manipulation in a loop. The
|
|
|
|
following table approximates the underlying implementation:
|
2013-11-13 22:45:21 +00:00
|
|
|
|
2013-11-13 22:48:19 +00:00
|
|
|
Ruby Pseudo-C
|
|
|
|
----------- ----------------
|
|
|
|
a = b + c a = malloc(b.len+c.len+1);
|
|
|
|
strcpy(a, b);
|
|
|
|
memcpy(a+b.len, c, c.len);
|
|
|
|
a[b.len + c.len] = '\0';
|
|
|
|
a = b a = b;
|
|
|
|
a << c a = realloc(a, a.len+c.len+1);
|
|
|
|
memcpy(a+a.len, c, c.len);
|
|
|
|
a[a.len + c.len] = '\0';
|
|
|
|
|
2010-07-09 16:19:22 +00:00
|
|
|
Note that the original value of 'b' is lost in the second case. Care
|
|
|
|
must be taken to duplicate strings that you do not want to modify.
|
|
|
|
|
2013-11-13 22:45:21 +00:00
|
|
|
7. For other Ruby 1.8.x/1.9.x compat issues, please see Sam Ruby's
|
2011-03-02 22:04:41 +00:00
|
|
|
excellent slide show at <http://slideshow.rubyforge.org/ruby19.html>
|
|
|
|
for an overview of common and not-so-common Ruby version related gotchas.
|
2010-06-25 05:36:05 +00:00
|
|
|
|
2013-11-13 22:45:21 +00:00
|
|
|
8. Never, ever use $global variables. This applies to modules, mixins,
|
2011-04-25 02:48:23 +00:00
|
|
|
and libraries. If you need a "global" within a specific class, you can
|
|
|
|
use @@class_variables, but most modules should use @instance variables
|
|
|
|
to store information between methods.
|
|
|
|
|
2010-06-18 22:06:53 +00:00
|
|
|
Creating New Modules
|
|
|
|
====================
|
|
|
|
|
|
|
|
When creating a new module, the simplest way to start is to copy
|
|
|
|
another module that uses the same protocol and modify it to your
|
|
|
|
needs. If you're creating an exploit module, generally you'll want
|
|
|
|
to edit the exploit() method. Auxiliary Scanner modules use one of
|
|
|
|
run_host(), run_range(), or run_batch() instead of exploit().
|
|
|
|
Non-scanner aux modules use run().
|
2010-05-09 20:16:48 +00:00
|
|
|
|
|
|
|
|
2010-11-30 01:23:47 +00:00
|
|
|
Submitting Your Code
|
|
|
|
====================
|
|
|
|
|
2013-04-05 15:18:58 +00:00
|
|
|
To get started with a Metasploit Framework source clone, simply:
|
|
|
|
|
|
|
|
- Fork rapid7/metasploit-framework to your GitHub account
|
|
|
|
- git clone git://github.com/YourName/metasploit-framework.git
|
|
|
|
- gem install bundler
|
|
|
|
- bundle install
|
|
|
|
|
|
|
|
More detailed documentation regarding the process for submitting new
|
|
|
|
modules via GitHub is documented here:
|
2011-10-12 16:01:06 +00:00
|
|
|
|
2012-05-21 20:23:13 +00:00
|
|
|
https://github.com/rapid7/metasploit-framework/wiki/Metasploit-Development-Environment
|
2011-11-11 02:37:15 +00:00
|
|
|
|
|
|
|
This describes the process of forking, editing, and generating a
|
|
|
|
pull request, and is the preferred method for bringing new modules
|
|
|
|
and framework enhancements to the attention of the core Metasploit
|
|
|
|
development team. Note that this process requires a GitHub account.
|
|
|
|
|
2012-08-20 15:30:01 +00:00
|
|
|
For Git commits, please adhere to 50/72 formatting: your commits should
|
|
|
|
start with a line 50 characters or less, followed by a blank line,
|
2012-10-06 07:24:30 +00:00
|
|
|
followed by one or more lines of explanatory text wrapped at at 72
|
|
|
|
characters Pull requests with commits not formatted this way will
|
2012-08-20 15:30:01 +00:00
|
|
|
be rejected without review.
|
|
|
|
|
2011-11-11 02:37:15 +00:00
|
|
|
For modules, note that Author field is not automatic, and should be
|
|
|
|
filled in in the format of 'Your Name <user[at]domain.tld>' so future
|
|
|
|
developers can contact you with any questions.
|
2010-11-30 01:23:47 +00:00
|
|
|
|
2010-05-09 20:16:48 +00:00
|
|
|
Licensing
|
|
|
|
=========
|
2010-06-18 22:06:53 +00:00
|
|
|
By submitting code contributions to the Metasploit Project it is
|
2011-10-12 16:01:06 +00:00
|
|
|
assumed that you are offering your code under the Metasploit License
|
|
|
|
or similar 3-clause BSD-compatible license. MIT and Ruby Licenses
|
|
|
|
are also fine. We specifically cannot include GPL code. LGPL code
|
|
|
|
is accepted on a case by case basis for libraries only and is never
|
|
|
|
accepted for modules.
|
2010-05-09 20:16:48 +00:00
|
|
|
|
2010-06-18 22:06:53 +00:00
|
|
|
When possible, such as aux and exploit modules, be sure to include
|
2010-08-14 21:37:29 +00:00
|
|
|
your license designation in the file in the appropriate place.
|
2010-05-09 20:16:48 +00:00
|
|
|
|