├── .drone.yml
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug-report.md
│ └── feature-request.md
└── workflows
│ └── codeql-analysis.yml
├── .gitignore
├── LICENSE
├── docs
├── _config.yml
├── architecture.md
├── building.md
├── configuration.md
├── index.md
├── modules.md
└── quickstart.md
├── libwraith
├── Config.go
├── Const.go
├── Mod.go
├── Shm.go
├── Shm_test.go
├── Wraith.go
├── Wraith_test.go
├── export_test.go
├── go.mod
└── go.sum
├── logo.png
└── readme.md
/.drone.yml:
--------------------------------------------------------------------------------
1 | kind: pipeline
2 | type: docker
3 | name: test
4 | steps:
5 | - name: test
6 | image: docker.io/golang:1.21-alpine
7 | depends_on: [ clone ]
8 | commands:
9 | - apk add --no-cache build-base git
10 | - go install mvdan.cc/garble@d3763143bd1e371733b96a234ce6fc8655e5acb3
11 | - cd libwraith
12 | - go version
13 | - garble version
14 | - garble -literals -tiny -seed=random test -v ./...
15 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom: ["https://etherscan.io/address/0x9bda2e5fa82947948d4bea9ca5693f1e9c2155f1"]
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug Report
3 | about: Report a bug in Wraith
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Details
11 | A clear and concise description of what the bug is.
12 |
13 | ## Reproducing
14 | Steps to reproduce the bug:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | ## Expectation
21 | A clear and concise description of what you expected to happen.
22 |
23 | ## Media
24 | If applicable, add screenshots or recordings to help explain your problem.
25 |
26 | ## Environment
27 | - OS: [e.g. Linux (Ubuntu 20.04)]
28 | - Wraith Version: [e.g. 22]
29 | - Build Env: [e.g. go 1.17 on Linux]
30 |
31 | ## Additional Context
32 | Add any other context about the problem here.
33 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature-request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature Request
3 | about: Suggest an idea for Wraith
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ indev, master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ indev ]
20 | schedule:
21 | - cron: '35 22 * * 3'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'go' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support
38 |
39 | steps:
40 | - name: Checkout repository
41 | uses: actions/checkout@v2
42 |
43 | # Initializes the CodeQL tools for scanning.
44 | - name: Initialize CodeQL
45 | uses: github/codeql-action/init@v1
46 | with:
47 | languages: ${{ matrix.language }}
48 | # If you wish to specify custom queries, you can do so here or in a config file.
49 | # By default, queries listed here will override any specified in a config file.
50 | # Prefix the list here with "+" to use these queries and those in the config file.
51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
52 |
53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54 | # If this step fails, then you should remove it and run the build manually (see below)
55 | - name: Autobuild
56 | uses: github/codeql-action/autobuild@v1
57 |
58 | # ℹ️ Command-line programs to run using the OS shell.
59 | # 📚 https://git.io/JvXDl
60 |
61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62 | # and modify them (or add more) to build your code if your project
63 | # uses a compiled language
64 |
65 | #- run: |
66 | # make bootstrap
67 | # make release
68 |
69 | - name: Perform CodeQL Analysis
70 | uses: github/codeql-action/analyze@v1
71 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-hacker
--------------------------------------------------------------------------------
/docs/architecture.md:
--------------------------------------------------------------------------------
1 | # Wraith Architecture (WIP)
2 | This document outlines how Wraith works in theory, how it communicates with C2, as well as how the codebase is structured.
3 |
4 | ## Index
5 | - [Overview](#overview) - High-level outline of Wraith's design and design considerations
6 | - [Features](#features) - Overview of Wraith's features and how they are implemented
7 | - [Protocol](#protocol) - Detailed description of how Wraith communicates
8 | - [Codebase Layout](#codebase-layout) - The layout of this repository
9 |
10 | ## Overview
11 | Wraith is designed with flexibility, resilience and versatility in mind. This means that it should never need manual updating (that is, updating via original infection vectors) once deployed and should be able to deal with C2 outages, or the server being taken down altogether. Furthermore, Wraith is also designed to be modular, to allow for effortless expansion of its functionality, without familiarity with the entire codebase.
12 |
13 | Wraith accomodates these requirements by utilising a unique architecture. The core component, libwraith, is tiny and lacks external dependencies, platform-specific code or cgo. It is designed to work as a library, meaning that it can be included in legitimate Go codebases with a minimal footprint, to provide a backdoor.
14 |
15 | This architecture also allows for all basic and advanced functionality to be implemented as modules. Those can be included or excluded individually depending on requirements for each individual build. Wraith therefore adapts to be as covert or a feature-complete as desired.
16 |
17 | As the C2 protocol is implemented as a plugin, it can be effortlessly switched out, or multiple protocols can work alongside each other for maximum resilience. In practice, this means that command and control can take place over any protocol, including DNS which is extremely difficult to block.
18 |
19 | ## Features
20 | - Library-like core:
21 | - Tiny
22 | - No external dependencies, platform-specific code or cgo
23 | - Can be injected into legitimate Go codebases
24 | - Extremely versatile:
25 | - Modules allow for adapting to each situation individually
26 | - Modules can be loaded remotely as long as at least one pre-included module supports this functionality
27 | - Difficult to detect:
28 | - Wraith is tailor-made to your requirements depending on which modules you include; this makes it difficult to detect
29 | - Core modules available, or write your own:
30 | - This repository contains a number of core modules within the stdmod package, which could be useful for general purpose usage
31 | - Modules are easy to write for more custom applications
32 |
33 | ## Protocol
34 | Wraith is not tied to a specific protocol as this is dependent on modules. Wraith's communication works as follows:
35 |
36 | - Internally, Wraith facilitates communication between modules by means of a shared memory interface. This is a thread-safe map-like structure which allows modules to write to "cells", read from them, and watch them for changes. The last of those also effectively makes the shared memory (shm) a pub/sub queue. Between those features, the shm provides a simple yet flexible way for modules to communicate.
37 | - Some cells in SharedMemory are standardised and used for specific purposes. These include `SHM_TX_QUEUE` and `SHM_RX_QUEUE` which are used to queue messages received by Wraith or to be sent by Wraith from/to C2.
38 | - Special modules exist which have standardised names and are expected to carry out specific tasks. One of those is `MOD_COMMS_MANAGER`, which is responsible for managing the aforementioned queues. This module effectively governs the communication format as it is responible for reading from the queues, encoding/decoding and encrypting/decrypting the data. Note that it is only the format of messages which is decided by this module, not the protocol they are sent over.
39 | - The comms manager module is then expected to pass the data on to other modules, depending on the queue the message was fetched from. Data from the TX queue, having been encoded and encrypted, should end up with a module capable of sending the data to C2. Meanwhile, messages read from the RX queue should end up with a module capable of processing them.
40 | - It is then up to the modules to send off the data over their chosen protocol or to process it as they see fit.
41 |
42 | Overall, the Wraith protocol is governed by the modules which are in use and entirely flexible. Modules even have the flexibility to bypass the comms manager altogether and make their own communication routes, though this is generally discouraged.
43 |
44 | All that said, the default comms manager implemented as part of `stdmod` uses an encrypted JWT-based protocol providing flexibility and decentralisation. Using this comms manager ensures that control of Wraith isn't dependent on access to one location (domain or IP address) but rather a signing key which is impossible to block, ban or report.
45 |
46 | ## Codebase Layout
47 | Due to the Wraith's modular architecture, the codebase is split into 2 main parts:
48 | - libwraith:
49 | - The core which doesn't provide any functionality on its own. It can be included in other programs as a library as long as some modules are also included for it to execute.
50 | - stdmod:
51 | - The standard module library - a collection of modules maintained by the authors of Wraith which can be included directly from this repo. These are what provide actual functionality to Wraith and can serve as examples for writing your own custom modules.
52 |
53 | In terms of the directory structure, that looks as follows:
54 |
55 | - root (metadata and other non-code files)
56 | - docs (documentation and guides)
57 | - wraith (code)
58 | - libwraith (a flat filestructure containing all the necessary code for Wraith's core, split into multiple files)
59 | - stdmod (a collection of standard modules and other miscellaneous helper functions for libwraith)
60 | - vendor (external dependencies of stdmod included in the repo)
--------------------------------------------------------------------------------
/docs/building.md:
--------------------------------------------------------------------------------
1 | # Building Wraith (WIP)
2 |
--------------------------------------------------------------------------------
/docs/configuration.md:
--------------------------------------------------------------------------------
1 | # Wraith Configuration Guide (WIP)
2 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | # Wraith Documentation
2 |
3 | ---
4 |
5 | The documentation is currently work-in-progress and subject to significant changes as the project develops!
6 |
7 | ---
8 |
9 | - [Quickstart Guide](quickstart.md)
10 | - [Project Architecture](architecture.md)
11 | - [Build Instructions](building.md)
12 | - [Configuration](configuration.md)
13 | - [Writing a Module](modules.md)
14 |
--------------------------------------------------------------------------------
/docs/modules.md:
--------------------------------------------------------------------------------
1 | # Wraith Module Guide (WIP)
2 |
--------------------------------------------------------------------------------
/docs/quickstart.md:
--------------------------------------------------------------------------------
1 | # Wraith Quickstart Guide
2 |
3 | ## Introduction
4 |
5 | Wraith is a framework and, as such, binaries are not provided.
6 |
7 | Instead, the user is expected to confirgure the Wraith via a small Go file, and build their own binary. This approach allows for more flexibility in terms of configuration and compilation targets and parameters.
8 |
9 | It also slightly raises the bar for entry, eliminating a good portion of script kiddies from the user base.
10 |
11 | Of course, this does require that a Go toolchain is installed to initially build a Wraith binary before deployment. This is unfortunate, but overall the benefits seem to outweigh the drawbacks.
12 |
13 | To install the Go toolchain, see https://go.dev/doc/install.
14 |
15 | ## Example
16 |
17 | Below is an example Go file which produces a working Wraith. It should give you a good starting point.
18 |
19 | The file can be built by invoking the `go build` command with the name of the file as the first and only parameter. Make sure to `go get` any non-standard dependencies first. In case of the below code, that would be everything going down from and including `"dev.l1qu1d.net/wraith-labs/wraith/wraith/libwraith"` in the import statement.
20 |
21 | More advanced users may wish to use a tool like [garble](https://github.com/burrowers/garble) to make their binaries harder to reverse-engineer.
22 |
23 | ```go
24 | package main
25 |
26 | import (
27 | "context"
28 | "crypto/ed25519"
29 | "encoding/hex"
30 | "os"
31 | "os/signal"
32 | "syscall"
33 | "time"
34 |
35 | "dev.l1qu1d.net/wraith-labs/wraith/wraith/libwraith"
36 |
37 | moduleexecgo "dev.l1qu1d.net/wraith-labs/wraith-module-execgo"
38 | modulepinecomms "dev.l1qu1d.net/wraith-labs/wraith-module-pinecomms"
39 | )
40 |
41 | const RESPECT_EXIT_SIGNALS = true
42 |
43 | var exitTrigger chan struct{}
44 |
45 | func setupCloseHandler(triggerChannel chan struct{}) {
46 | c := make(chan os.Signal, 2)
47 | signal.Notify(
48 | c,
49 | syscall.SIGHUP,
50 | syscall.SIGINT,
51 | syscall.SIGQUIT,
52 | syscall.SIGTERM,
53 | )
54 | if RESPECT_EXIT_SIGNALS {
55 | go func() {
56 | for range c {
57 | triggerChannel <- struct{}{}
58 | }
59 | }()
60 | }
61 | }
62 |
63 | func init() {
64 | exitTrigger = make(chan struct{})
65 | setupCloseHandler(exitTrigger)
66 | }
67 |
68 | func main() {
69 | // Create Wraith
70 | w := libwraith.Wraith{}
71 |
72 | // Create context for Wraith
73 | ctx, ctxCancel := context.WithCancel(context.Background())
74 |
75 | // Prepare some config values
76 | _, ownPrivKey, _ := ed25519.GenerateKey(nil)
77 | adminPubKey, _ := hex.DecodeString("0d1b9de8a9a2fe6cc30f45fd950d9722bf6d7e1687d18493e1a65e65cb94dd48") // REPLACE THIS WITH YOUR OWN PUBLIC KEY
78 |
79 | // Start Wraith in goroutine
80 | go w.Spawn(
81 | ctx,
82 | libwraith.Config{
83 | StrainId: "none",
84 | HeartbeatTimeout: 1 * time.Second,
85 | ModuleCrashloopDetectCount: 3,
86 | ModuleCrashloopDetectTime: 30 * time.Second,
87 | },
88 | &modulepinecomms.ModulePinecomms{
89 | OwnPrivKey: ownPrivKey,
90 | AdminPubKey: adminPubKey,
91 | ListenTcp: ":0",
92 | ListenWs: ":0",
93 | UseMulticast: true,
94 | StaticPeers: []string{
95 | "wss://pinecone.matrix.org/public",
96 | },
97 | },
98 | &moduleexecgo.ModuleExecGo{},
99 | )
100 |
101 | // Wait until the exit trigger fires
102 | <-exitTrigger
103 |
104 | // Kill Wraith and exit
105 | ctxCancel()
106 | time.Sleep(1 * time.Second) // wait to make sure everything has cleaned itself up
107 | }
108 | ```
109 |
--------------------------------------------------------------------------------
/libwraith/Config.go:
--------------------------------------------------------------------------------
1 | package libwraith
2 |
3 | import "time"
4 |
5 | // A struct providing configuration options for Wraith to allow
6 | // for altering behaviour without altering the code.
7 | type Config struct {
8 | // A string representing the family ID or strain ID of Wraith.
9 | // This can be useful to check what different versions of
10 | // Wraith are out there, or to target only one specific
11 | // strain with commands/payloads. This should be changed
12 | // whenever a significant change is made to Wraith before building.
13 | StrainId string
14 |
15 | // A function used to generate the fingerprint for this instance
16 | // of Wraith. That is, a unique string identifying specifically this
17 | // binary, on this host, in this process. It can be a UUID, for
18 | // instance, meaning that it serves only the purpose of identifiaction
19 | // and changes on every Wraith restart, or a string based on some
20 | // information such as MAC Address+Wraith PID.
21 | FingerprintGenerator func() string
22 |
23 | // The max time to wait for a heartbeat from Wraith's mainloop before
24 | // assuming that this instance is dead. Around 1 second is recommended.
25 | // Note that setting this too high can cause significant slowdowns when
26 | // Wraith does die.
27 | HeartbeatTimeout time.Duration
28 |
29 | // How many times modules should be allowed to crash within a time
30 | // specified in ModuleCrashLoopDetectTime before they are no longer
31 | // restarted. It is recommended to keep this relatively low to prevent
32 | // buggy modules from using up resources. The lower the value the more
33 | // strict the crashloop detection.
34 | ModuleCrashloopDetectCount int
35 |
36 | // After this time, module crashes are forgotten when evaluating whether
37 | // a module is crashlooping. It is recommended to keep this value relatively
38 | // high to ensure that crashlooped or buggy modules are always caught. The
39 | // higher the value the more strict the crashloop detection.
40 | ModuleCrashloopDetectTime time.Duration
41 | }
42 |
--------------------------------------------------------------------------------
/libwraith/Const.go:
--------------------------------------------------------------------------------
1 | package libwraith
2 |
3 | // Reserved locations in the shared memory with special purposes.
4 | // All other locations should be namespaced.
5 | const (
6 | // This cell holds the latest error which occurred, be it in a module
7 | // or Wraith itself. Can be used to send error logs to C2.
8 | SHM_ERRS = "err"
9 | )
10 |
11 | // Configuration options for shared memory.
12 | const (
13 | // The size of watcher channels. Making this bigger makes update
14 | // delivery more reliable and ordered but increases memory usage
15 | // if a watcher isn't reading its updates.
16 | SHMCONF_WATCHER_CHAN_SIZE = 255
17 |
18 | // Timeout in seconds after which notifications for watchers are
19 | // dropped if writing to the channel blocks.
20 | SHMCONF_WATCHER_NOTIF_TIMEOUT = 1
21 | )
22 |
--------------------------------------------------------------------------------
/libwraith/Mod.go:
--------------------------------------------------------------------------------
1 | package libwraith
2 |
3 | import "context"
4 |
5 | // An interface describing the structure of a Wraith Module
6 | type mod interface {
7 | // Start the module's mainloop. This is called as soon as the module is added to
8 | // the Wraith and is guaranteed to be called once at a time (that is, it will not
9 | // be called again until it returns).
10 | //
11 | // The method is called asynchronously and should block indefinitely (never return)
12 | // unless its context is cancelled. If this method returns or panics and the context
13 | // is not cancelled, it will be assumed to have crashed and will be restarted
14 | // immediately unless the max configured crashes occur within a configured time
15 | // at which point it will no longer be restarted.
16 | //
17 | // The method receives 2 arguments: a context which, when cancelled, should
18 | // cause the mainloop to exit (return); and a pointer to the module's parent
19 | // Wraith instance for communication purposes.
20 | //
21 | // Any errors should ideally be handled within the method and not propagate
22 | // up the stack; however, if an error cannot be handled, the mainloop should panic.
23 | // Wraith will catch the panic but, as modules can be very diverse, Wraith
24 | // is unable to correctly handle module errors and will resort to taking note
25 | // of them (for possible sending to C2 later) and moving on. Panicking modules will
26 | // be restarted provided they are not crashlooping.
27 | Mainloop(context.Context, *Wraith)
28 |
29 | // Return a string representing the name of the module. This is used to
30 | // generate a map of module names to allow for easy listing, and management
31 | // of modules.
32 | //
33 | // The method should consist of only a single return statement with a
34 | // hard-coded string.
35 | //
36 | // Module names should be globally unique. Multiple modules using the same
37 | // name will clash and only one of them will actually be activated.
38 | // Because of this, module name namespacing is highly recommended. For
39 | // example, the name "keylogger" is bad, because it's likely to be used by
40 | // multiple modules. Instead, "io.github.user.keylogger" could be used.
41 | //
42 | // Official modules use the special `w` namespace. Unofficial modules MUST NOT
43 | // use this namespace.
44 | WraithModuleName() string
45 | }
46 |
--------------------------------------------------------------------------------
/libwraith/Shm.go:
--------------------------------------------------------------------------------
1 | package libwraith
2 |
3 | import (
4 | "sync"
5 | "time"
6 | )
7 |
8 | // A struct for storing individual pieces of data within the
9 | // SharedMemory. Using a struct over simply values in a
10 | // map allows for storing additional metadata and simpler
11 | // interaction with the shared memory (ie. watchers can be
12 | // handled by the cell and don't need to be kept track of by
13 | // the memory).
14 | type shmCell struct {
15 | data any
16 | watchers map[int]chan any
17 | watcherCounter int
18 | }
19 |
20 | // Initialise the cell so that it's useable. Calling the cell's other
21 | // methods before this one can lead to panics. This should be called
22 | // exactly once as each consecutive call effectively wipes the cell.
23 | func (c *shmCell) init() {
24 | c.watchers = make(map[int]chan any)
25 | c.watcherCounter = 0
26 | }
27 |
28 | // Notify watchers of this cell about the current value of the cell.
29 | // This is a helper which should be called whenever the value is
30 | // changed by one of the other methods.
31 | //
32 | // All pushes to channels are done asynchronously as to return as
33 | // quickly as possible and therefore reduce the time taken to set
34 | // cells. This also means that watchers get updates as quickly as
35 | // possible. However, a goroutine is spawned for each watcher because
36 | // of this, though this should be fine because goroutines have
37 | // minimal overhead. The call will block until all goroutines return.
38 | //
39 | // Pushes time out after SHMCONF_WATCHER_NOTIF_TIMEOUT seconds,
40 | // so if a channel is full for longer than that, the watcher which
41 | // owns that channel will not receive that update.
42 | func (c *shmCell) notify() {
43 | wg := sync.WaitGroup{}
44 | wg.Add(len(c.watchers))
45 |
46 | for watcherId, watcherChannel := range c.watchers {
47 | go func(watcherId int, watcherChannel chan any) {
48 | // At the very end, mark this goroutine as done
49 | defer wg.Done()
50 | // The channel could be closed, in which case a panic will
51 | // occur. We don't want any panics so we will catch it here.
52 | // However, there is no point ever trying to send to this
53 | // channel again, so it should be removed.
54 | // TODO: Not relying on panics would be nice
55 | defer func() {
56 | if r := recover(); r != nil {
57 | delete(c.watchers, watcherId)
58 | }
59 | }()
60 |
61 | // Send to channel with timeout
62 | select {
63 | case watcherChannel <- c.data:
64 | case <-time.After(SHMCONF_WATCHER_NOTIF_TIMEOUT * time.Second):
65 | }
66 | }(watcherId, watcherChannel)
67 | }
68 |
69 | // Wait for all goroutines to finish, otherwise this function would
70 | // return, the SharedMemory might release the lock, another call might be
71 | // made to change the value and different watchers would get different
72 | // updates. As the goroutines have timeouts, this shouldn't take very
73 | // long.
74 | wg.Wait()
75 | }
76 |
77 | // Set the value of the cell to that passed as the argument. This
78 | // will also notify all watchers of the change.
79 | func (c *shmCell) set(value any) {
80 | c.data = value
81 |
82 | c.notify()
83 | }
84 |
85 | // Get the current value of the cell.
86 | func (c *shmCell) get() (value any) {
87 | return c.data
88 | }
89 |
90 | // Add a channel to the list of watchers for this cell. This means
91 | // that the channel will receive the value of this cell whenever it
92 | // changes. Returns the assigned ID of the channel which can be
93 | // used to unwatch the cell.
94 | func (c *shmCell) watch(channel chan any) int {
95 | defer func() { c.watcherCounter++ }()
96 |
97 | c.watchers[c.watcherCounter] = channel
98 |
99 | return c.watcherCounter
100 | }
101 |
102 | // Remove a channel from the list of watchers from this cell. This
103 | // means that the channel will no longer receive updates when the
104 | // value of this cell changes. Takes the ID returned by watch().
105 | func (c *shmCell) unwatch(id int) {
106 | delete(c.watchers, id)
107 | }
108 |
109 | // A struct for sharing memory between modules and Wraith in a
110 | // thread-safe way while providing facilities to watch individual
111 | // memory cells for updates.
112 | type shm struct {
113 | mutex sync.RWMutex
114 | mem map[string]*shmCell
115 | }
116 |
117 | // Lock the mutex and return the function to unlock it. This
118 | // allows for a simple, one-liner to lock and unlock the mutex
119 | // at the top of every method like so: `defer m.autolock()()`.
120 | func (m *shm) autolock() func() {
121 | m.mutex.Lock()
122 | return m.mutex.Unlock
123 | }
124 |
125 | // Same as autolock but locks for reading only
126 | func (m *shm) rautolock() func() {
127 | m.mutex.RLock()
128 | return m.mutex.RUnlock
129 | }
130 |
131 | // Create and init a cell with the given name and return its pointer.
132 | func (m *shm) createcell(name string) *shmCell {
133 | m.mem[name] = &shmCell{}
134 | m.mem[name].init()
135 | return m.mem[name]
136 | }
137 |
138 | // Initialise the shm. Successive calls will re-initialise the shm
139 | // thereby clearing the content of all cells.
140 | func (m *shm) Init() {
141 | defer m.autolock()()
142 |
143 | m.mem = make(map[string]*shmCell)
144 | }
145 |
146 | // Set the value of the given cell to that passed as the argument.
147 | // This will also notify all watchers of the change.
148 | func (m *shm) Set(cellName string, value any) {
149 | defer m.autolock()()
150 |
151 | // If the cell exists...
152 | if cell, exists := m.mem[cellName]; exists {
153 | // ...set its value
154 | cell.set(value)
155 | } else {
156 | // ...create the cell, then set its value
157 | m.createcell(cellName).set(value)
158 | }
159 | }
160 |
161 | // Get the current value of a given cell.
162 | func (m *shm) Get(cellName string) any {
163 | defer m.rautolock()()
164 |
165 | // If the cell exists...
166 | if cell, exists := m.mem[cellName]; exists {
167 | // ...return its value
168 | return cell.get()
169 | } else {
170 | // ...return nil because the cell is nil
171 | return nil
172 | }
173 | }
174 |
175 | // Add a channel to the list of watchers for this cell. This means
176 | // that the channel will receive the value of this cell whenever it
177 | // changes. If the cell does not exist, it will be created as to
178 | // allow watching for cells to be created in the future. Returns
179 | // the channel which will receive updates and the ID assigned to that
180 | // channel which can be used to unwatch the cell.
181 | func (m *shm) Watch(cellName string) (channel chan any, watchId int) {
182 | defer m.autolock()()
183 |
184 | // Create a channel, to be used for sending updates, with no buffer
185 | channel = make(chan any, SHMCONF_WATCHER_CHAN_SIZE)
186 |
187 | // If the cell exists...
188 | if cell, exists := m.mem[cellName]; exists {
189 | // ...add a watcher
190 | watchId = cell.watch(channel)
191 | } else {
192 | // ...create the cell, then add a watcher
193 | watchId = m.createcell(cellName).watch(channel)
194 | }
195 |
196 | return channel, watchId
197 | }
198 |
199 | // Remove a channel from the list of watchers from a given cell.
200 | // This means that the channel will no longer receive updates
201 | // when the value of this cell changes. Takes the ID returned
202 | // by Watch().
203 | func (m *shm) Unwatch(cellName string, watchId int) {
204 | defer m.autolock()()
205 |
206 | // If the cell exists...
207 | if cell, exists := m.mem[cellName]; exists {
208 | // ...remove the watcher (if the ID doesn't exist, this
209 | // is a no-op)
210 | cell.unwatch(watchId)
211 | }
212 | // ...otherwise, there's nothing to do
213 | }
214 |
215 | // Dump the entire contents of the shared memory as a map. Note
216 | // that this does not just return a property of shm; it loops
217 | // over each cell and fetches its value. This means that calls
218 | // might be quite resource-intensive depending on the shm size.
219 | func (m *shm) Dump() map[string]any {
220 | defer m.rautolock()()
221 |
222 | memdump := make(map[string]any)
223 |
224 | // Fetch data from all cells.
225 | for cellname, cell := range m.mem {
226 | memdump[cellname] = cell.get()
227 | }
228 |
229 | return memdump
230 | }
231 |
232 | // Delete all cells which hold a nil value and have no watchers.
233 | func (m *shm) Prune() int {
234 | defer m.autolock()()
235 |
236 | pruned := 0
237 |
238 | // Loop over all cells and find which are unused.
239 | for cellname, cell := range m.mem {
240 | if cell.get() == nil && len(cell.watchers) == 0 {
241 | delete(m.mem, cellname)
242 | pruned++
243 | }
244 | }
245 |
246 | return pruned
247 | }
248 |
--------------------------------------------------------------------------------
/libwraith/Shm_test.go:
--------------------------------------------------------------------------------
1 | package libwraith_test
2 |
3 | import (
4 | "sync"
5 | "testing"
6 | "time"
7 |
8 | "dev.l1qu1d.net/wraith-labs/wraith/libwraith"
9 | )
10 |
11 | func TestShmInit(t *testing.T) {
12 | testshm := libwraith.Shm{}
13 |
14 | testshm.Init()
15 | }
16 |
17 | func TestShmWriteReadReinit(t *testing.T) {
18 | testshm := libwraith.Shm{}
19 |
20 | testshm.Init()
21 |
22 | testshm.Set("foo", "bar")
23 |
24 | testshm.Init()
25 |
26 | if value := testshm.Get("foo"); value != nil {
27 | t.Errorf("shm reinit failed (re-initialised shm still holds old values)")
28 | }
29 | }
30 |
31 | func TestShmWriteRead(t *testing.T) {
32 | testshm := libwraith.Shm{}
33 |
34 | testshm.Init()
35 |
36 | dataset := map[string]interface{}{
37 | "hello": 1,
38 | "world": "foo",
39 | "bar": 0.125,
40 | "struct": struct{}{},
41 | "bool": true,
42 | }
43 |
44 | for key, value := range dataset {
45 | testshm.Set(key, value)
46 | }
47 |
48 | for key, value := range dataset {
49 | if testshm.Get(key) != value {
50 | t.Errorf("shm readback failed (wrote `%v` to `%s` but read `%v` back)", dataset[key], key, value)
51 | }
52 | }
53 | }
54 |
55 | func TestShmWriteReadWatchUnwatchAsync(t *testing.T) {
56 | testshm := libwraith.Shm{}
57 |
58 | testshm.Init()
59 |
60 | dataset := map[string]interface{}{
61 | "hello": 1,
62 | "world": "foo",
63 | "bar": 0.125,
64 | "struct": struct{}{},
65 | "bool": true,
66 | }
67 |
68 | wg := sync.WaitGroup{}
69 | wg.Add(len(dataset))
70 |
71 | for key, value := range dataset {
72 | go func(key string, value interface{}) {
73 | watcher, watcherId := testshm.Watch(key)
74 | testshm.Set(key, value)
75 | select {
76 | case data := <-watcher:
77 | if data != value {
78 | t.Errorf("shm watch failed (wrote `%v` to `%s` but watcher returned `%v` back)", dataset[key], key, data)
79 | }
80 | case <-time.After(500 * time.Millisecond):
81 | t.Errorf("shm watch failed (timed out waiting for value `%v` in cell `%s`)", value, key)
82 | }
83 | testshm.Unwatch(key, watcherId)
84 | testshm.Set(key, value)
85 | select {
86 | case <-watcher:
87 | t.Errorf("shm unwatch failed (unwatched cell `%s` still sent an update to watch channel)", key)
88 | case <-time.After(500 * time.Millisecond):
89 | }
90 | wg.Done()
91 | }(key, value)
92 | }
93 |
94 | wg.Wait()
95 | }
96 |
97 | func TestShmDump(t *testing.T) {
98 | testshm := libwraith.Shm{}
99 |
100 | testshm.Init()
101 |
102 | dataset := map[string]interface{}{
103 | "hello": 1,
104 | "world": "foo",
105 | "bar": 0.125,
106 | "struct": struct{}{},
107 | "bool": true,
108 | }
109 |
110 | for key, value := range dataset {
111 | testshm.Set(key, value)
112 | }
113 |
114 | for key, value := range testshm.Dump() {
115 | if origvalue, ok := dataset[key]; !ok {
116 | t.Errorf("shm dump failed (dump missing key `%s`)", key)
117 | } else if origvalue != value {
118 | t.Errorf("shm dump failed (dump key `%s` has incorrect value `%v` while `%v` expected)", key, value, origvalue)
119 | }
120 | }
121 | }
122 |
123 | func TestShmPrune(t *testing.T) {
124 | testshm := libwraith.Shm{}
125 |
126 | testshm.Init()
127 |
128 | dataset := map[string]interface{}{
129 | "hello": 1,
130 | "world": "foo",
131 | "bar": 0.125,
132 | "struct": struct{}{},
133 | "bool": true,
134 | "nil": nil,
135 | "nil2": nil,
136 | }
137 |
138 | for key, value := range dataset {
139 | testshm.Set(key, value)
140 | }
141 |
142 | testshm.Prune()
143 |
144 | shmdump := testshm.Dump()
145 |
146 | for key := range shmdump {
147 | if key == "nil" || key == "nil2" {
148 | t.Errorf("shm dump failed (nil-valued cell was not removed)")
149 | }
150 | }
151 |
152 | if len(shmdump) != len(dataset)-2 {
153 | t.Errorf("shm dump failed (incorrect number of cells pruned)")
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/libwraith/Wraith.go:
--------------------------------------------------------------------------------
1 | package libwraith
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "sync"
7 | "time"
8 | )
9 |
10 | type Wraith struct {
11 | //
12 | // Lifecycle control
13 | //
14 |
15 | // A mutex keeping track of whether this instance of Wraith is
16 | // running. This ensures that only one mainloop is running at
17 | // a time per instance of Wraith.
18 | instanceLock sync.Mutex
19 |
20 | // A context which controls Wraith's lifetime. This is derived
21 | // from a parent context provided to Wraith's Spawn method.
22 | ctx context.Context
23 |
24 | // A mutex protecting access to Wraith.ctx.
25 | ctxLock sync.RWMutex
26 |
27 | // A channel used to check whether Wraith's mainloop is running.
28 | heartbeat chan struct{}
29 |
30 | //
31 | // Metadata
32 | //
33 |
34 | // A time.Time instance keeping track of the time Wraith was
35 | // initialised/started at so it can be retrieved by modules if
36 | // needed.
37 | initTime time.Time
38 |
39 | //
40 | // Modules
41 | //
42 |
43 | // A shared memory instance used to facilitate communication
44 | // between modules and Wraith.
45 | shm shm
46 |
47 | // A map keeping track of which modules are registered to
48 | // prevent modules from being registered multiple times.
49 | mods map[string]struct{}
50 |
51 | // A mutex protecting access to Wraith.mods.
52 | modsLock sync.RWMutex
53 |
54 | //
55 | // Configuration
56 | //
57 |
58 | // An instance of WraithConf storing all configuration necessary
59 | // for Wraith to work correctly.
60 | conf Config
61 | }
62 |
63 | // Helper method to be deferred at the start of all Wraith methods
64 | // to ensure none of them panic and cause the entire program to crash.
65 | // Wraith is meant to be silent when embedded in other software, and
66 | // reliable.
67 | func (w *Wraith) catch() {
68 | recover()
69 | }
70 |
71 | // Spawn an instance of Wraith running synchronously. If you would
72 | // like Wraith to run asynchronously, start this function in a
73 | // goroutine. It can then be stopped by cancelling its context.
74 | //
75 | // The first argument is a context instance used to control Wraith's
76 | // lifetime. The second is an instance of WraithConf containing the
77 | // configuration for this instance of Wraith. It should be fully
78 | // initialised and filled out. An uninitialised config can lead to
79 | // undefined behaviour. The following arguments are modules which
80 | // should be available to Wraith. In case of a name conflict, the
81 | // first module in the list with the name will be used, the others
82 | // will be discarded.
83 | //
84 | // Modules are initialised and started in the order they are given.
85 | // It is highly recommended to pass the comms manager module first
86 | // (possibly preceded by modules it depends on) to make sure module
87 | // communications are not lost.
88 | func (w *Wraith) Spawn(pctx context.Context, conf Config, mods ...mod) {
89 | defer w.catch()
90 |
91 | // Make sure only one mainloop instance runs. If another mainloop
92 | // is running, exit immediately.
93 | single := w.instanceLock.TryLock()
94 | if !single {
95 | return
96 | }
97 | defer w.instanceLock.Unlock()
98 |
99 | // Take note of start time.
100 | w.initTime = time.Now()
101 |
102 | // Save a copy of the config.
103 | w.conf = conf
104 |
105 | // Init heartbeat channel.
106 | //
107 | // It is important that this channel is unbuffered, else it will
108 | // return false positives. It must also be initialised early on
109 | // or reads will block forever resulting in false negatives.
110 | w.heartbeat = make(chan struct{})
111 |
112 | // Initialise the shm. This must be done before any modules are
113 | // started because modules will assume the shm is post-init.
114 | w.shm.Init()
115 |
116 | // Save a copy of the provided context to control Wraith's lifetime.
117 | w.ctxLock.Lock()
118 | w.ctx = pctx
119 | w.ctxLock.Unlock()
120 |
121 | // Init map of modules to keep track of which modules are already
122 | // active.
123 | w.mods = make(map[string]struct{})
124 |
125 | // Activate any modules passed directly to this method.
126 | //
127 | // This is done asynchronously so the mainloop is able to
128 | // start. Otherwise this method will not detect a mainloop and
129 | // hence fail, carshing Wraith.
130 | go w.ModsReg(mods...)
131 |
132 | // Run mainloop.
133 | //
134 | // This is the place where any functions which need to be
135 | // carried out by Wraith itself are handled, based on an event
136 | // loop. Most functions are carried out by modules, so there
137 | // shouldn't be too much here.
138 | for {
139 | select {
140 | // If the context was closed...
141 | case <-w.ctx.Done():
142 | // ...exit.
143 | return
144 | // Write to heartbeat channel whenever an update is requested.
145 | case w.heartbeat <- struct{}{}:
146 | }
147 | }
148 | }
149 |
150 | // Check whether Wraith's mainloop is running by issuing a heartbeat
151 | // request and awaiting a response with a configured timeout.
152 | func (w *Wraith) IsAlive() bool {
153 | if w.heartbeat != nil {
154 | select {
155 | case <-w.heartbeat:
156 | // We have received a heartbeat; definitely running.
157 | return true
158 | case <-time.After(w.conf.HeartbeatTimeout):
159 | // We have reached a timeout without receiving a hearbeat;
160 | // almost certainly not running.
161 | return false
162 | }
163 | }
164 |
165 | // The heartbeat channel has not been initialised; definitely
166 | // not running.
167 | return false
168 | }
169 |
170 | //
171 | //
172 | // Proxy Methods
173 | //
174 | //
175 |
176 | // These are methods which allow access to Wraith's internal
177 | // properties in a limited manner, to make sure all access
178 | // is safe and will not cause unexpected behaviour.
179 |
180 | //
181 | // Init Time
182 | //
183 |
184 | // Return the time at which Wraith started initialisation (recorded
185 | // as soon as Wraith confirms that it is the only running instance).
186 | // This will be the time.Time zero value if Wraith has not yet
187 | // started initialisation.
188 | func (w *Wraith) GetInitTime() time.Time {
189 | defer w.catch()
190 |
191 | return w.initTime
192 | }
193 |
194 | //
195 | // Strain ID
196 | //
197 |
198 | // Get the strain ID of this Wraith.
199 | func (w *Wraith) GetStrainId() string {
200 | defer w.catch()
201 |
202 | return w.conf.StrainId
203 | }
204 |
205 | //
206 | // Shared Memory
207 | //
208 |
209 | // Proxy to shm.Get().
210 | //
211 | // Disallows reading from protected cells.
212 | func (w *Wraith) SHMGet(cellname string) any {
213 | defer w.catch()
214 |
215 | return w.shm.Get(cellname)
216 | }
217 |
218 | // Proxy to shm.Set().
219 | //
220 | // Disallows writing to protected cells.
221 | func (w *Wraith) SHMSet(cellname string, value any) {
222 | defer w.catch()
223 |
224 | w.shm.Set(cellname, value)
225 | }
226 |
227 | // Proxy to shm.Watch().
228 | //
229 | // Disallows watching protected cells.
230 | func (w *Wraith) SHMWatch(cellname string) (chan any, int) {
231 | defer w.catch()
232 |
233 | return w.shm.Watch(cellname)
234 | }
235 |
236 | // Proxy to shm.Unwatch()
237 | //
238 | // Disallows unwatching protected cells.
239 | func (w *Wraith) SHMUnwatch(cellname string, watchId int) {
240 | defer w.catch()
241 |
242 | w.shm.Unwatch(cellname, watchId)
243 | }
244 |
245 | // Proxy to shm.Dump()
246 | func (w *Wraith) SHMDump() map[string]any {
247 | defer w.catch()
248 |
249 | return w.shm.Dump()
250 | }
251 |
252 | // Proxy to shm.Prune()
253 | func (w *Wraith) SHMPrune() int {
254 | defer w.catch()
255 |
256 | return w.shm.Prune()
257 | }
258 |
259 | //
260 | // Modules
261 | //
262 |
263 | // Add a module to Wraith. These are started straight away automatically.
264 | //
265 | // Panics if Wraith is not running by the time this method is called.
266 | func (w *Wraith) ModsReg(mods ...mod) {
267 | w.ctxLock.RLock()
268 | defer w.ctxLock.RUnlock()
269 |
270 | if w.ctx == nil || w.ctx.Err() != nil || !w.IsAlive() {
271 | panic("wraith not running")
272 | }
273 |
274 | defer w.catch()
275 |
276 | w.modsLock.Lock()
277 | defer w.modsLock.Unlock()
278 |
279 | for _, module := range mods {
280 | modname := module.WraithModuleName()
281 |
282 | // Ignore module if already exists.
283 | if _, exists := w.mods[modname]; !exists {
284 | w.mods[modname] = struct{}{}
285 |
286 | // Run the module in a goroutine.
287 | go func(name string, module mod) {
288 | // Keep track of when and how many times the module has crashed
289 | // as not to re-start crashlooped modules.
290 | var moduleCrashCount int
291 | var lastModuleCrashTime time.Time
292 |
293 | for {
294 | // Create a context derived from Wraith's context to control the
295 | // module's lifetime.
296 | w.ctxLock.RLock()
297 | moduleCtx, moduleCtxCancel := context.WithCancel(w.ctx)
298 | w.ctxLock.RUnlock()
299 | defer moduleCtxCancel()
300 |
301 | // Run the module and catch any panics.
302 | err := func() (err error) {
303 | defer func() {
304 | if r := recover(); r != nil {
305 | err = fmt.Errorf("panic in module %s: %v", name, r)
306 | }
307 | }()
308 | module.Mainloop(moduleCtx, w)
309 | return nil
310 | }()
311 |
312 | // If there were any errors, report them.
313 | if err != nil {
314 | w.SHMSet(SHM_ERRS, err)
315 | }
316 |
317 | // If Wraith has exited, do not restart the module.
318 | w.ctxLock.RLock()
319 | if w.ctx == nil || w.ctx.Err() != nil || !w.IsAlive() {
320 | return
321 | }
322 | w.ctxLock.RUnlock()
323 |
324 | // Clear crash count if the last crash was a long time ago.
325 | if time.Since(lastModuleCrashTime) > w.conf.ModuleCrashloopDetectTime {
326 | moduleCrashCount = 0
327 | }
328 |
329 | // We have gotten here so the module has crashed and it wasn't
330 | // supposed to. Note that down.
331 | moduleCrashCount += 1
332 | lastModuleCrashTime = time.Now()
333 |
334 | // If the crash count has exceeded the max, do not restart, and
335 | // remove the module from the list of available modules.
336 | if moduleCrashCount > w.conf.ModuleCrashloopDetectCount {
337 | w.modsLock.Lock()
338 | delete(w.mods, name)
339 | w.modsLock.Unlock()
340 |
341 | return
342 | }
343 | }
344 | }(modname, module)
345 | }
346 | }
347 | }
348 |
349 | // Get a list of modules available to Wraith.
350 | func (w *Wraith) ModsGet() []string {
351 | defer w.catch()
352 |
353 | w.modsLock.RLock()
354 | defer w.modsLock.RUnlock()
355 |
356 | mods := make([]string, len(w.mods))
357 | index := 0
358 | for modname := range w.mods {
359 | mods[index] = modname
360 | index++
361 | }
362 | return mods
363 | }
364 |
--------------------------------------------------------------------------------
/libwraith/Wraith_test.go:
--------------------------------------------------------------------------------
1 | package libwraith_test
2 |
--------------------------------------------------------------------------------
/libwraith/export_test.go:
--------------------------------------------------------------------------------
1 | package libwraith
2 |
3 | //
4 | // This file exports some internal code for/when testing only
5 | //
6 |
7 | type Shm struct {
8 | shm
9 | }
10 |
--------------------------------------------------------------------------------
/libwraith/go.mod:
--------------------------------------------------------------------------------
1 | module dev.l1qu1d.net/wraith-labs/wraith/libwraith
2 |
3 | go 1.21
4 |
--------------------------------------------------------------------------------
/libwraith/go.sum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wraith-labs/wraith/83e47d2665d925e5c310c2dcb4ced02a50d43100/libwraith/go.sum
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wraith-labs/wraith/83e47d2665d925e5c310c2dcb4ced02a50d43100/logo.png
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | | :exclamation::exclamation::exclamation: **WARNING** :exclamation::exclamation::exclamation: |
2 | |-----------------------------------------|
3 | This project is currently heavily in development and hence is pretty unusable. Commits to this repository can be rare while I focus on other work, but the project is not abandoned. If you are interested in sponsoring or contributing to the project to speed up development, or even offering some suggestions, please get in touch via the discussions feature on GitHub, or via Matrix at [@0x/:l1qu1d.net](https://matrix.to/#/@0x/:l1qu1d.net).
4 |
5 | # wraith
6 | [](https://ci.l1qu1d.net/wraith-labs/wraith)
7 | [](wraith/go.mod)
8 | [](LICENSE)
9 | [](https://wraith-labs.github.io/wraith/)
10 | [](https://pkg.go.dev/dev.l1qu1d.net/wraith-labs/wraith/wraith)
11 |
12 | A free and open-source, modular Remote Administration Tool (RAT) / Payload Dropper written in Go(lang) with a flexible command and control (C2) system*.
13 |
14 | \* The C2 system can consist of static files on a HTTP server, static DNS records on a DNS server, or can be automated with a control panel (though this is not part of this project and while I may make a panel eventually, you are encouraged to make your own by all means).
15 |
16 | # WARNING!
17 | This is the In-Development branch **which has become the default branch as of 21/06/2020**. Any code found here is most likely **not tested, unstable and subject to change** as the project develops. To use the stable version please see the *releases* tab or the [master](https://dev.l1qu1d.net/wraith-labs/wraith/src/branch/master) branch.
18 |
19 | ## NOTE:
20 | The master branch currently contains Wraith v3.0.0 which is permanently in BETA due to a complete Wraith re-write for version 4.0.0. While useable, v3.0.0 of Wraith is not recommended for use. Instead, waiting for the 4.0.0 release is preferable as massive changes will be introduced making Wraith faster, more secure, more useable and easier to manage. Wraith v4.0.0 has no estimated release date but any contributions will speed up development :)
21 |
22 | ## Other notes:
23 | - 14/11/2021 22:10 - Celebrating 100 stars on GitHub! 🎉
24 | - 09/01/2023 04:30 - First contact between Wraith and C2 via pinecomms module! 🎉
25 |
--------------------------------------------------------------------------------