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~=DHZ~&]Q>*8R0vCҮLӪ6-8XcuG&{uurgMS pHLg<0_ʑkJFV-5*SMG ,\J̑ڂ 2XkE)z%{dgn\&":?2svqfqPDU_Z˚l[B`,sއugؖ1c&qCƴ ;a=0aٵ 4$wvM4U ZV2X$}[,[wѺ\>@]+mm6JxV)hr}#.yQ*JW>;0DZq#g9 ֭^ )Ѫ[7 HXq|<(ĥY@jd :_|מc<.ϯ;q>;i_.{d. "By~<'k?zRՇVfd.jA*XA/a _Bc@/+K(=os!V~9P_ [d7녵<m{q`58 tZgp[?3N#kZ_!{_Cw>sv=. ;ݶZ2֛,R2f\y kxV+.NR)SJx~\H䯛04 :ev7簬r^ B6Q_aatB߉EJ^hضn{5›5'WM,IMVjdzG8x+{+/װ%y#"/AsFWm;Z0{cUDx+#Vah S򣰹0YFG: #y03CҼݣO+h'AգW <ꄠVz%T*z+Cm< e7~aQd+HʥhXe`$~<Jnb/ptnƧR^IqaoZIb-xY # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General # Public License as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) AC_INIT([usbauth], [1.0.3], [stefan.koch10@gmail.com]) AM_INIT_AUTOMAKE([-Wall foreign]) AC_CONFIG_SRCDIR([config.h.in]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIRS([m4]) AC_SYS_LARGEFILE AM_PROG_AR LT_INIT # Checks for programs. AC_PROG_CXX AC_PROG_AWK AC_PROG_CC AC_PROG_CPP AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET # Checks for libraries. # Checks for header files. AC_CHECK_HEADERS([inttypes.h stdlib.h string.h sys/file.h unistd.h]) # Checks for typedefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL AC_TYPE_INT32_T AC_TYPE_SIZE_T # Checks for library functions. AC_CHECK_FUNCS([strtol]) PKG_CHECK_MODULES([USBAUTH], [libusbauth-configparser]) PKG_CHECK_MODULES([UDEV], [libudev]) PKG_CHECK_MODULES([DBUS], [dbus-1]) AC_CONFIG_FILES([Makefile data/Makefile src/Makefile usbauth.spec]) AC_OUTPUT COPYING0000644000000000000000000004366313776005747010643 0ustar rootrootThis program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. ############################################################################### GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. data/0000755000000000000000000000000013776005747010505 5ustar rootrootdata/20-usbauth.rules0000644000000000000000000000010413776005747013446 0ustar rootrootSUBSYSTEM=="usb", ACTION=="add", RUN+="/usr/sbin/usbauth udev-add" data/Makefile.am0000644000000000000000000000130413776005747012537 0ustar rootroot# Copyright (C) 2017 Stefan Koch # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General # Public License as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. man_MANS = usbauth.8 sysconf_DATA = usbauth.conf udevrulesdir = /lib/udev/rules.d dist_udevrules_DATA=20-usbauth.rules dbusservicedir = $(sysconfdir)/dbus-1/system.d dist_dbusservice_DATA = org.opensuse.usbauth.conf data/usbauth.80000644000000000000000000001400613776005747012252 0ustar rootroot.TH USBAUTH 8 .SH NAME usbauth \- USB firewall against BadUSB attacks .SH SYNOPSIS udev mode, called by udev .br .B usbauth udev-add .LP manual mode, called by notifier .br .B usbauth allow DEVNUM PATH .br .B usbauth deny DEVNUM PATH .br .br PATH: path of USB interface, example /sys/bus/usb/devices/3-2/3-2:1.0/ .br DEVNUM: value of attribute, example 16 (from /sys/bus/usb/devices/3-2/devnum) .LP init mode, does apply rules for all available devices .br .B usbauth init .LP .SH DESCRIPTION It is a firewall against BadUSB attacks. .br A config file describes in which way USB interfaces would be accepted or denied. .br To the kernel an interface authorization was developed with this firewall. .br The firewall sets the authorization mask according to the rules. .br .SH RULES .B Attribute .br [parameter operator value] .br An attribute consists of a parameter, an operator and a value. .LP .B The allow/deny rule .br allow|deny Attribute+ .br A allow/deny rule have at minimum one attribute. .br That a allow/deny rule will enforced an USB interface must match all attributes .br .br Example: A rule describes all interfaces with the HID class 0x03. .LP .B The condition .br condition Attribute+ case Attribute+ .br The first section describes the condition that must fulfilled. .br The second section with the keyword case defines for what interfaces the condition should apply. .br .br Example: .br All rules that describes HID interfaces should apply for two devices at maximum. .br Then the device counter must be fulfilled. The second section describes the interface class 0x03. .LP .B There are default rules .br allow|deny all .br These rules for the generic case. If no other rule matches an interface. .LP Rules will checked top down. A rule at top could be overwritten by a rule at down. .LP .SH Parameters .br The following parameters are defined at device section .br .B busnum: number of the USB bus .br .B devpath: nummer of the USB port .br .B idVendor: vendor ID, defines the vendor of the USB device .br .B idProduct: product ID, defines the product from a vendor .br .B bDeviceClass: USB device class .br .B bDeviceSubClass: USB device sub class .br .B bDeviceProtocol: USB device protocol .br .B bConfigurationValue: current USB configuration .br .B serial: serial number of the device .br .B manufacturer: manufacturer of device .br .B product: product name string .br .B connect_type: hotplug: external USB device, direct: internal USB device .br .B bcdDevice: USB protocol version .br .B speed: USB speed value .br .B bNumConfigurations: the number of available USB configurations .LP The following parameters are defined at configuration section .br .br .B bNumInterfaces: Number of available interfaces in active configuration .br .B bInterfaceNumber: interface number .br .B bInterfaceClass: interface class .br .B bInterfaceSubClass: current sub class of interface .br .B bInterfaceProtocol: In case of HID devices with this value keyboards (1) and mouses (2) could be distinct .br .B bNumEndpoints: number of endpoints for the interface .LP The following parameters are specific and calculated internally by the firewall. They are not available in the SysFS. .br They count how much devices or interfaces matches an rule. .br .B intfcount: Number of interfaces for an rule .br .B devcount: Number of devices for an rule .LP The keyword .B anyChild could be used for a parameter to check not only the own interfaces attribute, also check the silbings attribute. If one silbing mathes the rule is valid. .LP .SH Operators .br The following operators are defined: ==, !=, <=, >=, <, > .br With operators two values are compared. One frome the data structure of a rule the other from an USB interface .LP .SH Values .br Values are strings in the data strucures of the firewall. .br At first a numeric compare is attempt. If failed a string comparement will used. .br When using double quotes it is possible to specify strings containing spaces. .LP .SH Rule examples .br .B Default rule to allow everything: .br allow all .br .B Default rule to deny everything: .br deny all .br .B Every configuration file should allow hubs, only special cases should limit these: .br allow bDeviceClass==09 bInterfaceClass==09 .br .B Interfaces with device class 0 and interface class 08 (storage) will accepted: .br allow bDeviceClass==00 bInterfaceClass==08 .br allow bInterfaceClass==08 .br -> the device class is irrelevant in this case .br .B Two USB storage devices will accepted at specific USB ports. Not more then one storage device is allowed during a condition: .br allow idVendor==0781 idProduct==5406 bInterfaceClass==08 busnum==3 devpath==6 .br allow idVendor==8564 idProduct==1000 bInterfaceClass==08 busnum==3 devpath==4 .br condition devcount<=1 case bInterfaceClass==08 .br .br -> the condition is valid for all interfaces from class 08. Interfaces must comply with the condition for enforcing the two belonging allow rules. .br .B Allow two HID (example keyboard and mouse) devices at maximum .br allow bInterfaceClass==03 devcount<=2 .br .B Allow only one Keyboard: .br allow bInterfaceClass==03 anyChild bInterfaceProtocol==01 devcount<=1 .br .B Allow only one Mouse: .br allow bInterfaceClass==03 bInterfaceProtocol==02 devcount<=1 .br .br → The parent device children of the interface would enumerated to check for the attribute. If one matches the attribute then the rule will enforced. .br A keyboard should have two interfaces. The bInterfaceProtocol of the first interface is "1", from the second "0". br With anyChild it is possible to allow a rule matching for both interfaces. br .B Allow only certain interfaces: .br .B Example: A multi function device have three interfaces (0xFF, 0x07, 0x08). .br 0xFF is to scan, 0x07 is to print, and 0x08 is for storage devices connected to the multi function device. .br With the following rules only the 0xFF and 0x07 interfaces are allowed. The device class must be 0. .br .br allow idVendor==04b8 idProduct==089e bDeviceClass==00 bInterfaceClass==ff .br allow idVendor==04b8 idProduct==089e bDeviceClass==00 bInterfaceClass==07 .br data/org.opensuse.usbauth.conf0000644000000000000000000000142513776005747015457 0ustar rootroot data/usbauth.conf0000644000000000000000000000031013776005747013021 0ustar rootroot# example configuration file for usbauth #allow all # allow all #allow bDeviceClass==09 bInterfaceClass==09 # allow hubs #deny bInterfaceClass==03 devcount > 2 #deny HIDs if more than 2 are connected INSTALL0000644000000000000000000000033613776005747010627 0ustar rootrootTo compile and install run: ./autogen.sh ./configure make make install Alternatively you can build a RPM or DEB package. To generate the .spec file that is necessary to build a RPM package call: ./autogen.sh ./configure Makefile.am0000644000000000000000000000106313776005747011630 0ustar rootroot# Copyright (C) 2017 Stefan Koch # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General # Public License as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. SUBDIRS = src data ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = COPYING README README0000644000000000000000000001302013776005747010450 0ustar rootrootusbauth: USB firewall against BadUSB attacks It is a firewall against BadUSB attacks. A config file describes in which way USB interfaces would be accepted or denied. To the kernel an interface authorization was developed with this firewall. The firewall sets the authorization mask according to the rules. udev mode, called by udev usbauth udev-add manual mode, called by notifier usbauth allow DEVNUM PATH usbauth deny DEVNUM PATH PATH: path of USB interface, example /sys/bus/usb/devices/3-2/3-2:1.0/ DEVNUM: value of attribute, example 16 (from /sys/bus/usb/devices/3-2/devnum) init mode, does apply rules for all available devices usbauth init Rules ---------- Attribute [parameter operator value] An attribute consists of a parameter, an operator and a value. The allow/deny rule allow|deny Attribute+ A allow/deny rule have at minimum one attribute. That a allow/deny rule will enforced an USB interface must match all attributes Example: A rule describes all interfaces with the HID class 0x03. The condition condition Attribute+ case Attribute+ The first section describes the condition that must fullfilled. The second section with the keyword case defines for what interfaces the condition should apply. Example: All rules that describes HID interfaces should apply for two devices at maximum. Then the device counter must be fullfilled. The second section describes the interface class 0x03. There are default rules allow|deny all These rules for the generic case. If no other rule matches an interface. Rules will checked top down. A rule at top could be overwritten by a rule at down. Parameters ---------- The following parameters are defined at device section busnum: number of the USB bus devpath: nummer of the USB port idVendor: vendor ID, defines the vendor of the USB device idProduct: product ID, defines the product from a vendor bDeviceClass: USB device class bDeviceSubClass: USB device sub class bDeviceProtocol: USB device protocol bConfigurationValue: current USB configuration serial: serial number of the device manufacturer: manufacturer of device product: product name string connect_type: hotplug: external USB device, direct: internal USB device bcdDevice: USB protocol version speed: USB speed value bNumConfigurations: the number of available USB configurations bNumInterfaces: Number of available interfaces in active configuration The following parameters are defined at configuration section bInterfaceNumber: interface number bInterfaceClass: interface class bInterfaceSubClass: current sub class of interface bInterfaceProtocol: In case of HID devices with this value keyboards (1) and mouses (2) could be distinct bNumEndpoints: number of endpoints for the interface The following parameters are specific and calculated internally by the firewall. They are not available in the SysFS. They count how much devices or interfaces matches an rule intfcount: Number of interfaces for an rule devcount: Number of devices for an rule The keyword anyChild could be used for a parameter to check not only the own interfaces attribute, also check the silbings attribute. If one silbing mathes the rule is valid. Operators ---------- The following operators are defined: ==, !=, <=, >=, <, > With operators two values are compared. One frome the data structure of a rule the other from an USB interface Values ---------- Values are strings in the data strucures of the firewall. At first a numeric compare is attempt. If failed a string comparement will used. When using double quotes it is possible to specify strings containing spaces. Exampels ---------- Default rule to allow everything: allow all Default rule to deny everything: deny all Every configuration file should allow hubs, only special cases should limit these: allow bDeviceClass==09 bInterfaceClass==09 Interfaces with device class 0 and interface class 08 (storage) will accepted: allow bDeviceClass==00 bInterfaceClass==08 Interfaces interface class 08 (storage) will accepted: allow bInterfaceClass==08 -> the device class is irrelevant in this case Two USB storage devices will accepted at specific USB ports. Not more then one storage device is allowed during a condition: allow idVendor==0781 idProduct==5406 bInterfaceClass==08 busnum==3 devpath==6 allow idVendor==8564 idProduct==1000 bInterfaceClass==08 busnum==3 devpath==4 condition devcount<=1 case bInterfaceClass==08 -> the condition is valid for all interfaces from class 08. Interfaces must comply with the condition for enforcing the two belonging allow rules. Allow two HID (example keyboard and mouse) devices at maximum allow bInterfaceClass==03 devcount<=2 Allow only one Keyboard: allow bInterfaceClass==03 bInterfaceProtocol==01 devcount<=1 Allow only one Mouse: allow bInterfaceClass==03 anyChild bInterfaceProtocol==02 devcount<=1 → The parent device childs of the interface would enumerated to check for the attribute. If one matches the attribute then the rule will enforced. A keyboard should have two interfaces. The bInterfaceProtocol of the first interface is "1", from the second "0". With anyChild it is possible to allow a rule matching for both interfaces. Allow only certain interfaces: Example: A multi function device have three interfaces (0xFF, 0x07, 0x08). 0xFF is to scan, 0x07 is to print, and 0x08 is for storage devices connected to the multi function device. With the following rules only the 0xFF and 0x07 interfaces are allowed. The device class must be 0. allow idVendor==04b8 idProduct==089e bDeviceClass==00 bInterfaceClass==ff allow idVendor==04b8 idProduct==089e bDeviceClass==00 bInterfaceClass==07 src/0000755000000000000000000000000013776005747010363 5ustar rootrootsrc/Makefile.am0000644000000000000000000000125513776005747012422 0ustar rootroot# Copyright (C) 2017 Stefan Koch # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General # Public License as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. sbin_PROGRAMS = usbauth usbauth_CFLAGS = -include config.h $(USBAUTH_CFLAGS) $(UDEV_CFLAGS) $(DBUS_CFLAGS) usbauth_SOURCES = usbauth.c usbauth_LDADD = $(USBAUTH_LIBS) $(UDEV_LIBS) $(DBUS_LIBS) src/usbauth.c0000644000000000000000000005041013776005747012202 0ustar rootroot/* * Copyright (c) 2015 SUSE LLC. All Rights Reserved. * Author: Stefan Koch * * Copyright (c) 2017 Stefan Koch * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General * Public License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, contact SUSE LLC. * * To contact SUSE about this file by physical or electronic mail, * you may find current contact information at www.suse.com */ /* * Description : USB firewall against BadUSB attacks */ #include "usbauth.h" #include #include #include #include #include #include #include #include static FILE *logfile = NULL; static struct udev *udev = NULL; DBusConnection *bus = NULL; struct udev_device *plug_usb_device = NULL; static bool *iscounted = NULL; static bool debuglog = false; bool match_valsStr(const char *lval, enum Operator op, const char *rval) { bool ret = false; int cmp = strcmp(lval, rval); if (op == eq && cmp == 0) ret = true; else if (op == neq && cmp != 0) ret = true; else if (op == lt && cmp <= 0) ret = true; else if (op == gt && cmp >= 0) ret = true; else if (op == l && cmp < 0) ret = true; else if (op == g && cmp > 0) ret = true; if (debuglog) syslog(LOG_DEBUG, "match_valsStr:%i (%s %s %s)\n", ret, lval, usbauth_op_to_str(op), rval); return ret; } bool match_valsInt(int lval, enum Operator op, int rval) { bool ret = false; if (op == eq && lval == rval) ret = true; else if (op == neq && lval != rval) ret = true; else if (op == lt && lval <= rval) ret = true; else if (op == gt && lval >= rval) ret = true; else if (op == l && lval < rval) ret = true; else if (op == g && lval > rval) ret = true; return ret; } bool match_vals(const char *lvalStr, enum Operator op, const char *rvalStr) { bool ret = false; char* lend = NULL; char* rend = NULL; int lval = strtol(lvalStr, &lend, 16); int rval = strtol(rvalStr, &rend, 16); if (lend && *lend != 0) lval = -1; if (rend && *rend != 0) rval = -1; if (lval != -1 && rval != -1) ret = match_valsInt(lval, op, rval); else ret = match_valsStr(lvalStr, op, rvalStr); if (debuglog) syslog(LOG_DEBUG, "match_vals:%i (%s %s %s), (%i %s %i)\n", ret, lvalStr, usbauth_op_to_str(op), rvalStr, lval, usbauth_op_to_str(op), rval); return ret; } bool match_vals_interface(struct Auth *rule, struct Data *d, struct udev_device *interface) { bool ret = false; char* tmpStr = NULL; const char* lvalStr = NULL; const char* rvalStr = d->val; int rvalLen = 0; const char* type = udev_device_get_devtype(interface); char cntStr[16]; strcpy(cntStr, ""); if (!type || !rvalStr || strcmp(type, "usb_interface") != 0) return false; rvalLen = strlen(rvalStr); if (rvalLen >= 2 && rvalStr[0] == '"' && rvalStr[rvalLen-1] == '"') { rvalLen -= 2; tmpStr = calloc(rvalLen + 1, sizeof(char)); strncpy(tmpStr, rvalStr + 1, rvalLen); tmpStr[rvalLen] = '\0'; rvalStr = tmpStr; } if (intfcount == d->param) { // intfcount parameter is not in sysfs char* rend = NULL; int rval = strtol(rvalStr, &rend, 16); if (rend && *rend != 0) ret = false; else ret = match_valsInt(rule->intfcount + 1, d->op, rval); } else if (devcount == d->param) { // devcount parameter is not in sysfs char* rend = NULL; int rval = strtol(rvalStr, &rend, 16); if (rend && *rend != 0) ret = false; else ret = match_valsInt(rule->devcount + 1, d->op, rval); } else { lvalStr = usbauth_get_param_valStr(d->param, interface); // get parameter from sysfs if (lvalStr) ret = match_vals(lvalStr, d->op, rvalStr); } if (tmpStr) free(tmpStr); return ret; } bool match_vals_device(struct Auth *rule, struct Data *d, struct udev_device *device) { bool matches = false; const char *path = udev_device_get_syspath(device); const char *type = udev_device_get_devtype(device); struct udev_list_entry *devices = NULL, *entry = NULL; struct udev_enumerate *enumerate = NULL; int dev_class = 0; if (!path || !type || strcmp(type, "usb_device") != 0) return false; enumerate = udev_enumerate_new(udev); if (!enumerate) return false; udev_enumerate_add_match_parent(enumerate, device); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); if (!devices) return false; // get the current class from sysfs, because unmatched interfaces should be unchanged dev_class = usbauth_get_param_val(bDeviceClass, device); // iterate over the childs (usb_interface's) of the udevdev (usb_device) udev_list_entry_foreach(entry, devices) { const char *path = NULL; struct udev_device *interface = NULL; const char *type = NULL; if (entry) path = udev_list_entry_get_name(entry); if (path) interface = udev_device_new_from_syspath(udev, path); if (interface) type = udev_device_get_devtype(interface); if (type && strcmp(type, "usb_interface") == 0) { int intf_class = usbauth_get_param_val(bInterfaceClass, interface); if (dev_class == 9 && intf_class != 9) // dev class is HUB and intf class is not HUB continue; // skip device childs from hubs, use only hub's interfaces matches |= match_vals_interface(rule, d, interface); } if (interface) udev_device_unref(interface); } udev_enumerate_unref(enumerate); if (debuglog) syslog(LOG_DEBUG, "match_vals_device:%i\n", matches); return matches; } bool no_error_check_dbus(DBusError *error) { bool ret = true; if (dbus_error_is_set(error)) { ret = false; if (debuglog) syslog(LOG_DEBUG, "dbus_error: %s\n", error->message); dbus_error_free(error); } return ret; } void send_dbus(struct udev_device *udevdev, int32_t authorize, int32_t devn) { DBusMessage *msg = NULL; DBusError error; bool dbusret = false; const char *path = udev_device_get_syspath(udevdev); if (!bus) return; dbus_error_init(&error); dbus_bus_request_name(bus, "org.opensuse.usbauth", DBUS_NAME_FLAG_REPLACE_EXISTING, &error); if (!no_error_check_dbus(&error)) return; msg = dbus_message_new_signal("/usbauth/signal/Object", "org.opensuse.usbauth.Message", "usbauth"); if (!msg || !path) return; dbusret = dbus_message_append_args(msg, DBUS_TYPE_INT32, &authorize, DBUS_TYPE_INT32, &devn, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); if (dbusret) dbusret = dbus_connection_send(bus, msg, NULL); if (dbusret) dbus_connection_flush(bus); dbus_message_unref(msg); syslog(LOG_NOTICE, "send dbus message (path=%s)\n", path); } void probe_interface(struct udev_device *interface) { const char *type = udev_device_get_devtype(interface); if (type && strcmp(type, "usb_interface") == 0) { const char *name = udev_device_get_sysname(interface); FILE *probe = fopen("/sys/bus/usb/drivers_probe", "w"); if (!name || !probe) return; fprintf(probe, "%s", name); fclose(probe); } } void probe_device(struct udev_device *udevdev) { const char *path = udev_device_get_syspath(udevdev); const char *type = udev_device_get_devtype(udevdev); struct udev_list_entry *devices = NULL, *entry = NULL; struct udev_enumerate *enumerate = NULL; if (!path || !type || strcmp(type, "usb_device") != 0) return; enumerate = udev_enumerate_new(udev); if (!enumerate) return; udev_enumerate_add_match_parent(enumerate, udevdev); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); if (!devices) return; // iterate over the childs (usb_interface's) of the udevdev (usb_device) udev_list_entry_foreach(entry, devices) { const char *intfpath = NULL; struct udev_device *interface = NULL; if (entry) intfpath = udev_list_entry_get_name(entry); if (intfpath) interface = udev_device_new_from_syspath(udev, intfpath); if (interface) type = udev_device_get_devtype(interface); // probe interface probe_interface(interface); if (interface) udev_device_unref(interface); } udev_enumerate_unref(enumerate); } void authorize_interface(struct udev_device *interface, bool authorize, bool dbus) { const char *path = udev_device_get_syspath(interface); const char *type = udev_device_get_devtype(interface); int32_t devn = usbauth_get_param_val(devnum, interface); struct udev_device *parent = udev_device_get_parent(interface); char valueStr[16]; if (!path || !type || !parent || strcmp(type, "usb_interface") != 0) return; strcpy(valueStr, ""); snprintf(valueStr, 16, "%" SCNu8, authorize); udev_device_set_sysattr_value(interface, "authorized", valueStr); syslog(LOG_NOTICE, "%s interface %s/authorized\n", authorize ? "allow" : "deny", path); // probe all device's childs to avoid side-effects with drivers that need multiple interfaces probe_device(parent); if (dbus) send_dbus(interface, authorize, devn); } bool isRule(struct Auth *array, unsigned array_length) { bool ret = false; int i = 0; for (i = 0; i < array_length; i++) { if (array[i].type == ALLOW || array[i].type == DENY) ret = true; } return ret; } bool match_data(struct Auth *rule, struct Data *d, struct udev_device *interface) { bool ret = false; struct udev_device *parent = udev_device_get_parent(interface); if (d->anyChild) { ret = match_vals_device(rule, d, parent); } else { ret = match_vals_interface(rule, d, interface); } if (debuglog) syslog(LOG_DEBUG, "match_data:%i\n", ret); return ret; } struct match_ret match_auth_interface(struct Auth *rule, struct udev_device *interface) { int i; struct match_ret ret; bool match = false; ret.match_attrs = true; ret.match_conds = true; ret.match_attrs_nocnts = true; if (!rule || !interface || rule->type == COMMENT) { ret.match_attrs = false; ret.match_conds = false; ret.match_attrs_nocnts = false; return ret; } // iterate over the data structures (case parameters) from the auth structure // to check if the auth rule matches the cases for (i = 0; i < rule->attr_len; i++) { struct Data *d = &rule->attr_array[i]; if (!d || !d->val) { ret.match_attrs = false; ret.match_conds = false; ret.match_attrs_nocnts = false; return ret; } match = match_data(rule, d, interface); ret.match_attrs &= match; if (d->param != devcount && d->param != intfcount) ret.match_attrs_nocnts &= match; } // iterate over the data structures (condition parameters) from the auth structure // to check if the auth rule matches the conditions for (i = 0; i < rule->cond_len && ret.match_attrs; i++) { struct Data *d = &rule->cond_array[i]; if (!d || !d->val) { ret.match_attrs = false; ret.match_conds = false; ret.match_attrs_nocnts = false; return ret; } ret.match_conds &= match_data(rule, d, interface); } return ret; } struct auth_ret match_auths_interface(struct Auth *rule_array, size_t array_len, struct udev_device *usb_interface) { int i; struct auth_ret ret; ret.match = false; ret.allowed = false; // iterate over the rules without conditions from the auth array // for each rule that (case) attributes matches with the given interface for (i = 0; i < array_len; i++) { struct match_ret r1 = match_auth_interface(&rule_array[i], usb_interface); bool ruleApplicable = r1.match_attrs_nocnts; // true if interface is affected by rule if (rule_array[i].type != COND && ruleApplicable) { int j = 0; // iterate only over the conditions from the auth array // to check whether the auth rule matches the conditions for (j = 0; j < array_len; j++) { // conditions affecting only ALLOW rules if (rule_array[j].type == COND && rule_array[i].type == ALLOW) { struct match_ret r = match_auth_interface(&rule_array[j], usb_interface); // if the condition belongs to the interface (match_attrs is true, that are the case parameters) // AND the condition is fulfilled (match_conds is true, that are the condition parameters) if (r.match_attrs && r.match_conds) { rule_array[j].intfcount++; // count affects r.match_conds if (iscounted) iscounted[j] = true; // the devcount will incremented later to avoid side effects } else if (r.match_attrs && !r.match_conds) // only if the condition belongs to the interface (cases, match_attrs) and the condition is not fulfilled (conds, match_conds) ruleApplicable = false; // condition conflicts with affected rule then ignore the rule } } if (ruleApplicable) { // if current/iterated interface matched rule and was not disabled by conflicting condition rule_array[i].intfcount++; // describes how much interfaces are affected by the rule if (iscounted) iscounted[i] = true; // the devcount will incremented later to avoid side effects if (r1.match_attrs) { ret.match |= true; // if interface is affected by at least one rule do allow or deny it, otherwise skip allow/deny action ret.allowed = rule_array[i].type == ALLOW ? true : false; // allow or deny usb_interface, last rule is deciding } } } } if (debuglog) syslog(LOG_DEBUG, "match_auths_interface:%i:%i\n", ret.match, ret.allowed); return ret; } void match_auths_device_interfaces(struct Auth *rule_array, size_t array_len, struct udev_device *usb_device) { const char *type = udev_device_get_devtype(usb_device); const char *path = udev_device_get_syspath(usb_device); struct udev_list_entry *devices = NULL, *entry = NULL; struct udev_enumerate *enumerate = NULL; unsigned dev_class = 0; const char *plugpath = NULL; if (plug_usb_device) plugpath = udev_device_get_syspath(plug_usb_device); if (!path || !type) return; if (plugpath && strcmp(path, plugpath) == 0) return; if (strcmp(type, "usb_device") != 0) return; enumerate = udev_enumerate_new(udev); if (!enumerate) return; udev_enumerate_add_match_parent(enumerate, usb_device); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); if (!devices) return; dev_class = usbauth_get_param_val(bDeviceClass, usb_device); if (!iscounted) iscounted = calloc(array_len, sizeof(bool)); // iterate over the childs (usb_interface's) of the udevdev (usb_device) udev_list_entry_foreach(entry, devices) { const char *path = NULL; struct udev_device *interface = NULL; const char *type = NULL; if (entry) path = udev_list_entry_get_name(entry); if (path) interface = udev_device_new_from_syspath(udev, path); if (interface) type = udev_device_get_devtype(interface); if (type && strcmp(type, "usb_interface") == 0) { unsigned intf_class = usbauth_get_param_val(bInterfaceClass, interface); struct auth_ret r; if (dev_class == 9 && intf_class != 9) // dev class is HUB and intf class is not HUB continue; // skip device childs from hubs, use only hub's interfaces r = match_auths_interface(rule_array, array_len, interface); // do only if one rule has matched, so if there would no generic rule and no specific rule do nothing // now it's the correct device (if plug is set it's only initialization) // do not authorize interfaces and do not send dbus messages multiple times if (r.match && !plug_usb_device) authorize_interface(interface, r.allowed, true); } if (interface) udev_device_unref(interface); } // if multiple interfaces are counted by an rule count only once for device if (iscounted) { unsigned i; for (i=0; i 2 && (strcmp(argv[1], "allow") == 0 || strcmp(argv[1], "deny") == 0)) { // called by notifier perform_notifier(argv[1], argv[2], argv[3]); } else { syslog(LOG_ERR, "wrong syntax to call usbauth\n"); } if (bus) { dbus_connection_unref(bus); bus = NULL; } udev_unref(udev); udev = NULL; usbauth_config_free_auths(auths, length); // disconnect from syslog closelog(); return EXIT_SUCCESS; } src/usbauth.h0000644000000000000000000001447313776005747012220 0ustar rootroot/* * Copyright (c) 2015 SUSE LLC. All Rights Reserved. * Author: Stefan Koch * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General * Public License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, contact SUSE LLC. * * To contact SUSE about this file by physical or electronic mail, * you may find current contact information at www.suse.com */ /* * Description : USB firewall against BadUSB attacks */ #ifndef USBAUTH_H_ #define USBAUTH_H_ #include #include #include /** * checks string constraint * * lval op rval * examlpe: "01g" == "01g" : return true * * @lvalStr: left value * @op: operator * @rvalStr: right value * @parent: if not NULL parent will matched, too * * return: true if constraint is matched */ bool match_valsStr(const char *lval, enum Operator op, const char *rval); /** * checks integer constraint * * lval op rval * examlpe: 01 <= 02 : return true * * @lval: left value * @op: operator * @rval: right value * @parent: if not NULL parent will matched, too * * return: true if constraint is matched */ bool match_valsInt(int lval, enum Operator op, int rval); /** * checks constraint * tries first to convert strings to integer, if failed a string compare is processed * * lval op rval * examlpe: 01 <= 02 : return true * * @lvalStr: left value * @op: operator * @rvalStr: right value * @parent: if not NULL parent will matched, too * * return: true if constraint is matched */ bool match_vals(const char *lvalStr, enum Operator op, const char *rvalStr); /** * checks if constraint from rule and data matches for an interface * * @rule: rule to check including left value (lval) * @d: data structure with param and right value (rval) * @interface: udev_device from type "usb_interface" * * return: true if constraint is matched */ bool match_vals_interface(struct Auth *rule, struct Data *d, struct udev_device *interface); /** * checks if constraint from rule and data matches for at minimum one device's interface * * @rule: rule to check including left value (lval) * @d: data structure with param and right value (rval) * @device: udev_device from type "usb_device" * * return: true if constraint is matched for minimum one device's interface */ bool match_vals_device(struct Auth *rule, struct Data *d, struct udev_device *device); /* check if a device is already processed * * @dev: udev device * * Returns: true if device's mask was changed (so processed), otherwise false */ bool device_processed(struct udev_device* dev); /** * check dbus errors * * @error: dbus error structure * * Return: true if error, false if no error */ bool error_check_dbus(DBusError *error); /** * send dbus message to notifier service for interface * * @udevdev: udev_device with type "usb_interface" * @authorize: true for allow, false for deny * */ void send_dbus(struct udev_device *udevdev, int32_t authorize, int32_t devnum); /** * probe an interface * * @udevdev: udev_device with type "usb_interface" * */ void probe_interface(struct udev_device *interface); /** * probe all interfaces of a device * * @udevdev: udev_device with type "usb_device" * */ void probe_device(struct udev_device *udevdev); /** * allow or deny an interface * * @udevdev: udev_device with type "usb_interface" * @authorize: true for allow, false for deny * @dbus: if true, notifications would be enabled * */ void authorize_interface(struct udev_device *udevdev, bool authorize, bool dbus); /** * checks if there is at least one rule from type ALLOW or DENY * * example: false if there are only comments * * @array: auth rules * @array_length: auth rules length * * Return: true if there is at least one rule from type ALLOW or DENY */ bool isRule(struct Auth *array, unsigned array_length); /** * checks if an auth rule matches an USB interface * @rule: auth rule * @interface: udev_device with type "usb_interface" * * Return: match_attrs is true if the interface matches all (case) attributes * match_cond is true if the interface matches all condition attributes or has no such condition attributes */ struct match_ret match_auth_interface(struct Auth *a, struct udev_device *udevdev); /** * checks if an USB interface matches to all auth rules * if matches the interface will be allowed for use * * note: a condition that matches with the interface must apply, * otherwise the interface will denied * * @array: auth rules * @array_length: auth rules length * @interface: udev_device with type "usb_interface" * * Return: match is true if the interface matches with all rules * allowed: true if the interface should be allowed, otherwise false */ struct auth_ret match_auths_interface(struct Auth *array, size_t array_length, struct udev_device *udevdev); /** * checks if at minimum one auth rule matches to an USB device * and allows or denies the device then * * note: all interfaces of the USB devices are checked * if one interface doesn't match with any rule it will skipped * * @array: auth rules * @array_length: auth rules length * @usb_device: udev_device with type "usb_device" */ void match_auths_device_interfaces(struct Auth *array, size_t array_length, struct udev_device *usb_device); /** * perform rules on all USB devices * * @rule_array: auth rules * @array_length: auth rules length * @add: true if udev-add mode, false if udev-remove mode */ void perform_rules_devices(struct Auth *array, size_t array_length, bool add); /** * perform rules on udev environment * * @rule_array: auth rules * @array_length: auth rules length * @add: true if udev-add mode, false if udev-remove mode */ void perform_udev_env(struct Auth *auths, size_t length, bool add); /** * perform notifier command * * @action: allow or deny * @devnum: devnum of interface * @path: path to interface * */ void perform_notifier(const char* action, const char* devnum, const char* path); #endif /* USBAUTH_H_ */ usbauth.changelog0000644000000000000000000000016613776005747013123 0ustar rootroot* Tue Jan 22 2019 stefan.koch10@gmail.com - 1.0.1-1 - initial package for usbauth USB firewall against BadUSB attacks usbauth.changes0000644000000000000000000000161513776005747012604 0ustar rootroot------------------------------------------------------------------- Tue Jan 22 22:00:00 UTC 2019 - Stefan Koch - update to 1.0.1: * Fix string comparing * Support string quoting ------------------------------------------------------------------- Tue Feb 13 22:30:00 UTC 2018 - stefan.koch10@gmail.com - update outdated source (fix dbus group) - remove group creation within spec file ------------------------------------------------------------------- Mon Feb 5 08:19:29 UTC 2018 - meissner@suse.com - updated to current git ------------------------------------------------------------------- Thu Feb 1 06:41:46 UTC 2018 - meissner@suse.com - do not do groupdel ------------------------------------------------------------------- Thu Oct 12 06:56:57 UTC 2017 - meissner@suse.com - initial package, a USB device authentication tool that avoids BadUSB style attacks. usbauth-rpmlintrc0000644000000000000000000000006013776005747013176 0ustar rootrootsetBadness('suse-dbus-unauthorized-service', 0) usbauth.spec.in0000644000000000000000000000467413776005747012543 0ustar rootroot# # spec file for package usbauth # # Copyright (c) 2019 SUSE LLC # Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # Copyright (c) 2017 Stefan Koch # Copyright (c) 2015 SUSE LLC. All Rights Reserved. # Author: Stefan Koch # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # Name: @PACKAGE@ Version: @VERSION@ Summary: USB firewall against BadUSB attacks URL: https://github.com/kochstefan/usbauth-all/tree/master/usbauth Source: https://github.com/kochstefan/usbauth-all/archive/v%{version}.tar.gz %if 0%{?suse_version} Release: 0 License: GPL-2.0-only Group: Productivity/Security %else Release: 1%{?dist} License: GPLv2 %endif Requires: systemd Requires: udev BuildRequires: pkgconfig(libudev) BuildRequires: pkgconfig(dbus-1) BuildRequires: libusbauth-configparser-devel BuildRequires: gcc BuildRequires: libtool BuildRequires: libudev-devel %if 0%{?suse_version} BuildRequires: systemd-rpm-macros %endif %if 0%{?suse_version} %{!?_udevrulesdir: %global _udevrulesdir %(pkg-config --variable=udevdir udev)/rules.d } %endif %description It is a firewall against BadUSB attacks. A config file describes in which way devices would be accepted. %prep %autosetup -n usbauth-all-%{version} -p1 %build pushd %{name}/ autoreconf -f -i %configure %make_build popd %install pushd %{name}/ %make_install udevrulesdir=%_udevrulesdir popd %files %if 0%{?suse_version} %defattr(-,root,root) %endif %license %{name}/COPYING %doc %{name}/README doc %_mandir/man1/usbauth.1.* %_sbindir/usbauth %config %_sysconfdir/dbus-1/system.d/org.opensuse.usbauth.conf %config(noreplace) %_sysconfdir/usbauth.conf %_udevrulesdir/20-usbauth.rules %if 0%{?suse_version} %post %{?udev_rules_update:%udev_rules_update} %postun %{?udev_rules_update:%udev_rules_update} %endif %changelog