Thursday, January 15, 2015

Hardware Hacking!!!

This is a very special blog post as, for the first time in this class, we've done some actual hardware hacking!

First to go through the questions from the assignment:

Question 1: Currently you have the negative terminal of one battery connected to the negative rail,
and the positive terminal of the other battery connected to the positive rail. Is this a complete
circuit?

No, nothing is connecting the positive and negative rails so this is not a complete circuit.

Question 2: Why have we configured the battery in series and not in parallel?

When you put the batteries in parallel they only give 1.5V, and we need 3V to make our LEDs work, so we put them in series, causing their voltage to add together to give a total of 3V.

Question 3: You should have a complete circuit now! Congratulations. But, wait... does your LED
look like it just exploded? Why did this happen?

The two AA Batteries provide way more power than the LED wants and putting this much power through the LED will fry it pretty quickly.  In fact, if you want to see what this looks like for real my suite-mate (turns out EEs are really helpful when you're making circuits) intentionally fried an LED, which you can take a look at on his blog jerryjzy.blogspot.com.

After getting through the simple "Blinking Red Light" assignment I decided to take one of the suggested challenges and make a row of 4 LEDs that would display a binary number.  My first design was as simple as I could make it, 4 different output pins mapped to 4 different LEDs.  My code was a little more complicated, every second the Arduino incremented a counter and then passed that counter into a function called 'light(int num)' that handled lighting up the LEDs.  This function worked on the bits of the number passed in.  It checked if the smallest bit was set, and if that bit was set it turned on the first LED.  It then did a bitwise shift right on the number and checked the new smallest bit, and set the second LED based on that.  It repeated this process until it had set all four LEDs.  The code for the light() function is below.

 void light(int num) {  
   int led = 4;               // Counter to keep track of which LED we're setting  
   for(int i = 0; i < 4; i++) {  
    if(num%2 == 0) {      // If the number is divisibile by 2 the smallest bit isn't set, so turn the LED off  
     digitalWrite(led, LOW);  
    } else {               // Else the smallest bit is set, so turn the LED on  
     digitalWrite(led, HIGH);  
    }  
   led++;                    // Increment the LED counter  
   num = num >> 1;          // Bitwise shift to the right  
   }  
 }  

With that done I then decided to add a button so that instead of incrementing on a timer the counter would increment whenever the button was pressed.  Surprisingly, the push button in the simulator doesn't work as a normal push button but instead changes states from on to off whenever the button is pushed, so that after the first press the button completes the circuit and continues to do so until the button is pressed again.  To handle this I had my code remember the state of the button and recheck the state of the button every 1/10 of a second.  I chose 1/10 of a second because I don't care if the user presses the button too fast, the Arduino simply won't register those presses.  On every check it compares the saved state of the button to the new state and if there is a difference it increments the counter, calls light() and then changes the saved state of the button.


On the right of the breadboard are two projects I did to test the switch and the button, in both circuits toggling the switch/button will change the light from on to off or vice-versa.  On the left is the binary counter itself, the switch in the middle of the breadboard will increment the lights.  After building this circuit in the similar I decided to take it one step further and (once again taking advantage of my EE suite-mate) built this circuit in actual hardware.
Its Alive!
Since the push-button I had worked like a sane button, being on when depressed and off when released, I had to update my code a little bit so that it only increments the counter on change from on-state to off-state instead of on both - my first test had the lights incrementing by 2 for every button press.  Here's a quick video of the finished product.  At some point I press the button too quickly and the arduino doesn't catch it in its loop, but as I said above I don't really care if it misses a button press.

Wednesday, January 14, 2015

Dead Web Security Testing

I'd like to preface this blog post by saying that everything I'm doing is for educational purposes only and no one should ever use a tool like this for malicious purposes.

For this blog post I'm going to be focusing on website security.  There are a lot of ways websites can be insecure, and a lot of ways to test what kind of vulnerabilities different websites have.  Fortunately there are a lot of tools that exist already that bombard websites with all kinds of tests.  I'm going to be using one called Vega, which can be downloaded at https://subgraph.com/vega/download/.  This tool is very simple, simply give it a website URI and it does the rest, giving you a nice pretty printout with any security vulnerabilities it finds.

Since this is purely for educational purposes I'm going to be testing a fake website at http://testasp.vulnweb.com/search.asp. Here are the results of the Vega scan:

Vega Printout - 2 High Risk Flaws!!!
As you can see Vega is showing us 2 high risk errors, both having to do with cookies.

mmmmm cookies
Cookies, for anyone who doesn't know, are teeny tiny files that websites save on your computer so that website can look at them later and effectively use them to "remember" things.  In this case we have a cookie without the "Secure Flag" and a cookie without the "HttpOnly Flag".  Not having the "Secure Flag" means that the cookie can be sent over an insecure connection.  Basically, once you connect to a website you'll generally have an insecure connection but some websites will quickly redirect you to a secured connection.  The Secure Flag will stop the cookie from sending over the insecure connection and will make it wait for the secure connection before its sent.  Fixing this is quite simple, the developer simply has to mark the cookie as being "Secure Only".

The second vulnerability is marked "Cookie without the HttpOnly flag".  The HttpOnly flag affects who can access your cookies.  Enabling it means that only the webpage can look at your cookies, This is important as it can stop third parties from accessing you sensitive information through java script.  Again, fixing this is quite simple as its only requires a flag on the cookie to be set by the developer.

Wednesday, January 7, 2015

Laptop Charger

Assignment 1

My laptop charger is quite a big bigger than your average charger, so I'm going into this a with a little apprehension regarding how much money my laptop is consuming.  That being said, part of the beauty of a dorm room is you don't have to pay the electricity bill, so I guess I can just say this is my tuition doing work.  I've attached a picture here to give the reader an idea of what I mean when I say "bigger". (Expo marker for scale)

You could build a house out of these things

Now that we've established my charger's size its time to jump right into its specs.  On the back of the brick lives the sticker off of which I intend to get my information.
Lots and lots of logos and symbols I don't understand...
This sticker has a whole lot of logos/symbols/words I don't understand, but all I really care about is its input/output, which it lists in the top left.  It says that the charger takes an input of 100-240 Volts at 4.4 Amps and outputs 19.5 Volts at 16.9 Amps.  Using Ohms Law (V = I*R) we can calculate the resistance of the charger, our output voltage is 19.5V at 16.9A so 19.5 = 16.9 R, so R = 19.5/16.9 = 1.15Ω.

Using these numbers we can do a couple calculations which will give us the total power usage of the charger.  Since we know Power = Voltage * Amplitude we can take the output of 19.5 volts and 16.9 amps and calculate 19.5 * 16.9 = 329.55 watts.  Converting this to kilowatts gives us 0.32955 kW.  So my charger uses 0.32955 kWh.

I went to chooseenergy.com, a useful website that shows you kWh price ranges, and put in the zip code for Hopkins.  It looks like a residential building is charged around 0.09$ (or 9 cents) per kWh, so my charger uses 0.32955 kWh * 0.09$/kWh = 0.03$.  So my charger uses 3 cents per second.

Ultimately that's not as bad as I was expecting, until I take a look at my suitemate's blog and see that he's using a little bit more than half a penny per hour.

Tuesday, January 6, 2015

Hello World




Hello world! Welcome to my hardware hacking blog, where I'll be showing off all the (hopefully) awesome stuff that the teacher has us doing during this class!  Obligatory XKCD.
Color Codes