Showing posts with label Computer Programming. Show all posts
Showing posts with label Computer Programming. Show all posts

Monday, March 4, 2019

Computing - User Input, Web Applications, and Security

I found a marvelous source for creating the virtual environment I want, so I am happily configuring my virtual network environment. Or not so happily, as the case may be. Since software tends to update almost as soon as any guides are created, there's always a bit of fun to be had in figuring out how to apply the instructions to your actual system. (I got pfSense installed, and it can ping out, but I can't seem to access the website for configuring it from my laptop. Google isn't getting me the answer I want, as I keep getting hits for similar-but-not-quite-the-same problems. I wonder if the same would hold true if I created a VM on the virtual network?)

I've also been reading a rather excellent book on how hackers access information through a business's particular web site - The Web Application Hacker's Handbook, which explains so much about why/how security is so complicated these days.

The issue comes back, yet again, to user input. See, since computers use 1's and 0's for everything, the only way they know whether a sequence of 1's and 0's is supposed to be a number, or a letter, or a location, or an instruction is because of the context.

Most computer science programs will focus on teaching their students at least one programming language, in part to teach you programming logic. There are some slight differences (i.e. object-oriented programming and whatnot), but the basics are fairly similar.

It's the syntax that changes. Different languages have different ways of telling the computer when an instruction ends. And so in some languages we use a ';' to indicate the end of one line of instruction, so the computer knows when to stop. And if you go to your web browser and select 'web developer' or somesuch from the viewing options, you'll see the code for the webpage you are viewing. It will probably have something like <head> and </head> or <body> and </body> to indicate which text is part of the head, and should be formatted as indicated elsewhere for headers, and so on for the body. Note the closing '/' to indicate the end of a section.

It may seem overly technical to anyone not in computers, but bear with me.

A very common 'first program' in any language, is to print "Hello, World!" to your screen. In Java the particular line of code would be -


System.out.println("Hello, World!")


Running a program that includes that line will give you 'Hello, World!'. But let's say you want to add another line, "How are you?" You could enter


System.out.println("Hello, World! How are you?");


And the result would look something like "Hello, World! How are you?"

But what if you want it printed the second half to print on a new line (entering a carriage return, in old typing terminology.)

There's code for doing that, but the computer reads everything within the quotation marks as letters and prints accordingly. So you need an escape character, something to tell the computer "Hold up, wait. This needs to be processed differently."

In java, you can use the '/' as the escape character, so if you said


System.out.println("Hello, World!/nHow are you?");


It would print something like:

Hello World!
How are you?

Escape characters are actually kind of important, because that's how a hacker can tell the computer to process their input as commands rather than simple text.

I've only just begin to read the book on web hacking, but the first few chapters easily conveyed just how difficult it is to validate user input.

For example, a hacker might try typing <script> to do something (presumably start a script? Looks like the type of code you see in web pages, like those <header> bits, or xml code).

A business may code their application to remove all  <script> instances from user input. But what if they type in <scr<script>ipt>?

Now if you take out the <script>, it collapses the rest of the line into another <script>.

To add to the confusion, recall that every character can be represented by numbers (i.e. ASCII coding format)... so the hex number 27 can be read as an apostrophe, or 25 can be read as a %, 3c can be <, etc.

If you know what language is being used, and how the input is being read... to include the removal of certain characters... you can come up with a particular line of code that will get through all the filters and do something unintended.

Apparently, many businesses use multiple different tools to create their web applications. And if those tools use different programming languages, and react to different escape characters, then there's no one-size-fits-all way of checking user input for hacking attempts.

Tuesday, December 12, 2017

Lessons Learned

I got a 99% on one of my major semester programming projects.  I think it was the first truly complex programming assignment I've had (though that perspective might change as I get more experience) and I kind of wanted to jot down some thought on how it went.

When my previous workplace changed to our new Warehouse Management System, I experienced on a large scale something we all have as end users - attempts to fix one issue would often create another issue somewhere else.  It got to the point where every update we were left wondering what was going to go wrong this time, and how bad it would be.

For the first time, I experienced this from the other side.

We were simulating an ant colony, where each ant had specific tasks (i.e. the queen ant hatches new ants, the scout ant explores the area, the forager ant brings back food to the queen, and the soldier ant fights off enemy ants.)  I'd run it step-by-step for ten full turns, and suddenly all the ants would stop moving!
I'd figure out what was going on with that, would move on to other things, and then somehow whatever I did next would give me the exact same problem.  Again!  Though for a different reason of course...

You fix one thing, and it breaks something else.  It's very hard to capture the sheer level of frustration I felt as (yet again) my ants wouldn't act like they were supposed to!

On a related issue - I had a very hard time predicting how long it would take to finish the project.  I'd seem very, very close - ants were all acting perfectly - only to wind up right back where I started after making changes on something else.

I also learned that one of my dogs prefers to go out in freezing weather than sit in the warm, cozy living room while I  yell at my computer.

See, I have a bell hanging by the back door that they ring when they want to go outside.  I'd let out a particularly loud yell of frustration, and my dog would casually wonder over to the door and ring. 

It might be 10pm and below freezing outside, but she'll ring the bell.  And wait.  And if I don't get up to let her out, she rings it again.  And waits.   (To be fair, sometimes when I'm focused it'll take two or three rings before it registers that she's asking to go out).  I tell myself she's nuts to go out in weather like this, and she'll ring it again. 

When your dog is that persistent, then I guess she really wants to be outside.  In the cold.  (She generally gives a distinctive and repetitive yip at the door when she's ready to come back inside.)

So - right - my dog prefers freezing cold weather when I'm deeply frustrated.

Anyways, that's all done and I'm glad I got a 99%!  I missed one point on something that would have been an easy fix, and I probably should have caught it beforehand, but I'll take the 99%.  I've been a borderline A/B for this class and I really wanted to do well on this project.