├── LICENSE ├── README.md ├── misc_level1_big_zip ├── misc_level1_big_zip.md └── misc_zip.zip ├── misc_level2_pokemon ├── misc_level2_pokemon.md ├── misc_nds.zip └── pokemon_misc.pdf ├── pwn_level2_guestbook └── pwn_level2_guestbook.md ├── re_level2_ez_crackme ├── code │ ├── ez_crackme │ ├── ez_crackme.cpp │ ├── gen_flag.py │ └── makefile └── re_level2_ez_crackme.md └── re_level3_are_u_ok ├── code ├── build │ └── hctf{p1ay_Wi7h_p7r4Ce_1n__L1nuX} ├── config.h ├── debugger.cpp ├── debugger.cpp.templite ├── generate_one.py ├── machine.h ├── macros.h ├── portable.h └── rc6.h └── re_level2_are_u_ok.md /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hctf 2017 wp (部分 2 | -------------------------------------------------------------------------------- /misc_level1_big_zip/misc_level1_big_zip.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/misc_level1_big_zip/misc_level1_big_zip.md -------------------------------------------------------------------------------- /misc_level1_big_zip/misc_zip.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/misc_level1_big_zip/misc_zip.zip -------------------------------------------------------------------------------- /misc_level2_pokemon/misc_level2_pokemon.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/misc_level2_pokemon/misc_level2_pokemon.md -------------------------------------------------------------------------------- /misc_level2_pokemon/misc_nds.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/misc_level2_pokemon/misc_nds.zip -------------------------------------------------------------------------------- /misc_level2_pokemon/pokemon_misc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/misc_level2_pokemon/pokemon_misc.pdf -------------------------------------------------------------------------------- /pwn_level2_guestbook/pwn_level2_guestbook.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/pwn_level2_guestbook/pwn_level2_guestbook.md -------------------------------------------------------------------------------- /re_level2_ez_crackme/code/ez_crackme: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/re_level2_ez_crackme/code/ez_crackme -------------------------------------------------------------------------------- /re_level2_ez_crackme/code/ez_crackme.cpp: -------------------------------------------------------------------------------- 1 | //gcc re_vm.cpp -m32 -o re_vm 2 | #include 3 | #include 4 | 5 | int inloop = 0; 6 | char tmp_code[0x100] = { 0 }; 7 | int tmp_code_ip = 0; 8 | 9 | void mov(int *a, char b) { 10 | *a = b; 11 | } 12 | void mov32(int *a, int b) { 13 | *a = b; 14 | } 15 | void lea_ch(char **a, char *b) { 16 | *a = b; 17 | } 18 | void lea_int(int **a, int *b) { 19 | *a = b; 20 | } 21 | void ldr_int(int *a, int * b) { 22 | *a = *b; 23 | } 24 | void ldr_ch(int *a, char * b) { 25 | *a = *b; 26 | } 27 | 28 | void add(int *a, int b) { 29 | *a += b; 30 | } 31 | void add_pint(int **a, int b) { 32 | *a += b; 33 | } 34 | void add_pch(char **a, int b) { 35 | *a += b; 36 | } 37 | 38 | void my_xor(int *a, int b) { 39 | *a = *a^b; 40 | } 41 | void mod(int *a, int b) { 42 | mov(a, *a%b); 43 | } 44 | void my_or (int *a, int b) { 45 | mov(a, *a | b); 46 | } 47 | int my_and(int *a, int b) { 48 | mov(a, *a&b); 49 | return *a; 50 | } 51 | void push(int **esp, int a) { 52 | mov(*esp, a); 53 | add_pint(esp, 1); 54 | } 55 | void pop(int **esp, int *a) { 56 | add_pint(esp, -1); 57 | mov(a, **esp); 58 | } 59 | void shr(int *a, int b) { 60 | *a >>= b; 61 | mov(a, my_and (a, 0xff)); 62 | } 63 | void shl(int *a, int b) { 64 | *a <<= b; 65 | mov(a, my_and (a, 0xff)); 66 | } 67 | void ror(int *a, int b) { 68 | int off = b % 32; 69 | *a = ((*a >> off)&(((long long)1 << (32 - off)) - 1)) + ((*a&(((long long)1 << off) - 1)) << (32 - off)); 70 | } 71 | int cmpl(int a, int b) { 72 | if (a < b) { 73 | return 1; 74 | } 75 | return 0; 76 | } 77 | int cmpeq(char a, char b) { 78 | if (a == b) { 79 | return 0; 80 | } 81 | return 1; 82 | } 83 | 84 | char read_code(char * code, int &ip) { 85 | int tmp = ip; 86 | ip++; 87 | return code[tmp]; 88 | } 89 | 90 | 91 | //register 92 | #define _eax 0 93 | #define _ebx 1 94 | #define _ebx2 2 95 | #define _ecx 3 96 | #define _edx 4 97 | #define _esp 5 98 | #define _lf 6 99 | #define _neq 7 100 | #define _t_intp 8 101 | #define _t_chp 9 102 | #define _t_int 10 103 | #define _flag 11 104 | #define _enc 12 105 | #define _key 13 106 | //opcode 107 | #define _mov (0<<1) 108 | #define _mov32 (1<<1) 109 | #define _lea_ch (2<<1) 110 | #define _lea_int (3<<1) 111 | #define _ldr_int (4<<1) 112 | #define _ldr_ch (5<<1) 113 | #define _add (6<<1) 114 | #define _add_pint (7<<1) 115 | #define _add_pch (8<<1) 116 | #define _my_xor (9<<1) 117 | #define _mod (10<<1) 118 | #define _my_or (11<<1) 119 | #define _my_and (12<<1) 120 | #define _push (13<<1) 121 | #define _pop (14<<1) 122 | #define _shr (15<<1) 123 | #define _shl (16<<1) 124 | #define _ror (17<<1) 125 | #define _cmpl (18<<1) 126 | #define _cmpeq (19<<1) 127 | #define loop (20<<1) 128 | #define code_end (21<<1) 129 | //type 130 | #define rn 0 131 | #define rr 1 132 | 133 | #define read2arg() do{arg1 = read_code(code, ip);arg2 = read_code(code, ip);}while(0) 134 | 135 | void inter(char * code) { 136 | char cur_code = 0; 137 | char op = 0; 138 | char type = 0; 139 | int ip = 0; 140 | int loop_ip = 0; 141 | int eax = 0, ecx = 0, edx = 0; 142 | int * t_intp = 0; 143 | char * t_chp = 0; 144 | int t_int = 0; 145 | char * ebx = 0; 146 | int * ebx2 = 0; 147 | int stack[0x100] = { 0 }; 148 | int lf = 0; 149 | int neq = 0; 150 | int *esp = stack; 151 | char arg1, arg2; 152 | 153 | printf("Please input the flag:"); 154 | 155 | char *input = (char *)malloc(32); 156 | scanf("%32s", input); 157 | //char * input = "hctf{aaaaaaaaaaaaaaaaaaaaaaaaaa}"; 158 | char **flag = &input; 159 | 160 | char ans[] = {213, 165, 203, 249, 9, 185, 207, 253, 237, 189, 195, 33, 225, 177, 199, 245, 221, 181, 219, 9, 249, 97, 223, 13, 253, 205, 195, 1, 241, 193, 215, 77}; 161 | char * enc = ans; 162 | char ** p_enc = &enc; 163 | 164 | int key = 0xefbeadde; 165 | 166 | int * reg[] = { 167 | (int *)&eax, 168 | (int *)&ebx, 169 | (int *)&ebx2, 170 | (int *)&ecx, 171 | (int *)&edx, 172 | (int *)&esp, 173 | (int *)&lf, 174 | (int *)&neq, 175 | (int *)&t_intp, 176 | (int *)&t_chp, 177 | (int *)&t_int, 178 | (int *)flag, 179 | (int *)p_enc, 180 | (int *)&key, 181 | }; 182 | 183 | while (1) { 184 | cur_code = read_code(code, ip); 185 | op = cur_code & 0xfe; 186 | type = cur_code & 1; 187 | 188 | switch (op) { 189 | case _mov: 190 | //puts("mov"); 191 | read2arg(); 192 | switch (type) { 193 | case rr: 194 | mov(reg[arg1], (char)*reg[arg2]); 195 | break; 196 | case rn: 197 | mov(reg[arg1],arg2); 198 | break; 199 | } 200 | break; 201 | case _mov32: 202 | //puts("mov32"); 203 | read2arg(); 204 | switch (type) { 205 | case rr: 206 | mov32(reg[arg1], (int)*reg[arg2]); 207 | break; 208 | case rn: 209 | mov32(reg[arg1], arg2); 210 | break; 211 | } 212 | break; 213 | case _lea_ch: 214 | //puts("lea_ch"); 215 | switch (type) { 216 | case rr: 217 | read2arg(); 218 | lea_ch((char **)reg[arg1], (char *)*reg[arg2]); 219 | break; 220 | case rn: 221 | break; 222 | } 223 | break; 224 | case _lea_int: 225 | //puts("_lea_int"); 226 | read2arg(); 227 | switch (type) { 228 | case rr: 229 | lea_int((int **)reg[arg1], (int *)*reg[arg2]); 230 | break; 231 | case rn: 232 | break; 233 | } 234 | break; 235 | case _ldr_int: 236 | //puts("_ldr_int"); 237 | read2arg(); 238 | switch (type) { 239 | case rr: 240 | ldr_int((int *)reg[arg1], (int *)*reg[arg2]); 241 | break; 242 | case rn: 243 | break; 244 | } 245 | break; 246 | case _ldr_ch: 247 | //puts("_ldr_ch"); 248 | read2arg(); 249 | switch (type) { 250 | case rr: 251 | ldr_ch((int *)reg[arg1], (char *)*reg[arg2]); 252 | break; 253 | case rn: 254 | break; 255 | } 256 | break; 257 | case _add: 258 | //puts("_add"); 259 | read2arg(); 260 | switch (type) { 261 | case rr: 262 | add((int *)reg[arg1], (int)*reg[arg2]); 263 | break; 264 | case rn: 265 | add((int *)reg[arg1], arg2); 266 | break; 267 | } 268 | break; 269 | case _add_pint: 270 | //puts("_add_pint"); 271 | read2arg(); 272 | switch (type) { 273 | case rr: 274 | add_pint((int **)reg[arg1], (int)*reg[arg2]); 275 | break; 276 | case rn: 277 | add_pint((int **)reg[arg1], arg2); 278 | break; 279 | } 280 | break; 281 | case _add_pch: 282 | //puts("_add_pch"); 283 | read2arg(); 284 | switch (type) { 285 | case rr: 286 | add_pch((char **)reg[arg1], (int)*reg[arg2]); 287 | break; 288 | case rn: 289 | add_pch((char **)reg[arg1], arg2); 290 | break; 291 | } 292 | break; 293 | case _my_xor: 294 | //puts("_my_xor"); 295 | read2arg(); 296 | switch (type) { 297 | case rr: 298 | my_xor(reg[arg1], (int)*reg[arg2]); 299 | break; 300 | case rn: 301 | my_xor(reg[arg1], arg2); 302 | break; 303 | } 304 | break; 305 | case _mod: 306 | //puts("_mod"); 307 | read2arg(); 308 | switch (type) { 309 | case rr: 310 | break; 311 | case rn: 312 | mod(reg[arg1], arg2); 313 | //printf("%d ", *reg[arg1]); 314 | break; 315 | } 316 | break; 317 | case _my_or: 318 | //puts("_or"); 319 | read2arg(); 320 | switch (type) { 321 | case rr: 322 | my_or(reg[arg1], (int)*reg[arg2]); 323 | break; 324 | case rn: 325 | my_or(reg[arg1], arg2); 326 | break; 327 | } 328 | break; 329 | case _my_and: 330 | //puts("_my_and"); 331 | read2arg(); 332 | switch (type) { 333 | case rr: 334 | my_and(reg[arg1], (int)*reg[arg2]); 335 | break; 336 | case rn: 337 | my_and(reg[arg1], arg2); 338 | break; 339 | } 340 | break; 341 | case _push: 342 | //puts("_push"); 343 | read2arg(); 344 | switch (type) { 345 | case rr: 346 | push((int **)reg[arg1], (int)*reg[arg2]); 347 | break; 348 | case rn: 349 | push((int **)reg[arg1], arg2); 350 | break; 351 | } 352 | break; 353 | case _pop: 354 | //puts("_pop"); 355 | read2arg(); 356 | switch (type) { 357 | case rr: 358 | pop((int **)reg[arg1], (int*)reg[arg2]); 359 | break; 360 | case rn: 361 | break; 362 | } 363 | break; 364 | case _shr: 365 | //puts("_shr"); 366 | read2arg(); 367 | switch (type) { 368 | case rr: 369 | shr((int *)reg[arg1], (int)*reg[arg2]); 370 | break; 371 | case rn: 372 | shr((int *)reg[arg1], arg2); 373 | break; 374 | } 375 | break; 376 | case _shl: 377 | //puts("_shl"); 378 | read2arg(); 379 | switch (type) { 380 | case rr: 381 | shl((int *)reg[arg1], (int)*reg[arg2]); 382 | break; 383 | case rn: 384 | shl((int *)reg[arg1], arg2); 385 | break; 386 | } 387 | break; 388 | case _ror: 389 | //puts("_ror"); 390 | read2arg(); 391 | switch (type) { 392 | case rr: 393 | ror((int *)reg[arg1], (int)*reg[arg2]); 394 | break; 395 | case rn: 396 | ror((int *)reg[arg1], arg2); 397 | break; 398 | } 399 | break; 400 | case _cmpl: 401 | //puts("_cmpl"); 402 | read2arg(); 403 | switch (type) { 404 | case rr: 405 | lf = cmpl((int)*reg[arg1], (int)*reg[arg2]); 406 | break; 407 | case rn: 408 | lf = cmpl((int)*reg[arg1], arg2); 409 | break; 410 | } 411 | break; 412 | case _cmpeq: 413 | //puts("_cmpeq"); 414 | read2arg(); 415 | switch (type) { 416 | case rr: 417 | neq = cmpeq((int)*reg[arg1], (int)*reg[arg2]); 418 | break; 419 | case rn: 420 | neq = cmpeq((int)*reg[arg1], arg2); 421 | break; 422 | } 423 | break; 424 | case loop: 425 | //puts("loop"); 426 | if (!inloop) { 427 | inloop = 1; 428 | loop_ip = ip; 429 | } 430 | else { 431 | if (lf) { 432 | ip = loop_ip; 433 | } 434 | else { 435 | inloop = 0; 436 | } 437 | } 438 | break; 439 | case code_end: 440 | //puts("code_end"); 441 | goto end; 442 | } 443 | } 444 | 445 | end: 446 | if (!edx) { 447 | printf("success!!\n"); 448 | } 449 | else { 450 | printf("fail...\n"); 451 | } 452 | 453 | return; 454 | } 455 | 456 | 457 | 458 | int main(void) { 459 | char code[] = { 460 | _lea_ch | rr,_ebx, _flag, 461 | _my_xor | rr,_ecx, _ecx, 462 | _my_xor | rr,_eax,_eax, 463 | _my_xor | rr,_edx,_edx, 464 | 465 | loop, 466 | _add | rn,_eax, 51, 467 | _mod | rn,_eax, 32, 468 | _lea_ch | rr,_t_chp, _ebx, 469 | _add_pch | rr,_t_chp,_eax, 470 | _ldr_ch | rr,_t_int,_t_chp, 471 | _mov | rr,_edx,_t_int, 472 | _push | rr,_esp,_edx, 473 | _add | rn,_ecx, 1, 474 | _cmpl | rn, _ecx, 32, 475 | loop, 476 | 477 | _my_xor | rr,_eax,_eax, 478 | _lea_int | rr,_t_intp,_esp, 479 | _add_pint | rn,_t_intp, -32, 480 | _lea_int | rr,_ebx2,_t_intp, 481 | _ldr_int | rr,_t_int, _ebx2, 482 | _mov | rr,_eax,_t_int, 483 | _my_and | rn,_eax, 0xe0, 484 | _shr | rn,_eax, 5, 485 | _mov | rr,_edx,_eax, 486 | _my_xor | rr,_ecx, _ecx, 487 | loop, 488 | _ldr_int | rr,_t_int, _ebx2, 489 | _mov | rr,_eax,_t_int, 490 | _my_and | rn,_eax, 0x1f, 491 | _shl | rn,_eax, 3, 492 | _push | rr,_esp,_eax, 493 | _lea_int | rr,_t_intp,_esp, 494 | _add_pint | rn,_t_intp, -32, 495 | _lea_int | rr,_ebx2,_t_intp, 496 | _ldr_int | rr,_t_int, _ebx2, 497 | _mov | rr,_eax,_t_int, 498 | _my_and | rn,_eax, 0xe0, 499 | _shr | rn,_eax, 5, 500 | _pop | rr,_esp,_t_int, 501 | _add | rr,_t_int,_eax, 502 | _push | rr,_esp,_t_int, 503 | _add | rn,_ecx, 1, 504 | _cmpl | rn, _ecx, 31, 505 | loop, 506 | 507 | _ldr_int | rr,_t_int, _ebx2, 508 | _mov | rr,_eax,_t_int, 509 | _my_and | rn,_eax, 0x1f, 510 | _shl | rn,_eax, 3, 511 | _add | rr,_eax,_edx, 512 | _push | rr,_esp,_eax, 513 | 514 | _my_xor | rr,_ecx, _ecx, 515 | _mov32 | rr,_edx, _key, 516 | loop, 517 | _lea_int | rr,_t_intp,_esp, 518 | _add_pint | rn,_t_intp, -32, 519 | _lea_int | rr,_ebx2,_t_intp, 520 | _ldr_int | rr,_t_int, _ebx2, 521 | _mov | rr,_eax,_t_int, 522 | _push | rr,_esp,_eax, 523 | _mov | rr,_eax,_edx, 524 | _add | rr,_eax, _ecx, 525 | _pop | rr,_esp,_t_int, 526 | _my_xor | rr,_t_int,_eax, 527 | _push | rr,_esp,_t_int, 528 | _ror | rn,_edx, 8, 529 | _add | rn,_ecx, 1, 530 | _cmpl | rn, _ecx, 32, 531 | loop, 532 | 533 | _my_xor | rr,_ecx, _ecx, 534 | _my_xor | rr,_edx,_edx, 535 | _lea_ch | rr,_ebx,_enc, 536 | loop, 537 | _lea_ch | rr,_t_chp, _ebx, 538 | _add_pch | rr,_t_chp, _ecx, 539 | _ldr_ch | rr,_t_int,_t_chp, 540 | _mov | rr,_eax,_t_int, 541 | _push | rr,_esp,_eax, 542 | _lea_int | rr,_t_intp,_esp, 543 | _add_pint | rn,_t_intp, -33, 544 | _ldr_int | rr,_t_int,_t_intp, 545 | _pop | rr,_esp,_eax, 546 | _push | rr,_esp,_eax, 547 | _cmpeq | rr,_eax,_t_int, 548 | _my_or | rr,_edx, _neq, 549 | _add | rn,_ecx, 1, 550 | _cmpl | rn, _ecx, 32, 551 | loop, 552 | 553 | code_end 554 | }; 555 | inter(code); 556 | 557 | //system("pause"); 558 | return 0; 559 | } -------------------------------------------------------------------------------- /re_level2_ez_crackme/code/gen_flag.py: -------------------------------------------------------------------------------- 1 | flag = r"hctf{aaaaaaaaaaaaaaaaaaaaaaaaaa}" 2 | key = 'deadbeef'.decode('hex') 3 | 4 | def encrypt(flag): 5 | out=[] 6 | out2=[] 7 | x=0#gen box 8 | box=[] 9 | for i in range(32): 10 | x=(x+51)%32 11 | box.append(x) 12 | for i in range(32): 13 | out.append(ord(flag[box[i]])) 14 | head = (out[0]&0xe0)>>5 15 | for i in range(31): 16 | out[i] = ((out[i]&0x1f)<<3)+((out[i+1]&0xe0)>>5) 17 | out[31] = ((out[31]&0x1f)<<3) + head 18 | for i in range(32): 19 | out2.append(out[i]^((ord(key[i%4])+i)&0xff)) 20 | return out2 21 | 22 | 23 | def decrypt(enc_list): 24 | out=[] 25 | out2=[0]*32 26 | x=0#gen box 27 | box=[] 28 | for i in range(32): 29 | x=(x+51)%32 30 | box.append(x) 31 | for i in range(32): 32 | out.append(enc_list[i]^(ord(key[i%4])+i)) 33 | 34 | tail = out[31]&0x7 35 | for i in reversed(range(1,32)): 36 | out[i] = ((out[i]&0xf8)>>3)+((out[i-1]&0x7)<<5) 37 | out[0] = ((out[0]&0xf8)>>3)+(tail<<5) 38 | for i in range(32): 39 | out2[box[i]] = out[i] 40 | return ''.join(map(chr,out2)) 41 | 42 | 43 | enc = encrypt(flag) 44 | 45 | print enc 46 | #print decrypt(encrypt(flag)) 47 | -------------------------------------------------------------------------------- /re_level2_ez_crackme/code/makefile: -------------------------------------------------------------------------------- 1 | ez_crackme:ez_crackme.cpp 2 | gcc -m32 -s -pie -fstack-protector-all -Wl,-z,relro,-z,now ez_crackme.cpp -o ez_crackme -------------------------------------------------------------------------------- /re_level2_ez_crackme/re_level2_ez_crackme.md: -------------------------------------------------------------------------------- 1 | # re_level2_ez_crackme 2 | 3 | 考察对简单解释器的逆向能力。 4 | 5 | ## 加密解密过程 6 | 7 | ```python 8 | box=[] 9 | for i in range(32): 10 | x=(x+51)%32 11 | box.append(x) 12 | ``` 13 | 14 | 先用如上方式初始化一个box。 15 | 16 | 用这个box将输入的明文进行乱序。 17 | 18 | ```python 19 | head = (out[0]&0xe0)>>5 20 | for i in range(31): 21 | out[i] = ((out[i]&0x1f)<<3)+((out[i+1]&0xe0)>>5) 22 | out[31] = ((out[31]&0x1f)<<3) + head 23 | ``` 24 | 25 | 然后用如上方式,将乱序后的结果进行整体循环左移3位。 26 | 27 | ```python 28 | key = 'deadbeef'.decode('hex') 29 | for i in range(32): 30 | out2.append(out[i]^((ord(key[i%4])+i)&0xff)) 31 | ``` 32 | 33 | 然后利用key和下标i对左移后的结果做异或即可。 34 | 35 | 完整python加密解密脚本: 36 | 37 | ```python 38 | key = 'deadbeef'.decode('hex') 39 | 40 | def encrypt(flag): 41 | out=[] 42 | out2=[] 43 | x=0#gen box 44 | box=[] 45 | for i in range(32): 46 | x=(x+51)%32 47 | box.append(x) 48 | for i in range(32): 49 | out.append(ord(flag[box[i]])) 50 | head = (out[0]&0xe0)>>5 51 | for i in range(31): 52 | out[i] = ((out[i]&0x1f)<<3)+((out[i+1]&0xe0)>>5) 53 | out[31] = ((out[31]&0x1f)<<3) + head 54 | for i in range(32): 55 | out2.append(out[i]^((ord(key[i%4])+i)&0xff)) 56 | return out2 57 | 58 | 59 | def decrypt(enc_list): 60 | out=[] 61 | out2=[0]*32 62 | x=0#gen box 63 | box=[] 64 | for i in range(32): 65 | x=(x+51)%32 66 | box.append(x) 67 | for i in range(32): 68 | out.append(enc_list[i]^(ord(key[i%4])+i)) 69 | 70 | tail = out[31]&0x7 71 | for i in reversed(range(1,32)): 72 | out[i] = ((out[i]&0xf8)>>3)+((out[i-1]&0x7)<<5) 73 | out[0] = ((out[0]&0xf8)>>3)+(tail<<5) 74 | for i in range(32): 75 | out2[box[i]] = out[i] 76 | return ''.join(map(chr,out2)) 77 | ``` 78 | 79 | ## 解释器分析 80 | 81 | ```cpp 82 | //register 83 | #define _eax 0 84 | #define _ebx 1 85 | #define _ebx2 2 86 | #define _ecx 3 87 | #define _edx 4 88 | #define _esp 5 89 | #define _lf 6 90 | #define _neq 7 91 | #define _t_intp 8 92 | #define _t_chp 9 93 | #define _t_int 10 94 | #define _flag 11 95 | #define _enc 12 96 | #define _key 13 97 | //opcode 98 | #define _mov (0<<1) 99 | #define _mov32 (1<<1) 100 | #define _lea_ch (2<<1) 101 | #define _lea_int (3<<1) 102 | #define _ldr_int (4<<1) 103 | #define _ldr_ch (5<<1) 104 | #define _add (6<<1) 105 | #define _add_pint (7<<1) 106 | #define _add_pch (8<<1) 107 | #define _my_xor (9<<1) 108 | #define _mod (10<<1) 109 | #define _my_or (11<<1) 110 | #define _my_and (12<<1) 111 | #define _push (13<<1) 112 | #define _pop (14<<1) 113 | #define _shr (15<<1) 114 | #define _shl (16<<1) 115 | #define _ror (17<<1) 116 | #define _cmpl (18<<1) 117 | #define _cmpeq (19<<1) 118 | #define loop (20<<1) 119 | #define code_end (21<<1) 120 | //type 121 | #define rn 0 122 | #define rr 1 123 | ``` 124 | 125 | 126 | 定义了一些寄存器以及变量,解释器指令,以及指令后面的变量种类。一个完整的指令由高7位的类型和低1位的变量类型组成。 127 | 128 | `rr`表示`op reg,reg`,`rn`表示`op reg,num`。 129 | 130 | 131 | 用宏写的解释代码 132 | 133 | ```cpp 134 | char code[] = { 135 | _lea_ch | rr,_ebx, _flag, 136 | _my_xor | rr,_ecx, _ecx, 137 | _my_xor | rr,_eax,_eax, 138 | _my_xor | rr,_edx,_edx, 139 | 140 | loop, 141 | _add | rn,_eax, 51, 142 | _mod | rn,_eax, 32, 143 | _lea_ch | rr,_t_chp, _ebx, 144 | _add_pch | rr,_t_chp,_eax, 145 | _ldr_ch | rr,_t_int,_t_chp, 146 | _mov | rr,_edx,_t_int, 147 | _push | rr,_esp,_edx, 148 | _add | rn,_ecx, 1, 149 | _cmpl | rn, _ecx, 32, 150 | loop, 151 | 152 | _my_xor | rr,_eax,_eax, 153 | _lea_int | rr,_t_intp,_esp, 154 | _add_pint | rn,_t_intp, -32, 155 | _lea_int | rr,_ebx2,_t_intp, 156 | _ldr_int | rr,_t_int, _ebx2, 157 | _mov | rr,_eax,_t_int, 158 | _my_and | rn,_eax, 0xe0, 159 | _shr | rn,_eax, 5, 160 | _mov | rr,_edx,_eax, 161 | _my_xor | rr,_ecx, _ecx, 162 | loop, 163 | _ldr_int | rr,_t_int, _ebx2, 164 | _mov | rr,_eax,_t_int, 165 | _my_and | rn,_eax, 0x1f, 166 | _shl | rn,_eax, 3, 167 | _push | rr,_esp,_eax, 168 | _lea_int | rr,_t_intp,_esp, 169 | _add_pint | rn,_t_intp, -32, 170 | _lea_int | rr,_ebx2,_t_intp, 171 | _ldr_int | rr,_t_int, _ebx2, 172 | _mov | rr,_eax,_t_int, 173 | _my_and | rn,_eax, 0xe0, 174 | _shr | rn,_eax, 5, 175 | _pop | rr,_esp,_t_int, 176 | _add | rr,_t_int,_eax, 177 | _push | rr,_esp,_t_int, 178 | _add | rn,_ecx, 1, 179 | _cmpl | rn, _ecx, 31, 180 | loop, 181 | 182 | _ldr_int | rr,_t_int, _ebx2, 183 | _mov | rr,_eax,_t_int, 184 | _my_and | rn,_eax, 0x1f, 185 | _shl | rn,_eax, 3, 186 | _add | rr,_eax,_edx, 187 | _push | rr,_esp,_eax, 188 | 189 | _my_xor | rr,_ecx, _ecx, 190 | _mov32 | rr,_edx, _key, 191 | loop, 192 | _lea_int | rr,_t_intp,_esp, 193 | _add_pint | rn,_t_intp, -32, 194 | _lea_int | rr,_ebx2,_t_intp, 195 | _ldr_int | rr,_t_int, _ebx2, 196 | _mov | rr,_eax,_t_int, 197 | _push | rr,_esp,_eax, 198 | _mov | rr,_eax,_edx, 199 | _add | rr,_eax, _ecx, 200 | _pop | rr,_esp,_t_int, 201 | _my_xor | rr,_t_int,_eax, 202 | _push | rr,_esp,_t_int, 203 | _ror | rn,_edx, 8, 204 | _add | rn,_ecx, 1, 205 | _cmpl | rn, _ecx, 32, 206 | loop, 207 | 208 | _my_xor | rr,_ecx, _ecx, 209 | _my_xor | rr,_edx,_edx, 210 | _lea_ch | rr,_ebx,_enc, 211 | loop, 212 | _lea_ch | rr,_t_chp, _ebx, 213 | _add_pch | rr,_t_chp, _ecx, 214 | _ldr_ch | rr,_t_int,_t_chp, 215 | _mov | rr,_eax,_t_int, 216 | _push | rr,_esp,_eax, 217 | _lea_int | rr,_t_intp,_esp, 218 | _add_pint | rn,_t_intp, -33, 219 | _ldr_int | rr,_t_int,_t_intp, 220 | _pop | rr,_esp,_eax, 221 | _push | rr,_esp,_eax, 222 | _cmpeq | rr,_eax,_t_int, 223 | _my_or | rr,_edx, _neq, 224 | _add | rn,_ecx, 1, 225 | _cmpl | rn, _ecx, 32, 226 | loop, 227 | 228 | code_end 229 | }; 230 | ``` 231 | 232 | 其中loop的实现是用记录ip的方式来实现的。 233 | 234 | 235 | 完整的程序代码见附件。 236 | 237 | -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/build/hctf{p1ay_Wi7h_p7r4Ce_1n__L1nuX}: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/re_level3_are_u_ok/code/build/hctf{p1ay_Wi7h_p7r4Ce_1n__L1nuX} -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/config.h: -------------------------------------------------------------------------------- 1 | /* ecrypt-config.h */ 2 | 3 | /* *** Normally, it should not be necessary to edit this file. *** */ 4 | 5 | #ifndef ECRYPT_CONFIG 6 | #define ECRYPT_CONFIG 7 | 8 | /* ------------------------------------------------------------------------- */ 9 | 10 | /* Guess the endianness of the target architecture. */ 11 | 12 | /* 13 | * The LITTLE endian machines: 14 | */ 15 | #if defined(__ultrix) /* Older MIPS */ 16 | #define ECRYPT_LITTLE_ENDIAN 17 | #elif defined(__alpha) /* Alpha */ 18 | #define ECRYPT_LITTLE_ENDIAN 19 | #elif defined(i386) /* x86 (gcc) */ 20 | #define ECRYPT_LITTLE_ENDIAN 21 | #elif defined(__i386) /* x86 (gcc) */ 22 | #define ECRYPT_LITTLE_ENDIAN 23 | #elif defined(_M_IX86) /* x86 (MSC, Borland) */ 24 | #define ECRYPT_LITTLE_ENDIAN 25 | #elif defined(_MSC_VER) /* x86 (surely MSC) */ 26 | #define ECRYPT_LITTLE_ENDIAN 27 | #elif defined(__INTEL_COMPILER) /* x86 (surely Intel compiler icl.exe) */ 28 | #define ECRYPT_LITTLE_ENDIAN 29 | 30 | /* 31 | * The BIG endian machines: 32 | */ 33 | #elif defined(sun) /* Newer Sparc's */ 34 | #define ECRYPT_BIG_ENDIAN 35 | #elif defined(__ppc__) /* PowerPC */ 36 | #define ECRYPT_BIG_ENDIAN 37 | 38 | /* 39 | * Finally machines with UNKNOWN endianness: 40 | */ 41 | #elif defined (_AIX) /* RS6000 */ 42 | #define ECRYPT_UNKNOWN 43 | #elif defined(__hpux) /* HP-PA */ 44 | #define ECRYPT_UNKNOWN 45 | #elif defined(__aux) /* 68K */ 46 | #define ECRYPT_UNKNOWN 47 | #elif defined(__dgux) /* 88K (but P6 in latest boxes) */ 48 | #define ECRYPT_UNKNOWN 49 | #elif defined(__sgi) /* Newer MIPS */ 50 | #define ECRYPT_UNKNOWN 51 | #else /* Any other processor */ 52 | #define ECRYPT_UNKNOWN 53 | #endif 54 | 55 | /* ------------------------------------------------------------------------- */ 56 | 57 | /* 58 | * Find minimal-width types to store 8-bit, 16-bit, 32-bit, and 64-bit 59 | * integers. 60 | * 61 | * Note: to enable 64-bit types on 32-bit compilers, it might be 62 | * necessary to switch from ISO C90 mode to ISO C99 mode (e.g., gcc 63 | * -std=c99). 64 | */ 65 | 66 | #include 67 | 68 | /* --- check char --- */ 69 | 70 | #if (UCHAR_MAX / 0xFU > 0xFU) 71 | #ifndef I8T 72 | #define I8T char 73 | #define U8C(v) (v##U) 74 | 75 | #if (UCHAR_MAX == 0xFFU) 76 | #define ECRYPT_I8T_IS_BYTE 77 | #endif 78 | 79 | #endif 80 | 81 | #if (UCHAR_MAX / 0xFFU > 0xFFU) 82 | #ifndef I16T 83 | #define I16T char 84 | #define U16C(v) (v##U) 85 | #endif 86 | 87 | #if (UCHAR_MAX / 0xFFFFU > 0xFFFFU) 88 | #ifndef I32T 89 | #define I32T char 90 | #define U32C(v) (v##U) 91 | #endif 92 | 93 | #if (UCHAR_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) 94 | #ifndef I64T 95 | #define I64T char 96 | #define U64C(v) (v##U) 97 | #define ECRYPT_NATIVE64 98 | #endif 99 | 100 | #endif 101 | #endif 102 | #endif 103 | #endif 104 | 105 | /* --- check short --- */ 106 | 107 | #if (USHRT_MAX / 0xFU > 0xFU) 108 | #ifndef I8T 109 | #define I8T short 110 | #define U8C(v) (v##U) 111 | 112 | #if (USHRT_MAX == 0xFFU) 113 | #define ECRYPT_I8T_IS_BYTE 114 | #endif 115 | 116 | #endif 117 | 118 | #if (USHRT_MAX / 0xFFU > 0xFFU) 119 | #ifndef I16T 120 | #define I16T short 121 | #define U16C(v) (v##U) 122 | #endif 123 | 124 | #if (USHRT_MAX / 0xFFFFU > 0xFFFFU) 125 | #ifndef I32T 126 | #define I32T short 127 | #define U32C(v) (v##U) 128 | #endif 129 | 130 | #if (USHRT_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) 131 | #ifndef I64T 132 | #define I64T short 133 | #define U64C(v) (v##U) 134 | #define ECRYPT_NATIVE64 135 | #endif 136 | 137 | #endif 138 | #endif 139 | #endif 140 | #endif 141 | 142 | /* --- check int --- */ 143 | 144 | #if (UINT_MAX / 0xFU > 0xFU) 145 | #ifndef I8T 146 | #define I8T int 147 | #define U8C(v) (v##U) 148 | 149 | #if (ULONG_MAX == 0xFFU) 150 | #define ECRYPT_I8T_IS_BYTE 151 | #endif 152 | 153 | #endif 154 | 155 | #if (UINT_MAX / 0xFFU > 0xFFU) 156 | #ifndef I16T 157 | #define I16T int 158 | #define U16C(v) (v##U) 159 | #endif 160 | 161 | #if (UINT_MAX / 0xFFFFU > 0xFFFFU) 162 | #ifndef I32T 163 | #define I32T int 164 | #define U32C(v) (v##U) 165 | #endif 166 | 167 | #if (UINT_MAX / 0xFFFFFFFFU > 0xFFFFFFFFU) 168 | #ifndef I64T 169 | #define I64T int 170 | #define U64C(v) (v##U) 171 | #define ECRYPT_NATIVE64 172 | #endif 173 | 174 | #endif 175 | #endif 176 | #endif 177 | #endif 178 | 179 | /* --- check long --- */ 180 | 181 | #if (ULONG_MAX / 0xFUL > 0xFUL) 182 | #ifndef I8T 183 | #define I8T long 184 | #define U8C(v) (v##UL) 185 | 186 | #if (ULONG_MAX == 0xFFUL) 187 | #define ECRYPT_I8T_IS_BYTE 188 | #endif 189 | 190 | #endif 191 | 192 | #if (ULONG_MAX / 0xFFUL > 0xFFUL) 193 | #ifndef I16T 194 | #define I16T long 195 | #define U16C(v) (v##UL) 196 | #endif 197 | 198 | #if (ULONG_MAX / 0xFFFFUL > 0xFFFFUL) 199 | #ifndef I32T 200 | #define I32T long 201 | #define U32C(v) (v##UL) 202 | #endif 203 | 204 | #if (ULONG_MAX / 0xFFFFFFFFUL > 0xFFFFFFFFUL) 205 | #ifndef I64T 206 | #define I64T long 207 | #define U64C(v) (v##UL) 208 | #define ECRYPT_NATIVE64 209 | #endif 210 | 211 | #endif 212 | #endif 213 | #endif 214 | #endif 215 | 216 | /* --- check long long --- */ 217 | 218 | #ifdef ULLONG_MAX 219 | 220 | #if (ULLONG_MAX / 0xFULL > 0xFULL) 221 | #ifndef I8T 222 | #define I8T long long 223 | #define U8C(v) (v##ULL) 224 | 225 | #if (ULLONG_MAX == 0xFFULL) 226 | #define ECRYPT_I8T_IS_BYTE 227 | #endif 228 | 229 | #endif 230 | 231 | #if (ULLONG_MAX / 0xFFULL > 0xFFULL) 232 | #ifndef I16T 233 | #define I16T long long 234 | #define U16C(v) (v##ULL) 235 | #endif 236 | 237 | #if (ULLONG_MAX / 0xFFFFULL > 0xFFFFULL) 238 | #ifndef I32T 239 | #define I32T long long 240 | #define U32C(v) (v##ULL) 241 | #endif 242 | 243 | #if (ULLONG_MAX / 0xFFFFFFFFULL > 0xFFFFFFFFULL) 244 | #ifndef I64T 245 | #define I64T long long 246 | #define U64C(v) (v##ULL) 247 | #endif 248 | 249 | #endif 250 | #endif 251 | #endif 252 | #endif 253 | 254 | #endif 255 | 256 | /* --- check __int64 --- */ 257 | 258 | #ifdef _UI64_MAX 259 | 260 | #if (_UI64_MAX / INT64_C(0xFFFFFFFF) > INT64_C(0xFFFFFFFF)) 261 | #ifndef I64T 262 | #define I64T __int64 263 | #define U64C(v) (v##ui64) 264 | #endif 265 | 266 | #endif 267 | 268 | #endif 269 | 270 | /* ------------------------------------------------------------------------- */ 271 | 272 | #endif 273 | -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/debugger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "rc6.h"//modify from https://github.com/odzhan/rc6 12 | 13 | ///////////////////////////////////////////////PATCH 14 | //patch to puts("fail"); 15 | #define brk_addr_to_puts_fail 0x0000000000401CD5 16 | #define jmp_encrypt "\xE9\x47\xE6\xDF\xFF\xFF\xFF\xFF" 17 | #define rc6_encrypt_start 0x0000000000401541 18 | #define len_of_2encrypt_func 0x3f5+0xca 19 | #define jmp_leijun_xor_cc 0x201324ccecd82a25 20 | ///////////////////////////////////////////////PATCH 21 | 22 | 23 | #define keylen 32 24 | #define s_long (sizeof(long)) 25 | 26 | long brk_addr=brk_addr_to_puts_fail; 27 | 28 | unsigned char rc4_key[] = { 0x5a,0x98,0x2c,0x36,0x5f,0xea,0x90,0xc0,0xb1,0x51,0x71,0x1a,0x32,0xd5,0x86,0x4b,0x4f,0x33,0xb7,0xd9,0x15,0xf6,0x5b,0x99,0x10,0xbd,0x81,0x2e,0x73,0x33,0xde,0x07}; 29 | unsigned char s_box[256]; 30 | 31 | unsigned char plz_input_flag[] = {0x50,0x28,0x40,0xab,0xee,0xc4,0x5c,0x26,0xe3,0x46,0xbc,0x34,0xde,0xf0,0x91,0x74,0x89,0x1b,0x82,0x7e};//"Plz input the flag :" 32 | unsigned char got_it[] = {0x79,0x2b,0x4f,0xab,0xe0,0xc5,0x58,0x73,0xfe,0x12,0xe8,0x66,0x92};//"you got it :)" 33 | unsigned char again[] = {0x74,0x36,0x43,0xab,0xe6,0xcd,0x4d,0x3a,0xf9,0x46,0xf2,0x74};//"try again :(" 34 | unsigned char not_mifan[] = {0x43,0x31,0x40,0xab,0xf2,0x8a,0x4d,0x21,0xf2,0x46,0xa6,0x33,0xcf,0xf0,0x83,0x6a,0x9d,0x19,0x82,0x09,0xd8,0x8d,0x6e,0x5b,0xaa,0xc5,};//"Cuz u are not true Mifan!!" 35 | 36 | //char flag[] = "hctf{H499y_p7rCe_3vEry_d4y_xxxx}"; 37 | char flag[0x40]; 38 | unsigned char flag_enc[] = ${ flag_enc_enc }$; 39 | 40 | void rc4_init(void){ 41 | int i = 0, j = 0; 42 | unsigned char k[256] = { 0 }; 43 | char tmp; 44 | for (i = 0; i<256; i++) { 45 | s_box[i] = i; 46 | } 47 | for (i = 0; i<256; i++) { 48 | j = (j + s_box[i] + rc4_key[i%32]) % 256; 49 | tmp = s_box[i]; 50 | s_box[i] = s_box[j]; 51 | s_box[j] = tmp; 52 | } 53 | } 54 | 55 | void rc4_crypt(char*data, int len){ 56 | int i = 0, j = 0, t = 0; 57 | int k = 0; 58 | for (k = 0; k\n",tmp_str); 138 | send_data(pid, addr, tmp_str, len); 139 | } 140 | 141 | void debugloop(pid_t pid) 142 | { 143 | int status; 144 | struct user_regs_struct regs; 145 | int read_num=0; 146 | char write_flag=0; 147 | char set_pwn=0; 148 | while (1) 149 | { 150 | waitpid(pid,&status,0); 151 | 152 | if (WIFEXITED(status)) 153 | { 154 | break; 155 | } 156 | ptrace(PTRACE_GETREGS, pid, NULL, ®s); 157 | //printf("%llu\n",regs.orig_rax); 158 | if (regs.orig_rax == __NR_write && regs.rdx!=1) 159 | { 160 | decrypt_data(pid, regs.rsi, regs.rdx); 161 | } 162 | if(regs.orig_rax == __NR_close && regs.rsi==1){//close 163 | if(set_pwn==1){ 164 | long op; 165 | op=ptrace(PTRACE_PEEKDATA,pid,brk_addr,NULL); 166 | ptrace(PTRACE_POKEDATA,pid,brk_addr,0xcccccccccccccccc); 167 | 168 | decrypt_data(pid,rc6_encrypt_start,len_of_2encrypt_func); 169 | ptrace(PTRACE_CONT, pid, NULL, NULL); 170 | wait(&status); 171 | op=ptrace(PTRACE_PEEKDATA,pid,brk_addr,NULL); 172 | op^=jmp_leijun_xor_cc; 173 | ptrace(PTRACE_POKEDATA,pid,brk_addr,op); 174 | 175 | 176 | ptrace(PTRACE_GETREGS, pid, NULL, ®s); 177 | regs.rip--; 178 | regs.rdx=(unsigned long long)flag; 179 | ptrace(PTRACE_SETREGS,pid,NULL,®s); 180 | //printf("close : %llx %llx %llu | RBP: %llx | RSP: %llx | RIP : %llx\n",regs.rdi,regs.rsi,regs.rdx,regs.rbp,regs.rsp,regs.rip); 181 | ptrace(PTRACE_SYSCALL, pid, NULL, NULL); 182 | } 183 | 184 | set_pwn++; 185 | } 186 | if (regs.orig_rax == __NR_read && regs.rdx == 1) 187 | { 188 | if(!read_num){ 189 | 190 | }else if(read_num > 65){ 191 | puts("Try again :("); 192 | puts("Cuz u r not true Mifan!!"); 193 | kill(pid, SIGTERM); 194 | exit(0); 195 | } 196 | read_num++; 197 | //printf("read : %llx %llx %llu\n",regs.rdi,regs.rsi,regs.rdx); 198 | } 199 | 200 | ptrace(PTRACE_SYSCALL, pid, NULL, NULL); 201 | } 202 | } 203 | 204 | #define is_traced(pid) do{\ 205 | char buf1[512];\ 206 | FILE* fin;\ 207 | fin = fopen("/proc/self/status", "r");\ 208 | int tpid;\ 209 | while(fgets(buf1, 512, fin)) {\ 210 | if(!strncmp(buf1, "TracerPid", 9)) {\ 211 | sscanf(buf1, "TracerPid: %d", &tpid);\ 212 | if(tpid != pid) {\ 213 | __asm("pop rbp");\ 214 | __asm("mov rsp,rbp");\ 215 | __asm("ret");\ 216 | }\ 217 | }\ 218 | }\ 219 | fclose(fin);\ 220 | }while(0) 221 | 222 | void rc6_encrypt(void *K, void *input, void *output) { 223 | RC6_KEY key; 224 | uint32_t i, j, m, A, B, C, D, T0, T1, L[8], *kptr = (uint32_t*)K; 225 | 226 | // initialize L with key 227 | for (i = 0; i < keylen / 4; i++) { 228 | L[i] = kptr[i]; 229 | } 230 | 231 | A = RC6_P; 232 | 233 | // initialize S with constants 234 | for (i = 0; i < RC6_KR; i++) { 235 | key.x[i] = A; 236 | A += RC6_Q; 237 | } 238 | 239 | A = B = i = j = m = 0; 240 | 241 | // mix with key 242 | for (; m < RC6_KR * 3; m++) { 243 | A = key.x[i] = ROTL32(key.x[i] + A + B, 3); 244 | B = L[j] = ROTL32(L[j] + A + B, A + B); 245 | 246 | i++; 247 | i %= RC6_KR; 248 | 249 | j++; 250 | j %= keylen / 4; 251 | } 252 | 253 | 254 | rc6_blk *in, *out; 255 | 256 | uint32_t *k = (uint32_t*)key.x; 257 | 258 | in = (rc6_blk*)input; 259 | out = (rc6_blk*)output; 260 | 261 | // load plaintext/ciphertext 262 | A = in->w[0]; 263 | B = in->w[1]; 264 | C = in->w[2]; 265 | D = in->w[3]; 266 | 267 | 268 | B += *k; k++; 269 | D += *k; k++; 270 | 271 | 272 | for (i = 0; i < RC6_ROUNDS; i++){ 273 | T0 = ROTL32(B * (2 * B + 1), 5); 274 | T1 = ROTL32(D * (2 * D + 1), 5); 275 | 276 | A = ROTL32(A ^ T0, T1) + *k; k++; 277 | C = ROTL32(C ^ T1, T0) + *k; k++; 278 | // rotate 32-bits to the left 279 | T0 = A; 280 | A = B; 281 | B = C; 282 | C = D; 283 | D = T0; 284 | } 285 | A += *k; k++; 286 | C += *k; k++; 287 | 288 | // save plaintext/ciphertext 289 | out->w[0] = A; 290 | out->w[1] = B; 291 | out->w[2] = C; 292 | out->w[3] = D; 293 | } 294 | void encrypt(char * input_flag){//rc6 + fence_cipher 295 | int i = 0; 296 | int cmp = 0; 297 | uint8_t c[0x20]; 298 | 299 | while (i < 2) { 300 | rc6_encrypt(leijun, input_flag + (i * 16), c + (i * 16)); 301 | cmp |= memcmp(c + (i * 16), flag_enc + (i * 16), 16); 302 | i++; 303 | } 304 | if(!cmp){ 305 | puts((const char * )got_it); 306 | exit(0); 307 | } 308 | puts((const char *)again); 309 | puts((const char *)not_mifan); 310 | exit(0); 311 | 312 | } 313 | 314 | /* 315 | void rc6_decrypt(void *K, void *input, void *output) { 316 | RC6_KEY key; 317 | uint32_t i, j, m, A, B, C, D, T0, T1, L[8], *kptr = (uint32_t*)K; 318 | 319 | // initialize L with key 320 | for (i = 0; i < keylen / 4; i++) { 321 | L[i] = kptr[i]; 322 | } 323 | 324 | A = RC6_P; 325 | 326 | // initialize S with constants 327 | for (i = 0; i < RC6_KR; i++) { 328 | key.x[i] = A; 329 | A += RC6_Q; 330 | } 331 | 332 | A = B = i = j = m = 0; 333 | 334 | // mix with key 335 | for (; m < RC6_KR * 3; m++) 336 | { 337 | A = key.x[i] = ROTL32(key.x[i] + A + B, 3); 338 | B = L[j] = ROTL32(L[j] + A + B, A + B); 339 | 340 | i++; 341 | i %= RC6_KR; 342 | 343 | j++; 344 | j %= keylen / 4; 345 | } 346 | 347 | rc6_blk *in, *out; 348 | uint32_t *k = (uint32_t*)key.x; 349 | 350 | in = (rc6_blk*)input; 351 | out = (rc6_blk*)output; 352 | 353 | // load plaintext/ciphertext 354 | A = in->w[0]; 355 | B = in->w[1]; 356 | C = in->w[2]; 357 | D = in->w[3]; 358 | 359 | 360 | k += 43; 361 | C -= *k; k--; 362 | A -= *k; k--; 363 | 364 | 365 | for (i = 0; i < RC6_ROUNDS; i++) 366 | { 367 | 368 | T0 = ROTL32(A * (2 * A + 1), 5); 369 | T1 = ROTL32(C * (2 * C + 1), 5); 370 | 371 | B = ROTR32(B - *k, T0) ^ T1; k--; 372 | D = ROTR32(D - *k, T1) ^ T0; k--; 373 | // rotate 32-bits to the right 374 | T0 = D; 375 | D = C; 376 | C = B; 377 | B = A; 378 | A = T0; 379 | 380 | } 381 | 382 | 383 | D -= *k; k--; 384 | B -= *k; k--; 385 | 386 | // save plaintext/ciphertext 387 | out->w[0] = A; 388 | out->w[1] = B; 389 | out->w[2] = C; 390 | out->w[3] = D; 391 | } 392 | */ 393 | 394 | int main(int argc, char *argv[]) 395 | { 396 | setbuf(stdin,0); 397 | setbuf(stdout,0); 398 | rc4_init(); 399 | __asm(".intel_syntax noprefix"); 400 | if(argc==1){ 401 | //puts(leijun); 402 | pid_t parent_pid = getpid(); 403 | //printf("[DEBUG] parent pid : %d\n",parent_pid); 404 | 405 | pid_t pid; 406 | char dbg_pid[0x20]; 407 | sprintf(dbg_pid,"%d",parent_pid); 408 | char * new_argv[]= {argv[0],dbg_pid,0}; 409 | pid = fork(); 410 | if (pid < 0) 411 | { 412 | //puts("[DEBUG] fork error"); 413 | return 0; 414 | } 415 | else if (!pid) 416 | { //child 417 | ptrace(PTRACE_TRACEME, 0, NULL, NULL); 418 | if (execve(argv[0], new_argv, NULL) == -1) 419 | { 420 | //puts("[DEBUG] execl error!!"); 421 | return 0; 422 | } 423 | } 424 | else 425 | { //parent 426 | is_traced(0); 427 | debugloop(pid); 428 | } 429 | 430 | }else{ 431 | if(argc == 2){//real child 432 | puts((const char *)plz_input_flag); 433 | scanf("%48s",flag); 434 | 435 | is_traced(atoi(argv[1])); 436 | 437 | puts((const char *)again); 438 | puts((const char *)not_mifan); 439 | exit(0); 440 | } 441 | } 442 | return 0; 443 | } -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/debugger.cpp.templite: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "rc6.h"//modify from https://github.com/odzhan/rc6 12 | 13 | ///////////////////////////////////////////////PATCH 14 | //patch to puts("fail"); 15 | #define brk_addr_to_puts_fail 0x0000000000401CD5 16 | #define jmp_encrypt "\xE9\x47\xE6\xDF\xFF\xFF\xFF\xFF" 17 | #define rc6_encrypt_start 0x0000000000401541 18 | #define len_of_2encrypt_func 0x3f5+0xca 19 | #define jmp_leijun_xor_cc 0x201324ccecd82a25 20 | ///////////////////////////////////////////////PATCH 21 | 22 | 23 | #define keylen 32 24 | #define s_long (sizeof(long)) 25 | 26 | long brk_addr=brk_addr_to_puts_fail; 27 | 28 | unsigned char rc4_key[] = { 0x5a,0x98,0x2c,0x36,0x5f,0xea,0x90,0xc0,0xb1,0x51,0x71,0x1a,0x32,0xd5,0x86,0x4b,0x4f,0x33,0xb7,0xd9,0x15,0xf6,0x5b,0x99,0x10,0xbd,0x81,0x2e,0x73,0x33,0xde,0x07}; 29 | unsigned char s_box[256]; 30 | 31 | unsigned char plz_input_flag[] = {0x50,0x28,0x40,0xab,0xee,0xc4,0x5c,0x26,0xe3,0x46,0xbc,0x34,0xde,0xf0,0x91,0x74,0x89,0x1b,0x82,0x7e};//"Plz input the flag :" 32 | unsigned char got_it[] = {0x79,0x2b,0x4f,0xab,0xe0,0xc5,0x58,0x73,0xfe,0x12,0xe8,0x66,0x92};//"you got it :)" 33 | unsigned char again[] = {0x74,0x36,0x43,0xab,0xe6,0xcd,0x4d,0x3a,0xf9,0x46,0xf2,0x74};//"try again :(" 34 | unsigned char not_mifan[] = {0x43,0x31,0x40,0xab,0xf2,0x8a,0x4d,0x21,0xf2,0x46,0xa6,0x33,0xcf,0xf0,0x83,0x6a,0x9d,0x19,0x82,0x09,0xd8,0x8d,0x6e,0x5b,0xaa,0xc5,};//"Cuz u are not true Mifan!!" 35 | 36 | //char flag[] = "hctf{H499y_p7rCe_3vEry_d4y_xxxx}"; 37 | char flag[0x40]; 38 | unsigned char flag_enc[] = ${ flag_enc_enc }$; 39 | 40 | void rc4_init(void){ 41 | int i = 0, j = 0; 42 | unsigned char k[256] = { 0 }; 43 | char tmp; 44 | for (i = 0; i<256; i++) { 45 | s_box[i] = i; 46 | } 47 | for (i = 0; i<256; i++) { 48 | j = (j + s_box[i] + rc4_key[i%32]) % 256; 49 | tmp = s_box[i]; 50 | s_box[i] = s_box[j]; 51 | s_box[j] = tmp; 52 | } 53 | } 54 | 55 | void rc4_crypt(char*data, int len){ 56 | int i = 0, j = 0, t = 0; 57 | int k = 0; 58 | for (k = 0; k\n",tmp_str); 138 | send_data(pid, addr, tmp_str, len); 139 | } 140 | 141 | void debugloop(pid_t pid) 142 | { 143 | int status; 144 | struct user_regs_struct regs; 145 | int read_num=0; 146 | char write_flag=0; 147 | char set_pwn=0; 148 | while (1) 149 | { 150 | waitpid(pid,&status,0); 151 | 152 | if (WIFEXITED(status)) 153 | { 154 | break; 155 | } 156 | ptrace(PTRACE_GETREGS, pid, NULL, ®s); 157 | //printf("%llu\n",regs.orig_rax); 158 | if (regs.orig_rax == __NR_write && regs.rdx!=1) 159 | { 160 | decrypt_data(pid, regs.rsi, regs.rdx); 161 | } 162 | if(regs.orig_rax == __NR_close && regs.rsi==1){//close 163 | if(set_pwn==1){ 164 | long op; 165 | op=ptrace(PTRACE_PEEKDATA,pid,brk_addr,NULL); 166 | ptrace(PTRACE_POKEDATA,pid,brk_addr,0xcccccccccccccccc); 167 | 168 | decrypt_data(pid,rc6_encrypt_start,len_of_2encrypt_func); 169 | ptrace(PTRACE_CONT, pid, NULL, NULL); 170 | wait(&status); 171 | op=ptrace(PTRACE_PEEKDATA,pid,brk_addr,NULL); 172 | op^=jmp_leijun_xor_cc; 173 | ptrace(PTRACE_POKEDATA,pid,brk_addr,op); 174 | 175 | 176 | ptrace(PTRACE_GETREGS, pid, NULL, ®s); 177 | regs.rip--; 178 | regs.rdx=(unsigned long long)flag; 179 | ptrace(PTRACE_SETREGS,pid,NULL,®s); 180 | //printf("close : %llx %llx %llu | RBP: %llx | RSP: %llx | RIP : %llx\n",regs.rdi,regs.rsi,regs.rdx,regs.rbp,regs.rsp,regs.rip); 181 | ptrace(PTRACE_SYSCALL, pid, NULL, NULL); 182 | } 183 | 184 | set_pwn++; 185 | } 186 | if (regs.orig_rax == __NR_read && regs.rdx == 1) 187 | { 188 | if(!read_num){ 189 | 190 | }else if(read_num > 65){ 191 | puts("Try again :("); 192 | puts("Cuz u r not true Mifan!!"); 193 | kill(pid, SIGTERM); 194 | exit(0); 195 | } 196 | read_num++; 197 | //printf("read : %llx %llx %llu\n",regs.rdi,regs.rsi,regs.rdx); 198 | } 199 | 200 | ptrace(PTRACE_SYSCALL, pid, NULL, NULL); 201 | } 202 | } 203 | 204 | #define is_traced(pid) do{\ 205 | char buf1[512];\ 206 | FILE* fin;\ 207 | fin = fopen("/proc/self/status", "r");\ 208 | int tpid;\ 209 | while(fgets(buf1, 512, fin)) {\ 210 | if(!strncmp(buf1, "TracerPid", 9)) {\ 211 | sscanf(buf1, "TracerPid: %d", &tpid);\ 212 | if(tpid != pid) {\ 213 | __asm("pop rbp");\ 214 | __asm("mov rsp,rbp");\ 215 | __asm("ret");\ 216 | }\ 217 | }\ 218 | }\ 219 | fclose(fin);\ 220 | }while(0) 221 | 222 | void rc6_encrypt(void *K, void *input, void *output) { 223 | RC6_KEY key; 224 | uint32_t i, j, m, A, B, C, D, T0, T1, L[8], *kptr = (uint32_t*)K; 225 | 226 | // initialize L with key 227 | for (i = 0; i < keylen / 4; i++) { 228 | L[i] = kptr[i]; 229 | } 230 | 231 | A = RC6_P; 232 | 233 | // initialize S with constants 234 | for (i = 0; i < RC6_KR; i++) { 235 | key.x[i] = A; 236 | A += RC6_Q; 237 | } 238 | 239 | A = B = i = j = m = 0; 240 | 241 | // mix with key 242 | for (; m < RC6_KR * 3; m++) { 243 | A = key.x[i] = ROTL32(key.x[i] + A + B, 3); 244 | B = L[j] = ROTL32(L[j] + A + B, A + B); 245 | 246 | i++; 247 | i %= RC6_KR; 248 | 249 | j++; 250 | j %= keylen / 4; 251 | } 252 | 253 | 254 | rc6_blk *in, *out; 255 | 256 | uint32_t *k = (uint32_t*)key.x; 257 | 258 | in = (rc6_blk*)input; 259 | out = (rc6_blk*)output; 260 | 261 | // load plaintext/ciphertext 262 | A = in->w[0]; 263 | B = in->w[1]; 264 | C = in->w[2]; 265 | D = in->w[3]; 266 | 267 | 268 | B += *k; k++; 269 | D += *k; k++; 270 | 271 | 272 | for (i = 0; i < RC6_ROUNDS; i++){ 273 | T0 = ROTL32(B * (2 * B + 1), 5); 274 | T1 = ROTL32(D * (2 * D + 1), 5); 275 | 276 | A = ROTL32(A ^ T0, T1) + *k; k++; 277 | C = ROTL32(C ^ T1, T0) + *k; k++; 278 | // rotate 32-bits to the left 279 | T0 = A; 280 | A = B; 281 | B = C; 282 | C = D; 283 | D = T0; 284 | } 285 | A += *k; k++; 286 | C += *k; k++; 287 | 288 | // save plaintext/ciphertext 289 | out->w[0] = A; 290 | out->w[1] = B; 291 | out->w[2] = C; 292 | out->w[3] = D; 293 | } 294 | void encrypt(char * input_flag){//rc6 + fence_cipher 295 | int i = 0; 296 | int cmp = 0; 297 | uint8_t c[0x20]; 298 | 299 | while (i < 2) { 300 | rc6_encrypt(leijun, input_flag + (i * 16), c + (i * 16)); 301 | cmp |= memcmp(c + (i * 16), flag_enc + (i * 16), 16); 302 | i++; 303 | } 304 | if(!cmp){ 305 | puts((const char * )got_it); 306 | exit(0); 307 | } 308 | puts((const char *)again); 309 | puts((const char *)not_mifan); 310 | exit(0); 311 | 312 | } 313 | 314 | /* 315 | void rc6_decrypt(void *K, void *input, void *output) { 316 | RC6_KEY key; 317 | uint32_t i, j, m, A, B, C, D, T0, T1, L[8], *kptr = (uint32_t*)K; 318 | 319 | // initialize L with key 320 | for (i = 0; i < keylen / 4; i++) { 321 | L[i] = kptr[i]; 322 | } 323 | 324 | A = RC6_P; 325 | 326 | // initialize S with constants 327 | for (i = 0; i < RC6_KR; i++) { 328 | key.x[i] = A; 329 | A += RC6_Q; 330 | } 331 | 332 | A = B = i = j = m = 0; 333 | 334 | // mix with key 335 | for (; m < RC6_KR * 3; m++) 336 | { 337 | A = key.x[i] = ROTL32(key.x[i] + A + B, 3); 338 | B = L[j] = ROTL32(L[j] + A + B, A + B); 339 | 340 | i++; 341 | i %= RC6_KR; 342 | 343 | j++; 344 | j %= keylen / 4; 345 | } 346 | 347 | rc6_blk *in, *out; 348 | uint32_t *k = (uint32_t*)key.x; 349 | 350 | in = (rc6_blk*)input; 351 | out = (rc6_blk*)output; 352 | 353 | // load plaintext/ciphertext 354 | A = in->w[0]; 355 | B = in->w[1]; 356 | C = in->w[2]; 357 | D = in->w[3]; 358 | 359 | 360 | k += 43; 361 | C -= *k; k--; 362 | A -= *k; k--; 363 | 364 | 365 | for (i = 0; i < RC6_ROUNDS; i++) 366 | { 367 | 368 | T0 = ROTL32(A * (2 * A + 1), 5); 369 | T1 = ROTL32(C * (2 * C + 1), 5); 370 | 371 | B = ROTR32(B - *k, T0) ^ T1; k--; 372 | D = ROTR32(D - *k, T1) ^ T0; k--; 373 | // rotate 32-bits to the right 374 | T0 = D; 375 | D = C; 376 | C = B; 377 | B = A; 378 | A = T0; 379 | 380 | } 381 | 382 | 383 | D -= *k; k--; 384 | B -= *k; k--; 385 | 386 | // save plaintext/ciphertext 387 | out->w[0] = A; 388 | out->w[1] = B; 389 | out->w[2] = C; 390 | out->w[3] = D; 391 | } 392 | */ 393 | 394 | int main(int argc, char *argv[]) 395 | { 396 | setbuf(stdin,0); 397 | setbuf(stdout,0); 398 | rc4_init(); 399 | __asm(".intel_syntax noprefix"); 400 | if(argc==1){ 401 | //puts(leijun); 402 | pid_t parent_pid = getpid(); 403 | //printf("[DEBUG] parent pid : %d\n",parent_pid); 404 | 405 | pid_t pid; 406 | char dbg_pid[0x20]; 407 | sprintf(dbg_pid,"%d",parent_pid); 408 | char * new_argv[]= {argv[0],dbg_pid,0}; 409 | pid = fork(); 410 | if (pid < 0) 411 | { 412 | //puts("[DEBUG] fork error"); 413 | return 0; 414 | } 415 | else if (!pid) 416 | { //child 417 | ptrace(PTRACE_TRACEME, 0, NULL, NULL); 418 | if (execve(argv[0], new_argv, NULL) == -1) 419 | { 420 | //puts("[DEBUG] execl error!!"); 421 | return 0; 422 | } 423 | } 424 | else 425 | { //parent 426 | is_traced(0); 427 | debugloop(pid); 428 | } 429 | 430 | }else{ 431 | if(argc == 2){//real child 432 | puts((const char *)plz_input_flag); 433 | scanf("%48s",flag); 434 | 435 | is_traced(atoi(argv[1])); 436 | 437 | puts((const char *)again); 438 | puts((const char *)not_mifan); 439 | exit(0); 440 | } 441 | } 442 | return 0; 443 | } -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/generate_one.py: -------------------------------------------------------------------------------- 1 | import sys, random, os, tempfile 2 | from pwn import * 3 | from templite import Templite 4 | 5 | #flag = r"hctf{p1ay_Wi7h_p7r4Ce_1n__L1nuX}" 6 | enc_key = "52Mi!R_u_MiFans?DO_u_like_me?Tha" 7 | 8 | 9 | def rotl32(v,n): 10 | return (((((v)&0xffffffff) << (n%32))&0xffffffff) | (((v)&0xffffffff) >> (32 - (n%32)))) 11 | 12 | def encrypt16(flag): 13 | RC6_ROUNDS=20 14 | RC6_KR=(2*(RC6_ROUNDS+2)) 15 | RC6_P=0xB7E15163 16 | RC6_Q=0x9E3779B9 17 | keylen=32 18 | L = [0]*8 19 | key = [0]*RC6_KR 20 | 21 | for i in range(8): 22 | L[i] = u32(enc_key[i*4:i*4+4]) 23 | 24 | A = RC6_P 25 | 26 | for i in range(RC6_KR): 27 | key[i] = A 28 | A+=RC6_Q 29 | A=A&0xffffffff 30 | 31 | A=0 32 | B=0 33 | i=0 34 | j=0 35 | 36 | for m in range(3*RC6_KR): 37 | key[i] = rotl32(key[i]+A+B,3) 38 | A=key[i] 39 | L[j] = rotl32(L[j]+A+B, A+B); 40 | B = L[j] 41 | 42 | i+=1 43 | i%=RC6_KR 44 | 45 | j+=1 46 | j%=keylen/4 47 | 48 | p_in = [0]*4 49 | p_out= [0]*4 50 | t0=0 51 | t1=0 52 | 53 | for i in range(4): 54 | p_in[i] = u32(flag[i*4:i*4+4]) 55 | 56 | k=0 57 | 58 | p_in[1]+=key[k] 59 | k+=1 60 | p_in[3]+=key[k] 61 | k+=1 62 | 63 | 64 | for i in range(RC6_ROUNDS): 65 | t0=rotl32(p_in[1]*(2*p_in[1]+1),5) 66 | t1=rotl32(p_in[3]*(2*p_in[3]+1),5) 67 | 68 | p_in[0]=rotl32(p_in[0]^t0,t1)+key[k] 69 | k+=1 70 | p_in[2]=rotl32(p_in[2]^t1,t0)+key[k] 71 | k+=1 72 | 73 | t0=p_in[0] 74 | p_in[0]=p_in[1] 75 | p_in[1]=p_in[2] 76 | p_in[2]=p_in[3] 77 | p_in[3]=t0 78 | 79 | p_in[0]+=key[k] 80 | k+=1 81 | p_in[2]+=key[k] 82 | k+=1 83 | 84 | for i in range(4): 85 | p_out[i] = p32(p_in[i]&0xffffffff) 86 | 87 | return ''.join(p_out) 88 | 89 | def encrypt(flag): 90 | assert len(flag)==32,"the length of flag != 32" 91 | return encrypt16(flag[:16])+encrypt16(flag[16:]) 92 | 93 | def encrypt_function(filename): 94 | fp = open(filename,'rb') 95 | data = fp.read() 96 | fp.close() 97 | start=0x1541 98 | enc_len=0x3f5+0xca 99 | p = list(data[start:start+enc_len]) 100 | key = [0x5a,0x98,0x2c,0x36,0x5f,0xea,0x90,0xc0,0xb1,0x51,0x71,0x1a,0x32,0xd5,0x86,0x4b,0x4f,0x33,0xb7,0xd9,0x15,0xf6,0x5b,0x99,0x10,0xbd,0x81,0x2e,0x73,0x33,0xde,0x07 ] 101 | j=0 102 | sbox=range(256) 103 | 104 | for i in range(256): 105 | j=(j+sbox[i]+key[i%len(key)])%256 106 | sbox[i],sbox[j] = sbox[j],sbox[i] 107 | 108 | k=0 109 | j=0 110 | i=0 111 | for k in range(len(p)): 112 | i=(i+1)%256 113 | j=(j+sbox[i])%256 114 | t=(sbox[i]+sbox[j])%256 115 | p[k] = chr(ord(p[k])^sbox[t]) 116 | 117 | enc = data[:start]+''.join(p)+data[start+enc_len:] 118 | 119 | fp=open(filename,'wb') 120 | fp.write(enc) 121 | fp.close() 122 | 123 | def generate(argv): 124 | if len(argv) != 3: 125 | print 'Usage: python generate_one.py [flag] [output_file]' 126 | sys.exit() 127 | 128 | flag = argv[1] 129 | output_file = argv[2] 130 | flag_enc_enc = str(map(ord,list(encrypt(flag)))).replace('[','{').replace(']','}') 131 | 132 | template = open('debugger.cpp.templite', 'r').read() 133 | c_code = Templite(template).render(flag_enc_enc=flag_enc_enc) 134 | 135 | fp = open('temp_debugger.cpp','w') 136 | fp.write(c_code) 137 | fp.close() 138 | 139 | os.system('mkdir build 2>/dev/null') 140 | os.system('gcc -z execstack -masm=intel -std=c++11 temp_debugger.cpp -o ' + output_file) 141 | os.system('strip '+output_file) 142 | os.system('rm temp_debugger.cpp') 143 | encrypt_function(output_file) 144 | os.system('upx '+output_file+' 1>/dev/null') 145 | os.system("mv ./"+output_file+" ./build/"+output_file) 146 | if __name__ == '__main__': 147 | generate(sys.argv) -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/machine.h: -------------------------------------------------------------------------------- 1 | /* ecrypt-machine.h */ 2 | 3 | /* 4 | * This file is included by 'ecrypt-portable.h'. It allows to override 5 | * the default macros for specific platforms. Please carefully check 6 | * the machine code generated by your compiler (with optimisations 7 | * turned on) before deciding to edit this file. 8 | */ 9 | 10 | /* ------------------------------------------------------------------------- */ 11 | 12 | #if (defined(ECRYPT_DEFAULT_ROT) && !defined(ECRYPT_MACHINE_ROT)) 13 | 14 | #define ECRYPT_MACHINE_ROT 15 | 16 | #if (defined(WIN32) && defined(_MSC_VER)) 17 | 18 | #undef ROTL32 19 | #undef ROTR32 20 | #undef ROTL64 21 | #undef ROTR64 22 | 23 | #include 24 | 25 | #define ROTL32(v, n) _lrotl(v, n) 26 | #define ROTR32(v, n) _lrotr(v, n) 27 | #define ROTL64(v, n) _rotl64(v, n) 28 | #define ROTR64(v, n) _rotr64(v, n) 29 | 30 | #endif 31 | 32 | #endif 33 | 34 | /* ------------------------------------------------------------------------- */ 35 | 36 | #if (defined(ECRYPT_DEFAULT_SWAP) && !defined(ECRYPT_MACHINE_SWAP)) 37 | 38 | #define ECRYPT_MACHINE_SWAP 39 | 40 | /* 41 | * If you want to overwrite the default swap macros, put it here. And so on. 42 | */ 43 | 44 | #endif 45 | 46 | /* ------------------------------------------------------------------------- */ 47 | -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/macros.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef MACROS_H 4 | #define MACROS_H 5 | 6 | #include 7 | #include 8 | 9 | #include "portable.h" 10 | 11 | #define XCHG(x, y) (t) = (x); (x) = (y); (y) = (t); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/portable.h: -------------------------------------------------------------------------------- 1 | /* ecrypt-portable.h */ 2 | 3 | /* 4 | * WARNING: the conversions defined below are implemented as macros, 5 | * and should be used carefully. They should NOT be used with 6 | * parameters which perform some action. E.g., the following two lines 7 | * are not equivalent: 8 | * 9 | * 1) ++x; y = ROTL32(x, n); 10 | * 2) y = ROTL32(++x, n); 11 | */ 12 | 13 | /* 14 | * *** Please do not edit this file. *** 15 | * 16 | * The default macros can be overridden for specific architectures by 17 | * editing 'machine.h'. 18 | */ 19 | 20 | #ifndef ECRYPT_PORTABLE 21 | #define ECRYPT_PORTABLE 22 | 23 | #include "config.h" 24 | 25 | /* ------------------------------------------------------------------------- */ 26 | 27 | /* 28 | * The following types are defined (if available): 29 | * 30 | * u8: unsigned integer type, at least 8 bits 31 | * u16: unsigned integer type, at least 16 bits 32 | * u32: unsigned integer type, at least 32 bits 33 | * u64: unsigned integer type, at least 64 bits 34 | * 35 | * s8, s16, s32, s64 -> signed counterparts of u8, u16, u32, u64 36 | * 37 | * The selection of minimum-width integer types is taken care of by 38 | * 'config.h'. Note: to enable 64-bit types on 32-bit 39 | * compilers, it might be necessary to switch from ISO C90 mode to ISO 40 | * C99 mode (e.g., gcc -std=c99). 41 | */ 42 | 43 | #ifdef I8T 44 | typedef signed I8T s8; 45 | typedef unsigned I8T u8; 46 | #endif 47 | 48 | #ifdef I16T 49 | typedef signed I16T s16; 50 | typedef unsigned I16T u16; 51 | #endif 52 | 53 | #ifdef I32T 54 | typedef signed I32T s32; 55 | typedef unsigned I32T u32; 56 | #endif 57 | 58 | #ifdef I64T 59 | typedef signed I64T s64; 60 | typedef unsigned I64T u64; 61 | #endif 62 | 63 | /* 64 | * The following macros are used to obtain exact-width results. 65 | */ 66 | 67 | #define U8V(v) ((u8)(v) & U8C(0xFF)) 68 | #define U16V(v) ((u16)(v) & U16C(0xFFFF)) 69 | #define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) 70 | #define U64V(v) ((u64)(v) & U64C(0xFFFFFFFFFFFFFFFF)) 71 | 72 | /* ------------------------------------------------------------------------- */ 73 | 74 | /* 75 | * The following macros return words with their bits rotated over n 76 | * positions to the left/right. 77 | */ 78 | 79 | #define ECRYPT_DEFAULT_ROT 80 | 81 | #define ROTL8(v, n) \ 82 | (U8V((v) << (n)) | ((v) >> (8 - (n)))) 83 | 84 | #define ROTL16(v, n) \ 85 | (U16V((v) << (n)) | ((v) >> (16 - (n)))) 86 | 87 | #define ROTL32(v, n) \ 88 | (U32V((v) << (n)) | ((v) >> (32 - (n)))) 89 | 90 | #define ROTL64(v, n) \ 91 | (U64V((v) << (n)) | ((v) >> (64 - (n)))) 92 | 93 | #define ROTR8(v, n) ROTL8(v, 8 - (n)) 94 | #define ROTR16(v, n) ROTL16(v, 16 - (n)) 95 | #define ROTR32(v, n) ROTL32(v, 32 - (n)) 96 | #define ROTR64(v, n) ROTL64(v, 64 - (n)) 97 | 98 | #include "machine.h" 99 | 100 | /* ------------------------------------------------------------------------- */ 101 | 102 | /* 103 | * The following macros return a word with bytes in reverse order. 104 | */ 105 | 106 | #define ECRYPT_DEFAULT_SWAP 107 | 108 | #define SWAP16(v) \ 109 | ROTL16(v, 8) 110 | 111 | #define SWAP32(v) \ 112 | ((ROTL32(v, 8) & U32C(0x00FF00FF)) | \ 113 | (ROTL32(v, 24) & U32C(0xFF00FF00))) 114 | 115 | #ifdef ECRYPT_NATIVE64 116 | #define SWAP64(v) \ 117 | ((ROTL64(v, 8) & U64C(0x000000FF000000FF)) | \ 118 | (ROTL64(v, 24) & U64C(0x0000FF000000FF00)) | \ 119 | (ROTL64(v, 40) & U64C(0x00FF000000FF0000)) | \ 120 | (ROTL64(v, 56) & U64C(0xFF000000FF000000))) 121 | #else 122 | #define SWAP64(v) \ 123 | (((u64)SWAP32(U32V(v)) << 32) | (u64)SWAP32(U32V(v >> 32))) 124 | #endif 125 | 126 | #include "machine.h" 127 | 128 | #define ECRYPT_DEFAULT_WTOW 129 | 130 | #ifdef ECRYPT_LITTLE_ENDIAN 131 | #define U16TO16_LITTLE(v) (v) 132 | #define U32TO32_LITTLE(v) (v) 133 | #define U64TO64_LITTLE(v) (v) 134 | 135 | #define U16TO16_BIG(v) SWAP16(v) 136 | #define U32TO32_BIG(v) SWAP32(v) 137 | #define U64TO64_BIG(v) SWAP64(v) 138 | #endif 139 | 140 | #ifdef ECRYPT_BIG_ENDIAN 141 | #define U16TO16_LITTLE(v) SWAP16(v) 142 | #define U32TO32_LITTLE(v) SWAP32(v) 143 | #define U64TO64_LITTLE(v) SWAP64(v) 144 | 145 | #define U16TO16_BIG(v) (v) 146 | #define U32TO32_BIG(v) (v) 147 | #define U64TO64_BIG(v) (v) 148 | #endif 149 | 150 | #include "machine.h" 151 | 152 | /* 153 | * The following macros load words from an array of bytes with 154 | * different types of endianness, and vice versa. 155 | */ 156 | 157 | #define ECRYPT_DEFAULT_BTOW 158 | 159 | #if (!defined(ECRYPT_UNKNOWN) && defined(ECRYPT_I8T_IS_BYTE)) 160 | 161 | #define U8TO16_LITTLE(p) U16TO16_LITTLE(((u16*)(p))[0]) 162 | #define U8TO32_LITTLE(p) U32TO32_LITTLE(((u32*)(p))[0]) 163 | #define U8TO64_LITTLE(p) U64TO64_LITTLE(((u64*)(p))[0]) 164 | 165 | #define U8TO16_BIG(p) U16TO16_BIG(((u16*)(p))[0]) 166 | #define U8TO32_BIG(p) U32TO32_BIG(((u32*)(p))[0]) 167 | #define U8TO64_BIG(p) U64TO64_BIG(((u64*)(p))[0]) 168 | 169 | #define U16TO8_LITTLE(p, v) (((u16*)(p))[0] = U16TO16_LITTLE(v)) 170 | #define U32TO8_LITTLE(p, v) (((u32*)(p))[0] = U32TO32_LITTLE(v)) 171 | #define U64TO8_LITTLE(p, v) (((u64*)(p))[0] = U64TO64_LITTLE(v)) 172 | 173 | #define U16TO8_BIG(p, v) (((u16*)(p))[0] = U16TO16_BIG(v)) 174 | #define U32TO8_BIG(p, v) (((u32*)(p))[0] = U32TO32_BIG(v)) 175 | #define U64TO8_BIG(p, v) (((u64*)(p))[0] = U64TO64_BIG(v)) 176 | 177 | #else 178 | 179 | #define U8TO16_LITTLE(p) \ 180 | (((u16)((p)[0]) ) | \ 181 | ((u16)((p)[1]) << 8)) 182 | 183 | #define U8TO32_LITTLE(p) \ 184 | (((u32)((p)[0]) ) | \ 185 | ((u32)((p)[1]) << 8) | \ 186 | ((u32)((p)[2]) << 16) | \ 187 | ((u32)((p)[3]) << 24)) 188 | 189 | #ifdef ECRYPT_NATIVE64 190 | #define U8TO64_LITTLE(p) \ 191 | (((u64)((p)[0]) ) | \ 192 | ((u64)((p)[1]) << 8) | \ 193 | ((u64)((p)[2]) << 16) | \ 194 | ((u64)((p)[3]) << 24) | \ 195 | ((u64)((p)[4]) << 32) | \ 196 | ((u64)((p)[5]) << 40) | \ 197 | ((u64)((p)[6]) << 48) | \ 198 | ((u64)((p)[7]) << 56)) 199 | #else 200 | #define U8TO64_LITTLE(p) \ 201 | ((u64)U8TO32_LITTLE(p) | ((u64)U8TO32_LITTLE((p) + 4) << 32)) 202 | #endif 203 | 204 | #define U8TO16_BIG(p) \ 205 | (((u16)((p)[0]) << 8) | \ 206 | ((u16)((p)[1]) )) 207 | 208 | #define U8TO32_BIG(p) \ 209 | (((u32)((p)[0]) << 24) | \ 210 | ((u32)((p)[1]) << 16) | \ 211 | ((u32)((p)[2]) << 8) | \ 212 | ((u32)((p)[3]) )) 213 | 214 | #ifdef ECRYPT_NATIVE64 215 | #define U8TO64_BIG(p) \ 216 | (((u64)((p)[0]) << 56) | \ 217 | ((u64)((p)[1]) << 48) | \ 218 | ((u64)((p)[2]) << 40) | \ 219 | ((u64)((p)[3]) << 32) | \ 220 | ((u64)((p)[4]) << 24) | \ 221 | ((u64)((p)[5]) << 16) | \ 222 | ((u64)((p)[6]) << 8) | \ 223 | ((u64)((p)[7]) )) 224 | #else 225 | #define U8TO64_BIG(p) \ 226 | (((u64)U8TO32_BIG(p) << 32) | (u64)U8TO32_BIG((p) + 4)) 227 | #endif 228 | 229 | #define U16TO8_LITTLE(p, v) \ 230 | do { \ 231 | (p)[0] = U8V((v) ); \ 232 | (p)[1] = U8V((v) >> 8); \ 233 | } while (0) 234 | 235 | #define U32TO8_LITTLE(p, v) \ 236 | do { \ 237 | (p)[0] = U8V((v) ); \ 238 | (p)[1] = U8V((v) >> 8); \ 239 | (p)[2] = U8V((v) >> 16); \ 240 | (p)[3] = U8V((v) >> 24); \ 241 | } while (0) 242 | 243 | #ifdef ECRYPT_NATIVE64 244 | #define U64TO8_LITTLE(p, v) \ 245 | do { \ 246 | (p)[0] = U8V((v) ); \ 247 | (p)[1] = U8V((v) >> 8); \ 248 | (p)[2] = U8V((v) >> 16); \ 249 | (p)[3] = U8V((v) >> 24); \ 250 | (p)[4] = U8V((v) >> 32); \ 251 | (p)[5] = U8V((v) >> 40); \ 252 | (p)[6] = U8V((v) >> 48); \ 253 | (p)[7] = U8V((v) >> 56); \ 254 | } while (0) 255 | #else 256 | #define U64TO8_LITTLE(p, v) \ 257 | do { \ 258 | U32TO8_LITTLE((p), U32V((v) )); \ 259 | U32TO8_LITTLE((p) + 4, U32V((v) >> 32)); \ 260 | } while (0) 261 | #endif 262 | 263 | #define U16TO8_BIG(p, v) \ 264 | do { \ 265 | (p)[0] = U8V((v) ); \ 266 | (p)[1] = U8V((v) >> 8); \ 267 | } while (0) 268 | 269 | #define U32TO8_BIG(p, v) \ 270 | do { \ 271 | (p)[0] = U8V((v) >> 24); \ 272 | (p)[1] = U8V((v) >> 16); \ 273 | (p)[2] = U8V((v) >> 8); \ 274 | (p)[3] = U8V((v) ); \ 275 | } while (0) 276 | 277 | #ifdef ECRYPT_NATIVE64 278 | #define U64TO8_BIG(p, v) \ 279 | do { \ 280 | (p)[0] = U8V((v) >> 56); \ 281 | (p)[1] = U8V((v) >> 48); \ 282 | (p)[2] = U8V((v) >> 40); \ 283 | (p)[3] = U8V((v) >> 32); \ 284 | (p)[4] = U8V((v) >> 24); \ 285 | (p)[5] = U8V((v) >> 16); \ 286 | (p)[6] = U8V((v) >> 8); \ 287 | (p)[7] = U8V((v) ); \ 288 | } while (0) 289 | #else 290 | #define U64TO8_BIG(p, v) \ 291 | do { \ 292 | U32TO8_BIG((p), U32V((v) >> 32)); \ 293 | U32TO8_BIG((p) + 4, U32V((v) )); \ 294 | } while (0) 295 | #endif 296 | 297 | #endif 298 | 299 | #include "machine.h" 300 | 301 | /* ------------------------------------------------------------------------- */ 302 | 303 | #endif 304 | -------------------------------------------------------------------------------- /re_level3_are_u_ok/code/rc6.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | // RC6 in C 4 | // Odzhan 5 | 6 | #ifndef RC6_H 7 | #define RC6_H 8 | 9 | #include 10 | 11 | #include "macros.h" 12 | 13 | #define RC6_ROUNDS 20 14 | #define RC6_KR (2*(RC6_ROUNDS+2)) 15 | #define RC6_P 0xB7E15163 16 | #define RC6_Q 0x9E3779B9 17 | 18 | #define RC6_ENCRYPT 1 19 | #define RC6_DECRYPT 0 20 | 21 | typedef struct _RC6_KEY { 22 | uint32_t x[RC6_KR]; 23 | } RC6_KEY; 24 | 25 | typedef union _rc6_blk_t { 26 | uint8_t b[16]; 27 | uint32_t w[4]; 28 | uint64_t q[2]; 29 | } rc6_blk; 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | // asm prototype 36 | void rc6_setkeyx (RC6_KEY*, void*, uint32_t); 37 | void rc6_cryptx (RC6_KEY*, void*, void*, int); 38 | 39 | // C prototype 40 | void rc6_setkey (RC6_KEY*, void*, uint32_t); 41 | void rc6_crypt (RC6_KEY*, void*, void*, int); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #ifdef USE_ASM 48 | #define rc6_setkey(x, y, z) rc6_setkeyx (x, y, z) 49 | #define rc6_crypt(w, x, y, z) rc6_cryptx (w, x, y, z) 50 | #endif 51 | 52 | #endif -------------------------------------------------------------------------------- /re_level3_are_u_ok/re_level2_are_u_ok.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veritas501/hctf_wp/534e581b3b8d8a19b202f5e988d3ac6b488cc352/re_level3_are_u_ok/re_level2_are_u_ok.md --------------------------------------------------------------------------------