{"id":868,"date":"2015-02-15T12:26:37","date_gmt":"2015-02-15T18:26:37","guid":{"rendered":"http:\/\/www.jedge.com\/wordpress\/?page_id=868"},"modified":"2015-03-02T09:51:23","modified_gmt":"2015-03-02T15:51:23","slug":"remote-hid-attacks-testing-setup","status":"publish","type":"page","link":"https:\/\/www.jedge.com\/wordpress\/remote-hid-attacks-testing-setup\/","title":{"rendered":"Remote HID Attacks &#8211; Testing \/ Setup"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.jedge.com\/images\/gl-inet.part4\/banner1.png\" width=\"801\" height=\"184\" class=\"alignnone\" \/><br \/>\n<strong>Part 4 \u2013 Remote HID Attacks with a Teensy \u2013 Testing Your Build \/ Getting Started<\/strong><\/p>\n<p><strong>GL-iNet GPIO Setup<\/strong><br \/>\nPins 18,19,20,21,22 are available as GPIOs for the GL-iNet.  The script below will activate the GPIOs and set them to &#8220;low&#8221;.  GPIO 21 is responsible for the Teensy 2.0 USB communication.  GPIOs 18, 19, 20, &#038; 22 provide the option to execute Teensy HID commands and will be discussed below.  From the GL-iNet command prompt we can download the code below.<br \/>\n<pre><code>#!\/bin\/sh \/etc\/rc.common\n#set GPIO\nSTART=10\nstart() {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n\n&nbsp;&nbsp;echo 18 &gt; \/sys\/class\/gpio\/export\n&nbsp;&nbsp;echo out &gt; \/sys\/class\/gpio\/gpio18\/direction\n&nbsp;&nbsp;echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio18\/value\n\n&nbsp;&nbsp;echo 19 &gt; \/sys\/class\/gpio\/export\n&nbsp;&nbsp;echo out &gt; \/sys\/class\/gpio\/gpio19\/direction\n&nbsp;&nbsp;echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio19\/value\n\n&nbsp;&nbsp;echo 20 &gt; \/sys\/class\/gpio\/export\n&nbsp;&nbsp;echo out &gt; \/sys\/class\/gpio\/gpio20\/direction\n&nbsp;&nbsp;echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio20\/value\n\n&nbsp;&nbsp;echo 21 &gt; \/sys\/class\/gpio\/export\n&nbsp;&nbsp;echo out &gt; \/sys\/class\/gpio\/gpio21\/direction\n&nbsp;&nbsp;echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio21\/value\n\n&nbsp;&nbsp;echo 22 &gt; \/sys\/class\/gpio\/export\n&nbsp;&nbsp;echo out &gt; \/sys\/class\/gpio\/gpio22\/direction\n&nbsp;&nbsp;echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio22\/value\n}<\/code><\/pre><\/p>\n<p><pre><code>root@OpenWrt:\/# cd \/etc\/init.d\nroot@OpenWrt:\/etc\/init.d#&nbsp;&nbsp;wget http:\/\/www.jedge.com\/code\/setgpio\nroot@OpenWrt:\/etc\/init.d#&nbsp;&nbsp;chmod 755 setgpio\nroot@OpenWrt:\/etc\/init.d#&nbsp;&nbsp;\/etc\/init.d\/setgpio enable<\/code><\/pre><strong>Does It Work?<\/strong><br \/>\nFirst things first, how do we know what we built in <a href=\"http:\/\/www.jedge.com\/wordpress\/remote-hid-attacks-the-build\/\">Part 3<\/a> ( or <a href=\"http:\/\/www.jedge.com\/wordpress\/remote-hid-attacks-the-build-3-1\/\" title=\"Remote HID Attacks \u2013 The Build 3.1\">3.1<\/a>) actually works?  The first round of code for the Teensy will allow is to test it to ensure all that soldering actually connected your knee bone to your thigh bone.  Our test code will ensure that we can access the SD card and that activation of the GPIOs from the GL-iNet are seen by the Teensy.<\/p>\n<p><strong>The Software<\/strong><br \/>\nI\u2019m not going to go into too much detail on getting your environment setup and configured to work with the Teensy.  Excellent tutorials exist on downloading and installing the Arduino and Teensy software for your platform of choice.  I will be using the following on a Windows 7 system:  <\/p>\n<p>Teensyduino &#8211; <a href=\"https:\/\/www.pjrc.com\/teensy\/teensyduino.html\" target=\"_blank\">https:\/\/www.pjrc.com\/teensy\/teensyduino.html<\/a><br \/>\nTeensy Loader &#8211; <a href=\"https:\/\/www.pjrc.com\/teensy\/loader.html\" target=\"_blank\">https:\/\/www.pjrc.com\/teensy\/loader.html<\/a><\/p>\n<p><strong>Format the SD Card<\/strong><br \/>\nEnsure your SD Card is properly formatted.  Use the formatter tool from sdcard.org to properly format your card for best read\/write performance for use with the Teensy.  For this tutorial my SD Card is called  SDCARD.<\/p>\n<p><strong>Teensy 2.0 Test Sketch<\/strong><br \/>\nGo <a href=\"http:\/\/www.jedge.com\/code\/gl-inet-teensy_blink_test.ino\" target=\"_blank\">here<\/a> for the sketch file.  Before we compile and install the code ensure you have Disk(SD Card) + Keyboard selected (Figure 1).<\/p>\n<figure class=\"thumbnail wp-caption alignnone\" style=\"width: 710px\"><a href=\"http:\/\/www.jedge.com\/images\/gl-inet.part4\/Figure1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.jedge.com\/images\/gl-inet.part4\/Figure1.png\" width=\"700\" height=\"632\" class \/><\/a><figcaption class=\"caption wp-caption-text\">Figure 1:  Select SD Card + Keyboard<\/figcaption><\/figure>\n<p>When you compile and install the code, if your Teensy is set to automatically reboot, you should be prompted with an Autoplay window (Figure 2).<\/p>\n<figure class=\"thumbnail wp-caption alignnone\" style=\"width: 344px\"><a href=\"http:\/\/www.jedge.com\/images\/gl-inet.part4\/Figure2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.jedge.com\/images\/gl-inet.part4\/Figure2.png\" width=\"334\" height=\"203\" class \/><\/a><figcaption class=\"caption wp-caption-text\">Figure 2<\/figcaption><\/figure>\n<p><strong>Connect to your GL-iNet<\/strong><\/p>\n<p>Access a shell on your GL-iNet, either from the serial port or SSH, and run the setgpio shell script from Part 2.  Ensure you are able to see the LED on your Teensy.  Activation of the GPIOs will cause the LED to blink 1-4 times based on which GPIO is activated.  In this example we will activate GPIO 19 which should cause the LED to blink twice every 4 seconds.<br \/>\n<pre><code>root@OpenWrt:~# echo 1 &gt; \/sys\/devices\/virtual\/gpio\/gpio19\/value\n<\/code><\/pre>Test each of the GPIOs by activating and deactivating them.  To deactivate the GPIO just assign a zero (0) to the vale.<br \/>\n<pre><code>root@OpenWrt:~# echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio19\/value\n<\/code><\/pre>Note that if more than one GPIO is activated the LED will blink based on the order of the \u201cif\u201d statements from the code.  For example, activation of GPIO 20 and 18 will cause the LED to blink once, wait four (4) seconds, blink three (3) times, wait four (4) seconds, and repeat.<\/p>\n<p><strong>Test the Relay Switch<\/strong><br \/>\nNow we will activate GPIO 21 which should switch the relay and connect the Teensy USB connection from the workstation to the GL-iNet.  If you are connected through the serial port you will immediately see the success of the drive being recognized.<br \/>\n<pre><code>root@OpenWrt:~# echo 1 &gt; \/sys\/devices\/virtual\/gpio\/gpio21\/value\nroot@OpenWrt:~# [17231.710000] usb 1-1: new full-speed USB device number 3 using ehci-platform\n[17231.870000] scsi0 : usb-storage 1-1:1.0\n[17232.870000] scsi 0:0:0:0: Direct-Access&nbsp;&nbsp;&nbsp;&nbsp; Generic&nbsp;&nbsp;USB Flash Disc&nbsp;&nbsp; 1.00 PQ: 0 ANSI: 4\n[17232.890000] sd 0:0:0:0: [sda] 1984000 512-byte logical blocks: (1.01 GB\/968 MiB)\n[17232.890000] sd 0:0:0:0: [sda] Write Protect is off\n[17232.900000] sd 0:0:0:0: [sda] No Caching mode page present\n[17232.910000] sd 0:0:0:0: [sda] Assuming drive cache: write through\n[17232.930000] sd 0:0:0:0: [sda] No Caching mode page present\n[17232.940000] sd 0:0:0:0: [sda] Assuming drive cache: write through\n[17232.950000]&nbsp;&nbsp;sda: sda1\n[17232.970000] sd 0:0:0:0: [sda] No Caching mode page present\n[17232.970000] sd 0:0:0:0: [sda] Assuming drive cache: write through\n[17232.980000] sd 0:0:0:0: [sda] Attached SCSI removable disk\n<\/code><\/pre>If you are connected through SSH you will need to run dmesg.  The last 10-15 lines should show the same information.<br \/>\n<pre><code>root@OpenWrt:~# dmesg |tail -n 15\n[17200.550000] usbcore: registered new interface driver ums-usbat\n[17231.710000] usb 1-1: new full-speed USB device number 3 using ehci-platform\n[17231.870000] scsi0 : usb-storage 1-1:1.0\n[17232.870000] scsi 0:0:0:0: Direct-Access&nbsp;&nbsp;&nbsp;&nbsp; Generic&nbsp;&nbsp;USB Flash Disc&nbsp;&nbsp; 1.00 PQ: 0 ANSI: 4\n[17232.890000] sd 0:0:0:0: [sda] 1984000 512-byte logical blocks: (1.01 GB\/968 MiB)\n[17232.890000] sd 0:0:0:0: [sda] Write Protect is off\n[17232.900000] sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00\n[17232.900000] sd 0:0:0:0: [sda] No Caching mode page present\n[17232.910000] sd 0:0:0:0: [sda] Assuming drive cache: write through\n[17232.930000] sd 0:0:0:0: [sda] No Caching mode page present\n[17232.940000] sd 0:0:0:0: [sda] Assuming drive cache: write through\n[17232.950000]&nbsp;&nbsp;sda: sda1\n[17232.970000] sd 0:0:0:0: [sda] No Caching mode page present\n[17232.970000] sd 0:0:0:0: [sda] Assuming drive cache: write through\n[17232.980000] sd 0:0:0:0: [sda] Attached SCSI removable disk\n<\/code><\/pre>You can now mount the SD Card and access your files.<br \/>\n<pre><code>root@OpenWrt:~# mkdir \/mnt\/sda1\nroot@OpenWrt:~# mount \/dev\/sda1 \/mnt\/sda1 \n<\/code><\/pre>We probably want to safely unmount the SD Card every time we switch the USB connection.  I slapped together a simple shell script to switch the USB connection.<br \/>\n<pre><code>#!\/bin\/sh\ncurrentval=`cat \/sys\/devices\/virtual\/gpio\/gpio21\/value`\n\nif [ &quot;$1&quot; = &quot;internal&quot; ]; then\n&nbsp;&nbsp;if [ &quot;$currentval&quot; = &quot;1&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;USB connection is already set to GL-iNet.&nbsp;&nbsp;Nothing to do.&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;exit 1\n&nbsp;&nbsp;elif [ $currentval = &quot;0&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;echo 1 &gt; \/sys\/devices\/virtual\/gpio\/gpio21\/value\n&nbsp;&nbsp;&nbsp;&nbsp;sleep 3\n&nbsp;&nbsp;&nbsp;&nbsp;if [ ! -d &quot;\/mnt\/sda1&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mkdir \/mnt\/sda1\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;&nbsp;&nbsp;mount \/dev\/sda1 \/mnt\/sda1\n&nbsp;&nbsp;fi\nfi\n\nif [ &quot;$1&quot; = &quot;external&quot; ]; then\n&nbsp;&nbsp;if [ &quot;$currentval&quot; = &quot;0&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;USB connection is already set to Host.&nbsp;&nbsp;Nothing to do.&quot;\n&nbsp;&nbsp;&nbsp;&nbsp;exit 1\n&nbsp;&nbsp;elif [ $currentval = &quot;1&quot; ]; then\n&nbsp;&nbsp;&nbsp;&nbsp;umount \/mnt\/sda1\n&nbsp;&nbsp;&nbsp;&nbsp;sleep 3\n&nbsp;&nbsp;&nbsp;&nbsp;echo 0 &gt; \/sys\/devices\/virtual\/gpio\/gpio21\/value\n&nbsp;&nbsp;fi\nfi\n<\/code><\/pre><strong>Teensy 3.1 Test Sketch<\/strong><br \/>\nGo <a href=\"http:\/\/www.jedge.com\/code\/gl-inet-teensy-3_1_blink_test.ino\">here<\/a> for the Teensy 3.1 sketch file.  The pins are different than the Teensy 2.0 and also mounted in different locations when it was connected to the GL-iNet.  Probably due to the Teensy 2.0 having and SD Card and my use of a pitch adapter in that build&#8230;or something like that.  Bottom line the code is modified to work with the Teensy 3.1 but you get the same blinkly blinky with the LED when you activate the appropriate GPIO on the GL-iNet.<\/p>\n<p><strong>References<\/strong><br \/>\nInstalling Arduino Libraries<br \/>\n<a href=\"http:\/\/arduino.cc\/en\/Guide\/Libraries\" target=\"_blank\">http:\/\/arduino.cc\/en\/Guide\/Libraries<\/a><\/p>\n<p>SdFat Arduino Library<br \/>\n<a href=\"https:\/\/github.com\/greiman\/SdFat\" target=\"_blank\">https:\/\/github.com\/greiman\/SdFat<\/a><\/p>\n<p>SD Card Formater<br \/>\n<a href=\"http:\/\/www.sdcard.org\/downloads\/\" target=\"_blank\">http:\/\/www.sdcard.org\/downloads\/<\/a><\/p>\n<p>Openwrt Wiki on Storage<br \/>\n<a href=\"http:\/\/wiki.openwrt.org\/doc\/howto\/storage\" target=\"_blank\">http:\/\/wiki.openwrt.org\/doc\/howto\/storage<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 4 \u2013 Remote HID Attacks with a Teensy \u2013 Testing Your Build \/ Getting Started GL-iNet GPIO Setup Pins 18,19,20,21,22 are available as GPIOs for the GL-iNet. The script below will activate the GPIOs and set them to &#8220;low&#8221;. GPIO 21 is responsible for the Teensy 2.0 USB communication. GPIOs 18, 19, 20, &#038; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-868","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/pages\/868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/comments?post=868"}],"version-history":[{"count":14,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/pages\/868\/revisions"}],"predecessor-version":[{"id":928,"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/pages\/868\/revisions\/928"}],"wp:attachment":[{"href":"https:\/\/www.jedge.com\/wordpress\/wp-json\/wp\/v2\/media?parent=868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}